File: ssl-verifier.sh

package info (click to toggle)
golang-github-cloudflare-cfssl 1.2.0%2Bgit20160825.89.7fb22c8-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,916 kB
  • ctags: 2,827
  • sloc: sh: 146; sql: 62; python: 11; makefile: 8
file content (47 lines) | stat: -rwxr-xr-x 856 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

KEY=$1
CRT=$2
IMM=$3

if [ "`cat $KEY | grep ENCRYPTED`" ]; then
    echo >&2 "Key is password-protected"
    exit 1
fi

KEYMOD=`openssl rsa -noout -modulus -in $KEY`
CRTMOD=`openssl x509 -noout -modulus -in $CRT`

if [ "$KEYMOD" != "$CRTMOD" ]; then
    echo >&2 "Key doesn't match the certificate"
    exit 1
fi

if [ -n "$IMM" ]; then
    cat $CRT $IMM > bundle.crt

    if [ "`openssl verify bundle.crt`" == "$CRT: OK" ]; then
        echo "Done (bundle ok)"
        exit 0
    fi
fi

while true; do

    if [ "`openssl verify $CRT`" == "$CRT: OK" ]; then
        echo "Done"
        exit 0
    fi

    NEXT=`openssl x509 -noout -issuer_hash -in $CRT`

    if [ ! -f $NEXT ]; then
        echo >&2 "Could not generate trusted bundle"
        exit 1
    fi

    cat $CRT $NEXT > tmp.crt
    mv tmp.crt bundle.crt
    CRT="bundle.crt"

done