
A typical company may have dozens or hundreds of hosts with SSL/TLS certificates, the crucial bit of glue that enables encrypted (“https”) connections to web servers that may be running on those hosts.
Unfortunately, sometimes there can be problems with SSL/TLS certificates. One of the most common issues is for a certificate to expire before it gets renewed. When that (or other issues) arise with a cert, web browsers such as
Chrome
or
Firefox
won’t trust those hosts, typically throwing up a scary-looking warning message. For example:

Figure 1. Sample Firefox Warning When Encountering An Expired Cert
If you want to do a thorough check of a web site’s crypto and cert usage, Qualys SSL Labs provides a nice free web-based tester (see Qualys SSL Labs )
That Qualys SSL Labs testing tool is truly brilliant!
Sometimes, though, you may just want to do a ‘quick-and-dirty’ check of all the hosts under a domain for a particular issue (such as expired certs). For that, the Qualys tester may be overkill, sort of like swatting a mosquito with a sledge hammer.
For a straightforward jobs like checking for expired certs, we’ll just check it directly ourselves — describing how to do it takes longer than actually just doing it.
The first thing we’ll need is a list of publicly-visible hosts for the domain name of interest.
DNSDB can be used to provide a list of all recently-seen publicly-visible hosts for a given delegation point. For example the following command will return a list of
farsightsecurity.com
hosts:
$ dnsdbq -r \*.farsightsecurity.com -A90d -j | jq -r '.rrname' | sort -u | sed 's/\.$//' > temp.txt
Decoding that command pipeline:
dnsdbq
-r \*.farsightsecurity.com
.farsightsecurity.com
-A90d
-j
|
jq
-r
'.rrname'
sort -u
sed 's/\.$//'
> temp.txt
The output in
temp.txt
then looks like:
_spf.farsightsecurity.com
archive.farsightsecurity.com
back.farsightsecurity.com
dl.farsightsecurity.com
dl.iad1.farsightsecurity.com
farsightsecurity.com
front-update.farsightsecurity.com
front.farsightsecurity.com
info.farsightsecurity.com
lists.farsightsecurity.com
my.farsightsecurity.com
support.farsightsecurity.com
www-dyn.farsightsecurity.com
www.farsightsecurity.com
So now we have a list of hosts we can test for expired certs.
But how can we actually test them? Let’s try the
openssl s_client
command.
openssl s_client CommandOpenSSL
(see https://www.openssl.org/ ) is a popular cryptographic library that often is used to handle the cryptographic “heavy lifting” for secure web sites. In addition to supporting secure web sites, it also includes some handy command line tools, such as
openssl s_client.
The basic form of the
openssl s_client
command that we’re going to use is:
openssl s_client -connect <hostname>:<portnumber> -servername <hostname>
We’ll need to make two tweaks to that. We need to ensure that we:
GNU Coreutil
openssl s_client
So as a concrete example, if we wanted to just check
www.farsightsecurity.com
on the standard https port (port 443), we’d run:
$ timeout 10 openssl s_client -connect www.farsightsecurity.com:443 -servername www.farsightsecurity.com <<< "Q"
Voluminous output will then follow. Part of that output looks like:
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, CN = DigiCert SHA2 Secure Server CA
verify return:1
depth=0 C = US, ST = CA, L = San Mateo, O = "Farsight Security, Inc.", CN = farsightsecurity.com
verify return:1
[additional content omitted here]
---
DONE
That output shows that the cert has not expired and in fact, if we “double check” with the Qualys tester, it actually gives the site’s SSL/TLS configuration an A+ evaluation.
Now let’s see what an expired cert would look like.
openssl s_clientSometimes certs are intentionally non-renewed. For example, Farsight has a host that’s slated for decommissioning, so we intentionally haven’t bothered to renew its cert. If we try to connect to that host with
openssl s_client
, we see:
$ timeout 10 openssl s_client -connect <elided>.fsi.io:443 -servername <elided>.fsi.io <<< Q
CONNECTED(00000005)
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, CN = DigiCert SHA2 Secure Server CA
verify return:1
depth=0 C = US, ST = CA, L = San Mateo, O = "Farsight Security, Inc.", CN = <elided>.fsi.ioverify error:num=10:certificate has expired
notAfter=Apr 16 12:00:00 2019 GMT
verify return:1
[snip]
If we double check that same server on the Qualys site, it receives a
T
(untrusted) rating because the certificate for the site has expired, confirming the results reported by
openssl s_client
Assuming we’ve got a list of hostnames to test in the file
temp.txt
from section II, we could build a little script to read and run tests for the names of interest, but since we only have a handful of names, we can also just build a script to test those hosts by saying:
$ awk '{print "timeout 10 openssl s_client -connect", $1, ":443 -servername ", $1, "<<< Q"}' < temp.txt | sed 's/ :/:/' > temp2.txt
Decoding that command pipeline:
awk
$1
< temp.txt
temp.txt
|
sed
> temp2.txt
temp2.txt
Once we run this command, our command file (temp2.txt) looks like:
timeout 10 openssl s_client -connect _spf.farsightsecurity.com:443 -servername _spf.farsightsecurity.com <<< Q
timeout 10 openssl s_client -connect archive.farsightsecurity.com:443 -servername archive.farsightsecurity.com <<< Q
timeout 10 openssl s_client -connect back.farsightsecurity.com:443 -servername back.farsightsecurity.com <<< Q
[etc]
All-in-all, there were 14 lines in that file:
$ wc -l temp2.txt
14 temp2.txt
We’ll then run the commands in
temp2.txt
by saying:
$ bash temp2.txt &> temp3.txt
When we look at the output in
temp3.txt
, ten of those hosts had certs:
$ grep "BEGIN CERTIFICATE" temp3.txt | wc -l
10
Reviewing the
temp3.txt
output file in an editor, we can confirm that none of the certs were in fact expired (search that file for
expired
).
You’ve now seen how you can use DNSDB in conjunction with the
openssl s_client
tool to find expired SSL/TLS certificates for hosts under a given domain.
Isn’t it time you got access to DNSDB, so you can check your domains at scale, too?
For more information about DNSDB, contact Farsight Sales at
.
Joe St Sauver Ph.D. is a Distinguished Scientist with Farsight Security®, Inc.