PKI, Digital Certificates and TLS Explained With Practice
When you see the padlock in your browser, a large and carefully designed system is working behind it: certificates, certificate authorities, public-key cryptography and the TLS protocol. Understanding this system helps you configure servers correctly, diagnose certificate errors and spot the mistakes attackers rely on. This lesson explains how trust is established on the internet and gives you practice inspecting real certificates.
The Problem Certificates Solve
Public-key cryptography lets you encrypt to someone’s public key, but how do you know a public key really belongs to mybank.example and not to an impostor? The answer is a digital certificate: a document binding a public key to an identity, signed by a trusted third party called a certificate authority (CA).
What Is in a Certificate?
| Field | Meaning |
|---|---|
| Subject | Who the certificate is for (the domain name or organisation) |
| Subject Alternative Names (SAN) | The list of hostnames the certificate is valid for; browsers rely on this field |
| Public key | The key being certified |
| Issuer | The CA that signed it |
| Validity period | Not-before and not-after dates |
| Key usage / extended key usage | What the key may be used for (such as server authentication) |
| Signature | The CA’s signature over the whole certificate |
| Serial number and fingerprints | Identification and revocation references |
The Chain of Trust
Certificates form a chain: the website’s leaf certificate is signed by an intermediate CA, which is signed by a root CA. Your operating system and browser ship with a store of trusted root certificates. Validation walks up the chain until it reaches a trusted root, checking signatures, dates and names at each step. Root private keys are kept offline and rarely used, so day-to-day issuing is done by intermediates.
Validation levels: Domain Validated (DV) proves control of a domain; Organisation Validated (OV) and Extended Validation (EV) add checks on the organisation, though browsers no longer prominently display the difference. Free automated CAs such as Let’s Encrypt have made DV certificates available to everyone, so a padlock proves the connection is encrypted to the named domain, not that the site is trustworthy. Phishing sites routinely use valid certificates.
Certificate Lifecycle and Revocation
- Generate a key pair and a Certificate Signing Request (CSR).
- The CA validates your control of the domain or identity.
- The CA issues the certificate.
- Install and monitor the certificate and chain on the server.
- Renew before expiry (automate it).
- Revoke if the private key is compromised.
Revocation is checked using Certificate Revocation Lists (CRLs) or the Online Certificate Status Protocol (OCSP), with “OCSP stapling” allowing the server to deliver the signed status itself. Expired certificates cause outages more often than attacks do, so inventory and automate renewal. Certificate Transparency logs publicly record issued certificates, helping domain owners spot mis-issuance; you can search them on sites such as crt.sh.
How TLS Works
Transport Layer Security (TLS) protects data between a client and a server. A simplified TLS 1.3 handshake:
- ClientHello: the client sends supported versions, cipher suites and a key share.
- ServerHello: the server picks parameters and sends its key share.
- Certificate and proof: the server sends its certificate and proves possession of the private key with a signature.
- Key derivation: both sides derive the same symmetric session keys from the exchanged values (using ephemeral Diffie-Hellman).
- Encrypted application data: the HTTP traffic now flows, encrypted and integrity-protected with a fast symmetric cipher.
Because session keys are ephemeral, TLS 1.3 gives forward secrecy: stealing the server’s long-term key later does not let an attacker decrypt past recorded traffic.
| Version | Status |
|---|---|
| SSL 2.0 / 3.0 | Obsolete and insecure |
| TLS 1.0 / 1.1 | Deprecated; disable |
| TLS 1.2 | Acceptable with strong configuration |
| TLS 1.3 | Recommended; simpler and faster with only strong options |
Mutual TLS and Related Ideas
- mTLS: the client also presents a certificate, commonly used between services in zero-trust architectures.
- HSTS: a header telling browsers to use HTTPS only for a site, defending against downgrade attacks.
- Certificate pinning: an app accepts only specific certificates or keys; powerful but operationally risky.
- Self-signed certificates: fine for labs, but clients will warn because no trusted CA vouches for them.
Practice Lab 1: Inspect a Real Certificate
These commands make a normal TLS connection to a public site, exactly as a browser does:
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
Read the output: who is it issued to, which CA issued it, and when does it expire? Next, view the whole chain:
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | grep -E "s:|i:"
curl -vI https://example.com 2>&1 | grep -E "SSL connection|subject|issuer|expire"
Also open a site in your browser, click the padlock and view the certificate. Compare with the command-line output.
Practice Lab 2: Create Your Own Lab Certificate
# Create a self-signed certificate valid for 30 days for a lab hostname
openssl req -x509 -newkey rsa:2048 -nodes -keyout lab.key -out lab.crt -days 30 -subj "/CN=lab.local" -addext "subjectAltName=DNS:lab.local"
# Inspect it
openssl x509 -in lab.crt -noout -text | less
# Serve it locally to see a browser warning (lab only)
openssl s_server -accept 8443 -cert lab.crt -key lab.key -www
Visit https://localhost:8443 and observe the browser warning. Why does it appear, even though the connection is encrypted? (Because no trusted CA signed it.) Stop the server with Ctrl+C and delete the key.
Practice Lab 3: Check Your Own Site’s TLS
If you operate a website or blog, test it with a free public tool such as Qualys SSL Labs’ server test, which is designed for testers to check their own domains, and aim for strong grades. In your own lab you can also enumerate cipher suites on a server you control with Nmap:
nmap --script ssl-enum-ciphers -p 443 192.168.56.102
Safe TLS Configuration Checklist
- Enable TLS 1.3 and TLS 1.2 only; disable older versions.
- Use strong cipher suites with forward secrecy (ECDHE) and AEAD ciphers (AES-GCM, ChaCha20-Poly1305).
- Use certificates with at least RSA 2048 or ECDSA P-256 keys and SHA-256 signatures.
- Serve the full chain, and automate renewal and expiry monitoring.
- Redirect HTTP to HTTPS and enable HSTS.
- Protect private keys: restricted permissions, ideally in a hardware security module or managed key service.
- Monitor Certificate Transparency logs for unexpected certificates for your domains.
Common Mistakes
- Letting certificates expire because renewal is manual.
- Disabling certificate validation in code “temporarily” and shipping it.
- Reusing one private key across many servers or leaving keys in repositories.
- Telling users that a padlock means a site is safe.
- Installing unknown root certificates on devices, which allows traffic interception.
Practice Exercises
- Draw the chain of trust for a site you use and list each certificate’s issuer.
- Explain how TLS provides confidentiality, integrity and authentication, mapping each to a step in the handshake.
- Why is certificate expiry a security and an availability concern?
- What does forward secrecy protect against?
- Create a certificate with the wrong hostname in your lab and describe the browser error you see.
Mentor tip: Whenever you are troubleshooting a TLS error, check four things in order: hostname match, expiry date, full chain and trust store. These four cause the vast majority of certificate failures.
Educational use only: practise security techniques only on systems you own or have explicit written permission to test.
- Certificates bind public keys to identities, and CAs sign them to create chains of trust.
- A padlock proves encryption to the named domain, not that a site is legitimate.
- TLS 1.3 uses ephemeral key exchange for forward secrecy; disable TLS 1.0 and 1.1.
- Automate renewal, protect private keys and monitor certificate transparency.
- Check hostname, expiry, chain and trust when debugging errors.