Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Tasks/issue 5 #7

Merged
merged 49 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
973b626
Add initial schematron.
aj-stein-gsa Oct 23, 2020
4cba4ef
Actually add Schematron file, not just placeholder README.
aj-stein-gsa Oct 23, 2020
bdb510b
initial structure and instructions
Oct 23, 2020
ba4789e
add id's an add missing $ to variable
Oct 27, 2020
5628506
add xpec and additional sample file
Oct 27, 2020
0f5b28d
Updating submodules to use HTTP
david-waltermire Sep 25, 2020
16714a2
Setup CI workflow to not push when not in the home repo on the master…
david-waltermire Sep 25, 2020
a2b18b6
Publishing auto-converted artifacts
oscalbuilder Oct 10, 2020
a50fa0a
Fix typo reported in issue #58.
aj-stein-gsa Sep 25, 2020
7e01b81
Publishing auto-converted artifacts
oscalbuilder Oct 10, 2020
0829dec
Report on impact levels and assert if not valid.
aj-stein-gsa Oct 23, 2020
b0e7aca
Minor fix in security-sensitivity-level versus impact-level.
aj-stein-gsa Oct 23, 2020
2d68f0e
Reorganize let bindings.
aj-stein-gsa Oct 27, 2020
2a08309
Conditional pluralization.
aj-stein-gsa Oct 27, 2020
c42125b
Remove debug stmt for security-sensitivity-level values.
aj-stein-gsa Oct 27, 2020
aa2a9dc
Clean up spacing a little.
aj-stein-gsa Oct 27, 2020
951a0c3
Debug: get required controls for low.
aj-stein-gsa Oct 27, 2020
b785ad9
Clearer debugging.
aj-stein-gsa Oct 28, 2020
db85fa1
Preliminary basic checking.
aj-stein-gsa Oct 28, 2020
9a9c0f4
Merge branch 'master' into tasks/issue-5
Oct 28, 2020
cce5441
Move Schematron to correct ./src folder.
aj-stein-gsa Oct 28, 2020
b40a7fb
Remove old prototype fedramp_ssp_statistics.sch file.
aj-stein-gsa Oct 28, 2020
bfc89cf
Merge branch 'tasks/issue-2-implemented-requirements-stats' into task…
Oct 28, 2020
17e9784
Merge branch 'tasks/issue-2-implemented-requirements-stats' into task…
Oct 28, 2020
de84104
update to renamed schematron file
Oct 28, 2020
daa4c18
add test all harness as example
Oct 28, 2020
67be2a4
add instructions for new test_all.xspec
Oct 28, 2020
ad2cc0f
Add back schema.
aj-stein-gsa Oct 28, 2020
e4c4232
Merge branch 'tasks/issue-2-implemented-requirements-stats' into task…
Oct 28, 2020
1e759bb
Update relative paths for relocation.
aj-stein-gsa Oct 28, 2020
183f317
Add schematron as a submodule.
aj-stein-gsa Oct 28, 2020
d636015
Add back schema.
aj-stein-gsa Oct 28, 2020
9d7a492
Update relative paths for relocation.
aj-stein-gsa Oct 28, 2020
698eef2
Add schematron as a submodule.
aj-stein-gsa Oct 28, 2020
4786a24
Merge branch 'tasks/issue-2-implemented-requirements-stats' into task…
Oct 28, 2020
226de7c
Update .gitignore to ignore development files.
aj-stein-gsa Oct 28, 2020
65771ec
Add placeholder .gitempty files for reports folders.
aj-stein-gsa Oct 28, 2020
a91eada
Relocate Schematron and XSpec to lib sub-dir.
aj-stein-gsa Oct 28, 2020
a4c3714
Merge branch 'tasks/issue-2-implemented-requirements-stats' of github…
Oct 28, 2020
b2934aa
Relocate reports->report.
aj-stein-gsa Oct 28, 2020
f970118
Update documentation.
aj-stein-gsa Oct 28, 2020
95c2b6e
Merge branch 'tasks/issue-2-implemented-requirements-stats' of github…
Oct 28, 2020
a8df416
Update .gitignore for report path.
aj-stein-gsa Oct 28, 2020
02e0903
Fix spacing.
aj-stein-gsa Oct 28, 2020
d065a86
Update .gitignore
Oct 28, 2020
6e8a53b
add shell for compiling and running validation
Oct 28, 2020
ec80c6d
add SAXON override and instructions
Oct 28, 2020
21bde12
Merge branch 'tasks/issue-2-implemented-requirements-stats' of github…
Oct 29, 2020
aede1b0
PR review tweaks
Oct 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
documents/source
utils
utils
.history/*

resources/validations/src/ssp.xsl
resources/validations/report
resources/validations/target
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
path = oscal
url = https://github.com/usnistgov/OSCAL.git
branch = master
[submodule "resources/validations/test/xspec"]
path = resources/validations/lib/xspec
url = https://github.com/xspec/xspec.git
[submodule "resources/validations/src/schematron"]
path = resources/validations/lib/schematron
url = https://github.com/schematron/schematron.git
42 changes: 42 additions & 0 deletions resources/validations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Schematron Validations for OSCAL
===

project structure
---

`/src` for the sch files
`/lib` for toolchain dependencies (e.g. Schematron)
`/report/test` for XSpec outputs
`/report/schematron` for final validations in Schematron SVRL reporting format
`/target` for intermediary and compiled artifacts (e.g. XSLT stylesheets)
`/test` for any XSpec or other testing artifacts
`/test/demo` xml files for validating XSpec against

To validate xml files using schematron
---

example

`./validate_with_schematron.sh test/demo/FedRAMP-SSP-OSCAL-Template.xml`

you must pass in a file name you want validated as argument `$1`. by default it will compile and validate the input with all `src/*.sch` files.

if you wish to override the default version (currently 10.2) of `SAXON HE`, you may pass it as the argument `$2`



To Run Tests
---

```sh
cd /path/to/fedramp-automation/resources/validations
export SAXON_CP=yourpath/Saxon-HE-X.Y.Z.jar
export TEST_DIR=$(pwd)/report/test
lib/xspec/bin/xspec.sh -s -j test/test_all.xspec
```

Adding tests to the harness
---

To add new tests, add an import to the `test-all.xpec`
ex: `<x:import href="new_test.xspec" />`
43 changes: 43 additions & 0 deletions resources/validations/bin/validate_with_schematron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

if [ ! -e "$1" ]; then
echo "no file input for report, exiting"
exit 1
fi
DOC_TO_VALIDATE="$1"
echo "doc requested to be validated: ${DOC_TO_VALIDATE}"

# Delete pre-existing XSLT report
rm -rf target/*.xsl;
SAXON_VERSION=$2
SAXON_VERSION=${SAXON_VERSION:-10.2}

echo "using saxon version ${SAXON_VERSION}"

mvn -q org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=https://mvnrepository.com/ \
-DartifactId=Saxon-HE \
-DgroupId=net.sf.saxon \
-Dversion="${SAXON_VERSION}"

# Delete pre-existing SVRL report
rm -rf report/schematron/*.results.xml

for qualifiedSchematronName in src/*.sch; do
[ -e "${qualifiedSchematronName}" ] || continue

# compute name without .sch
schematronName=${qualifiedSchematronName##*/}
schematronRoot=${schematronName%.*}

# Use Saxon XSL transform to convert our Schematron to pure XSL 2.0 stylesheet
saxon_jar=~/.m2/repository/net/sf/saxon/Saxon-HE/"${SAXON_VERSION}"/Saxon-HE-"${SAXON_VERSION}".jar
java -cp "${saxon_jar}" net.sf.saxon.Transform -o:target/"${schematronRoot}".xsl -s:"${qualifiedSchematronName}" lib/schematron/trunk/schematron/code/iso_svrl_for_xslt2.xsl
echo "compiling: ${qualifiedSchematronName} to: target/${schematronRoot}.xsl"

# Use Saxon XSL transform to use XSL-ified Schematron rules to analyze full FedRAMP-SSP-OSCAL template
# and dump the result into reports.
reportName="report/schematron/${DOC_TO_VALIDATE}__${schematronRoot}.results.xml"
echo "validating doc: ${DOC_TO_VALIDATE} with ${qualifiedSchematronName} output found in ${reportName}"
java -cp "${saxon_jar}" net.sf.saxon.Transform -o:"${reportName}" -s:"${DOC_TO_VALIDATE}" target/"${schematronRoot}".xsl
done
1 change: 1 addition & 0 deletions resources/validations/lib/schematron
Submodule schematron added at 02f370
1 change: 1 addition & 0 deletions resources/validations/lib/xspec
Submodule xspec added at e43b3c
Empty file.
Empty file.
41 changes: 41 additions & 0 deletions resources/validations/src/ssp.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:o="http://csrc.nist.gov/ns/oscal/1.0">

<sch:ns prefix="f" uri="https://fedramp.gov/ns/oscal"/>
<sch:ns prefix="o" uri="http://csrc.nist.gov/ns/oscal/1.0"/>
<sch:ns prefix="oscal" uri="http://csrc.nist.gov/ns/oscal/1.0"/>

<sch:title>FedRAMP System Security Plan Validations</sch:title>

<sch:let name="values" value="doc(resolve-uri('../../xml/fedramp_values.xml'))"/>
<sch:let name="levels" value="$values/f:fedramp-values/f:value-set[@name='security-sensitivity-level']/f:allowed-values/f:enum/@value"/>

<sch:let name="low-p" value="doc(resolve-uri('../../../baselines/xml/FedRAMP_LOW-baseline_profile.xml'))"/>
<sch:let name="mod-p" value="doc(resolve-uri('../../../baselines/xml/FedRAMP_MODERATE-baseline_profile.xml'))"/>
<sch:let name="high-p" value="doc(resolve-uri('../../../baselines/xml/FedRAMP_HIGH-baseline_profile.xml'))"/>

<sch:pattern>
<sch:rule context="o:system-security-plan/o:system-characteristics/o:security-sensitivity-level">
<sch:assert test=". = $levels"><sch:value-of select="./name()"/> is an invalid value <sch:value-of select="."/></sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern>
<sch:rule context="o:system-security-plan">
<sch:let name="all" value="o:control-implementation/o:implemented-requirement[o:annotation[@name='implementation-status']]"/>
<sch:let name="planned" value="o:control-implementation/o:implemented-requirement[o:annotation[@name='implementation-status' and @value='planned']]"/>
<sch:let name="partial" value="o:control-implementation/o:implemented-requirement[o:annotation[@name='implementation-status' and @value='partial']]"/>
<sch:report test="true()">I see <sch:value-of select="count($partial)"/> partial<sch:value-of select="if (count($partial)=1) then ' control implementation' else ' control implementations'"/>.</sch:report>
<sch:report test="true()">I see <sch:value-of select="count($planned)"/> planned<sch:value-of select="if (count($planned)=1) then ' control implementation' else ' control implementations'"/>.</sch:report>
<sch:report test="true()">I see <sch:value-of select="count($all)"/> total<sch:value-of select="if (count($all)=1) then ' control implementation' else ' control implementations'"/>.</sch:report>
</sch:rule>
<sch:rule context="/o:system-security-plan/o:control-implementation">
<sch:let name="required" value="$low-p/o:profile/o:import/o:include/o:call"/>
<sch:let name="implemented" value="o:implemented-requirement"/>
<sch:let name="missing" value="$required[not(@control-id = $implemented/@control-id)]"/>
<sch:report test="true()">The following <sch:value-of select="count($required)"/><sch:value-of select="if (count($required)=1) then ' control' else ' controls'"/> are required: <sch:value-of select="$required/@control-id"/></sch:report>
<sch:assert test="count($missing) = 0">This SSP has not implemented <sch:value-of select="count($missing)"/><sch:value-of select="if (count($missing)=1) then ' control' else ' controls'"/>: <sch:value-of select="$missing/@control-id"/></sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
Loading