]> WPIA git - nre.git/blob - verify.sh
upd: find libfaketime platform independently
[nre.git] / verify.sh
1 #!/bin/bash
2 set -e
3 [ "$1" == "" ] && echo "Usage: $0 <year>" && exit 1
4 year=$1
5
6 . structure
7 cd generated
8
9 verify(){ # crt, [untrusted], additional
10     untrusted="$2"
11     [[ "$untrusted" != "" ]] && untrusted="-untrusted $untrusted"
12     openssl verify $3 -CAfile root.ca/key.crt $untrusted "$1" || error "$1 did not verify"
13 }
14
15 error() { # message
16     echo $1
17     exit -1
18 }
19
20 verifyExtlist() { # ext
21         EXTLIST=`echo "$1" | grep "X509v3\|Authority Information" | sed "s/^[ \t]*//"`
22         VAR="X509v3 extensions:
23 X509v3 Basic Constraints: $2
24 X509v3 Key Usage: 
25 ${3}X509v3 Subject Key Identifier: 
26 X509v3 Authority Key Identifier: 
27 X509v3 CRL Distribution Points: 
28 Authority Information Access: "
29
30         diff <(echo "$EXTLIST") <(echo "$VAR") || error "Extensions order is wrong for $ca"
31
32 }
33
34 # Verify root
35 verify root.ca/key.crt
36 verifyExtlist "$(openssl x509 -in "root.ca/key.crt" -noout -text)"
37
38 # Verify level-1 structure
39 for ca in $STRUCT_CAS; do
40     verify $ca.ca/key.crt
41     verifyExtlist "$(openssl x509 -in "$ca.ca/key.crt" -noout -text)"
42 done
43
44 # Verify level-2 (time) structure
45 for ca in ${STRUCT_CAS}; do
46     for i in $TIME_IDX; do
47         . ../CAs/$ca
48         if [ "$ca" == "env" ]; then
49             CA_FILE=$year/ca/${ca}_${year}_${i}.ca/key.crt
50         else
51             CA_FILE=$year/ca/${ca}_${year}_${i}.crt
52         fi
53         time=${points[${i}]}
54         timestamp=$(date --date="${time:0:2}/${time:2:2}/${year} 03:00:00 UTC" +"%s")
55         verify "$CA_FILE" "$ca.ca/key.crt" "-attime ${timestamp}"
56         EXT=`openssl x509 -in "$CA_FILE" -noout -text`
57
58         verifyExtlist "$EXT"
59
60         echo "$EXT" | grep "Subject: " | grep "CN=$name" > /dev/null || error "Subject field did not verify"
61
62         echo "$EXT" | grep -A 2 "Basic Constraints" | grep "CA:TRUE" > /dev/null || error "Basic Constraints field is wrong for $ca"
63         echo "$EXT" | grep -A 2 "Key Usage" | grep "^ *Certificate Sign, CRL Sign$" > /dev/null || error "KeyUsage field is wrong for $ca"
64
65         echo "$EXT" | grep -A 4 "CRL Distribution" | grep "g2.crl.${DOMAIN}/g2/$ca.crl" > /dev/null || error "CRL field is wrong for $ca"
66         echo "$EXT" | grep "CA Issuers" | grep "/$ca.crt" | grep "g2.crt.${DOMAIN}/g2/" > /dev/null || error "CA Issuers field is wrong for $ca"
67         echo "$EXT" | grep "OCSP" | grep "http://g2.ocsp.${DOMAIN}" > /dev/null || error "OCSP field is wrong for $ca"
68     done
69 done
70
71 # Verify infra keys
72 cat env.ca/key.crt $year/ca/env_${year}_1.ca/key.crt > envChain.crt
73
74 for key in $SERVER_KEYS; do
75     verify ${year}/keys/$key.crt envChain.crt
76     verifyExtlist "$(openssl x509 -in "${year}/keys/$key.crt" -noout -text)" critical "X509v3 Extended Key Usage: 
77 "
78 done
79
80 rm envChain.crt
81