Check TLS certificate revocation via CRL with OpenSSL
Step-by-step procedure to check whether a website's TLS certificate appears in its certificate authority's revocation list (CRL).
This article explains how to check, from a domain name, whether a website's TLS certificate has been revoked, using the Certificate Revocation List (CRL) published by the certificate authority.
Prerequisites
You need openssl, curl and the system CA store.
# Arch Linux
sudo pacman -Syu openssl ca-certificates curl
# Debian / Ubuntu
sudo apt install openssl ca-certificates curl
Retrieve the site's certificate chain
Replace example.com with the domain to check:
openssl s_client -connect example.com:443 -showcerts </dev/null 2>/dev/null \
| awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/' > chain.pem
Split the chain into separate files. cert1.pem contains the site certificate, cert2.pem the intermediate certificate, and so on:
awk 'BEGIN{n=0}/BEGIN CERTIFICATE/{n++}{print > "cert" n ".pem"}' chain.pem
Find the CRL URL
The CRL Distribution Points extension of the certificate gives the location of the CRL:
openssl x509 -in cert1.pem -noout -text | grep -A4 "CRL Distribution Points"
Typical output:
CRL Distribution Points:
Full Name:
URI:http://crl.example.com/intermediate-ca.crl
Download and convert the CRL
Published CRLs are usually binary DER files. Download the file and convert it to readable text:
curl -sL -o crl.der "http://crl.example.com/intermediate-ca.crl"
openssl crl -inform DER -in crl.der -noout -text > crl.txt
Check whether the certificate is revoked
Get the serial number of the site certificate:
openssl x509 -in cert1.pem -noout -serial
For example: serial=04DFAE5678D99A18D3D93BDF00000000C4A.
Search for this number in the CRL. Search the text version (crl.txt), not the PEM file, because serial numbers are not visible in base64 content:
grep -i "04DFAE5678D99A18D3D93BDF00000000C4A" crl.txt && echo "Revoked" || echo "Not listed in the CRL"
Automated script
The script below combines the steps above. It takes the domain as its argument:
#!/bin/bash
DOMAIN=$1
TMPDIR=$(mktemp -d)
cd "$TMPDIR" || exit 1
echo "Retrieving the certificate of $DOMAIN..."
openssl s_client -connect "$DOMAIN:443" -showcerts </dev/null 2>/dev/null \
| awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/' > chain.pem
awk 'BEGIN{n=0}/BEGIN CERT/{n++}{print > "cert" n ".pem"}' chain.pem
CRL_URL=$(openssl x509 -in cert1.pem -noout -text | grep -A4 "CRL Distribution" | grep URI | head -1 | cut -d: -f2-)
if [ -z "$CRL_URL" ]; then
echo "No CRL distribution point in the certificate of $DOMAIN."
rm -rf "$TMPDIR"
exit 0
fi
SERIAL=$(openssl x509 -in cert1.pem -noout -serial | cut -d= -f2)
echo "Serial number: $SERIAL"
echo "Downloading the CRL from: $CRL_URL"
curl -sL "$CRL_URL" -o crl.der
openssl crl -inform DER -in crl.der -noout -text > crl.txt 2>/dev/null
if grep -iq "$SERIAL" crl.txt; then
echo "The certificate of $DOMAIN is REVOKED."
else
echo "The certificate of $DOMAIN is not listed in the CRL (not revoked)."
fi
rm -rf "$TMPDIR"
Usage:
chmod +x check_crl.sh
./check_crl.sh example.com
Notes
- A serial number missing from the CRL does not guarantee that the certificate is valid: the CRL is a snapshot taken when it was issued. The
Next Updatefield shows until when it is expected to be current. - The script checks only the site certificate against the CRL of its direct issuer. It does not check revocation of intermediate certificates, and it does not use OCSP, the alternative to CRLs.
- Some certificates publish no CRL distribution point and rely only on OCSP.