Part 2 of 9 · 3 min read
TLS
Encryption, authentication and integrity for a network connection.
Sending bytes over a network is like sending a postcard: anyone along the route can read or change it. UDS says the answer is Transport Layer Security (TLS). It runs on top of TCP and encrypts the channel so that protocols such as HTTP can use it safely (HTTP over TLS is HTTPS). In short it gives three things: encryption, authentication and integrity.
Encryption. Data is scrambled so that only the two ends can read it. When the connection opens, client and server each make a pair of keys, one private and one public. By swapping public keys they work out a shared secret, which is never sent over the wire. This asymmetric step is slow, so it is used only to agree a key. After that, fast symmetric encryption with the shared key carries the data, and the key is renegotiated from time to time to limit what a broken key can reveal. UDS says the cost in CPU is negligible on modern processors, and that unless there is a very good reason, TLS should be used for all communication, even inside your own network.
Authentication. The client must check that the server is who it claims to be. The server proves it by signing messages with its private key, and the client checks the signature with the matching public key. But how does the client know the public key is the real one? A certificate proves ownership of a public key. It holds the owner's details, an expiry date, the public key and the digital signature of the certificate authority (CA) that issued it. The CA itself has a certificate, and the chain ends at a root CA that signs its own. A device trusts a certificate if it, or one of its ancestors, is in the device's trusted store. Root CAs run by the large public authorities are in that store by default. The client checks the chain, including expiry dates and signatures.
Integrity. TLS adds a message digest (an HMAC), so if bits are swapped or damaged, the receiver sees a mismatch and drops the message. UDS notes that TCP's own checksum lets through damage in somewhere between 1 in 16 million and 1 in 10 billion packets. With 1 KB packets, that is one bad packet per 16 GB to 10 TB sent.
Handshake. At the start the two sides agree a cipher suite (the set of algorithms), create the shared secret, and the client verifies the server's certificate. The server may also verify a client certificate. It takes 2 round trips with TLS 1.2 and one with TLS 1.3, so opening a connection is costly, which is a reason to reuse connections and to place servers near clients.
The classic outage. UDS says one of the most common TLS mistakes is letting a certificate expire. Clients can no longer verify the server, connections fail, and a whole service can go down. Automatic renewal and a monitor on expiry dates (module 2) are worth the effort.
Certificate
A certificate is a signed document that ties a public key to a named owner and an expiry date, so that others can trust the key.
Example: the certificate for shop.example.com is signed by a CA that your browser already trusts, and is valid until 2027-03-01.
Check yourself: 1. What three guarantees does TLS give? 2. Why is symmetric encryption used for the data itself? 3. What happens when a certificate expires?