There are countless ways to get information about the certificates of a site. Such as using curl and then grep the information or processing it with awk. A very simple way for me to solve this differently is nmap.
Nmap is a popular tool for scanning networks and gathering information about hosts and services. In addition to scanning ports and services, Nmap can also be used to check the certificate of a website.
To check the certificate of a website using Nmap, use the following command:
nmap -p 443 --script ssl-cert <website_domain>
The -p 443 parameter instructs Nmap to scan port 443, as this port is commonly used for HTTPS.
The --script ssl-cert parameter instructs Nmap to check the website’s certificate.
The following example demonstrates how to check the certificate of the website cbm-bremen.de with Nmap:
vagrant@bookworm ~> nmap -p 443 --script ssl-cert cbm-bremen.de
Starting Nmap 7.93 ( https://nmap.org ) at 2023-11-12 00:31 UTC
Nmap scan report for cbm-bremen.de (178.77.100.125)
Host is up (0.021s latency).
Other addresses for cbm-bremen.de (not scanned): 2a01:488:66:1000:b24d:647d:0:1
rDNS record for 178.77.100.125: lvps178-77-100-125.dedicated.hosteurope.de
PORT STATE SERVICE
443/tcp open https
| ssl-cert: Subject: commonName=cbm-bremen.de
| Subject Alternative Name: DNS:cbm-bremen.de, DNS:cbm-wir-lieben-bildung.de, DNS:www.cbm-bremen.de
| Issuer: commonName=R3/organizationName=Let's Encrypt/countryName=US
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2023-10-07T09:12:09
| Not valid after: 2024-01-05T09:12:08
| MD5: b599b9bc89b4a95e285009207aff070b
|_SHA-1: e459c6b77746252829dd301a79bfa5d539bb4a2e
Nmap done: 1 IP address (1 host up) scanned in 0.34 seconds
The Nmap output displays key information about the certificate, including:
- Subject: The name of the website for which the certificate was issued.
- Subject Alternative Name: A list of additional names for which the certificate is valid.
- Issuer: The name of the certification authority that issued the certificate.
- Public Key type: The type of public key used in the certificate.
- Public Key bits: The length of the public key in bits.
- Signature Algorithm: The algorithm used to sign the certificate.
- Not valid before: The date from which the certificate is valid.
- Not valid after: The date after which the certificate is no longer valid.
- MD5: The MD5 hash of the certificate.
- SHA-1: The SHA-1 hash of the certificate.
If the certificate is valid and issued for the correct domain name, it can be assumed that the website is secure. However, if the certificate is invalid or issued for the wrong domain name, it is advisable not to visit the website.