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
omega-mv / om / tls / test / net / lib.sh
| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # Shared by hostile.sh and badssl.sh (sourced; needs $omc, $tls and $out set by the caller). |
| 3 | # build NAME TLSFILE: compose test/tls/client.om after every unit (the given tls.om) into |
| 4 | # $out/NAME/bin, exactly as test/tls/run.sh does; accepted only with rc 0 and empty stderr. |
| 5 | build() { |
| 6 | mkdir -p "$out/$1" |
| 7 | for u in sha2 hkdf drbg x25519 sha3 mlkem chacha aesgcm ec ecdh rsa x509 rev fips; do cp "$tls/$u.om" "$out/$1/"; done |
| 8 | cp "$2" "$out/$1/tls.om"; cp "$tls/build.sh" "$out/$1/" |
| 9 | sh "$out/$1/build.sh" "$omc" "$tls/test/tls/client.om" "$out/$1/bin" 2> "$out/$1.err" |
| 10 | rc=$? |
| 11 | if [ "$rc" != 0 ] || [ -s "$out/$1.err" ]; then echo "FAIL build $1 (rc $rc): $(cat "$out/$1.err")"; return 1; fi |
| 12 | } |
| 13 | q() { "$@" > /dev/null 2>&1 || { echo "SETUP FAIL: $*"; exit 2; }; } |
| 14 | # mkpki DIR: root -> intermediate -> leaves for localhost (EC P-256 "good", RSA-2048 "rsa"), and |
| 15 | # an unrelated EC key "other.key". Throwaway, made with the openssl CLI (test tooling). |
| 16 | mkpki() { |
| 17 | rm -rf "$1"; mkdir -p "$1" |
| 18 | ( cd "$1" || exit 2 |
| 19 | printf '[ca]\ndefault_ca = d\n[d]\ndatabase = index.txt\nnew_certs_dir = .\nserial = serial\ndefault_md = sha256\npolicy = p\ncopy_extensions = copy\nunique_subject = no\n[p]\ncommonName = supplied\n[v3ca]\nbasicConstraints = critical,CA:true\nkeyUsage = critical,keyCertSign,cRLSign\n[v3leaf]\nbasicConstraints = critical,CA:false\nkeyUsage = critical,digitalSignature\nextendedKeyUsage = serverAuth\n' > ca.cnf |
| 20 | : > index.txt; echo 1000 > serial |
| 21 | for k in root int good other; do q openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out $k.key; done |
| 22 | q openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out rsa.key |
| 23 | q openssl req -x509 -new -key root.key -subj /CN=omega-net-test-root -days 30 -sha256 \ |
| 24 | -addext basicConstraints=critical,CA:true -addext keyUsage=critical,keyCertSign,cRLSign -out root.pem |
| 25 | q openssl req -new -key int.key -subj /CN=omega-net-test-int -out int.csr |
| 26 | q openssl ca -batch -config ca.cnf -cert root.pem -keyfile root.key -extensions v3ca -days 30 -in int.csr -out int.pem -notext |
| 27 | for n in good rsa; do |
| 28 | q openssl req -new -key $n.key -subj /CN=$n -addext subjectAltName=DNS:localhost -out $n.csr |
| 29 | q openssl ca -batch -config ca.cnf -cert int.pem -keyfile int.key -extensions v3leaf -days 10 -in $n.csr -out $n.pem -notext |
| 30 | done ) || exit 2 |
| 31 | } |