Encryption, from the ground up · Puzzle 7 · 8 of 9

Proof of who you are

In puzzle 3, the key exchange worked with whoever answered, and in puzzle 5 an attacker could swap a digest. Both gaps close the same way: a mark on the data that only the real server can make.

The problem

Two gaps are open. In puzzle 3, your app agreed on a secret with whoever answered, which might be the listener pretending to be your server. In puzzle 5, a digest only helped if the attacker couldn't swap it. Both come down to one question: how does your app know that something really comes from your server?

See it

The server has a private key and a public key; it signs a digest with the private key; the app checks it with the public key; a certificate signed by an authority the phone trusts says which public key is the server's; a listener's fake fails your server your app privatepublic digest + private key= signature checks out ✓ certificatename + public key✓signed by authority
  1. Unlike puzzle 2's single key, the server has a key pair: a private key it never shows, and a public key anyone may have.

    Step 1 of 4
  2. It hashes the data and runs the digest through a step only its private key can do: a signature.

    Step 2 of 4
  3. Your app checks it with the public key. It only checks out if the private key made it and the data is unchanged. Predict: but whose public key is it?

    Step 3 of 4
  4. A certificate says so: the server's name and public key, signed by a certificate authority whose key your phone already trusts.

    Step 4 of 4

The building block

This needs a different kind of key from puzzle 2. There, one key did both jobs. Here the server has a key pair: two keys made together, a private key it never shows anyone and a public key anyone may have. What one does, only its partner can check. That's why this kind is also called asymmetric.

  • To make a signature, the server hashes the data (puzzle 5) and runs the digest through a signing step that needs its private key.
  • Anyone with the public key can check the signature against the data: it checks out only if it was made with the matching private key and the data hasn't changed since.
  • Without the private key, nobody can make a signature that checks out. Not the listener, not anyone. (Signing isn't encrypting: the data stays readable; the signature only proves who made it and that it's unchanged.)

So a signature proves two things at once: who sent it, and that it wasn't changed. That closes puzzle 4's gap: in HTTPS, the server signs the key exchange, including its public value, so a swapped value from a man in the middle can't carry the server's signature.

That moves the question: how does your app know which public key is really your server's? A listener could hand over its own. The answer is a certificate: a small document with your server's name and its public key, signed by a certificate authority, an organization whose public key is already built into your phone. Before it signs, the authority checks that whoever asks really controls that name. Certificates aren't secret: your server shows its certificate to every visitor, so anyone can copy one. A certificate signed by anyone else, including one the server signs itself, fails that check. Your app checks the authority's signature on the certificate, checks that the name matches the one in the address it asked for, and from then on trusts that public key. Puzzle 8 shows why a copied certificate alone gets the listener nowhere.

Note the look-alike from puzzle 3: a key exchange's private value is thrown away when the connection ends; a server's private key is kept for years and proves who it is.

The analogy

A wax seal. Only the king has the seal (private key), but everyone knows what it looks like (public key), so anyone can check a letter is really his and unopened. And how do you know what the king's seal looks like? A register kept by someone you already trust (the certificate authority) shows it, with the king's name beside it.

Check yourself

A listener makes its own certificate with your server's name and its own public key. What does your app see?

Not quite. The name isn't enough: the certificate must carry a trusted authority's signature.

Right. Only an authority's signature makes a certificate trusted.

Not quite. Only a signature from an authority your phone trusts counts, and authorities check who controls the name. Re-read that part ↑

Why can't anyone make a signature that checks out with your server's public key?

Not quite. Signing doesn't need AES; it's the private key that makes it unforgeable.

Not quite. Public keys are meant to be shared; the protection is the private key.

Right. No private key, no valid signature.

What's the difference between a server's private key and a key exchange's private value?

Not quite. They're separate: one proves identity, the other makes this connection's secret. Re-read that part ↑

Right. Long-lived identity vs one-time secret.

Sources

What you now know

A key pair is a private key the owner keeps and a public key anyone may have. Signing computes a signature from a digest and the private key; anyone can check it with the public key, and nobody can fake it without the private key. A certificate is a server's name and public key, signed by a certificate authority your phone already trusts.