It is enough to compare the "fingerprint" of the local certificate against the live certificate.
The two fingerprints can be obtained by the following two commands:
openssl x509 -in /etc/letsencrypt/live/example.com/cert.pem -fingerprint -noout
echo | openssl s_client -showcerts -connect example.com:443 -servername example.com 2>&1 | openssl x509 -fingerprint -noout
To make the comparison easier, I put them into a script with error checking. It accepts a domain name as an argument and exits with a failure status if the two differ. It can be used like:
if ! ./lets-encrypt-installed-test.sh --quiet example.com
then
./example.com-cert-deploy.sh
fi
Here is the full contents of the script:
#!/bin/sh
set -e
quiet=0
for var in "$@"
do
case "$var" in
-q)
quiet=1
;;
--quiet)
quiet=1
;;
-*)
echo "Unexpected argument $var" >&2
exit 1
;;
*.*)
domain="$var"
;;
*)
echo "Expected argument $var" >&2
exit 1
;;
esac
done
if [ "z$domain" == "z" ]
then
echo "Expected domain as parameter to $0" >&2
exit 1
fi
lefile="/etc/letsencrypt/live/$domain/cert.pem"
if [ ! -e $lefile ]
then
echo "Lets Encrypt file does not exist: $lefile" >&2
exit 1
fi
leprint=`openssl x509 -in $lefile -fingerprint -noout`
case "$leprint" in
*Fingerprint*)
;;
*)
echo "No fingerprint from $lefile" >&2
exit 1
;;
esac
liveprint=`echo | openssl s_client -showcerts -connect "$domain":443 -servername "$domain" 2>&1 | openssl x509 -fingerprint | grep -i fingerprint`
case "$liveprint" in
*Fingerprint*)
;;
*)
echo "No fingerprint from SSL cert of https://$domain/" >&2
exit 1
;;
esac
if [ "$leprint" != "$liveprint" ]
then
if [ "$quiet" == "0" ]
then
echo "Fingerprints for local and remote SSL certificates differ:" >&2
echo "$lefile: $leprint" >&2
echo "https://$domain/: $liveprint" >&2
fi
exit 1
fi
exit 0