The Developer's Guide to TLS

I find most joy in learning things that I know practically nothing about. In this post, I am sharing my newly gained knowledge around TLS. After explaining the importance of TLS (or rather justifying to myself why I'm investing time in this...), this post goes through the basic flows of the basic and mutual TLS.

Why should you care?

Because doge cares. Doge meme about much security

Oh and because TLS is a crucial cryptography protocol that every web developer should at least be aware of. It is the standard technology for securing client-server conversations and yet, one can probably have a happy and successful tech career without knowing its details but what do I know I am a newbie. Usually, it is something you just know exists and works.

A situation at work required me to deep-dive into TLS. In particular, the team needed self-signed certificates as part of a technical spike1. I paired with my colleague Dale (check him out on Twitter) who has an impressive amount of knowledge and industry experience. My only previous experience stems from having had to deal with TLS briefly for my website, actually which I also described in a previous post.

While working on the task, it took me some initially frustrating but eventually rewarding days - Dale was on holiday - to eventually understand it to a bloggable degree. In fact, I am so excited about finally getting it, that I need to share it.

SSL? TLS? mTLS?

SSL and TLS refer to the handshake that happens between a client and a server that enables a secure, confidential conversation that is hard to intercept by third parties. SSL is the predecessor of the TLS protocol which is essentially SSLv4.

TLS can take place one-way, in which only the server has to prove to the client that it is a verified party. On the contrary, mTLS refers to mutual authentication where both conversation parties are verified to each other.

One-way TLS Authentication

In fact, this website, like all that use https, uses this mechanism to securely serve content to the client. In your browser, next to the url bar, you should see a lock sign that means that the source of this website, i.e. my S3 bucket that is accessed through a CloudFront CDN, has a certificate that is trusted by a certificate authority that your browser trusts.

The conversation that takes place between client and server goes approximately like depicted in the below interaction diagram.

The client sends a hello to the server (1). As part of that, it asks about the version of TLS the server implements as well as the cipher is uses.

The server responds with a hello back and sends along the requested information on TLS version and cipher (2). It also sends a certificate that the client then needs to validate. The validation works by checking with authorities if the certificate is known to them. If the validation is successful, the client sends back a key that is encrypted inside the server's certificate (3). Using this key, a master key can be calculated by the client and the server. This negotiated secret can be used for encrypting future messages (4) and so they sent messages securely happily ever after.

Simple TLS interaction diagram

Mutual TLS (mTLS) Authentication

In TLS, there is an option to authenticate the client as well as the server, thus establishing mutual trust. This mechanism is used when the security requirements are higher than usual.

The first step (1) of this client-server interaction is identical to the basic TLS. The difference is that when the server sends back its hello and certificate, it requests the client's certificate (3). The client then complies by sending its certificate that the server can verify (4) as well as a client key which contains a pre-master secret (5).

What is different in mTLS is that the client sends a message that verifies its certificate. The verification message (6) is generated using the client's private key. The server can confirm that the client truly signed it by checking it against the client's public key that was sent along with its certificate.

Everything else continues just like in one-way TLS; Both parties compute the master key and use it to continue to send each other encrypted messages.

Simple TLS interaction diagram

And that is it! That's the TLS handshake. It's the best kind of handshake. Germ-free and secure.

Useful Links


  1. A tech spike is a technical investigation of some sort that helps to drive out risk and uncertainty. It is usually time-boxed.