Debian Codegraph @

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

raw
1 %%
2 %% This is file `cvss.ins',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% cvss.dtx (with options: `install')
8 %% ----------------------------------------------------------------
9 %% cvss --- A package to compute and display CVSS base scores
10 %% E-mail: [email protected]
11 %% Released under the LaTeX Project Public License v1.3c or later
12 %% See http://www.latex-project.org/lppl.txt
13 %% ----------------------------------------------------------------
14 %%
15 \input docstrip.tex
16 \keepsilent
17 \askforoverwritefalse
18 \preamble
19 ----------------------------------------------------------------
20 cvss --- A package to compute and display CVSS base scores
21 E-mail: [email protected]
22 Released under the LaTeX Project Public License v1.3c or later
23 See http://www.latex-project.org/lppl.txt
24 ----------------------------------------------------------------
25
26 \endpreamble
27 \postamble
28
29 Copyright (C) 2022 by Pierre VIVEGNIS <[email protected]>
30
31 This work may be distributed and/or modified under the
32 conditions of the LaTeX Project Public License (LPPL), either
33 version 1.3c of this license or (at your option) any later
34 version. The latest version of this license is in the file:
35
36 http://www.latex-project.org/lppl.txt
37
38 This work is "maintained" (as per LPPL maintenance status) by
39 Pierre VIVEGNIS.
40
41 This work consists of the file cvss.dtx
42 and the derived files cvss.ins,
43 cvss.pdf and
44 cvss.sty.
45
46 \endpostamble
47 \usedir{tex/latex/cvss}
48 \generate{
49 \file{\jobname.sty}{\from{\jobname.dtx}{package}}
50 }
51 \endbatchfile
52 % \begin{syntax}
53 % \end{function}
54 % \begin{syntax}
55 % \cs{cvssLevel} \Arg{CVSS string}
56 % \end{syntax}
57 % \begin{syntax}
58 % \cs{cvssLevelpretty} \Arg{CVSS string}
59 % \end{syntax}
60 % \begin{syntax}
61 % \cs{cvssTag} \Arg{CVSS string}
62 % \end{syntax}
63 % \begin{syntax}
64 % \cs{category} \Arg{CVSS score}
65 % \end{syntax}
66
67
68
69
70
71
72
73 %%\category{9.9}
74 \RequirePackage{expl3}
75 \RequirePackage[skins]{tcolorbox}
76 \tcbuselibrary{xparse}
77 \RequirePackage{xstring}
78 \RequirePackage{hyperref}
79 \def\scoreLow{0.1}
80 \def\scoreMed{4.0}
81 \def\scoreHigh{7.0}
82 \def\scoreCrit{9.0}
83 \definecolor{color@cvss@None}{RGB}{83, 170, 51}
84 \definecolor{color@cvss@Low}{RGB}{255, 203, 13}
85 \definecolor{color@cvss@Medium}{RGB}{249, 160, 9}
86 \definecolor{color@cvss@High}{RGB}{223, 61, 3}
87 \definecolor{color@cvss@Critical}{RGB}{204, 5, 0}
88 \ExplSyntaxOn
89 \cs_new:Npn \__CVSS_roundup:n #1 {
90 \fp_eval:n { ceil(#1,1) }
91 \fp_compare:nT { ceil(#1,1)=ceil(#1,0) } {.0}
92 }
93 \msg_new:nnn { CVSS } { invalid-option }{ Value~'#2'~invalid~for~#1~#3.}
94 \msg_new:nnn { CVSS } { invalid-structure } { CVSS~metric~#1~is~not~correct~(#2)~#3.}
95 \msg_new:nnn { CVSS } { invalid-length } { CVSS~vector~"#1"~is~badly~formatted~#2.}
96 \msg_new:nnn { CVSS } { wrong-version } { Wrong~CVSS~version~(#2)~#3.}
97 \cs_new:Npn \__CVSS_parseAV:n #1
98 {
99 \str_case_e:nnF {#1}
100 {
101 { N } { 0.85 } % Network
102 { A } { 0.62 } % Adjacent
103 { L } { 0.55 } % Local
104 { P } { 0.2 } % Physical
105 }
106 { \msg_error:nnxxx { CVSS } { invalid-option } { parseAV } {#1} {\msg_line_context:} }
107 }
108 \cs_new:Npn \__CVSS_parseAC:n #1
109 {
110 \str_case_e:nnF {#1}
111 {
112 { H } { 0.44 } % High
113 { L } { 0.77 } % Low
114
115 }
116 { \msg_error:nnxxx { CVSS } { invalid-option } { parseAC } {#1} {\msg_line_context:} }
117 }
118 \cs_new:Npn \__CVSS_parsePRScopeUnchanged:n #1
119 {
120 \str_case_e:nnF {#1}
121 {
122 { N } { 0.85 } % None
123 { L } { 0.62 } % Low
124 { H } { 0.27 } % High
125 }
126 { \msg_error:nnxxx { CVSS } { invalid-option } { parsePRScopeUnchanged } {#1} {\msg_line_context:} }
127 }
128 \cs_new:Npn \__CVSS_parsePRScopeChanged:n #1
129 {
130 \str_case_e:nnF {#1}
131 {
132 { N } { 0.85 } % None
133 { L } { 0.68 } % Low
134 { H } { 0.50 } % High
135 }
136 { \msg_error:nnxxx { CVSS } { invalid-option } { parsePRScopeChanged } {#1} {\msg_line_context:} }
137 }
138 \cs_new:Npn \__CVSS_parsePR:nn #1#2
139 {
140 % #1 Privilege Required
141 % #2 Scope
142 \str_case_e:nnF {#2}
143 {
144 { U } { \exp_args:Ne \__CVSS_parsePRScopeUnchanged:n {#1} }
145 { C } { \exp_args:Ne \__CVSS_parsePRScopeChanged:n {#1} }
146 }
147 { \msg_error:nnxxx { CVSS } { invalid-option } { parsePR } {#1} {\msg_line_context:} }
148 }
149 \cs_new:Npn \__CVSS_parseUI:n #1
150 {
151 \str_case_e:nnF {#1}
152 {
153 { N } { 0.85 } % None
154 { R } { 0.62 } % Required
155 }
156 { \msg_error:nnxxx { CVSS } { invalid-option } { parseUI } {#1} {\msg_line_context:} }
157 }
158
159
160 \cs_new:Npn \__CVSS_parseCIA:n #1
161 {
162 \str_case_e:nnF {#1}
163 {
164 { H } { 0.56 }
165 { L } { 0.22 }
166 { N } { 0.00 }
167 }
168 { \msg_error:nnxxx { CVSS } { invalid-option } { parseCIA } {#1} {\msg_line_context:} }
169 }
170 \cs_new:Npn \__CVSS_calcISS:nnn #1#2#3
171 {
172 % #1 Confidentiality Impact %High H, Low L, None N
173 % #2 Integrity Impact %High H, Low L, None N
174 % #3 Availability Impact %High H, Low L, None N
175 1 - ( (1 - (\__CVSS_parseCIA:n {#1})) * (1 - (\__CVSS_parseCIA:n {#2})) * (1 - (\__CVSS_parseCIA:n {#3})) )
176 }
177 \cs_new:Npn \__CVSS_calcImpact:nn #1#2
178 {
179 % #1 = Scope
180 % #2 = ISS
181 % Scope Unchanged 6.42 × ISS
182 % Scope Changed 7.52 × [ISS-0.029] - 3.25 × [ISS-0.02]15
183 \str_case_e:nnF {#1}
184 {
185 { U } { \fp_eval:n { 6.42 * (#2) } } % Scope UNCHANGED
186 { C } { \fp_eval:n { 7.52 * ( (#2) - 0.029 ) - 3.25 * ( (#2) - 0.02 )^15 } } % Scope CHANGED
187 }
188 { \msg_error:nnxxx { CVSS } { invalid-option } { calcISC } {#1} {\msg_line_context:} }
189 }%
190 \cs_new:Npn \__CVSS_calcExploitability:nnnnn #1#2#3#4#5
191 {
192 % #1 Attack Vector
193 % #2 Attack Complexity
194 % #3 Privileges Required
195 % #4 User Interaction
196 % #5 Scope
197 % 8.22 × AttackVector × AttackComplexity × PrivilegeRequired × UserInteraction
198 8.22 * (\__CVSS_parseAV:n {#1}) * (\__CVSS_parseAC:n {#2}) * (\__CVSS_parsePR:nn {#3}{#5}) * (\__CVSS_parseUI:n {#4})%
199 }
200 \cs_new:Npn \__CVSS_cvssBaseScore:nnnnnnnn #1#2#3#4#5#6#7#8 {
201 % #1 Attack Vector %Network N, Adjacent A, Local L, Physical P
202 % #2 Attack Complexity %Low L, High H
203 % #3 Privileges Required %None N, Low L, High H
204 % #4 User Interaction %None N, Required R
205 % #5 Scope %Unchanged U, Changed C
206 % #6 Confidentiality Impact %High H, Low L, None N
207 % #7 Integrity Impact %High H, Low L, None N
208 % #8 Availability Impact %High H, Low L, None N
209 %
210 \fp_compare:nTF { \exp_args:Ne \__CVSS_calcImpact:nn {#5}{\exp_args:Ne \__CVSS_calcISS:nnn {#6}{#7}{#8}} <= 0 }
211 % IF ISC <=0
212 {
213 % ISC <=0
214 0.0
215 }{
216 % ISC > 0
217 \str_case_e:nnF {#5}
218 {
219 { U } { % SCOPE UNCHANGED
220 \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) } }%
221 }
222 { C } { % SCOPE CHANGED
223 \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) } }%
224 }
225 }
226 { \msg_error:nnxxx { CVSS } { invalid-option } { parseScope } {#1} {\msg_line_context:} }
227 }%
228 }
229 \NewExpandableDocumentCommand \cvssScore { m }{%
230 % Check that there are 44 chars
231 \int_compare:nNnTF { \str_count_ignore_spaces:n {#1} } = {44}{}{
232 \msg_error:nnxx{CVSS}{invalid-length}{#1}{\msg_line_context:}
233 }
234 % Check CVSS: value
235 \str_if_eq:eeTF {\str_range:nnn {#1} {1} {5}} {CVSS:}
236 {} {
237 \msg_error:nnxxx{CVSS}{invalid-structure}{AV}{\str_range:nnn {#1} {1} {5}}{\msg_line_context:}
238 }
239 % Check 3.1 value
240 \str_if_eq:eeTF {\str_range:nnn {#1} {6} {8}} {3.1}
241 {} {
242 \msg_error:nnxxx{CVSS}{wrong-version}{3.1}{\str_range:nnn {#1} {6} {8}}{\msg_line_context:}
243 }
244 % Check 3.1 value
245 \str_if_eq:eeTF {\str_range:nnn {#1} {9} {9}} {/}
246 {} {
247 \msg_error:nnxxx{CVSS}{wrong-version}{/}{\str_range:nnn {#1} {9} {9}}{\msg_line_context:}
248 }
249 % Check AV value
250 \str_if_eq:eeTF {\str_range:nnn {#1} {10} {12}} {AV:}
251 {} {
252 \msg_error:nnxxx{CVSS}{invalid-structure}{AV}{\str_range:nnn {#1} {10} {12}}{\msg_line_context:}
253 }
254 % Check AC value
255 \str_if_eq:eeTF {\str_range:nnn {#1} {14} {17}} {/AC:}
256 {} {
257 \msg_error:nnxxx{CVSS}{invalid-structure}{AC}{\str_range:nnn {#1} {14} {17}}{\msg_line_context:}
258 }
259
260 % Check PR value
261 \str_if_eq:eeTF {\str_range:nnn {#1} {19} {22}} {/PR:}
262 {} {
263 \msg_error:nnxxx{CVSS}{invalid-structure}{PR}{\str_range:nnn {#1} {19} {22}}{\msg_line_context:}
264 }
265
266 % Check UI value
267 \str_if_eq:eeTF {\str_range:nnn {#1} {24} {27}} {/UI:}
268 {} {
269 \msg_error:nnxxx{CVSS}{invalid-structure}{UI}{\str_range:nnn {#1} {24} {27}}{\msg_line_context:}
270 }
271
272 % Check S value
273 \str_if_eq:eeTF {\str_range:nnn {#1} {29} {31}} {/S:}
274 {} {
275 \msg_error:nnxxx{CVSS}{invalid-structure}{S}{\str_range:nnn {#1} {29} {31}}{\msg_line_context:}
276 }
277
278 % Check I value
279 \str_if_eq:eeTF {\str_range:nnn {#1} {33} {35}} {/C:}
280 {} {
281 \msg_error:nnxxx{CVSS}{invalid-structure}{C}{\str_range:nnn {#1} {33} {35}}{\msg_line_context:}
282 }
283
284 % Check I value
285 \str_if_eq:eeTF {\str_range:nnn {#1} {37} {39}} {/I:}
286 {} {
287 \msg_error:nnxxx{CVSS}{invalid-structure}{I}{\str_range:nnn {#1} {37} {39}}{\msg_line_context:}
288 }
289
290 % Check A value
291 \str_if_eq:eeTF {\str_range:nnn {#1} {41} {43}} {/A:}
292 {} {
293 \msg_error:nnxxx{CVSS}{invalid-structure}{A}{\str_range:nnn {#1} {41} {43}}{\msg_line_context:}
294 }
295
296 \exp_args:Ne \__CVSS_cvssBaseScore:nnnnnnnn
297 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 13 } }
298 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 18 } }
299 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 23 } }
300 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 28 } }
301 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 32 } }
302 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 36 } }
303 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 40 } }
304 { \str_use:N \str_item_ignore_spaces:nn { #1 }{ 44 } }
305 }%
306 \ExplSyntaxOff
307 \ExplSyntaxOn
308 \NewExpandableDocumentCommand \category { m }{%
309 \fp_compare:nNnTF {#1}<{\scoreLow}{None}
310 {
311 \fp_compare:nNnTF{#1}<{\scoreMed}{Low}
312 {
313 \fp_compare:nNnTF{#1}<{\scoreHigh}{Medium}
314 {
315 \fp_compare:nNnTF{#1}<{\scoreCrit}{High}
316 {Critical}
317 }%
318 }%
319 }%
320 }%
321 \ExplSyntaxOff
322 \newcommand{\cvssScorepretty}[1]{%
323 \def\CVSScategory{\category{\cvssScore{#1}}}%
324 \textcolor{color@cvss@\CVSScategory}{\cvssScore{#1}}%
325 }%
326 \newcommand{\cvssLevel}[1]{%
327 \def\CVSSscore{\cvssScore{#1}}%
328 \category{\CVSSscore}%
329 }%
330 \newcommand{\cvssLevelpretty}[1]{%
331 \def\CVSScategory{\category{\cvssScore{#1}}}%
332 \textcolor{color@cvss@\CVSScategory}{\CVSScategory}%
333 }%
334 \DeclareTotalTCBox{\cvssFrame}{m}{
335 enhanced,nobeforeafter,
336 tcbox raise base,
337 boxrule=0.4pt,
338 top=0mm,bottom=0mm,right=1mm,left=1mm,
339 arc=1pt,
340 boxsep=2pt,
341 colframe=color@cvss@#1,
342 colback=tcbcolframe,
343 coltext=black,
344 }{#1}%
345
346 \MakeRobust\cvssFrame
347 \newcommand{\cvssTag}[1]{%
348 \def\CVSSscore{\cvssScore{#1}}%
349 \cvssFrame{\category{\CVSSscore}}%
350 }%
351 \newcommand{\cvssPrint}[1]{%
352 \def\CVSSscore{\cvssScore{#1}}
353 \cvssFrame{\category{\CVSSscore}} \quad \CVSSscore \quad%
354 \href{https://www.first.org/cvss/calculator/3.1\##1}{#1}
355 }%
356
357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358 %%
359 %% Copyright (C) 2022 by Pierre VIVEGNIS <[email protected]>
360 %%
361 %% This work may be distributed and/or modified under the
362 %% conditions of the LaTeX Project Public License (LPPL), either
363 %% version 1.3c of this license or (at your option) any later
364 %% version. The latest version of this license is in the file:
365 %%
366 %% http://www.latex-project.org/lppl.txt
367 %%
368 %% This work is "maintained" (as per LPPL maintenance status) by
369 %% Pierre VIVEGNIS.
370 %%
371 %% This work consists of the file cvss.dtx
372 %% and the derived files cvss.ins,
373 %% cvss.pdf and
374 %% cvss.sty.
375 %%
376 %%
377 %% End of file `cvss.ins'.