Debian Codegraph @

texmf-dist/source/latex/cvss/cvss.dtx

raw
1 % \iffalse meta-comment
2 %<*internal>
3 \iffalse
4 %</internal>
5 %<*readme>
6 ----------------------------------------------------------------
7 cvss --- A Package to compute and display CVSS base scores
8 E-mail: [email protected]
9 Released under the LaTeX Project Public License v1.3c or later
10 See http://www.latex-project.org/lppl.txt
11 ----------------------------------------------------------------
12
13 The LaTeX package allows a user to compute the CVSS base score for
14 an input CVSS vector, as well as other artifacts (CVSS level etc)
15 %</readme>
16 %<*internal>
17 \fi
18 \def\nameofplainTeX{plain}
19 \ifx\fmtname\nameofplainTeX\else
20 \expandafter\begingroup
21 \fi
22 %</internal>
23 %<*install>
24 \input docstrip.tex
25 \keepsilent
26 \askforoverwritefalse
27 \preamble
28 ----------------------------------------------------------------
29 cvss --- A package to compute and display CVSS base scores
30 E-mail: [email protected]
31 Released under the LaTeX Project Public License v1.3c or later
32 See http://www.latex-project.org/lppl.txt
33 ----------------------------------------------------------------
34
35 \endpreamble
36 \postamble
37
38 Copyright (C) 2022 by Pierre VIVEGNIS <[email protected]>
39
40 This work may be distributed and/or modified under the
41 conditions of the LaTeX Project Public License (LPPL), either
42 version 1.3c of this license or (at your option) any later
43 version. The latest version of this license is in the file:
44
45 http://www.latex-project.org/lppl.txt
46
47 This work is "maintained" (as per LPPL maintenance status) by
48 Pierre VIVEGNIS.
49
50 This work consists of the file cvss.dtx
51 and the derived files cvss.ins,
52 cvss.pdf and
53 cvss.sty.
54
55 \endpostamble
56 \usedir{tex/latex/cvss}
57 \generate{
58 \file{\jobname.sty}{\from{\jobname.dtx}{package}}
59 }
60 %</install>
61 %<install>\endbatchfile
62 %<*internal>
63 \usedir{source/latex/cvss}
64 \generate{
65 \file{\jobname.ins}{\from{\jobname.dtx}{install}}
66 }
67 \nopreamble\nopostamble
68 \usedir{doc/latex/cvss}
69 \generate{
70 \file{README.txt}{\from{\jobname.dtx}{readme}}
71 }
72 \ifx\fmtname\nameofplainTeX
73 \expandafter\endbatchfile
74 \else
75 \expandafter\endgroup
76 \fi
77 %</internal>
78 %<*package>
79 \NeedsTeXFormat{LaTeX2e}
80 \ProvidesPackage{cvss}[2022/12/02 v1.1.0 ]
81 %</package>
82 %<*driver>
83 \documentclass{l3doc}
84 \usepackage{\jobname}
85 \EnableCrossrefs
86 \CodelineIndex
87 \RecordChanges
88 \setlength{\parindent}{0pt}
89 \begin{document}
90 \DocInput{\jobname.dtx}
91 \newpage
92 \PrintChanges
93 \PrintIndex
94 \end{document}
95 %</driver>
96 % \fi
97 %
98 % \begin{documentation}
99 %
100 %\GetFileInfo{\jobname.sty}
101 %
102 %\title{
103 % The \textsf{cvss} package\thanks{
104 % This file describes version \fileversion, last revised \filedate.
105 % }
106 %}
107 %\author{
108 % Pierre VIVEGNIS\thanks{E-mail: [email protected]}
109 %}
110 %\date{Released \filedate}
111 %
112 %\maketitle
113 % \tableofcontents
114 %
115 % \newpage
116 % \section{Introduction}
117 %
118 % The \textsf{cvss} package allows the user to compute CVSS 3.1 base scores and use them in documents. The Common Vulnerability Scoring System (CVSS) is an open framework for communicating the characteristics and severity of software vulnerabilities. CVSS consists of three metric groups: Base, Temporal, and Environmental.
119 %
120 % This packages only deal with Base score. Temporal and Environental scores will be part of a future release.
121 %
122 % More information can be found at \texttt{https://www.first.org/cvss/specification-document}.
123 %
124 % \section{Acknowledgements}
125 %
126 % I want to thank Alexander Lill who first created a cvss project in \LaTeX (available at \texttt{https://github.com/AlexanderLill/cvss3tex}).
127 %
128 % \section{Usage}
129 %
130 % The goal of this package is to compute the CVSS base score for an input CVSS vector, and to give the user macro to output it in 3 different forms
131 % \begin{itemize}
132 % \item The CVSS \textbf{score} (fron 0.0 to 10)
133 % \item the \textbf{level} (None, Info, Low, Medium, High or Critical)
134 % \item the \textbf{colored level}
135 % \item the \textbf{tag} which is a colored frame around the level
136 % \end{itemize}
137 %
138 % All macros are expandable, which makes them usable in any context.
139 %
140 % The macros of this packages are divided in 2 categories:
141 % \begin{itemize}
142 % \item \textbf{direct macros} : that will take as input the CVSS base score and give you the result
143 % \item \textbf{indirect macros} : that are intermediary, in the way that they only compute a form based on the precedent one.
144 % \end{itemize}
145 %
146 % \subsection{Direct Macros}
147 % \begin{function}{\cvssScore}
148 % \changes{v1.0.0}{2022/10/22}{Full CVSS vector as input is now supported}
149 % \changes{v1.1.0}{2022/12/02}{Full CVSS vector as input is now supported}
150 % \begin{syntax}
151 % \cs{cvssScore} \Arg{CVSS string}
152 % \end{syntax}
153 % This is the main macro of this package, responsible for computing the base CVSS 3.1 score of an \marg{input vector} (without \texttt{CVSS3.1/}). The output of this macro is a floating point CVSS score, for example \texttt{5.4}.
154 % \end{function}
155 %
156 %
157 %
158 % \begin{verbatim}
159 % \cvssScore{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}
160 % \end{verbatim}
161 %
162 % This will output the following CVSS base score: \texttt{\cvssScore{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}}
163 %
164 %
165 % \begin{function}{\cvssScorepretty}
166 % \begin{syntax}
167 % \cs{cvssScorepretty} \Arg{CVSS string}
168 % \end{syntax}
169 % This macro will print a \textbf{colored} base CVSS 3.1 score of an \marg{input vector} (without \texttt{CVSS3.1/}). The output of this macro is a floating point CVSS score.
170 % \end{function}
171 %
172 % \begin{verbatim}
173 % \cvssScorepretty{CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:L/A:N}
174 % \end{verbatim}
175 %
176 % This will output the following CVSS score: \cvssScorepretty{CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:L/A:N}
177 %
178 %
179 % \begin{function}{\cvssLevel}
180 % \begin{syntax}
181 % \cs{cvssLevel} \Arg{CVSS string}
182 % \end{syntax}
183 % This macro will output the CVSS level from an \marg{input vector} (without \texttt{CVSS3.1/}), for example \texttt{Info}.
184 % \end{function}
185 %
186 % \begin{verbatim}
187 % \cvssLevel{CVSS:3.1/AV:A/AC:H/PR:H/UI:R/S:U/C:H/I:L/A:N}
188 % \end{verbatim}
189 %
190 % This will output the following CVSS level: \cvssLevel{CVSS:3.1/AV:A/AC:H/PR:H/UI:R/S:U/C:H/I:L/A:N}
191 %
192 %
193 % \begin{function}{\cvssLevelpretty}
194 % \begin{syntax}
195 % \cs{cvssLevelpretty} \Arg{CVSS string}
196 % \end{syntax}
197 % This macro will output the \textbf{colored} CVSS level from an \marg{input vector} (without \texttt{CVSS3.1/}).
198 % \end{function}
199 %
200 % \begin{verbatim}
201 % \cvssLevelpretty{CVSS:3.1/AV:A/AC:H/PR:H/UI:R/S:U/C:L/I:L/A:N}
202 % \end{verbatim}
203 %
204 % This will output the following CVSS level: \cvssLevelpretty{CVSS:3.1/AV:A/AC:H/PR:H/UI:R/S:U/C:L/I:L/A:N}
205 %
206 %
207 % \begin{function}{\cvssTag}
208 % \begin{syntax}
209 % \cs{cvssTag} \Arg{CVSS string}
210 % \end{syntax}
211 % This macro will output a colored tag with the CVSS level inside, from an \marg{input vector} (without \texttt{CVSS3.1/}).
212 % \end{function}
213 %
214 % \begin{verbatim}
215 % \cvssTag{CVSS:3.1/AV:A/AC:H/PR:H/UI:R/S:U/C:N/I:N/A:N}
216 % \end{verbatim}
217 %
218 % This will output the following CVSS level: \cvssTag{CVSS:3.1/AV:A/AC:H/PR:H/UI:R/S:U/C:N/I:N/A:N}.
219 %
220 %
221 % \begin{function}{\cvssPrint}
222 % \begin{syntax}
223 % \cs{cvssPrint} \Arg{CVSS string}
224 % \end{syntax}
225 % This macro will print all details of a CVSS string: colored level, score, and hyperlink to FIRST calculator, from an \marg{input vector} (without \texttt{CVSS3.1/}).
226 % \end{function}
227 %
228 % \begin{verbatim}
229 % \cvssPrint{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H}
230 % \end{verbatim}
231 %
232 % This will output the following CVSS level:
233 %
234 % \cvssPrint{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H}
235 %
236 %
237 %
238 % \subsection{Indirect Macros}
239 %
240 % \changes{v1.0.0}{2022/11/03}{First public release}
241 %
242 % \begin{function}{\category}
243 % \begin{syntax}
244 % \cs{category} \Arg{CVSS score}
245 % \end{syntax}
246 % This macro will output the CVSS category (None, Info, Low, Medium, High or Critical) based on the input CVSS vector passed as argument \marg{numerical score}. The mandatory argument is a floating point CVSS score, for example \texttt{5.4}.
247 % \end{function}
248 %
249 % \begin{verbatim}
250 % \category{9.9}
251 % \end{verbatim}
252 %
253 % This will output the following scope: \category{9.9}.
254 %
255 %
256 % \begin{function}{\cvssFrame}
257 % \begin{syntax}
258 % \cs{cvssFrame} \Arg{CVSS score}
259 % \end{syntax}
260 % This macro will output a CVSS tag based on a CVSS \textbf{level} passed as argument. The mandatory argument must be one of the defined CVSS levels (None, Info, Low, Medium, High or Critical), for example \texttt{Info}.
261 % \end{function}
262 %
263 % \begin{verbatim}
264 % \cvssFrame{High}
265 % \end{verbatim}
266 %
267 % This will output the following tag: \cvssFrame{High}.
268 %
269 %
270
271 % \section{Examples}
272 %
273 % \subsection{Direct Form}
274
275 %\begin{minipage}{.85\textwidth}
276 % \begin{verbatim}
277 %\\cvssScore{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}
278 % \end{verbatim}
279 %\end{minipage}%
280 %\begin{minipage}{0.15\textwidth}
281 %\cvssScore{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}
282 %\end{minipage}
283
284 %\begin{minipage}{.85\textwidth}
285 % \begin{verbatim}
286 %\\cvssLevel{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}
287 % \end{verbatim}
288 %\end{minipage}%
289 %\begin{minipage}{0.15\textwidth}
290 %\cvssLevel{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}
291 %\end{minipage}
292
293
294 %\begin{minipage}{.85\textwidth}
295 % \begin{verbatim}
296 %\\cvssLevelpretty{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H}
297 % \end{verbatim}
298 %\end{minipage}%
299 %\begin{minipage}{0.15\textwidth}
300 %\cvssLevelpretty{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H}
301 %\end{minipage}
302
303 %\begin{minipage}{.85\textwidth}
304 % \begin{verbatim}
305 %\\cvssTag{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H}
306 % \end{verbatim}
307 %\end{minipage}%
308 %\begin{minipage}{0.15\textwidth}
309 %\cvssTag{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H}
310 %\end{minipage}%
311 %\newline
312 %
313 % We can thus embed this in text lines like this:
314 % \begin{verbatim}
315 %\\textbf{\cvssLevel{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}}-level
316 % \end{verbatim}
317 %
318 % Which will be rendered like this : \textit{the vuln has a \textbf{\cvssLevel{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}}-level and we can output it inline.}
319 %\subsection{Imbricated Form}
320
321 %\begin{minipage}{.5\textwidth}
322 % \begin{verbatim}
323 %\\cvssFrame{Low}
324 % \end{verbatim}
325 %\end{minipage}%
326 %\begin{minipage}{0.5\textwidth}
327 %\cvssFrame{Low}
328 %\end{minipage}
329
330 %\begin{minipage}{.5\textwidth}
331 % \begin{verbatim}
332 %%\category{9.9}
333 % \end{verbatim}
334 %\end{minipage}%
335 %\begin{minipage}{0.5\textwidth}
336 %\category{9.9}
337 %\end{minipage}
338 %\newline
339 %
340 % We can even combine them:
341 % \begin{verbatim}
342 %\\category{\cvssScore{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}}
343 % \end{verbatim}
344 %
345 %And this outputs: \category{\cvssScore{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}}
346 %
347 % \begin{verbatim}
348 %\\cvssFrame{\category{\cvssScore{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}}}
349 % \end{verbatim}
350 % And the result is: %\cvssFrame{\category{\cvssScore{CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N}}}
351 %
352 %\subsection{Test Computations}
353 % \begin{verbatim}
354 % Should be 7.3: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L}
355 %
356 % Should be 8.3: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:L/A:L}
357 %
358 % Should be 9.9: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:L/A:H}
359 %
360 % Should be 9.9: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:H/A:L}
361 %
362 % Should be 7.2: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:L/A:N}
363 %
364 % Should be 7.1: \cvssScore{CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:C/C:L/I:L/A:L}
365 %
366 % Should be 5.8: \cvssScore{CVSS:3.1/AV:A/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:L}
367 %
368 % Should be 5.5: \cvssScore{CVSS:3.1/AV:A/AC:H/PR:L/UI:N/S:C/C:L/I:L/A:L}
369 %
370 % Should be 5.1: \cvssScore{CVSS:3.1/AV:A/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L}
371 %
372 % Should be 4.3: \cvssScore{CVSS:3.1/AV:A/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:L}
373 %
374 % Should be 2.4: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:U/C:L/I:N/A:N}
375 %
376 % Should be 0.0: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:N/A:N}
377 % \end{verbatim}
378 %
379 % And the results of the computations:
380 %
381 %Should be 7.3: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L}
382 %
383 %Should be 8.3: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:L/A:L}%
384 %
385 %Should be 9.9: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:L/A:H}%
386 %
387 %Should be 9.9: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:H/A:L}%
388 %
389 %Should be 7.2: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:L/A:N}%
390 %
391 %Should be 7.1: \cvssScore{CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:C/C:L/I:L/A:L}%
392 %
393 %Should be 5.8: \cvssScore{CVSS:3.1/AV:A/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:L}%
394 %
395 %Should be 5.5: \cvssScore{CVSS:3.1/AV:A/AC:H/PR:L/UI:N/S:C/C:L/I:L/A:L}%
396 %
397 %Should be 5.1: \cvssScore{CVSS:3.1/AV:A/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L}%
398 %
399 %Should be 4.3: \cvssScore{CVSS:3.1/AV:A/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:L}%
400 %
401 %Should be 2.4: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:U/C:L/I:N/A:N}
402 %
403 %Should be 0.0: \cvssScore{CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:N/A:N}
404 %
405 % \end{documentation}
406 %\newpage
407 % \begin{implementation}
408 % \section{Implementation}
409 % \subsection{Initial set up}
410 %
411 % Load the essential support (\pkg{expl3}, \pkg{tcolorbox}, \pkg{xstring} and \pkg{hyperref}).
412 % \begin{macrocode}
413 \RequirePackage{expl3}
414 \RequirePackage[skins]{tcolorbox}
415 \tcbuselibrary{xparse}
416 \RequirePackage{xstring}
417 \RequirePackage{hyperref}
418 % \end{macrocode}
419 %
420 % Then, we define the thresholds:
421 % \begin{macrocode}
422 % These are the thresholds
423 \def\scoreLow{0.1}
424 \def\scoreMed{4.0}
425 \def\scoreHigh{7.0}
426 \def\scoreCrit{9.0}
427 % \end{macrocode}
428 % And finally the colors for each level (taken from the FIRST CVSS calulator website\footnote{Available at \url{https://www.first.org/cvss/calculator/3.1}})
429 % \begin{macrocode}
430 \definecolor{color@cvss@None}{RGB}{83, 170, 51}
431 \definecolor{color@cvss@Low}{RGB}{255, 203, 13}
432 \definecolor{color@cvss@Medium}{RGB}{249, 160, 9}
433 \definecolor{color@cvss@High}{RGB}{223, 61, 3}
434 \definecolor{color@cvss@Critical}{RGB}{204, 5, 0}
435 % \end{macrocode}
436 %
437 % \subsection{Round up function}
438 %
439 % First we defined the \texttt{roundup} function\footnote{This function was inspired by the following posts: \url{https://tex.stackexchange.com/a/615358/28926}} according to the precision mentionned by FIRST (\url{https://www.first.org/cvss/specification-document Appendix A}).
440 % .
441 % \begin{macrocode}
442 \ExplSyntaxOn
443 %
444 \cs_new:Npn \__CVSS_roundup:n #1 {
445 \fp_eval:n { ceil(#1,1) }
446 \fp_compare:nT { ceil(#1,1)=ceil(#1,0) } {.0}
447 }
448 % \end{macrocode}
449 %
450 % \subsection{Error messages}
451 % We define some error message to help with the troubleshooting
452 %
453 % \begin{macrocode}
454 \msg_new:nnn { CVSS } { invalid-option }{ Value~'#2'~invalid~for~#1~#3.}
455 \msg_new:nnn { CVSS } { invalid-structure } { CVSS~metric~#1~is~not~correct~(#2)~#3.}
456 \msg_new:nnn { CVSS } { invalid-length } { CVSS~vector~"#1"~is~badly~formatted~#2.}
457 \msg_new:nnn { CVSS } { wrong-version } { Wrong~CVSS~version~(#2)~#3.}
458 % \end{macrocode}%
459 %
460 %
461 % \subsection{CVSS metrics parsing}
462 %
463 % Then we can define the numerical values for each of the CVSS metric (Attack Vector, Attack Complexity, ...).
464 % This is done by checking the string value of the argument, and outputting the correpsondant value.
465 % For each function, a error message is thrown if the value is not one acceptable for that metric.
466 %
467 % \subsubsection{Attack Vector}
468 % The value for the Attack Vector can only by either \texttt{N} (None), \texttt{A} (Adjacent), \texttt{L} (Local) or \texttt{P} (Physical).
469 %
470 %\begin{macro}{\__CVSS_parseAV}
471 % \begin{macrocode}
472 \cs_new:Npn \__CVSS_parseAV:n #1
473 {
474 \str_case_e:nnF {#1}
475 {
476 { N } { 0.85 } % Network
477 { A } { 0.62 } % Adjacent
478 { L } { 0.55 } % Local
479 { P } { 0.2 } % Physical
480 }
481 { \msg_error:nnxxx { CVSS } { invalid-option } { parseAV } {#1} {\msg_line_context:} }
482 }
483 % \end{macrocode}%
484 %\end{macro}
485 %
486 % \subsubsection{Attack Complexity}
487 % The value for the Attack Complexity metric can only by either \texttt{L} (Low) or \texttt{H} (High).
488 %
489 %\begin{macro}{\__CVSS_parseAC}
490 % \begin{macrocode}
491 \cs_new:Npn \__CVSS_parseAC:n #1
492 {
493 \str_case_e:nnF {#1}
494 {
495 { H } { 0.44 } % High
496 { L } { 0.77 } % Low
497
498 }
499 { \msg_error:nnxxx { CVSS } { invalid-option } { parseAC } {#1} {\msg_line_context:} }
500 }
501 % \end{macrocode}
502 %\end{macro}
503 %
504 % \subsubsection{Privileges Required}
505 % The value for the Privilged Required metric can only by either \texttt{N} (None), \texttt{L} (Low) or \texttt{H} (High).
506 % Hoever since the computation is different wheter the Scope is changed or not, we've defined 2 functions.
507 %
508 % 3 Internal macros are thus used, one per choice (Scope unchanged and Scope change), plus the function to choose which one to take into account.
509 %
510 %\begin{macro}{\__CVSS_parsePRScopeUnchanged}
511 % \begin{macrocode}
512 \cs_new:Npn \__CVSS_parsePRScopeUnchanged:n #1
513 {
514 \str_case_e:nnF {#1}
515 {
516 { N } { 0.85 } % None
517 { L } { 0.62 } % Low
518 { H } { 0.27 } % High
519 }
520 { \msg_error:nnxxx { CVSS } { invalid-option } { parsePRScopeUnchanged } {#1} {\msg_line_context:} }
521 }
522 % \end{macrocode}%
523 %\end{macro}
524 %\begin{macro}{\__CVSS_parsePRScopeChanged}
525 % \begin{macrocode}
526 \cs_new:Npn \__CVSS_parsePRScopeChanged:n #1
527 {
528 \str_case_e:nnF {#1}
529 {
530 { N } { 0.85 } % None
531 { L } { 0.68 } % Low
532 { H } { 0.50 } % High
533 }
534 { \msg_error:nnxxx { CVSS } { invalid-option } { parsePRScopeChanged } {#1} {\msg_line_context:} }
535 }
536 % \end{macrocode}%
537 %\end{macro}
538 %\begin{macro}{\__CVSS_parsePR}
539 % \begin{macrocode}
540 \cs_new:Npn \__CVSS_parsePR:nn #1#2
541 {
542 % #1 Privilege Required
543 % #2 Scope
544 \str_case_e:nnF {#2}
545 {
546 { U } { \exp_args:Ne \__CVSS_parsePRScopeUnchanged:n {#1} }
547 { C } { \exp_args:Ne \__CVSS_parsePRScopeChanged:n {#1} }
548 }
549 { \msg_error:nnxxx { CVSS } { invalid-option } { parsePR } {#1} {\msg_line_context:} }
550 }
551 % \end{macrocode}%
552 %\end{macro}
553 %
554 % \subsubsection{User Interaction}
555 % The value for the User Interaction metric can only by either \texttt{N} (None) or \texttt{R} (Required).
556 %
557 %\begin{macro}{\__CVSS_parseUI}
558 % \begin{macrocode}
559 \cs_new:Npn \__CVSS_parseUI:n #1
560 {
561 \str_case_e:nnF {#1}
562 {
563 { N } { 0.85 } % None
564 { R } { 0.62 } % Required
565 }
566 { \msg_error:nnxxx { CVSS } { invalid-option } { parseUI } {#1} {\msg_line_context:} }
567 }
568
569 % \end{macrocode}
570 %\end{macro}
571 %
572 % \subsubsection{Confidentiality, Integrity and Availability}
573 % The value for the Confidentiality, Integrity or Availability metrics can only by either \texttt{N} (None), \texttt{L} (Low) or \texttt{H} (High).
574 % Since the values are the same for the 3 metrics, we've grouped them together.
575 %
576 %\begin{macro}{\__CVSS_parseCIA}
577 % \begin{macrocode}
578
579 \cs_new:Npn \__CVSS_parseCIA:n #1
580 {
581 \str_case_e:nnF {#1}
582 {
583 { H } { 0.56 }
584 { L } { 0.22 }
585 { N } { 0.00 }
586 }
587 { \msg_error:nnxxx { CVSS } { invalid-option } { parseCIA } {#1} {\msg_line_context:} }
588 }
589 % \end{macrocode}
590 %\end{macro}
591 %
592 % \subsection{CVSS computation}
593 % \subsubsection{Impact Sub Score (ISS)}
594 % The value for the Impact Sub-Score (ISS) is conmputed from the Confidentiality, Availability and Integrity values, as follows
595 %\begin{equation}
596 % ISS = 1 - \Bigr[ (1 - \text{Confidentiality}) \times (1 - \text{Integrity}) \times (1 - \text{Availability}) \Bigr]
597 %\end{equation}
598 %
599 % This equation is then translated into \TeX code :
600 %
601 %\begin{macro}{\__CVSS_calcISS}
602 % \begin{macrocode}
603 \cs_new:Npn \__CVSS_calcISS:nnn #1#2#3
604 {
605 % #1 Confidentiality Impact %High H, Low L, None N
606 % #2 Integrity Impact %High H, Low L, None N
607 % #3 Availability Impact %High H, Low L, None N
608 1 - ( (1 - (\__CVSS_parseCIA:n {#1})) * (1 - (\__CVSS_parseCIA:n {#2})) * (1 - (\__CVSS_parseCIA:n {#3})) )
609 }
610 % \end{macrocode}
611 %\end{macro}
612 %
613 % \subsubsection{Impact}
614 % The calculations for the impact depends whether the scope is changed or not, and will be computed differently:
615 % \begin{equation}
616 % \text{Impact} \rightarrow
617 % \begin{cases}
618 % \text{Scope Unchanged} & 6.42 \times ISS\\
619 % \text{Scope Changed} & 7.52 \times (ISS - 0.029) - 3.25 \times (ISS - 0.02)^{15}\\
620 % \end{cases}
621 % \end{equation}
622 %
623 % This gives the following implementation:
624 %
625 %\begin{macro}{\__CVSS_calcImpact}
626 % \begin{macrocode}
627 \cs_new:Npn \__CVSS_calcImpact:nn #1#2
628 {
629 % #1 = Scope
630 % #2 = ISS
631 % Scope Unchanged 6.42 × ISS
632 % Scope Changed 7.52 × [ISS-0.029] - 3.25 × [ISS-0.02]15
633 \str_case_e:nnF {#1}
634 {
635 { U } { \fp_eval:n { 6.42 * (#2) } } % Scope UNCHANGED
636 { C } { \fp_eval:n { 7.52 * ( (#2) - 0.029 ) - 3.25 * ( (#2) - 0.02 )^15 } } % Scope CHANGED
637 }
638 { \msg_error:nnxxx { CVSS } { invalid-option } { calcISC } {#1} {\msg_line_context:} }
639 }%
640 % \end{macrocode}
641 %\end{macro}
642 %
643 % \subsubsection{Exploitability}
644 % The equation to compute the exploitability is the following:
645 % \begin{equation}
646 % 8.22 \times \text{AttackVector} \times \text{AttackComplexity} \times \text{PrivilegesRequired} \times \text{UserInteraction}
647 % \end{equation}
648 %
649 % This gives the following implementation:
650 %
651 %\begin{macro}{\__CVSS_calcExploitability}
652 % \begin{macrocode}
653 \cs_new:Npn \__CVSS_calcExploitability:nnnnn #1#2#3#4#5
654 {
655 % #1 Attack Vector
656 % #2 Attack Complexity
657 % #3 Privileges Required
658 % #4 User Interaction
659 % #5 Scope
660 % 8.22 × AttackVector × AttackComplexity × PrivilegeRequired × UserInteraction
661 8.22 * (\__CVSS_parseAV:n {#1}) * (\__CVSS_parseAC:n {#2}) * (\__CVSS_parsePR:nn {#3}{#5}) * (\__CVSS_parseUI:n {#4})%
662 }
663 % \end{macrocode}
664 %\end{macro}
665 %
666 % \subsubsection{CVSS Base Score}
667 % Now that all the pre-requisites are calculated, we can compute the CVSS base score as follows:
668 % \begin{equation}
669 % \text{Base Score} =
670 % \begin{cases}
671 % 0 & \text{if Impact $\geq 0$ } \\
672 % Roundup \Bigr( min \bigr[(\text{Impact} + \text{Exploitability}), 10\bigr]\Bigr) & \text{if Scope is Unchanged} \\
673 % Roundup \Bigr(min \bigr[1.08 \times (\text{Impact} + \text{Exploitability}), 10\bigr]\Bigr) & \text{if Scope is changed}
674 % \end{cases}
675 %\end{equation}
676 %
677 % This gives the following implementation:
678 %
679 %\begin{macro}{\__CVSS_cvssBaseScore}
680 % \begin{macrocode}
681 \cs_new:Npn \__CVSS_cvssBaseScore:nnnnnnnn #1#2#3#4#5#6#7#8 {
682 % #1 Attack Vector %Network N, Adjacent A, Local L, Physical P
683 % #2 Attack Complexity %Low L, High H
684 % #3 Privileges Required %None N, Low L, High H
685 % #4 User Interaction %None N, Required R
686 % #5 Scope %Unchanged U, Changed C
687 % #6 Confidentiality Impact %High H, Low L, None N
688 % #7 Integrity Impact %High H, Low L, None N
689 % #8 Availability Impact %High H, Low L, None N
690 %
691 \fp_compare:nTF { \exp_args:Ne \__CVSS_calcImpact:nn {#5}{\exp_args:Ne \__CVSS_calcISS:nnn {#6}{#7}{#8}} <= 0 }
692 % IF ISC <=0
693 {
694 % ISC <=0
695 0.0
696 }{
697 % ISC > 0
698 \str_case_e:nnF {#5}
699 {
700 { U } { % SCOPE UNCHANGED
701 \fp_eval:n { \__CVSS_roundup:n { min( ((\__CVSS_calcImpact:nn {#5}{\__CVSS_calcISS:nnn {#6}{#7}{#8}}) + (\__CVSS_calcExploitability:nnnnn {#1}{#2}{#3}{#4}{#5})), 10) } }%
702 }
703 { C } { % SCOPE CHANGED
704 \fp_eval:n { \__CVSS_roundup:n { min( (1.08 * ((\__CVSS_calcImpact:nn {#5}{\__CVSS_calcISS:nnn {#6}{#7}{#8}}) + (\__CVSS_calcExploitability:nnnnn {#1}{#2}{#3}{#4}{#5}))), 10) } }%
705 }
706 }
707 { \msg_error:nnxxx { CVSS } { invalid-option } { parseScope } {#1} {\msg_line_context:} }
708 }%
709 }
710 % \end{macrocode}
711 %\end{macro}
712 %
713 % \subsubsection{CVSS Base Score}
714 % Now we can use a macro to check the validity of the CVSS string and \textbf{finally} call \texttt{\textbackslash{}__CVSS_cvssBaseScore} internally.
715 % This is the most important macro of this whole package, and is expandable.
716 %
717 %\begin{macro}{\cvssScore}
718 % \begin{macrocode}
719 \NewExpandableDocumentCommand \cvssScore { m }{%
720 % Check that there are 44 chars
721 \int_compare:nNnTF { \str_count_ignore_spaces:n {#1} } = {44}{}{
722 \msg_error:nnxx{CVSS}{invalid-length}{#1}{\msg_line_context:}
723 }
724 % Check CVSS: value
725 \str_if_eq:eeTF {\str_range:nnn {#1} {1} {5}} {CVSS:}
726 {} {
727 \msg_error:nnxxx{CVSS}{invalid-structure}{AV}{\str_range:nnn {#1} {1} {5}}{\msg_line_context:}
728 }
729 % Check 3.1 value
730 \str_if_eq:eeTF {\str_range:nnn {#1} {6} {8}} {3.1}
731 {} {
732 \msg_error:nnxxx{CVSS}{wrong-version}{3.1}{\str_range:nnn {#1} {6} {8}}{\msg_line_context:}
733 }
734 % Check 3.1 value
735 \str_if_eq:eeTF {\str_range:nnn {#1} {9} {9}} {/}
736 {} {
737 \msg_error:nnxxx{CVSS}{wrong-version}{/}{\str_range:nnn {#1} {9} {9}}{\msg_line_context:}
738 }
739 % Check AV value
740 \str_if_eq:eeTF {\str_range:nnn {#1} {10} {12}} {AV:}
741 {} {
742 \msg_error:nnxxx{CVSS}{invalid-structure}{AV}{\str_range:nnn {#1} {10} {12}}{\msg_line_context:}
743 }
744 % Check AC value
745 \str_if_eq:eeTF {\str_range:nnn {#1} {14} {17}} {/AC:}
746 {} {
747 \msg_error:nnxxx{CVSS}{invalid-structure}{AC}{\str_range:nnn {#1} {14} {17}}{\msg_line_context:}
748 }
749
750
751 % Check PR value
752 \str_if_eq:eeTF {\str_range:nnn {#1} {19} {22}} {/PR:}
753 {} {
754 \msg_error:nnxxx{CVSS}{invalid-structure}{PR}{\str_range:nnn {#1} {19} {22}}{\msg_line_context:}
755 }
756
757 % Check UI value
758 \str_if_eq:eeTF {\str_range:nnn {#1} {24} {27}} {/UI:}
759 {} {
760 \msg_error:nnxxx{CVSS}{invalid-structure}{UI}{\str_range:nnn {#1} {24} {27}}{\msg_line_context:}
761 }
762
763 % Check S value
764 \str_if_eq:eeTF {\str_range:nnn {#1} {29} {31}} {/S:}
765 {} {
766 \msg_error:nnxxx{CVSS}{invalid-structure}{S}{\str_range:nnn {#1} {29} {31}}{\msg_line_context:}
767 }
768
769 % Check I value
770 \str_if_eq:eeTF {\str_range:nnn {#1} {33} {35}} {/C:}
771 {} {
772 \msg_error:nnxxx{CVSS}{invalid-structure}{C}{\str_range:nnn {#1} {33} {35}}{\msg_line_context:}
773 }
774
775 % Check I value
776 \str_if_eq:eeTF {\str_range:nnn {#1} {37} {39}} {/I:}
777 {} {
778 \msg_error:nnxxx{CVSS}{invalid-structure}{I}{\str_range:nnn {#1} {37} {39}}{\msg_line_context:}
779 }
780
781 % Check A value
782 \str_if_eq:eeTF {\str_range:nnn {#1} {41} {43}} {/A:}
783 {} {
784 \msg_error:nnxxx{CVSS}{invalid-structure}{A}{\str_range:nnn {#1} {41} {43}}{\msg_line_context:}
785 }
786
787 \exp_args:Ne \__CVSS_cvssBaseScore:nnnnnnnn
788 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 13 } }
789 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 18 } }
790 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 23 } }
791 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 28 } }
792 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 32 } }
793 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 36 } }
794 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 40 } }
795 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 44 } }
796 }%
797 \ExplSyntaxOff
798 % \end{macrocode}
799 %\end{macro}
800 %
801 % \subsection{CVSS levels}
802 % Since we can compute the numerical score of a given CVSS string, we can now get the classification of a CVSS vector using the
803 % FIRST terminology :
804 %\begin{table}[!ht]
805 % \centering
806 % \begin{tabular}{cc}
807 % \hline
808 % \textbf{Rating} & \textbf{CVSS Score} \\ \hline
809 % None & $0.0$ \\
810 % Low & $0.1 - 3.9$ \\
811 % Medium & $4.0 - 6.9$ \\
812 % High & $7.0 - 8.9$ \\
813 % Critical & $9.0 - 10.0$ \\ \hline
814 % \end{tabular}
815 %\end{table}
816 %
817 % Then we can build our switch case to assign a level to the numerical CVSS score
818 %\begin{macro}{\category}
819 % This macro will output a CVSS level based on the numerical CVSS score.
820 % \begin{macrocode}
821 \ExplSyntaxOn
822 \NewExpandableDocumentCommand \category { m }{%
823 \fp_compare:nNnTF {#1}<{\scoreLow}{None}
824 {
825 \fp_compare:nNnTF{#1}<{\scoreMed}{Low}
826 {
827 \fp_compare:nNnTF{#1}<{\scoreHigh}{Medium}
828 {
829 \fp_compare:nNnTF{#1}<{\scoreCrit}{High}
830 {Critical}
831 }%
832 }%
833 }%
834 }%
835 \ExplSyntaxOff
836 % \end{macrocode}
837 % We can even have a colored version of the score.
838 %\begin{macro}{\cvssScorepretty}
839 % This macro will output the \textbf{colored} CVSS level based on the CVSS vector.
840 % \begin{macrocode}
841 \newcommand{\cvssScorepretty}[1]{%
842 \def\CVSScategory{\category{\cvssScore{#1}}}%
843 \textcolor{color@cvss@\CVSScategory}{\cvssScore{#1}}%
844 }%
845 % \end{macrocode}
846 %\end{macro}
847 %\end{macro}
848 % We have also built a macro that will output the CVSS level based on the CVSS string, that combines \texttt{\textbackslash{}cvssScore} and \texttt{\textbackslash{}category}:
849 %\begin{macro}{\cvssLevel}
850 % This macro will output a CVSS level based on the numerical CVSS score.
851 % \begin{macrocode}
852 \newcommand{\cvssLevel}[1]{%
853 \def\CVSSscore{\cvssScore{#1}}%
854 \category{\CVSSscore}%
855 }%
856 % \end{macrocode}
857 %\end{macro}
858 % And we can even have a colored version of this level.
859 %\begin{macro}{\cvssLevelpretty}
860 % This macro will output the \textbf{colored} CVSS level based on the numerical CVSS score.
861 % \begin{macrocode}
862 \newcommand{\cvssLevelpretty}[1]{%
863 \def\CVSScategory{\category{\cvssScore{#1}}}%
864 \textcolor{color@cvss@\CVSScategory}{\CVSScategory}%
865 }%
866 % \end{macrocode}
867 %\end{macro}
868 % \subsection{Fancy prints}
869 % \subsubsection{Framed CVSS Level}
870 % For nice display of the CVSS score we created also tags, that can be used to highlight the CVSS score.
871 %\begin{macro}{\cvssFrame}
872 % First, we define \texttt{cvssFrame}, a type of \texttt{tcolorbox} we are going to use:
873 % \begin{macrocode}
874 \DeclareTotalTCBox{\cvssFrame}{m}{
875 enhanced,nobeforeafter,
876 tcbox raise base,
877 boxrule=0.4pt,
878 top=0mm,bottom=0mm,right=1mm,left=1mm,
879 arc=1pt,
880 boxsep=2pt,
881 colframe=color@cvss@#1,
882 colback=tcbcolframe,
883 coltext=black,
884 }{#1}%
885
886 \MakeRobust\cvssFrame
887 % \end{macrocode}
888 %\end{macro}
889 %
890 % Then we can call this box in conjunction with \texttt{cvssScore}.
891 %\begin{macro}{\cvssTag}
892 % This macro will output the \textbf{colored} CVSS level based on the numerical CVSS score.
893 % \begin{macrocode}
894 \newcommand{\cvssTag}[1]{%
895 \def\CVSSscore{\cvssScore{#1}}%
896 \cvssFrame{\category{\CVSSscore}}%
897 }%
898 % \end{macrocode}
899 %\end{macro}
900 %
901 % \subsubsection{Full CVSS display}
902 % We can even have a nice all-in display of the category, the scrore and a hyperlink to the FIRST calculator using a combination of all the functions we've defined:
903 %\begin{macro}{\cvssPrint}
904 % {v1.1}{2022/11/30}{Full CVSS vector as input is now supported}
905 % This macro will output the \textbf{colored} CVSS level based on the numerical CVSS score.
906 % \begin{macrocode}
907 \newcommand{\cvssPrint}[1]{%
908 \def\CVSSscore{\cvssScore{#1}}
909 \cvssFrame{\category{\CVSSscore}} \quad \CVSSscore \quad%
910 \href{https://www.first.org/cvss/calculator/3.1\##1}{#1}
911 }%
912 % \end{macrocode}
913 %\end{macro}
914
915 % \end{implementation}
916 % \Finale
917 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
918 \endinput
919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%