interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / om / tls / test / rev / run.sh

186 lines · 9661 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Test suite for om/tls/rev.om. Usage: sh om/tls/test/rev/run.sh OMC
4# Builds om2 + sha2 hkdf ec rsa x509 rev + driver.om into build/tls/rev/, runs vectors/cases.txt
5# (generated by gen_rev.py with python cryptography; real/ holds a real Let's Encrypt CRL and its
6# issuer), cross-checks every OCSP response and CRL verdict class with openssl where it can, and runs
7# the source mutants. Exit 0 only when everything passes; final line "REV PASS cases=N mutants=M/M".
8set -eu
9omc=${1:?usage: run.sh OMC}
10here=$(cd "$(dirname "$0")" && pwd)
11tls=$(cd "$here/../.." && pwd)
12root=$(cd "$tls/../.." && pwd)
13pin=$(sed -n 's/^OMC_PIN=//p' "$root/om/units.sh")
14out="$root/build/tls/rev"
15vec="$here/vectors"
16mkdir -p "$out"
17bad=0
18say() { printf '%s\n' "$*"; }
19fail() { say "FAIL $*"; bad=1; }
20run() { nice -n 19 ionice -c3 "$@"; }
21
22[ "$(sha256sum < "$omc" | cut -c1-64)" = "$pin" ] || { say "FAIL omc is not the pinned compiler"; exit 1; }
23
24# build LIB DRIVER BIN [X509] (X509: the x509.om text to compose, default om/tls/x509.om)
25build() {
26 { echo om2; cat "$tls/sha2.om" "$tls/hkdf.om" "$tls/ec.om" "$tls/rsa.om" "${4:-$tls/x509.om}" "$1" "$2"; } > "$3.om"
27 if ! run "$omc" < "$3.om" > "$3" 2> "$3.err" || [ -s "$3.err" ]; then
28 say "omc refused $3.om: $(cat "$3.err")"
29 return 1
30 fi
31 chmod +x "$3"
32}
33
34build "$tls/rev.om" "$here/driver.om" "$out/driver" || { say "REV FAIL build"; exit 1; }
35say "omc sha256 $pin"
36say "library sha256 $(sha256sum < "$tls/rev.om" | cut -c1-64) ($(grep -c '^fn ' "$tls/rev.om") functions)"
37say "driver sha256 $(sha256sum < "$out/driver" | cut -c1-64)"
38# cases.txt (gen_rev.py) and the weak revocation signers (gen_revweak.py)
39cat "$vec/cases.txt" "$vec/revweak/cases.txt" > "$out/cases.txt"
40ncase=$(grep -c '^[OUIHAE] ' "$out/cases.txt")
41
42# drive FILE BIN NAME -> sets rc, last
43drive() {
44 set +e
45 (cd "$vec" && run "$2" < "$1") > "$out/$3.out" 2>&1
46 rc=$?
47 set -e
48 last=$(tail -n 1 "$out/$3.out")
49}
50
51drive "$out/cases.txt" "$out/driver" main
52checks=$(printf '%s\n' "$last" | awk '$1 == "rev" && $2 == "driver:" && $4 == "checks," && $5 == "0" && $6 == "failed" { print $3 }')
53if [ "$rc" -eq 0 ] && [ -n "$checks" ]; then
54 say "PASS cases.txt: $last"
55 grep '^fuzz ' "$out/main.out" | sed 's/^/PASS /'
56else
57 fail "cases.txt: exit $rc: $(grep -E 'MISMATCH|driver' "$out/main.out" | head -n 20 | tr '\n' ' ')"
58fi
59
60# oracle: openssl agrees with the generated OCSP status classes (good / revoked / unknown) and with
61# the CRL signature verdicts, so the expectations are not only gen_rev.py's word
62oracle=0
63oraclen=0
64if command -v openssl > /dev/null 2>&1; then
65 pem() { openssl x509 -inform DER -in "$vec/$1" -out "$out/$2.pem"; }
66 pem pki/iss.der iss
67 pem pki/root.der root
68 pem real/ye2.der ye2
69 # openssl ocsp checks thisUpdate/nextUpdate against the wall clock, not -attime; a tolerance of
70 # (now - attime) seconds makes its expiry test equal to one evaluated at the vectors' attime
71 # (the vectors' nextUpdate is 2026-10-30, so without it every row reads "WARNING" after that)
72 skew=$(( $(date +%s) - 1793059200 )); [ "$skew" -gt 300 ] || skew=300
73 for c in good:good revoked:revoked unknown:unknown deleg:good deleg_revoked:revoked; do
74 f=${c%%:*}; want=${c#*:}
75 oraclen=$((oraclen + 1))
76 got=$(openssl ocsp -respin "$vec/pki/o_$f.der" -issuer "$out/iss.pem" -cert "$vec/pki/leaf.der" -VAfile "$out/iss.pem" -no_nonce -CAfile "$out/root.pem" -attime 1793059200 -validity_period "$skew" 2>/dev/null | awk -F': ' '$1 ~ /leaf.der$/ { print $2; exit }') || true
77 if [ "$got" = "$want" ]; then oracle=$((oracle + 1)); else fail "openssl ocsp $f: got '$got' want '$want'"; fi
78 done
79 # openssl crl exits 0 even on "verify failure", so the verdict is its "verify OK" line
80 for c in revoked:0 clean:0 bad_sig:1 root_signed:1; do
81 f=${c%%:*}; want=${c#*:}
82 oraclen=$((oraclen + 1))
83 if openssl crl -inform DER -in "$vec/pki/c_$f.der" -CAfile "$out/iss.pem" -noout 2>&1 | grep -qx 'verify OK'; then got=0; else got=1; fi
84 if [ "$got" = "$want" ]; then oracle=$((oracle + 1)); else fail "openssl crl $f: verify exit $got want $want"; fi
85 done
86 oraclen=$((oraclen + 1))
87 if openssl crl -inform DER -in "$vec/real/ye2-74.crl" -CAfile "$out/ye2.pem" -noout 2>&1 | grep -qx 'verify OK' \
88 && openssl crl -inform DER -in "$vec/real/ye2-74.crl" -noout -text | grep -q '050A72B7AE90C2E1C61BB7D1568032F79549'; then
89 oracle=$((oracle + 1))
90 else
91 fail "openssl: real CRL signature or listed serial"
92 fi
93 say "PASS openssl oracle $oracle/$oraclen"
94fi
95
96# mutants: each must make the driver finish with exit 1 and MISMATCH lines (or an Omega trap, 101..114)
97mut=0
98mutok=0
99# mutant SED NAME [x509 [ROWS]]: sed applied to rev.om, or to x509.om when the third argument is x509.
100# Any status other than 1 or an Omega trap (a launch failure 126/127, a signal 128+) is not a detection.
101# With ROWS (strict): only exit 1 with the completed driver summary (as many checks as the unmutated run,
102# $checks) and a MISMATCH for every named row.
103mutant() {
104 mut=$((mut + 1))
105 rows=${4:-}
106 src=$tls/rev.om
107 [ "${3:-}" != x509 ] || src=$tls/x509.om
108 sed "$1" "$src" > "$out/mut-$2-lib.om"
109 if cmp -s "$src" "$out/mut-$2-lib.om"; then fail "mutant $2: sed changed nothing"; return; fi
110 if [ "$src" = "$tls/rev.om" ]; then set -- "$1" "$2" "$out/mut-$2-lib.om" "$tls/x509.om"; else set -- "$1" "$2" "$tls/rev.om" "$out/mut-$2-lib.om"; fi
111 if ! build "$3" "$here/driver.om" "$out/mut-$2" "$4"; then fail "mutant $2: build"; return; fi
112 drive "$out/cases.txt" "$out/mut-$2" "mut-$2"
113 n=$(grep -c '^MISMATCH ' "$out/mut-$2.out" || true)
114 if [ -n "$rows" ]; then
115 miss=
116 for r in $rows; do grep -q "^MISMATCH line [0-9][0-9]* $r got " "$out/mut-$2.out" || miss="$miss $r"; done
117 if [ "$rc" -eq 1 ] && [ "$n" -gt 0 ] && [ -z "$miss" ] && [ -n "${checks:-}" ] && printf '%s\n' "$last" | grep -q "^rev driver: $checks checks, $n failed$"; then
118 mutok=$((mutok + 1))
119 say "PASS mutant $2 detected ($n MISMATCH, required rows:$(printf ' %s' $rows))"
120 else
121 fail "mutant $2 not detected as required: exit $rc, $n MISMATCH, rows without a MISMATCH:${miss:- none}: $last"
122 fi
123 return
124 fi
125 if [ "$rc" -eq 1 ] && [ "$n" -gt 0 ] && printf '%s\n' "$last" | grep -q "^rev driver: [0-9][0-9]* checks, $n failed$"; then
126 mutok=$((mutok + 1))
127 say "PASS mutant $2 detected ($n MISMATCH: $(grep '^MISMATCH ' "$out/mut-$2.out" | head -n 2 | cut -d' ' -f4 | tr '\n' ' '))"
128 elif [ "$rc" -ge 101 ] && [ "$rc" -le 114 ]; then
129 mutok=$((mutok + 1))
130 say "PASS mutant $2 detected (driver trapped, exit $rc, after $n MISMATCH)"
131 else
132 fail "mutant $2 not detected: exit $rc: $last"
133 fi
134}
135# freshness: nextUpdate in the past accepted
136mutant 's/^if le get o 18 nw$/if lt get o 18 0/' fresh-next-update
137# freshness: thisUpdate in the future accepted (skew unbounded)
138mutant 's/^if gt get o 17 add nw RVSKEW$/if gt get o 17 add nw 99999999/' fresh-skew
139# signature: OCSP and CRL signatures not checked
140mutant 's/^ret chain_sig d kd part w 0 mul X5RSZ 2$/ret 0/' signature-skipped
141# CertID: serial bytes not compared
142mutant 's/^if ne get d add a i get t add RVSER i$/if eq i 999999/' serial-bytes
143# CertID: issuer key hash not compared
144mutant 's/^if ne get d add s i get t add q i$/if eq i 999999/' certid-hash
145# certStatus ignored (everything good)
146mutant 's/^put o 16 v$/put o 16 0/' cert-status
147# must-staple ignored
148mutant 's/^ret RVENOST$/ret 0/' must-staple
149# delegated responder: OCSPSigning EKU not required
150mutant 's/^if ne rev_ocspeku c part w 0 X5RSZ 0$/if eq rev_ocspeku c part w 0 X5RSZ 9/' responder-eku
151# delegated responder: not required to be issued by the leaf's issuer
152mutant 's/^if ne chain_link c is part w 0 64 0$/if eq chain_link c is part w 0 64 99/' responder-issuer
153# delegated responder: validity not checked
154mutant 's/^if ne chain_time part w 0 X5RSZ get o 0 0$/if eq chain_time part w 0 X5RSZ get o 0 99/' responder-validity
155# CRL: issuer Name not compared
156mutant 's/^if not der_same part cr get o 28 get o 29 /if and false not der_same part cr get o 28 get o 29 /' crl-issuer-name
157# CRL: issuer keyUsage cRLSign not required
158mutant 's/^if eq and get w add X5RSZ X5RKUB 2 0$/if eq and get w add X5RSZ X5RKUB 2 9/' crl-sign-ku
159# CRL: issuingDistributionPoint not matched against the leaf
160mutant 's/^v = rev_dpmatch part b get p 7 get p 8 lb w o$/v = ulong 0/' crl-idp-scope
161# CRL: delta and indirect CRL extensions not refused
162mutant 's/^if or eq o 11 eq o 15$/if eq o 99/' crl-delta-indirect
163# CRL: listed serial ignored
164mutant 's/^ret RVEREV$/ret 0/' revoked-verdict
165# SHA-1 round constant
166mutant 's/^ret 0x8f1bbcdc$/ret 0x8f1bbcdd/' sha1-constant
167# x509.om: the exponent policy merged into the RSA bit count again, so a 1024-bit CRL issuer or OCSP
168# responder with e = 2^32+1 passes chain_sig (revweak crl_issuer_rsa1024_e2_32_plus_1, ocsp_responder_*)
169mutant 's/^ret bits$/ret add bits mul sub 1 x509_rsaeok k 4294967296/' size-exponent-merged x509 'ocsp_responder_rsa1024_e2_32_plus_1 crl_issuer_rsa1024_e2_32_plus_1'
170# expectation mutant: one expected code changed
171mut=$((mut + 1))
172sed 's/^O ocsp_good X509_OK /O ocsp_good REV_ERR_STALE /' "$out/cases.txt" > "$out/mut-expect.txt"
173drive "$out/mut-expect.txt" "$out/driver" mut-expect
174if [ "$rc" -eq 1 ] && printf '%s\n' "$last" | grep -q '^rev driver: [0-9][0-9]* checks, 1 failed$' && grep -q '^MISMATCH .* ocsp_good ' "$out/mut-expect.out"; then
175 mutok=$((mutok + 1))
176 say "PASS mutant expectation detected"
177else
178 fail "expectation mutant not detected: exit $rc: $last"
179fi
180
181say "driver checks=${checks:-0}"
182if [ "$bad" -ne 0 ]; then
183 say "REV FAIL cases=$ncase mutants=$mutok/$mut"
184 exit 1
185fi
186say "REV PASS cases=$ncase mutants=$mutok/$mut"