These are the notes for Cybersecurity Fundamentals (defensive), episode 16. Episode 15 ended with a gap: a man in the middle can hand Riya his own public key and pretend to be Aman. Today you close that gap by inventing each idea from a real-life problem: the digital signature (and sign vs encrypt), the signature algorithms RSA-PSS, ECDSA and Ed25519, the certificate and its X.509 fields, the certificate authority (CA), root and intermediate CAs, the chain of trust, the trust store, the CSR, self-signed certificates, revocation (CRL, OCSP, OCSP stapling), certificate transparency logs, ACME and Let's Encrypt, and code signing. Every term is explained the first time it appears, and the Glossary at the end defines them all again.
Riya, Aman, Mallory, shop.example and the messages are made up (.example is a name reserved for documentation). Every code sample runs with Python 3.13 and the cryptography package (version 50.0.1); outputs are real, copied from actual runs. Random keys, serial numbers and ECDSA signature sizes differ on every run. In tracebacks, long file paths are shortened to the file name. The toy PKI below is for understanding only: in real code, use your platform's certificate verifier.
The problems you'll solve
| Problem | Idea it teaches |
|---|---|
| A hash attached to a message | Why a hash alone proves nothing about who made it |
| Something only Aman can make, anyone can check | Digital signature, sign vs encrypt, non-repudiation |
| Which signature algorithm? | RSA-PSS, ECDSA, Ed25519 |
| The signature checks out, with whose key? | Certificate, X.509 fields, self-signed certificate |
| Who vouches for the name? | Certificate authority, root and intermediate CAs, chain of trust, trust store, PKI |
| How do I ask a CA? | CSR (certificate signing request) |
| A private key is stolen | Revocation: CRL, OCSP, OCSP stapling, short lifetimes |
| A CA itself is hacked | Certificate transparency logs |
| Renewing by hand is painful | ACME, Let's Encrypt |
| Apps and updates | Code signing |
Problem 1: a hash is not enough
Aman sends a payment note to his bank: "Pay Rs 500 to Riya." On the way it passes through many hands, including Mallory, an attacker in the middle (a man in the middle, or MITM, is someone sitting between two parties who can read and change their messages).
The obvious fix: attach a hash, the short fingerprint of any data from episode 13 (SHA-256 turns any input into 32 bytes; change one bit of input and the hash changes completely).
Demo 1: the forgery passes
import hashlib
def send(msg): # sender attaches a hash
return msg, hashlib.sha256(msg).hexdigest()
def check(msg, digest): # receiver recomputes it
return hashlib.sha256(msg).hexdigest() == digest
msg, h = send(b"Pay Rs 500 to Riya")
print("original ok? ", check(msg, h))
# the attacker in the middle changes the message
fake = b"Pay Rs 50000 to Mallory"
fake_h = hashlib.sha256(fake).hexdigest() # ...and the hash
print("forgery ok? ", check(fake, fake_h))
Output:
original ok? True
forgery ok? True
Why it failed: a hash proves data wasn't changed by accident, but anyone can compute a hash. Mallory changed the message and recomputed the hash.
An HMAC (episode 12: a hash mixed with a secret key) would stop Mallory, but it needs a secret shared in advance, and both sides hold it. The bank could forge a note and blame Aman, and Aman could deny sending a real one. We need something only Aman can make and everyone can check.
Problem 2: digital signatures
Real-life example: your handwritten signature. Only your hand makes it; anyone (like a bank with your specimen signature) can compare it; and it belongs to one page.
| On paper | Digitally |
|---|---|
| Only your hand makes it | Sign with your private key (never leaves you) |
| Anyone compares it with a specimen | Verify with your public key (shared with everyone) |
| Bound to this page | Computed from the exact bytes: change one bit and it fails |
A digital signature is a small piece of data, computed with a private key over a message, that anyone with the matching public key can check. It gives three guarantees:
- Integrity: the message wasn't changed.
- Authenticity: it came from the holder of the private key.
- Non-repudiation (episode 2): the signer can't later deny signing it, because nobody else holds the key.
Demo 2: sign and verify with Ed25519
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
Ed25519PrivateKey)
aman = Ed25519PrivateKey.generate() # private: stays home
aman_pub = aman.public_key() # public: give to all
msg = b"Pay Rs 500 to Riya"
sig = aman.sign(msg) # only Aman can do this
print(len(sig), "byte signature:", sig.hex()[:24], "...")
aman_pub.verify(sig, msg) # anyone can check
print("genuine message: verified")
fake = b"Pay Rs 50000 to Mallory"
aman_pub.verify(sig, fake) # a changed message?
Output:
64 byte signature: 5b9e77d52302f91f47ef07c5 ...
genuine message: verified
Traceback (most recent call last):
File "main.py", line 15, in <module>
aman_pub.verify(sig, fake) # a changed message?
~~~~~~~~~~~~~~~^^^^^^^^^^^
cryptography.exceptions.InvalidSignature
sign()uses the private key;verify()uses the public key.verify()returns nothing on success and raisesInvalidSignatureon failure, so you can't accidentally ignore a bad result.- Mallory can't make a new signature for her note: she doesn't have Aman's private key.
Sign vs encrypt
| Which key? | Goal | Is the message hidden? | |
|---|---|---|---|
| Encrypt | Receiver's public key; receiver's private key decrypts | Secrecy | Yes |
| Sign | Sender's private key; sender's public key verifies | Proof of origin + integrity | No, it stays readable |
Signature algorithms first hash the message, then sign the small hash ("hash-then-sign"), so signing a 2 GB file costs about the same as signing a short note (plus the hashing).
Never "sign" by encrypting with a private key using textbook RSA, and never encrypt by "signing": use the dedicated sign/verify and encrypt/decrypt functions.
Problem 3: which signature algorithm?
| Algorithm | What it is | Notes |
|---|---|---|
| RSA-PSS | RSA signing with PSS padding (Probabilistic Signature Scheme), which mixes a random salt into each signature | Big signatures (384 bytes at 3072 bits); widely supported |
| ECDSA | Elliptic Curve Digital Signature Algorithm, on a curve like P-256 | Needs a fresh, secret random number (a nonce) per signature; reusing it even twice lets anyone compute the private key |
| Ed25519 | EdDSA (Edwards-curve Digital Signature Algorithm) on Curve25519 | 64-byte signatures, 32-byte public keys, fast, deterministic (no random nonce to get wrong) |
Demo 3: three algorithms side by side
from cryptography.hazmat.primitives.asymmetric import (
rsa, ec, ed25519, padding)
from cryptography.hazmat.primitives import hashes
msg = b"release v2.1 of the app"
pss = padding.PSS(mgf=padding.MGF1(hashes.SHA256()),
salt_length=padding.PSS.MAX_LENGTH)
r = rsa.generate_private_key(public_exponent=65537,
key_size=3072)
e = ec.generate_private_key(ec.SECP256R1())
d = ed25519.Ed25519PrivateKey.generate()
ecdsa = ec.ECDSA(hashes.SHA256())
s1 = r.sign(msg, pss, hashes.SHA256())
s2, s3 = e.sign(msg, ecdsa), d.sign(msg)
print("RSA-PSS (3072):", len(s1), "bytes")
print("ECDSA (P-256): ", len(s2), "bytes")
print("Ed25519: ", len(s3), "bytes")
print("same Ed25519 sig twice?", d.sign(msg) == s3)
print("same ECDSA sig twice? ", e.sign(msg, ecdsa) == s2)
Output (ECDSA is 70-72 bytes, it varies):
RSA-PSS (3072): 384 bytes
ECDSA (P-256): 72 bytes
Ed25519: 64 bytes
same Ed25519 sig twice? True
same ECDSA sig twice? False
- RSA-3072, P-256 and Ed25519 all target about 128-bit security (episode 15), but the signature sizes differ a lot.
- Ed25519 is deterministic: same key + same message = same signature. ECDSA uses a random nonce, so its signatures differ each time.
- For new code, Ed25519 is a great default. If you must use NIST curves (some regulations require them), use ECDSA P-256 through a vetted library. Use RSA-PSS (not the older PKCS#1 v1.5) when you need RSA.
Problem 4: certificates
Signatures work, but Riya verifies with "Aman's" public key, which she downloaded over the open network. If Mallory swapped in her own public key, Mallory can sign anything with her own private key and it verifies perfectly:
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
Ed25519PrivateKey)
aman = Ed25519PrivateKey.generate()
mallory = Ed25519PrivateKey.generate()
msg = b"Pay Rs 500 to Riya"
sig = mallory.sign(msg) # Mallory signs
try:
aman.public_key().verify(sig, msg) # checked with Aman's key
print("accepted")
except Exception as e:
print("rejected:", type(e).__name__)
mallory.public_key().verify(sig, msg) # with Mallory's own key
print("verifies fine with Mallory's key: so WHOSE key matters")
Output:
rejected: InvalidSignature
verifies fine with Mallory's key: so WHOSE key matters
Signature maths can't tell you whose key it is. We need an ID card for keys: a document that says "this public key belongs to this name", signed by someone Riya already trusts. That document is a certificate.
The X.509 certificate fields
X.509 is the standard certificate format used on the web (defined for the internet in RFC 5280). Like a passport, it has fixed fields:
| Field | Meaning | Example |
|---|---|---|
| Version | Format version; today always v3 | v3 |
| Serial number | Unique number the issuer gives this certificate | 0x295736b68576... |
| Subject | Who the certificate is for (CN = common name, O = organisation) | CN=shop.example,O=Shop |
| Subject Alternative Name (SAN) | The exact domain names it covers; browsers check this | shop.example, www.shop.example |
| Public key | The key being vouched for | an ECDSA P-256 public key |
| Issuer | Who signed it | CN=Inter CA |
| Validity | Not before and not after dates | 2026-10-30 to 2027-01-28 |
| Extensions | Extra rules, e.g. Basic Constraints (is this a CA?), Key Usage | CA: false |
| Signature algorithm + signature | The issuer's signature over all the fields above | ecdsa-with-SHA256 |
Because the issuer's signature covers every field, changing any field (the name, the dates, the key) breaks the signature.
Demo 4: a self-signed certificate
from datetime import datetime as D
from cryptography import x509
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import hashes
key = ec.generate_private_key(ec.SECP256R1())
me = x509.Name.from_rfc4514_string("CN=shop.example,O=Shop")
cert = (x509.CertificateBuilder()
.subject_name(me).issuer_name(me) # self-signed
.public_key(key.public_key())
.serial_number(x509.random_serial_number())
.not_valid_before(D(2026, 10, 30))
.not_valid_after(D(2027, 1, 28))
.sign(key, hashes.SHA256()))
print("version:", cert.version.name)
print("subject:", cert.subject.rfc4514_string())
print("issuer: ", cert.issuer.rfc4514_string())
print("valid: ", cert.not_valid_before_utc.date(),
"to", cert.not_valid_after_utc.date())
print("sig alg:", cert.signature_algorithm_oid._name)
Output:
version: v3
subject: CN=shop.example,O=Shop
issuer: CN=shop.example,O=Shop
valid: 2026-10-30 to 2027-01-28
sig alg: ecdsa-with-SHA256
The subject and issuer are identical and the certificate was signed by its own key: a self-signed certificate. It vouches for itself. That's fine for testing, or inside a company that deliberately installs it on its own machines, but Mallory can make an identical one in a second, so from a stranger it proves nothing. That's why browsers show a full-page warning for one.
Problem 5: CAs and the chain of trust
Real-life example: a passport.
| Passports | PKI |
|---|---|
| The government, which everyone already trusts | Root CA: its certificate is pre-installed in your trust store |
| A regional passport office, authorised by the government | Intermediate CA: signed by the root, does the daily signing |
| Your passport | Leaf (end-entity) certificate for shop.example |
- A certificate authority (CA) is an organisation that checks who you are (for websites: that you control the domain) and signs your certificate.
- A root CA sits at the top. Its certificate is self-signed and trusted only because it ships with your device. Its private key is kept offline.
- An intermediate CA is signed by the root and signs leaf certificates, so the root key is rarely used. If an intermediate is compromised, it can be revoked without replacing the root on billions of devices.
- The chain of trust: leaf ← signed by intermediate ← signed by root ← in your trust store.
- The trust store is the list of root certificates your operating system, browser or language runtime trusts.
- PKI (public key infrastructure) is the whole system: CAs, certificates, policies, revocation and the software that checks them.
How a browser checks a site:
- The server sends its leaf certificate and the intermediate(s).
- Each signature is checked with the parent's public key.
- The chain must end at a root that is in the trust store.
- The name you typed must match the SAN, the dates must be valid, CA flags must be right, and the certificate must not be revoked.
Demo 5: a toy chain of trust, and a forged leaf
from datetime import datetime as D
from cryptography import x509
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import hashes
nm = lambda s: x509.Name.from_rfc4514_string("CN=" + s)
def make(cn, by, by_key): # by_key signs the cert
k = ec.generate_private_key(ec.SECP256R1())
return (x509.CertificateBuilder().subject_name(nm(cn))
.issuer_name(nm(by)).public_key(k.public_key()).serial_number(1)
.not_valid_before(D(2026, 10, 1)).not_valid_after(D(2026, 12, 30))
.sign(by_key or k, hashes.SHA256())), k
root, rk = make("Root CA", "Root CA", None) # self-signed
inter, ik = make("Inter CA", "Root CA", rk)
leaf, _ = make("shop.example", "Inter CA", ik)
fake, _ = make("shop.example", "Inter CA", None) # forged
for c in (leaf, fake):
inter.verify_directly_issued_by(root) # link 2
c.verify_directly_issued_by(inter) # link 1
print("trusted chain:", c.subject.rfc4514_string())
Output:
trusted chain: CN=shop.example
Traceback (most recent call last):
File "main.py", line 18, in <module>
c.verify_directly_issued_by(inter) # link 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
cryptography.exceptions.InvalidSignature
make()builds a certificate signed by whichever key we pass (by_key), or by its own key for a self-signed root.verify_directly_issued_by(parent)checks that the child's issuer name matches the parent's subject and that the parent's public key verifies the child's signature.- Mallory wrote
Inter CAin her issuer field (names are free to write), but she doesn't have the intermediate's private key, so the signature fails. - This loop is only to see the idea. Real verification also checks the trust store, dates, SAN, Basic Constraints, Key Usage, path length and revocation: use your platform's verifier (for example Python's
sslmodule with default settings, orcryptography.x509.verification).
Problem 6: asking for a certificate (the CSR)
The CA must sign your public key, but your private key must never leave your server. So:
- You generate the key pair on your server.
- You create a CSR (certificate signing request): your name and public key, signed with your private key to prove you hold it.
- The CA checks that you control the domain, then sends back a signed certificate.
Demo 6: build a CSR
from cryptography import x509
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.serialization import (
Encoding)
key = ec.generate_private_key(ec.SECP256R1()) # stays on server
csr = (x509.CertificateSigningRequestBuilder()
.subject_name(x509.Name.from_rfc4514_string(
"CN=shop.example"))
.add_extension(x509.SubjectAlternativeName(
[x509.DNSName("shop.example")]), critical=False)
.sign(key, hashes.SHA256())) # proves you hold key
pem = csr.public_bytes(Encoding.PEM).decode()
print(pem.splitlines()[0])
print(pem.splitlines()[1][:40], "...")
print("subject:", csr.subject.rfc4514_string())
print("self-signature valid?", csr.is_signature_valid)
Output:
-----BEGIN CERTIFICATE REQUEST-----
MIH7MIGjAgEAMBcxFTATBgNVBAMMDHNob3AuZXhh ...
subject: CN=shop.example
self-signature valid? True
PEM is the text format with -----BEGIN ...----- and -----END ...----- lines around Base64 data. The CSR contains only the public key.
Problem 7: revocation
A server's private key leaks, but its certificate is valid for months. Like a stolen passport, it must be cancelled early: that's revocation.
| Method | How it works | Trade-off |
|---|---|---|
| CRL (certificate revocation list) | The CA publishes a signed list of revoked serial numbers; clients download it | Lists grow; clients may check slowly |
| OCSP (Online Certificate Status Protocol) | The client asks the CA about one certificate and gets good or revoked | Tells the CA which sites you visit (privacy); adds a network request |
| OCSP stapling | The server fetches a fresh, signed OCSP answer and attaches ("staples") it to the TLS handshake | Fixes the privacy and speed problem, but only if the server does it |
| Short-lived certificates | Certificates expire quickly | A stolen key stops working soon even if revocation fails |
Real-world updates:
- Let's Encrypt removed OCSP URLs from its certificates on 7 May 2025 and turned off its OCSP responders on 6 August 2025, using CRLs instead, mainly because OCSP lets a CA see which site an IP address visits.
- Under CA/Browser Forum ballot SC-081, the maximum lifetime of a public TLS certificate is 200 days from 15 March 2026, 100 days from 15 March 2027 and 47 days from 15 March 2029.
A toy revocation check (expiry first, then a CRL of serial numbers):
from datetime import datetime, timezone
REVOKED = {0x1001, 0x2002} # a toy CRL: revoked serials
certs = [
{"cn": "shop.example", "serial": 0x1000,
"not_after": datetime(2027, 1, 28, tzinfo=timezone.utc)},
{"cn": "old.example", "serial": 0x3003,
"not_after": datetime(2026, 9, 1, tzinfo=timezone.utc)},
{"cn": "leaked.example", "serial": 0x2002,
"not_after": datetime(2027, 3, 1, tzinfo=timezone.utc)},
]
now = datetime(2026, 10, 30, tzinfo=timezone.utc)
for c in certs:
if now > c["not_after"]:
status = "EXPIRED"
elif c["serial"] in REVOKED:
status = "REVOKED"
else:
status = "ok"
print(f'{c["cn"]:15} serial {c["serial"]:#06x}: {status}')
Output:
shop.example serial 0x1000: ok
old.example serial 0x3003: EXPIRED
leaked.example serial 0x2002: REVOKED
Problem 8: certificate transparency
The chain of trust is only as strong as every CA in your trust store. In 2011, attackers broke into DigiNotar, a Dutch CA. An audit by Fox-IT listed 531 rogue certificates (the attacker deleted logs, so the true number is unknown), including ones for Google, Facebook, Skype and Microsoft. Microsoft, Google and Mozilla stopped trusting DigiNotar, and the company went bankrupt in September 2011.
The lesson: any trusted CA could issue a certificate for your domain, and you'd never know. The fix is Certificate Transparency (CT), described in RFC 6962 (June 2013, by Ben Laurie, Adam Langley and Emilia Kasper of Google; now updated by RFC 9162): CAs submit every certificate to public, append-only logs (entries can be added, never edited or removed) that anyone can audit.
Defenders monitor CT logs for certificates issued for their own domains: an unexpected one means a mis-issuance or an attack.
Problem 9: ACME and Let's Encrypt
Getting certificates by hand meant forms, emails, payments, and forgotten renewals that took websites down. With certificates heading to 47 days, manual renewal is impossible.
ACME (Automatic Certificate Management Environment) is a protocol where a small client on your server:
- asks the CA for a certificate for a domain,
- proves it controls the domain by completing a challenge (for example, the HTTP-01 challenge: serve a token the CA chose at a specific URL on that domain; or the DNS-01 challenge: publish it as a DNS record),
- receives the certificate and renews it automatically before it expires.
ACME was designed by ISRG for Let's Encrypt and became RFC 8555 in March 2019. Let's Encrypt is a free, automated CA that launched publicly in December 2015, and it made HTTPS normal for small websites.
Problem 10: code signing
Real-life example: a sealed medicine strip with the maker's name. You check the seal before use and return a strip with a broken seal.
Code signing is when a software publisher signs its app or update with a private key (usually under a code-signing certificate), and the operating system or updater verifies the signature before installing. A tampered download fails verification and is rejected.
Mini project: a signed updater
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
Ed25519PrivateKey)
from cryptography.exceptions import InvalidSignature
# --- publisher side (keeps the private key offline) ---
publisher = Ed25519PrivateKey.generate()
PUBLIC = publisher.public_key() # shipped inside the app
def release(data):
return data, publisher.sign(data)
# --- updater side (only has PUBLIC) ---
def install(data, sig):
try:
PUBLIC.verify(sig, data)
except InvalidSignature:
return "REJECTED: signature does not match"
return f"installed {len(data)} bytes"
update, sig = release(b"app v2.1 " + b"\x90" * 1000)
print(install(update, sig))
tampered = update.replace(b"v2.1", b"evil")
print(install(tampered, sig))
Output:
installed 1009 bytes
REJECTED: signature does not match
The publisher's private key stays offline; the app ships with only the public key. Even if Mallory controls the download server, she can't produce a valid signature for her modified update.
The whole chain
| Step | Problem | Invention |
|---|---|---|
| 1 | A hash attached → attacker rehashes | A hash isn't proof of origin |
| 2 | Only Aman can make it, anyone can check | Digital signature; sign vs encrypt |
| 3 | Which one? | RSA-PSS, ECDSA, Ed25519 |
| 4 | Whose key is it? | Certificate, X.509, self-signed |
| 5 | Who vouches? | CA, root and intermediate, chain of trust, trust store, PKI |
| 6 | How to ask? | CSR |
| 7 | A key is stolen | Revocation: CRL, OCSP, stapling, short lifetimes |
| 8 | A CA is hacked | Certificate transparency |
| 9 | Renewals by hand | ACME, Let's Encrypt |
| 10 | Apps and updates | Code signing |
| ? | How do these bytes travel? | Networking (episode 17) |
Common mistakes (and what they print)
| Mistake | What you see | Why | Fix |
|---|---|---|---|
| Attaching a bare hash as "protection" | forgery ok? True |
Anyone can recompute a hash | Sign it (or HMAC with a shared key) |
| Verifying a changed message, or with the wrong key | cryptography.exceptions.InvalidSignature |
A signature covers the exact bytes and one key pair | Treat as an attack; reject, never retry around it |
| Trusting a public key that came over the network unauthenticated | A forged signature verifies with Mallory's key | Signature maths doesn't prove ownership | Get the key from a certificate chained to a trusted root |
| Trusting any self-signed certificate | Browser: "Your connection is not private" | Anyone can make one | Use a CA-issued certificate, or pin a known one internally |
requests.get(url, verify=False) to silence a certificate error |
No error at all, and no protection | Accepts every certificate, including a MITM's | Fix the chain (send the intermediate, trust your internal CA) |
| Reusing an ECDSA nonce, or a home-made random number | The private key can be computed | ECDSA needs a unique secret nonce per signature | Use Ed25519, or a vetted library's ECDSA |
| Forgetting renewal | Site down: certificate expired | Manual process | Automate with ACME |
Practice
1. Sign and verify a file with Ed25519, sending the public key as 32 raw bytes.
Solution
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
Ed25519PrivateKey, Ed25519PublicKey)
from cryptography.hazmat.primitives.serialization import (
Encoding, PublicFormat)
key = Ed25519PrivateKey.generate()
data = b"notes.txt contents\n" * 50
sig = key.sign(data)
raw_pub = key.public_key().public_bytes(Encoding.Raw, PublicFormat.Raw)
print("public key:", len(raw_pub), "bytes; signature:", len(sig), "bytes")
# someone else rebuilds the public key from its 32 raw bytes
pub = Ed25519PublicKey.from_public_bytes(raw_pub)
pub.verify(sig, data)
print("verified with the rebuilt public key")
Output:
public key: 32 bytes; signature: 64 bytes
verified with the rebuilt public key
2. Extend the toy chain to two intermediates (root → inter 1 → inter 2 → leaf) and verify every link.
Solution
from datetime import datetime as D
from cryptography import x509
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import hashes
nm = lambda s: x509.Name.from_rfc4514_string("CN=" + s)
def make(cn, by, by_key):
k = ec.generate_private_key(ec.SECP256R1())
c = (x509.CertificateBuilder().subject_name(nm(cn))
.issuer_name(nm(by)).public_key(k.public_key())
.serial_number(1).not_valid_before(D(2026, 10, 1))
.not_valid_after(D(2026, 12, 30))
.sign(by_key or k, hashes.SHA256()))
return c, k
root, rk = make("Root CA", "Root CA", None)
i1, k1 = make("Inter CA 1", "Root CA", rk)
i2, k2 = make("Inter CA 2", "Inter CA 1", k1)
leaf, _ = make("shop.example", "Inter CA 2", k2)
chain = [leaf, i2, i1, root]
for child, parent in zip(chain, chain[1:]):
child.verify_directly_issued_by(parent)
print(child.subject.rfc4514_string(), "<- signed by",
parent.subject.rfc4514_string())
print("chain of", len(chain), "verified")
Output:
CN=shop.example <- signed by CN=Inter CA 2
CN=Inter CA 2 <- signed by CN=Inter CA 1
CN=Inter CA 1 <- signed by CN=Root CA
chain of 4 verified
3. Why does a valid signature from an unknown key prove nothing?
Answer
Anyone can make a key pair and sign with it. The signature only proves "whoever holds the private key matching this public key signed this". You still need to know that the public key belongs to the person you think, which is what a certificate chained to a trusted root gives you.
4. A server's certificate expires in 80 days, but its key leaked today. What should happen, and what limits the damage if clients don't check revocation?
Answer
Revoke the certificate now (the CA adds its serial number to its CRL), generate a new key pair, get a new certificate and deploy it. If some clients never check revocation, the stolen certificate keeps working until it expires, which is why shorter certificate lifetimes limit the damage.
5. Homework (browser): click the padlock on any HTTPS site and find the leaf, intermediate and root certificates. Which fields from the X.509 table can you see?
What to look for
The subject and SAN (the site's names), the issuer (an intermediate CA), the validity dates, the public key algorithm (often ECDSA P-256 or RSA-2048), the signature algorithm, and the root at the top of the chain, which is in your trust store.
Quick quiz
Aman signs a software update, and Riya's laptop must verify it. Which keys are used?
A. Aman signs with Riya's public key B. Aman signs with his public key C. Aman signs with his private key; Riya verifies with his public key D. Both use one shared secret key
Answer
C. Signing uses the signer's private key, so only Aman can sign. Anyone verifies with Aman's public key, which Riya trusts because it's in a certificate chained to a root in her trust store. (D describes an HMAC, which can't give non-repudiation.)
Interview questions
- What's the difference between signing and encrypting? Encrypting uses the receiver's public key and gives confidentiality; signing uses the sender's private key, is verified with the sender's public key, and gives integrity, authenticity and non-repudiation. A signed message stays readable.
- Why isn't a hash enough to protect a message in transit? Anyone can compute a hash, so an attacker can change the message and recompute it. You need a key: an HMAC (shared key) or a signature (private key).
- HMAC vs digital signature? An HMAC uses one shared secret, so both sides can create it: no non-repudiation, and keys must be shared in advance. A signature uses a key pair: only the signer can create it, anyone can verify.
- Compare RSA-PSS, ECDSA and Ed25519. RSA-PSS: big keys and signatures, widely supported. ECDSA: small, but needs a unique random nonce per signature. Ed25519: small, fast and deterministic; a good default for new systems.
- What is a certificate, and what are its key fields? A signed statement binding a public key to a name: subject, SAN, public key, issuer, serial, validity, extensions and the issuer's signature.
- Explain the chain of trust. The leaf is signed by an intermediate, the intermediate by a root, and the root is trusted because it's in the client's trust store. Each signature is verified with the parent's public key.
- Why do CAs use intermediates? The root key stays offline; an intermediate can be revoked and replaced without updating trust stores on every device.
- CRL vs OCSP vs OCSP stapling? CRL: a downloaded list of revoked serials. OCSP: ask the CA about one certificate (privacy and latency cost). Stapling: the server attaches a signed OCSP response to the handshake.
- What problem does Certificate Transparency solve? Mis-issued or rogue certificates going unnoticed; CAs log every certificate publicly, and domain owners monitor the logs.
- What is ACME? RFC 8555: a protocol that automates proving domain control and issuing and renewing certificates; used by Let's Encrypt.
- What is a CSR and why doesn't it contain the private key? A certificate signing request: the name and public key, self-signed to prove possession of the private key. The private key never leaves the server.
Glossary
| Term | Meaning in plain words | Example |
|---|---|---|
| Man in the middle (MITM) | An attacker between two parties who can read or change their messages | Mallory swaps keys |
| Hash | A short fixed-size fingerprint of any data | SHA-256 |
| HMAC | A hash mixed with a shared secret key | Episode 12 |
| Digital signature | Data made with a private key over a message, checkable with the public key | Ed25519 sign() |
| Sign / verify | Make a signature (private key) / check it (public key) | aman.sign(msg), pub.verify(sig, msg) |
| Sign vs encrypt | Signing proves origin and integrity; encrypting hides content; they use opposite keys | Update signed, chat encrypted |
| Integrity | The data wasn't changed | One flipped bit fails |
| Authenticity | The data came from who it claims | Only Aman's key verifies |
| Non-repudiation | The signer can't deny signing | Only Aman holds the key |
| Hash-then-sign | Signing the hash of a message instead of the whole message | Signing a 2 GB file quickly |
| RSA-PSS | RSA signatures with randomised PSS padding | 384-byte signatures at 3072 bits |
| ECDSA | Elliptic Curve Digital Signature Algorithm | ECDSA on P-256 |
| Nonce | A number used once; ECDSA needs a secret, unique one per signature | Reuse leaks the key |
| EdDSA / Ed25519 | Edwards-curve signatures; Ed25519 uses Curve25519, is fast and deterministic | 64-byte signatures |
| Deterministic signature | Same key + message always gives the same signature | Ed25519 |
| Certificate | A signed document binding a public key to a name | Cert for shop.example |
| X.509 | The standard certificate format used on the web | v3 certificates |
| Subject / CN | Who a certificate is for / its common name | CN=shop.example |
| SAN (subject alternative name) | The domain names a certificate is valid for | shop.example, www.shop.example |
| Issuer | Who signed a certificate | CN=Inter CA |
| Serial number | A unique number the issuer assigns to each certificate | 0x295736b68576... |
| Validity (not before / not after) | The dates a certificate is valid between | 2026-10-30 to 2027-01-28 |
| Extensions | Extra certificate rules | Basic Constraints CA: false |
| Self-signed certificate | A certificate signed by its own key; subject = issuer | Test servers, root CAs |
| Certificate authority (CA) | An organisation that verifies identities and signs certificates | Let's Encrypt |
| Root CA | The top CA, trusted because its certificate is in the trust store | Root CA in Demo 5 |
| Intermediate CA | A CA signed by the root that signs leaf certificates | Inter CA |
| Leaf (end-entity) certificate | The certificate for an actual server or person | shop.example |
| Chain of trust | Leaf ← intermediate ← root, each verified by its parent | Demo 5 |
| Trust store | The list of root certificates a device or browser trusts | Your OS's root store |
| PKI | Public key infrastructure: CAs, certificates, rules and checking software | The web's HTTPS system |
| CSR | Certificate signing request: name + public key, self-signed | Demo 6 |
| PEM | Text format with BEGIN/END lines around Base64 data | -----BEGIN CERTIFICATE REQUEST----- |
| Revocation | Cancelling a certificate before it expires | After a key leak |
| CRL | Certificate revocation list: a signed list of revoked serials | Let's Encrypt's CRLs |
| OCSP | Online Certificate Status Protocol: ask the CA about one certificate | "good" / "revoked" |
| OCSP stapling | The server attaches a signed OCSP answer to the handshake | Saves a lookup, protects privacy |
| Short-lived certificate | A certificate with a short validity period | 47 days by 2029 |
| Certificate Transparency (CT) | Public append-only logs of every issued certificate | RFC 6962 |
| Append-only log | A record you can add to but never edit or delete | CT logs |
| ACME | Automatic Certificate Management Environment: automated issuance and renewal | RFC 8555 |
| Challenge (ACME) | A task proving you control a domain | HTTP-01, DNS-01 |
| Let's Encrypt | A free, automated CA run by ISRG | Launched Dec 2015 |
| Code signing | Signing software so systems can verify the publisher and integrity | Signed app updates |
| Code-signing certificate | A certificate for a software publisher's signing key | Used by OS installers |
Summary
- A hash can't prove who made a message; a digital signature can: sign with the private key, verify with the public key.
- Sign vs encrypt: opposite keys, opposite goals; signing hides nothing.
- RSA-PSS, ECDSA and Ed25519 are the common signature algorithms; Ed25519 is small, fast and deterministic.
- Signatures don't say whose key it is. A certificate (X.509) binds a public key to a name, signed by an issuer.
- A CA vouches for names. Leaf ← intermediate ← root, with the root in your trust store, is the chain of trust; the whole system is PKI.
- You ask for a certificate with a CSR; your private key never leaves your server.
- Stolen keys need revocation (CRL, OCSP, OCSP stapling) and short-lived certificates.
- Certificate Transparency logs catch rogue certificates; ACME and Let's Encrypt automate everything; code signing protects software updates.
Next episode: networking from a security view: the OSI and TCP/IP models, encapsulation, frames, packets and segments, MAC addresses, IP addresses, ports, protocols, and where each security control lives.
Sources: RFC 6962, Certificate Transparency (June 2013), rfc-editor.org; Let's Encrypt, "Ending OCSP Support in 2025" (5 Dec 2024); Sectigo Root Causes 486 on CA/Browser Forum ballot SC-081; "Automated Certificate Management Environment" (Wikipedia mirror) for RFC 8555 (March 2019) and Let's Encrypt's December 2015 launch; CCDCOE cyber law wiki, "DigiNotar (2011)". Code outputs from Python 3.13 with cryptography 50.0.1. Fetched 30 Oct 2026.