1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/bin/sh
- URL=`curl -w "%{url_effective}\n" -I -L -s -S $1 -o /dev/null`
- HOST=`echo $URL | awk -F[/:] '{print $4}'`
- FILENAME=`echo $HOST | sed -e 's/\./_/g'`.h
- TMPFILE=/tmp/cert.get_cert
- openssl s_client -showcerts -connect $HOST:443 < /dev/null 2>/dev/null| sed -n 'H; /^-----BEGIN CERTIFICATE-----/h; ${g;p;}' |sed -e '/-----END CERTIFICATE-----/q' > $TMPFILE
-
- NOTAFTER=`cat $TMPFILE | openssl x509 -noout -dates | grep 'notAfter'`
- ISSUER=`cat $TMPFILE | openssl x509 -noout -issuer`
- echo "The effective download URL (after resolving forwards) is:"
- echo " $URL"
- cat > $FILENAME <<EOF
- // This is the root certificate include file for $HOST
- // as obtained by the get_cert script on: `date`
- //
- //
- // Certificate info:
- // $ISSUER
- // $NOTAFTER
- //
- const char* root_cert = \\
- EOF
-
- cat $TMPFILE | sed 's/^/ "/g' | sed 's/$/\\n" \\/g' | sed '$ s/..$/;/' >> $FILENAME
- rm $TMPFILE
- echo ""
- echo "The root certificate include file is saved as:"
- echo " $FILENAME"
|