Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/tls/test/net/hostile.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / tls / test / net / hostile.sh` 74 lines ยท 4669 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Malicious-server suite for the om/tls client (Omega has no TLS server: every case is a scripted 4 # hostile TLS 1.3 server, hostile.py, against a build of test/tls/client.om). 5 # usage: sh om/tls/test/net/hostile.sh OMC [CASE...] 6 # 1. ClientHello policy: what the client offers (versions, suites, groups, signature schemes). 7 # 2. Every case of hostile.tsv (or the named ones): RFC 8446 section, expected abort and alert, 8 # observed client error and the alert the client sent (decrypted by the server). 9 # 3. Mutants of tls.om that the table must catch (full run only). 10 # Needs python3 with `cryptography` and the openssl CLI; listens on 127.0.0.1 only. 11 # Final line: HOSTILE PASS|FAIL cases=N pass=P fail=F (mutants are reported above it and make it FAIL). 12 set -u 13 omc=${1:?usage: hostile.sh OMC [CASE...]}; shift 14 here=$(cd "$(dirname "$0")" && pwd) 15 tls=$(cd "$here/../.." && pwd) 16 root=$(cd "$tls/../.." && pwd) 17 out="$root/build/tls/net-hostile" 18 . "$here/lib.sh" 19 rm -rf "$out"; mkdir -p "$out" 20 echo "omc $(sha256sum "$omc" | cut -c1-64)" 21 echo "tls.om $(sha256sum "$tls/tls.om" | cut -c1-64)" 22 echo "python $(python3 -c 'import sys,cryptography;print(sys.version.split()[0],"cryptography",cryptography.__version__)') $(openssl version)" 23 build client "$tls/tls.om" || { echo "HOSTILE FAIL cases=0 pass=0 fail=1"; exit 1; } 24 mkpki "$out/pki" 25 cl="$out/client/bin" 26 27 # 1. ClientHello policy 28 p=$(python3 -c 'import socket;s=socket.socket();s.bind(("127.0.0.1",0));print(s.getsockname()[1])') 29 python3 "$here/hostile.py" "$p" "$out/pki" ch_policy > "$out/ch.log" 2>&1 & 30 sp=$! 31 sleep 0.5 32 timeout 20 "$cl" localhost "$p" get 127.0.0.1 "$out/pki/root.pem" > /dev/null 2>&1 33 wait $sp 34 pol=$(grep '^SRV ch_policy' "$out/ch.log") 35 echo "$pol" 36 polfail=0 37 case "$pol" in *" bad=none") ;; *) echo "FAIL ClientHello policy"; polfail=1 ;; esac 38 39 # 2. the case table 40 python3 "$here/hostile_run.py" "$cl" "$out/pki" "$here/hostile.tsv" "$@" > "$out/table.log" 2>&1 41 trc=$? 42 grep -v '^HOSTILE ' "$out/table.log" 43 final=$(grep '^HOSTILE ' "$out/table.log") 44 [ -n "$final" ] || { cat "$out/table.log"; final="HOSTILE FAIL cases=0 pass=0 fail=1"; trc=1; } 45 46 # 3. mutants (full run only): each mutant of tls.om must turn at least one case that passes on the 47 # real tls.om into FAIL (the named cases all pass on the unmodified file) 48 mfail=0 49 if [ $# = 0 ]; then 50 mut() { # LABEL CASES SED-EXPR 51 sed "$3" "$tls/tls.om" > "$out/m.om" 52 if cmp -s "$out/m.om" "$tls/tls.om"; then echo "FAIL mutant $1: the mutation did not apply"; mfail=1; return; fi 53 build mut "$out/m.om" || { mfail=1; return; } 54 if python3 "$here/hostile_run.py" "$out/mut/bin" "$out/pki" "$here/hostile.tsv" $2 > "$out/mut.log" 2>&1; then 55 echo "FAIL mutant $1: not detected ($2)"; mfail=1 56 else echo "PASS mutant $1: detected ($(grep -c '^FAIL' "$out/mut.log") of $(echo $2 | wc -w) cases fail)"; fi 57 } 58 mut "EE unknown extension accepted" "ee_unsol ee_mfl" 's/^if or eq bit 0 ne and seen bit 0$/if ne and seen bit 0/' 59 mut "SH extension type not checked" "sh_ext_unsol sh_ext_ksalias" 's/^if or ne t 51 ne and seen 2 0$/if ne and seen 2 0/' 60 mut "post-handshake type not checked (parsed as KeyUpdate)" "post_cr post_unknown_hs" '/^fn tls_post /,/^fn /{s/^if ne t 24$/if eq t 99999/}' 61 # the F1-F7 fixes (TlsProto): each mutant restores one pre-fix behaviour 62 mut "supported_versions value is protocol_version" "sh_sv0303 sh_sv7f" '/^fn tls_shext /,/^fn /{/^if ne tls_gn c q 2 772$/{n;s/^ret TLEILL$/ret TLEVER/}}' 63 mut "illegal_parameter unmapped" "sh_ext_sni ee_ks" 's/^if or eq e TLEHRR or eq e TLETKT eq e TLEILL$/if or eq e TLEHRR eq e TLETKT/' 64 mut "SH recognised extension is unsupported" "sh_ext_sni sh_ext_cookie" 's/^if and ne t 51 and ne tls_kext t 0 ne t 41$/if eq t 99999/' 65 mut "EE recognised extension is unsupported" "ee_ks ee_sv" 's/^if ne tls_eebad t 0$/if eq t 99999/' 66 mut "supported_versions length is extension" "sh_svlen" '/^fn tls_shext /,/^fn /{/^if ne l 2$/{n;s/^ret TLEDEC$/ret TLEEXT/}}' 67 mut "empty Certificate is bad_certificate" "cert_empty" '/^if lt cl 5$/{n;s/^ret TLEDEC$/ret TLECERT/}' 68 mut "short record is record error" "rec_short" '/^if lt ln 17$/{n;s/^ret TLEMAC$/ret TLEREC/}' 69 mut "inner plaintext unbounded" "rec_overflow_inner" 's/^if gt ln 16401$/if gt ln 99999/' 70 mut "application data interleaved" "post_interleave" '/^fn tls_rdapp /,/^fn /{/^if ne tls_gn c TLHF 4 0$/{n;s/^ret TLEUNEX$/ret 0/}}' 71 fi 72 73 if [ $trc = 0 ] && [ $polfail = 0 ] && [ $mfail = 0 ]; then echo "$final"; exit 0; fi 74 echo "$final" | sed 's/^HOSTILE PASS/HOSTILE FAIL/'; exit 1