Podcast
Root Causes 430: How Does a TLS Handshake Work?


In this episode we give a high level explanation of what happens in a TLS 1.3 handshake and then discuss what will happen when PQC is included.
Podcast Transcript
We tried to do this a few times. One of the most recent ones was we tried to explain lattice mathematics. And let me try and tell you what we try to do with these podcasts, which is, I oversimplify to the point where I know that the tech people who really understand it are going to throw stones at me because they're like, that's partly wrong. I want to take the pedantic out of it, because I want people to understand what's really going on, and there's a purpose to understanding it, and that's what we'll get to at the end of this, Tim.
So the TLS 1.3 handshake is what happens when you go to www.timswebsite.com and Tim’s website.com is being served by a web server and your web browser are making a handshake. And if there is an SSL certificate, a TLS certificate, that is actually being used to encrypt the communication between the web server and web browser, there initially has to be a handshake between the browser and the server, and these are two parties that do not know each other from beans. You're going over the hostile internet.
And a miracle happens, an encrypted session happens between the web server and the browser, and you don't think about it, and that's a good thing. It's good that you are browsing for your news and doing your banking and whatever you're doing on your browsing, and you're able to do this over the hostile internet. It's a real miracle.
But this TLS 1.3 handshake, TLS 1.3 added some defaults, Tim, that were really important that I think people need to know about. But let's talk about what occurs in the handshake. And the very first thing is the browser makes the initiation. The browser actually goes off and says to the web server, the address to that web server has been resolved. You go to paypal.com. Well, paypal.com actually translates into a DNS. And then there is a client hello that is sent over to the web server. And so that client hello actually comes along with some things, and that is a random number and a cipher suite menu.
So in other words, the browser says to the web server, hey, I'm capable of receiving a public key that has been generated with RSA or ECC, as an example. And of course, if this is an ongoing session, the pre-shared key will be included in the client hello. But we're talking about you've never talked to this website before. And so that client hello is a random number and a menu of your cipher suite that is available. Interesting. The reason I mentioned that cipher suite is what happens in post-quantum. Your cipher suite is gonna be a lot more exotic than it is today.
So, number two, the server now chimes in, and the server actually chooses its own random number, sends that to the client, and then also makes a cipher suite choice. It's the server that says RSA or ECC, because it's the server who's actually gonna, in this next step, send the browser the public key.
That occurs. Now, the one thing that is also sent is if the public cert happens to be elliptic curve based, ECC, then some parameters around how to deal with ECC are also sent. Because, in other words, there are many kinds of elliptic curves. Which ones are we using in this particular public cert? So that's also sent. So the public cert is sent, and the parameters, if it's ECC, is also sent. The client then takes that public certificate, and if it chains up to a certificate that's in its trust store, then it knows, okay, I'm dealing with a trusted, valid, publicly trusted certificate, and we can start to really, truly, begin to do the next set of steps. So is it the public key that actually is then encrypting the communication? It's not, Tim.
And then what happens is that pre-master secret, which is generated by the client, is encrypted by the public key that came from the web server.
And then really what happens - the final step - is the key generation occurs. And this key generation is the key pair that will be involved with the actual encrypted communications. But here's the miracle, Tim. This key generation happens on both the web server and the client side, and both the client and server independently come up with a key pair that is the same. How in the world could it be the same? And it's because of these random numbers that were done in step one and two.
I don't think people realize that the public cert, which is something that the web server had to do a lot of work with a CA to get and to get into that root store ultimately, and do that chain of trust all the way up, is not what is doing the encryption of the communication. It’s the session keys that are generated independently and identically on both sides.
And the beauty of having fresh session keys every session is that you get, you get the advantage of forward secrecy. So you just made one of the really good points. This happens so fast that that's why you don't think about it.
Number two, forward secrecy is awesome, because if your communication is being recorded, there's nothing stopping a bad guy from being right in the middle of recording this encrypted session, but until quantum computers come around, it's going to be awfully difficult to decrypt this encrypted session. The beauty is, is that these session keys are what is enabling a fresh set of encryption. So if one of the private keys of that gets compromised, then only one session will be decrypted. Let's say you and I had a permanent set of keys that we always encrypted with.