7. Digital Certificates & Public Key Infrastructure (PKI)
X.509 Certificate Structure
The X.509 standard defines the format for public key certificates. Every certificate acts as a digital passport, binding a public key to an identity. Key components include the Version, Serial Number, Issuer (who signed it), Subject (the entity), Validity period, and Subject Alternative Name (SAN).
SAN is critical in modern security as it allows a single certificate to be valid for multiple domains, replacing the now-deprecated Common Name (CN) field. You can inspect these details using OpenSSL to see the raw ASN.1 structure.
openssl x509 -in certificate.crt -text -noout
Certificate Authorities (CA) Hierarchy
PKI relies on trust. A Root CA is the top-level entity whose public key is hardcoded into trust stores. Because the Root CA is highly sensitive, it typically signs Intermediate CAs, which then sign end-entity certificates.
This chain allows the Root CA to remain offline for security, delegating signing duties. Validation involves tracing the signature back through the intermediates to the trusted Root. If any link is broken or untrusted, the certificate chain is invalid.
openssl verify -CAfile rootCA.crt intermediate.crt end-entity.crt
Revocation: CRL and OCSP
When a certificate's private key is compromised, it must be invalidated before its expiry. Certificate Revocation Lists (CRL) are lists of serial numbers published by the CA. However, CRLs grow large and are hard to update.
OCSP (Online Certificate Status Protocol) provides real-time revocation checking. A client sends the certificate serial to an OCSP responder and receives a signed good, revoked, or unknown response. OCSP stapling improves performance by allowing the server to provide the status directly to the client.
openssl ocsp -issuer ca.crt -cert server.crt -url http://ocsp.example.com
Certificate Transparency (CT) Logs
CT logs provide an open auditing system for all certificates issued by CAs. By requiring publicly auditable logs, it becomes impossible for a CA to issue a fraudulent certificate for a domain without the domain owner detecting it via monitoring.
Logs store 'Signed Certificate Timestamps' (SCTs). When you inspect a modern SSL certificate, look for the SCT extension to verify that it has been logged and is transparent.
curl -s https://crt.sh/?q=voidx.academy&output=json
Inspecting Certificates with Python
You can programmatically fetch and validate SSL certificates using Python's ssl and socket libraries. This is useful for automated monitoring of expiration dates or auditing certificate chains.
The script below connects to a host, retrieves the binary certificate, and decodes the common subject fields.
import socket, ssl, datetime host = 'google.com' context = ssl.create_default_context() with socket.create_connection((host, 443)) as sock: with context.wrap_socket(sock, server_hostname=host) as ssock: cert = ssock.getpeercert() print(f'Issuer: {cert['issuer'][1][0][1]}') print(f'Expiry: {cert['notAfter']}')
Knowledge Check
Ready to test your understanding of 7. Digital Certificates & Public Key Infrastructure (PKI)?