forked from mtusi2026/mtusi2026lab7
lab7
This commit is contained in:
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
temp=$(mktemp -d)
|
||||
trap 'rm -rf "$temp"' EXIT
|
||||
export PKI_DIR="$temp/certs" CA_DIR="$temp/ca"
|
||||
scripts/bootstrap-pki.sh >/dev/null
|
||||
cp "$PKI_DIR/client-api/client-api.crt" "$temp/old-client.crt"
|
||||
cp "$PKI_DIR/ca.crt" "$temp/old-root.crt"
|
||||
scripts/ca-rollover.sh prepare --offline
|
||||
# During overlap both old production leaves and candidate-root canaries verify.
|
||||
openssl verify -CAfile "$PKI_DIR/ca.crt" -CRLfile "$PKI_DIR/ca.crl" -crl_check "$temp/old-client.crt" >/dev/null
|
||||
scripts/ca-rollover.sh reissue --offline
|
||||
openssl verify -CAfile "$PKI_DIR/ca.crt" -CRLfile "$PKI_DIR/ca.crl" -crl_check "$temp/old-client.crt" >/dev/null
|
||||
openssl verify -CAfile "$PKI_DIR/ca.crt" -CRLfile "$PKI_DIR/ca.crl" -crl_check "$PKI_DIR/client-api/client-api.crt" >/dev/null
|
||||
scripts/ca-rollover.sh retire --offline
|
||||
if openssl verify -CAfile "$PKI_DIR/ca.crt" "$temp/old-client.crt" >"$temp/error" 2>&1; then echo 'FAIL: retired root still trusted'; exit 1; fi
|
||||
grep -Eq 'unable to get local issuer certificate|unable to verify' "$temp/error"
|
||||
for cert in "$PKI_DIR"/*/*.crt; do
|
||||
[[ "$cert" == "$PKI_DIR/trust/"* ]] && continue
|
||||
openssl verify -CAfile "$PKI_DIR/ca.crt" -CRLfile "$PKI_DIR/ca.crl" -crl_check "$cert" >/dev/null
|
||||
done
|
||||
python3 - <<'PY'
|
||||
import json,os,subprocess
|
||||
from pathlib import Path
|
||||
ca=Path(os.environ['CA_DIR']);pki=Path(os.environ['PKI_DIR']);s=json.loads((ca/'rollover.json').read_text())
|
||||
assert s['phase']=='retired' and s['old']!=s['new']
|
||||
assert (pki/'ca.crt').read_text().count('BEGIN CERTIFICATE')==1
|
||||
assert (ca/'active').resolve().name==s['new']
|
||||
assert (ca/'generations'/s['old']/'ca.key').stat().st_mode & 0o077 == 0
|
||||
old = ca/'generations'/s['old']
|
||||
serial = subprocess.check_output(['openssl','x509','-in',old/'issuer.crt','-noout','-serial'],text=True).strip().split('=')[1]
|
||||
rows = [row.split('\t') for row in (old/'index.txt').read_text().splitlines()]
|
||||
assert any(row[0]=='R' and int(row[3],16)==int(serial,16) for row in rows), 'Old root serial was not revoked'
|
||||
print('PASS: isolated dual trust, cross-issuer leaf reissue, current CRL, old anchor removal, protected CA generations')
|
||||
PY
|
||||
# Existing renewal/revocation remains usable after a completed rollover.
|
||||
scripts/bootstrap-pki.sh client-api >/dev/null
|
||||
openssl verify -CAfile "$PKI_DIR/ca.crt" -CRLfile "$PKI_DIR/ca.crl" -crl_check "$PKI_DIR/client-api/client-api.crt" >/dev/null
|
||||
Reference in New Issue
Block a user