matteocorti / check_ssl_cert

A shell script (that can be used as a Nagios/Icinga plugin) to check an SSL/TLS connection.
GNU General Public License v3.0
368 stars 132 forks source link

Fix inconsistent output format in openssl x509 command (crl_uri) #452

Closed benbyr closed 1 year ago

benbyr commented 1 year ago

The output of the openssl x509 command with the -text and -noout options has changed between OpenSSL versions 1.1 and 3.0. Specifically, the output format of the "X509v3 CRL Distribution Points" section has changed. This commit updates the script to use a more robust and future-proof command that works with both versions.

The old output format looked like this:

            X509v3 CRL Distribution Points:

                Full Name:
                  URI:http://crl.usertrust.com/USERTrustRSACertificationAuthority.crl

            Authority Information Access:
                CA Issuers - URI:http://crt.usertrust.com/USERTrustRSAAddTrustCA.crt

The new output format looks like this:

            X509v3 CRL Distribution Points:
                Full Name:
                  URI:http://crl.usertrust.com/USERTrustRSACertificationAuthority.crl
            Authority Information Access:
                CA Issuers - URI:http://crt.usertrust.com/USERTrustRSAAddTrustCA.crt

Here's an example of it returning multipe URIs due to the change in output between 1.1 and 3.0:

# openssl x509 -in test.txt -text -noout | grep -F -A 4 'X509v3 CRL Distribution Points' | grep -F URI | sed 's/^.*URI://'
http://crl.usertrust.com/USERTrustRSACertificationAuthority.crl
http://crt.usertrust.com/USERTrustRSAAddTrustCA.crt

With my suggested changes:

# openssl x509 -in test.txt -text -noout | grep -A 4 'X509v3 CRL Distribution Points' | grep -o -P 'URI:\K\S+' | head -n 1
http://crl.usertrust.com/USERTrustRSACertificationAuthority.crl
matteocorti commented 1 year ago

Thanks!