Part 5 of 8 · 2 min read
A private channel: TLS
Encryption, proof of identity and tamper detection, and the certificate problem.
Think of a letter sent in a sealed envelope with a wax seal. The envelope hides the contents. The seal shows who sent it and proves no one opened it on the way.
TCP delivers bytes, but anyone on the path can read them. TLS wraps the channel in protection.
TLS
TLS (Transport Layer Security) is a protocol that runs on top of TCP and gives three things: encryption (only the two ends can read the data), authentication (the client knows it is talking to the real server) and integrity (any change to the data on the way is noticed).
Example: when a browser shows a padlock, TLS is protecting the connection.
Encryption. The two sides agree on a shared secret key, without sending it over the wire. They use a method with pairs of keys: a public key, which can be shared with anyone, and a private key, which is kept secret. A slow but clever method creates the shared key. After that, a fast method uses the shared key for all data. The key is changed every so often, so a stolen key exposes only a little data. The extra processing cost is small on modern machines. The rule of thumb is to use TLS for every connection, including those between a company's own servers.
Authentication. Encryption is not enough. A client must know it is talking to the real server and not to an impostor. The server proves its identity with a certificate.
Certificate
A certificate is a signed document that ties a public key to a named owner, such as a website. It carries the owner's name, an expiry date, the public key and the signature of the company that issued it.
Example: the certificate of www.example.com says that this public key belongs to that website.
The signer is a certificate authority. Its own certificate is signed by a higher authority, and so on, up to a root authority whose certificate every device already trusts. The server sends the whole chain. The client checks it link by link, including the expiry dates and the signatures.
Integrity. Each message carries a short fingerprint calculated from its contents and the shared key. The receiver recomputes it. If they differ, the message was damaged or changed, and it is dropped. TCP's checksum is not enough for this, because it is weak and cannot stop an attacker.
Common mistake
Letting a certificate expire. When that happens, clients refuse to connect, and a perfectly healthy service goes down. Automation that watches expiry dates and renews certificates in good time is well worth building.
Cost. TLS adds at least one more round trip before data flows, and more for older versions. Reusing connections is the main way to avoid paying it again and again.
Check yourself:
- Which of the three things TLS gives would stop an impostor?
- Why does an expired certificate break a service?