Debian Codegraph @

xsl/xccdf-share.xsl

raw symbols SCIP
1 <?xml version="1.0" encoding="utf-8" ?>
2
3 <!--
4 Copyright 2010 - 2014 Red Hat Inc., Durham, North Carolina.
5 All Rights Reserved.
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 Authors:
22 Martin Preisler <[email protected]>
23 Lukas Kuklinek <[email protected]>
24 -->
25
26 <xsl:stylesheet version="1.1"
27 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
28 xmlns:cdf="http://checklists.nist.gov/xccdf/1.2"
29 exclude-result-prefixes="xsl cdf">
30
31 <xsl:param name="verbosity"/>
32
33 <xsl:key name="values" match="//cdf:Value" use="concat(ancestor::cdf:Benchmark/@id, '|', @id)"/>
34 <xsl:key name="reference_names" match="//cdf:Benchmark/cdf:reference" use="@href"/>
35
36 <xsl:template name="rule-result-tooltip">
37 <xsl:param name="ruleresult"/>
38 <!-- The texts are sourced from XCCDF 1.2 specification with minor modifications -->
39 <xsl:choose>
40 <xsl:when test="$ruleresult = 'pass'">The target system or system component satisfied all the conditions of the rule.</xsl:when>
41 <xsl:when test="$ruleresult = 'fixed'">The Rule had failed, but was then fixed (possibly by a tool that can automatically apply remediation, or possibly by the human auditor).</xsl:when>
42 <xsl:when test="$ruleresult = 'informational'">The Rule was checked, but the output from the checking engine is simply information for auditors or administrators; it is not a compliance category. This status value is designed for Rule elements whose main purpose is to extract information from the target rather than test the target.</xsl:when>
43
44 <xsl:when test="$ruleresult = 'fail'">The target system or system component did not satisfy at least one condition of the rule.</xsl:when>
45 <xsl:when test="$ruleresult = 'error'">The checking engine could not complete the evaluation, therefore the status of the target's compliance with the rule is not certain. This could happen, for example, if a testing tool was run with insufficient privileges and could not gather all of the necessary information.</xsl:when>
46 <xsl:when test="$ruleresult = 'unknown'">The testing tool encountered some problem and the result is unknown. For example, a result of 'unknown' might be given if the testing tool was unable to interpret the output of the checking engine (the output has no meaning to the testing tool).</xsl:when>
47
48 <xsl:when test="$ruleresult = 'notchecked'">The Rule was not evaluated by the checking engine. This status is designed for Rule elements that have no check elements or that correspond to an unsupported checking system. It may also correspond to a status returned by a checking engine if the checking engine does not support the indicated check code.</xsl:when>
49 <xsl:when test="$ruleresult = 'notselected'">The Rule was not selected in the evaluation. This may be caused by the rule not being selected by default in the benchmark or by the profile unselecting it.</xsl:when>
50 <xsl:when test="$ruleresult = 'notapplicable'">The Rule was not applicable to the target of the test. For example, the Rule might have been specific to a different version of the target OS, or it might have been a test against a platform feature that was not installed.</xsl:when>
51 </xsl:choose>
52 </xsl:template>
53
54 <xsl:template match="cdf:ident" mode="ident">
55 <xsl:choose>
56 <xsl:when test="starts-with(@system, 'http://cve.mitre.org')">
57 <a href="{concat('https://cve.mitre.org/cgi-bin/cvename.cgi?name=', text())}"><abbr title="{concat(@system, concat(': ', text()))}"><xsl:value-of select="text()"/></abbr></a>
58 </xsl:when>
59 <xsl:when test="starts-with(@system, 'https://access.redhat.com/errata')">
60 <a href="{concat('https://access.redhat.com/errata/', concat(text(), '.html'))}"><abbr title="{concat(@system, concat(': ', text()))}"><xsl:value-of select="text()"/></abbr></a>
61 </xsl:when>
62 <xsl:otherwise>
63 <abbr title="{concat(@system, concat(': ', text()))}"><xsl:value-of select="text()"/></abbr>
64 </xsl:otherwise>
65 </xsl:choose>
66 </xsl:template>
67
68 <xsl:template name="item-title">
69 <xsl:param name="item"/>
70 <xsl:param name="profile"/>
71
72 <xsl:choose>
73 <xsl:when test="$item/cdf:title">
74 <xsl:apply-templates mode="sub-testresult" select="$item/cdf:title">
75 <xsl:with-param name="benchmark" select="$item/ancestor::cdf:Benchmark"/>
76 <xsl:with-param name="profile" select="$profile"/>
77 </xsl:apply-templates>
78 </xsl:when>
79 <xsl:otherwise>
80 ID: <xsl:value-of select="$item/@id"/>
81 </xsl:otherwise>
82 </xsl:choose>
83
84 </xsl:template>
85
86 <xsl:template name="item-idents-refs">
87 <xsl:param name="item"/>
88 <xsl:if test="$item/cdf:ident">
89 <tr>
90 <td>
91 <span class="label label-info" title="A globally meaningful identifiers for this rule. MAY be the name or identifier of a security configuration issue or vulnerability that the rule remediates. By setting an identifier on a rule, the benchmark author effectively declares that the rule instantiates, implements, or remediates the issue for which the name was assigned.">Identifiers:</span>
92 </td>
93 <td class="identifiers">
94 <xsl:call-template name="item-idents">
95 <xsl:with-param name="item" select="$item"/>
96 </xsl:call-template>
97 </td>
98 </tr>
99 </xsl:if>
100 <xsl:if test="$item/cdf:reference">
101 <tr>
102 <td>
103 <span class="label label-default" title="Provide a reference to a document or resource where the user can learn more about the subject of the Rule or Group.">References:</span>
104 </td>
105 <td class="identifiers">
106 <xsl:call-template name="item-refs">
107 <xsl:with-param name="item" select="$item"/>
108 </xsl:call-template>
109 </td>
110 </tr>
111 </xsl:if>
112 </xsl:template>
113
114 <xsl:template name="item-idents">
115 <xsl:param name="item"/>
116 <p>
117 <xsl:for-each select="$item/cdf:ident">
118 <xsl:apply-templates mode="ident" select="."/>
119 <xsl:if test="position() != last()">, </xsl:if>
120 </xsl:for-each>
121 </p>
122 </xsl:template>
123
124 <xsl:template name="item-refs">
125 <xsl:param name="item"/>
126 <table class="table table-striped table-bordered">
127 <xsl:for-each select="$item/cdf:reference">
128 <xsl:variable name="href" select="@href"/>
129 <xsl:if test="not(preceding-sibling::cdf:reference[@href=$href])">
130 <tr>
131 <td>
132 <a href="{@href}">
133 <xsl:choose>
134 <xsl:when test="key('reference_names', $href)">
135 <xsl:value-of select="key('reference_names', $href)"/>
136 </xsl:when>
137 <xsl:otherwise>
138 <xsl:value-of select="@href"/>
139 </xsl:otherwise>
140 </xsl:choose>
141 </a>
142 </td>
143 <td>
144 <xsl:for-each select="$item/cdf:reference[@href=$href]">
145 <xsl:value-of select="text()"/>
146 <xsl:if test="position() != last()">, </xsl:if>
147 </xsl:for-each>
148 </td>
149 </tr>
150 </xsl:if>
151 </xsl:for-each>
152 </table>
153 </xsl:template>
154
155 <!-- works for both XCCDF Rule elements and rule-result elements -->
156 <xsl:template name="item-severity">
157 <xsl:param name="item"/>
158 <xsl:param name="profile"/>
159 <xsl:variable name="refine-rule" select="$profile/cdf:refine-rule[@idref=$item/@id]" />
160 <xsl:choose>
161 <xsl:when test="$refine-rule/@severity">
162 <xsl:value-of select="$refine-rule/@severity"/>
163 </xsl:when>
164 <xsl:otherwise>
165 <xsl:choose>
166 <xsl:when test="$item/@severity">
167 <xsl:value-of select="$item/@severity"/>
168 </xsl:when>
169 <xsl:otherwise>unknown</xsl:otherwise>
170 </xsl:choose>
171 </xsl:otherwise>
172 </xsl:choose>
173 </xsl:template>
174
175 <!-- substitution for testresults, used in HTML report -->
176 <xsl:template mode="sub-testresult" match="text()">
177 <xsl:param name="testresult"/>
178 <xsl:param name="benchmark"/>
179 <xsl:param name="profile"/>
180
181 <xsl:value-of select="."/>
182 </xsl:template>
183
184 <xsl:template mode="sub-testresult" match="cdf:fix//cdf:instance">
185 <xsl:param name="testresult"/>
186 <xsl:param name="benchmark"/>
187 <xsl:param name="profile"/>
188
189 <xsl:variable name='ctx' select='@context'/>
190
191 <xsl:choose>
192 <xsl:when test="$testresult/cdf:rule-result/cdf:instance[@context=$ctx]">
193 <abbr title="context: {$ctx}"><xsl:value-of select="$testresult/cdf:rule-result/cdf:instance[@context=$ctx]"/></abbr>
194 </xsl:when>
195 <xsl:otherwise>
196 <abbr class="cdf-sub-context" title="replace with actual {$ctx} context"><xsl:value-of select="$ctx"/></abbr>
197 </xsl:otherwise>
198 </xsl:choose>
199 </xsl:template>
200
201 <xsl:template mode="sub-testresult" match="cdf:sub">
202 <xsl:param name="testresult"/>
203 <xsl:param name="benchmark"/>
204 <xsl:param name="profile"/>
205
206 <xsl:variable name="subid" select="./@idref"/>
207
208 <xsl:choose>
209 <xsl:when test="$testresult and $testresult/cdf:set-value[@idref = $subid]">
210 <abbr title="from TestResult: {$subid}"><xsl:value-of select="$testresult/cdf:set-value[@idref = $subid][last()]"/></abbr>
211 </xsl:when>
212 <xsl:when test="$profile and $profile/cdf:set-value[@idref = $subid]">
213 <abbr title="from Profile/set-value: {$subid}"><xsl:value-of select="$profile/cdf:set-value[@idref = $subid][last()]/text()"/></abbr>
214 </xsl:when>
215 <xsl:otherwise>
216 <!-- We have to look up the cdf:Value in benchmark and that's a
217 performance hit. Let's treat it as a special case and do
218 do the lookup once -->
219 <xsl:variable name="value" select="key('values', concat($benchmark/@id, '|', $subid))"/>
220
221 <xsl:choose>
222 <xsl:when test="$profile and $profile/cdf:refine-value[@idref = $subid]">
223 <xsl:variable name="selector" select="$profile/cdf:refine-value[@idref = $subid][last()]/@selector"/>
224 <abbr title="from Profile/refine-value: {$subid}"><xsl:value-of select="$value/cdf:value[@selector = $selector][last()]/text()"/></abbr>
225 </xsl:when>
226 <xsl:otherwise>
227 <xsl:variable name="value_lastselector" select="$value/cdf:value[not(@selector)][last()]"/>
228 <xsl:choose>
229 <xsl:when test="$value_lastselector and $value[@prohibitChanges='true']">
230 <xsl:value-of select="$value_lastselector"/>
231 </xsl:when>
232 <xsl:when test="$value_lastselector">
233 <abbr title="from Benchmark/Value: {$subid}"><xsl:value-of select="$value_lastselector"/></abbr>
234 </xsl:when>
235 <xsl:otherwise>
236 <abbr title="Substitution failed: {$subid}">(N/A)</abbr>
237 </xsl:otherwise>
238 </xsl:choose>
239 </xsl:otherwise>
240 </xsl:choose>
241 </xsl:otherwise>
242 </xsl:choose>
243 </xsl:template>
244
245 <xsl:template mode="sub-testresult" match="*[namespace-uri()='http://www.w3.org/1999/xhtml']">
246 <xsl:param name="testresult"/>
247 <xsl:param name="benchmark"/>
248 <xsl:param name="profile"/>
249
250 <xsl:choose>
251 <xsl:when test="local-name() = 'br'">
252 <!-- <br></br> shows up as 2 <br> elements in HTML5, this horrible hack prevents that -->
253 <xsl:text disable-output-escaping="yes">&#60;br&#62;</xsl:text>
254 </xsl:when>
255 <xsl:otherwise>
256 <xsl:element name="{local-name()}">
257 <xsl:copy-of select="@*"/>
258 <xsl:apply-templates select="./text() | ./*" mode="sub-testresult">
259 <xsl:with-param name="testresult" select="$testresult"/>
260 <xsl:with-param name="benchmark" select="$benchmark"/>
261 <xsl:with-param name="profile" select="$profile"/>
262 </xsl:apply-templates>
263 </xsl:element>
264 </xsl:otherwise>
265 </xsl:choose>
266 </xsl:template>
267
268 <xsl:template mode="sub-testresult" match="node() | @*">
269 <xsl:param name="testresult"/>
270 <xsl:param name="benchmark"/>
271 <xsl:param name="profile"/>
272
273 <xsl:copy>
274 <xsl:copy-of select="@*"/>
275
276 <xsl:apply-templates select="node()" mode="sub-testresult">
277 <xsl:with-param name="testresult" select="$testresult"/>
278 <xsl:with-param name="benchmark" select="$benchmark"/>
279 <xsl:with-param name="profile" select="$profile"/>
280 </xsl:apply-templates>
281 </xsl:copy>
282 </xsl:template>
283
284 <xsl:template mode="sub-testresult" match="cdf:title | cdf:description | cdf:fix | cdf:fixtext | cdf:front-matter | cdf:rear-matter | cdf:rationale | cdf:warning | cdf:notice">
285 <xsl:param name="testresult"/>
286 <xsl:param name="benchmark"/>
287 <xsl:param name="profile"/>
288
289 <xsl:apply-templates select="node()" mode="sub-testresult">
290 <xsl:with-param name="testresult" select="$testresult"/>
291 <xsl:with-param name="benchmark" select="$benchmark"/>
292 <xsl:with-param name="profile" select="$profile"/>
293 </xsl:apply-templates>
294 </xsl:template>
295
296 <xsl:template name="show-fixtext">
297 <xsl:param name="fixtext"/>
298 <xsl:param name="testresult"/>
299 <xsl:param name="benchmark"/>
300 <xsl:param name="profile"/>
301
302 <span class="label label-success">Remediation description:</span>
303 <div class="panel panel-default"><div class="panel-body">
304 <xsl:apply-templates mode="sub-testresult" select="$fixtext">
305 <xsl:with-param name="testresult" select="$testresult"/>
306 <xsl:with-param name="benchmark" select="$benchmark"/>
307 <xsl:with-param name="profile" select="$profile"/>
308 </xsl:apply-templates>
309 </div></div>
310 </xsl:template>
311
312 <xsl:template name="show-fix">
313 <xsl:param name="fix"/>
314 <xsl:param name="testresult"/>
315 <xsl:param name="benchmark"/>
316 <xsl:param name="profile"/>
317
318 <xsl:variable name="fix_type">
319 <xsl:choose>
320 <xsl:when test="$fix/@system = 'urn:xccdf:fix:script:sh'">Shell script</xsl:when>
321 <xsl:when test="$fix/@system = 'urn:xccdf:fix:script:ansible'">Ansible snippet</xsl:when>
322 <xsl:when test="$fix/@system = 'urn:xccdf:fix:script:puppet'">Puppet snippet</xsl:when>
323 <xsl:when test="$fix/@system = 'urn:redhat:anaconda:pre'">Anaconda snippet</xsl:when>
324 <xsl:when test="$fix/@system = 'urn:xccdf:fix:script:kubernetes'">Kubernetes snippet</xsl:when>
325 <xsl:when test="$fix/@system = 'urn:redhat:osbuild:blueprint'">OSBuild Blueprint snippet</xsl:when>
326 <xsl:otherwise>script</xsl:otherwise>
327 </xsl:choose>
328 </xsl:variable>
329
330 <a class="btn btn-success" data-toggle="collapse" data-target="#{generate-id($fix)}" tabindex="0" role="button" aria-expanded="false" title="Activate to reveal" href="#!">Remediation <xsl:value-of select="$fix_type"/> &#8690;</a><br />
331 <div class="panel-collapse collapse" id="{generate-id($fix)}">
332 <xsl:if test="$fix/@complexity or $fix/@disruption or $fix/@reboot or $fix/@strategy">
333 <table class="table table-striped table-bordered table-condensed">
334 <xsl:if test="$fix/@complexity">
335 <tr>
336 <th>Complexity:</th>
337 <td><xsl:value-of select="$fix/@complexity" /></td>
338 </tr>
339 </xsl:if>
340 <xsl:if test="$fix/@disruption">
341 <tr>
342 <th>Disruption:</th>
343 <td><xsl:value-of select="$fix/@disruption" /></td>
344 </tr>
345 </xsl:if>
346 <xsl:if test="$fix/@reboot">
347 <tr>
348 <th>Reboot:</th>
349 <td><xsl:value-of select="$fix/@reboot" /></td>
350 </tr>
351 </xsl:if>
352 <xsl:if test="$fix/@strategy">
353 <tr>
354 <th>Strategy:</th>
355 <td><xsl:value-of select="$fix/@strategy" /></td>
356 </tr>
357 </xsl:if>
358 </table>
359 </xsl:if>
360 <pre><code>
361 <xsl:apply-templates mode="sub-testresult" select="$fix">
362 <xsl:with-param name="testresult" select="$testresult"/>
363 <xsl:with-param name="benchmark" select="$benchmark"/>
364 <xsl:with-param name="profile" select="$profile"/>
365 </xsl:apply-templates>
366 </code></pre>
367 </div>
368 </xsl:template>
369
370 <xsl:template name="show-title-front-matter-description-notices">
371 <!-- TODO: please invent a better name for this template -->
372
373 <xsl:param name="benchmark"/>
374 <xsl:param name="profile"/>
375
376 <h2>
377 <xsl:choose>
378 <xsl:when test="$benchmark/cdf:title">
379 <xsl:apply-templates mode="sub-testresult" select="$benchmark/cdf:title[1]">
380 <xsl:with-param name="benchmark" select="$benchmark"/>
381 <xsl:with-param name="profile" select="$profile"/>
382 </xsl:apply-templates>
383 </xsl:when>
384 <xsl:otherwise>
385 <xsl:value-of select="$benchmark/@id"/>
386 </xsl:otherwise>
387 </xsl:choose>
388 </h2>
389 <xsl:if test="$profile">
390 <blockquote>with profile <mark>
391 <xsl:choose>
392 <xsl:when test="$profile/cdf:title/text()">
393 <xsl:apply-templates mode="sub-testresult" select="$profile/cdf:title[1]">
394 <xsl:with-param name="benchmark" select="$benchmark"/>
395 <xsl:with-param name="profile" select="$profile"/>
396 </xsl:apply-templates>
397 </xsl:when>
398 <xsl:otherwise>
399 <xsl:value-of select="$profile/@id"/>
400 </xsl:otherwise>
401 </xsl:choose></mark>
402 <xsl:if test="$profile/cdf:description/text()">
403 <div class="col-md-12 well well-lg horizontal-scroll">
404 <div class="description profile-description"><small>
405 <xsl:apply-templates mode="sub-testresult" select="$profile/cdf:description[1]">
406 <xsl:with-param name="benchmark" select="$benchmark"/>
407 <xsl:with-param name="profile" select="$profile"/>
408 </xsl:apply-templates></small>
409 </div>
410 </div>
411 </xsl:if>
412 </blockquote>
413 </xsl:if>
414
415 <div class="col-md-12 well well-lg horizontal-scroll">
416 <xsl:if test="$benchmark/cdf:front-matter">
417 <div class="front-matter">
418 <xsl:apply-templates mode="sub-testresult" select="$benchmark/cdf:front-matter[1]">
419 <xsl:with-param name="benchmark" select="$benchmark"/>
420 <xsl:with-param name="profile" select="$profile"/>
421 </xsl:apply-templates>
422 </div>
423 </xsl:if>
424 <xsl:if test="$benchmark/cdf:description/text()">
425 <div class="description">
426 <xsl:apply-templates mode="sub-testresult" select="$benchmark/cdf:description[1]">
427 <xsl:with-param name="benchmark" select="$benchmark"/>
428 <xsl:with-param name="profile" select="$profile"/>
429 </xsl:apply-templates>
430 </div>
431 </xsl:if>
432 <xsl:if test="$benchmark/cdf:notice/text()">
433 <div class="top-spacer-10">
434 <xsl:for-each select="$benchmark/cdf:notice">
435 <div class="alert alert-info">
436 <xsl:apply-templates mode="sub-testresult" select=".">
437 <xsl:with-param name="benchmark" select="$benchmark"/>
438 <xsl:with-param name="profile" select="$profile"/>
439 </xsl:apply-templates>
440 </div>
441 </xsl:for-each>
442 </div>
443 </xsl:if>
444 </div>
445 </xsl:template>
446
447 <xsl:template name="rear-matter">
448 <xsl:param name="benchmark"/>
449 <xsl:param name="profile"/>
450
451 <div id="rear-matter">
452 <div class="row top-spacer-10">
453 <div class="col-md-12 well well-lg">
454 <xsl:if test="$benchmark/cdf:rear-matter">
455 <div class="rear-matter">
456 <xsl:apply-templates mode="sub-testresult" select="$benchmark/cdf:rear-matter[1]">
457 <xsl:with-param name="benchmark" select="$benchmark"/>
458 <xsl:with-param name="profile" select="$profile"/>
459 </xsl:apply-templates>
460 </div>
461 </xsl:if>
462 </div>
463 </div>
464 </div>
465 </xsl:template>
466
467 <xsl:template name="warn-unresolved">
468 <xsl:param name="benchmark"/>
469
470 <xsl:if test="$benchmark[not(@resolved=1)][not(@resolved='true')]">
471 <xsl:message>WARNING: Processing an unresolved XCCDF document. This may have unexpected results.</xsl:message>
472 <xsl:message>You can resolve the document using "oscap xccdf resolve -o resolved-xccdf.xml xccdf.xml"</xsl:message>
473 </xsl:if>
474 </xsl:template>
475
476 </xsl:stylesheet>