Find a course

Module 4: Public-Key CryptographyLesson 9 of 1115 min

Digital Signatures and Certificates

Learn how signing with a private key proves authorship, how certificates and certificate authorities link public keys to names, and how browsers check them.

Step 1 of 12Learn

Signing: the keys run backward

Encryption uses the recipient's public key so that only they can read. A digital signature flips the roles: the signer uses their private key to sign, and anyone can use the signer's public key to verify.

Signing a document works like this:

  1. Hash the document, for example with SHA-256, producing a short digest.
  2. Apply the signing algorithm to the digest using the private key. The result is the signature.
  3. Publish the document and the signature together.

Verifying:

  1. Hash the received document yourself.
  2. Use the signer's public key to check the signature against that hash.
  3. If it checks out, two things are proven: the document hasn't changed since it was signed (integrity), and it was signed by whoever holds the private key (authenticity). Because only the signer holds that key, they can't plausibly deny signing it (non-repudiation).

Common signature algorithms include RSA signatures (with the PSS padding scheme in new designs), ECDSA on elliptic curves, and Ed25519, a fast, modern elliptic curve scheme designed to avoid implementation pitfalls. ECDSA has a notorious weakness: if a signer ever reuses the per-signature random value, the private key can be computed from two signatures. That exact mistake let hackers extract the code-signing key of a popular game console in 2010. Ed25519 avoids the problem by deriving that value deterministically.

You rely on signatures constantly: operating system updates, app store downloads, HTTPS certificates, signed PDFs and cryptocurrency transactions are all verified this way.

Step 2 of 12Practice · Diagram

Which key does what

Which operation needs the signer's private key?

Tap the shape that answers the question, then press Check.

Which key does whatTwo-by-two matrix: Sender encrypts, Anyone verifies, Recipient decrypts, Signer signs.Sender encryptsAnyone verifiesRecipient decryptsSigner signsPurposeEncryptionSignaturesKeyPrivate keyPublic key
Sender encrypts

Uses the recipient's public key.

Anyone verifies

Uses the signer's public key.

Recipient decrypts

Only the private key holder can.

Signer signs

Only the private key holder can produce the signature.

Step 3 of 12Practice · Match the pairs

Match each operation to the key it uses.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. Encrypting a message for Bob
  2. Decrypting a message sent to Bob
  3. Signing a document as Alice
  4. Verifying Alice's signature

Step 4 of 12Learn

Whose key is this?

Signatures solve the man-in-the-middle problem only if you have the right public key. If Mallory can convince you that her public key belongs to your bank, she can sign anything as the bank. So how does your browser know the public key it received really belongs to the website in the address bar?

The answer on the web is public key infrastructure (PKI), built from certificates.

A certificate is a small signed document that binds a public key to an identity. A website's certificate (an X.509 certificate) contains, among other things:

  • The domain names it's valid for, such as example.com and www.example.com.
  • The site's public key.
  • A validity period, a start and end date.
  • The name of the issuer.
  • The issuer's digital signature over all of the above.

The issuer is a certificate authority (CA), an organization trusted to verify that whoever requests a certificate actually controls the domain. To get one, a site owner proves control, for example by placing a specific file on the web server or adding a DNS record, and the CA signs the certificate.

Let's Encrypt, a nonprofit CA launched in 2015, issues certificates for free with fully automated checks. It now secures hundreds of millions of websites and is a big reason why the large majority of web page loads today use HTTPS.

Step 5 of 12Diagram

What a certificate contains

What a certificate containsParts diagram: X.509 certificate, Subject (domain name), Subject's public key, Issuer (the CA), Validity dates, CA's signature.X.509certificateSubject(domain name)Subject'spublic keyIssuer (theCA)Validity datesCA'ssignature

Tap a shape with to see more.

X.509 certificate
Subject (domain name)

For example www.example.com.

Subject's public key

The key the certificate vouches for.

Issuer (the CA)

Who checked the domain and signed.

Validity dates

Not before / not after.

CA's signature

Binds everything above together. Change one byte and verification fails.

Step 6 of 12Learn

The chain of trust

How does your browser trust the CA's signature? Through a chain of trust.

Your operating system and browser ship with a root store: a list of a hundred or so root CA certificates that their makers have vetted under strict audit programs. Root certificates are self-signed and kept extremely secure, often offline in hardware security modules. Root CAs don't usually sign website certificates directly. Instead, they sign intermediate CA certificates, and intermediates sign the website certificates.

When you visit a site, the server sends its certificate plus the intermediate certificate. Your browser checks:

  1. The site certificate's signature was made by the intermediate's key.
  2. The intermediate's certificate was signed by a root in the root store.
  3. Every certificate in the chain is within its validity period and not revoked.
  4. The domain in the address bar matches a name in the site certificate.
  5. The server proves it holds the site certificate's private key, by signing part of the connection handshake.

If every check passes, you get a secure connection with no warning. If any fails, such as an expired certificate, a wrong domain or an unknown issuer, the browser shows a full-page warning.

The system has a weak point: any trusted CA can issue a certificate for any domain. Mis-issuance has happened; the Dutch CA DigiNotar was hacked in 2011 and issued fake certificates, then was removed from root stores and went bankrupt. Today, Certificate Transparency requires CAs to publish every certificate they issue in public, append-only logs, so domain owners and researchers can spot unauthorized certificates quickly.

Step 7 of 12Practice · Diagram

A certificate chain of trust

Your browser starts at the website certificate and walks up until it reaches a root it already trusts.

Which certificate must already be present on your device for the chain to be trusted?

Tap the shape that answers the question, then press Check.

A certificate chain of trustHierarchy diagram: Root CA (in root store), Intermediate CA, www.example.com, shop.example.org.Root CA (in rootstore)Intermediate CAwww.example.comshop.example.org
Root CA (in root store)

Self-signed, shipped with your OS or browser, kept offline.

Intermediate CA

Signed by the root; does day-to-day signing.

www.example.com

Leaf certificate presented by the server.

shop.example.org

Another leaf signed by the same intermediate.

Step 8 of 12Practice · Put in order

Order the checks a browser makes when validating a website certificate chain, starting from the certificate the site sends.

Drag the items, or use the arrow buttons, to put them in order.

  1. Check validity dates and revocation status for the chain
  2. Confirm the server holds the certificate's private key
  3. Verify the site certificate was signed by the intermediate CA
  4. Verify the intermediate was signed by a root in the trusted store
  5. Confirm the domain in the address bar matches the certificate

Step 9 of 12Note

Step 10 of 12Practice · Select all that apply

Which of these does a valid HTTPS certificate tell you? Select all that apply.

Select all that apply.

Step 11 of 12Practice · What would you do?

What would you do?

A user receives an email with a link to paypa1-security.com. The page shows a padlock and a valid certificate. The user concludes the site must be legitimate because the connection is secure. What's the flaw in that reasoning?

Step 12 of 12Practice · True or false

If an attacker modifies a signed software update after it is signed, verification with the publisher's public key will fail.