The SSL handshake sets up every HTTPS connection.
Let’s talk about the SSL handshake. On the internet, SSL/TLS is the accepted solution for securing connections between a webserver and its visitors. You may not realize it, but you use SSL every day. If you see HTTPS and/or the padlock icon in your browser’s address bar, you have a secure connection with that site created by SSL/TLS.
In the last few years, SSL/TLS has gotten much more publicity and attention from the public and the I.T. industry as part of a larger focus on user security. Last year, 50% of all web traffic was encrypted with SSL/TLS for the first time. But many people still don’t really know how SSL/TLS works.
One of the most important parts of the SSL/TLS protocol is the SSL handshake. The handshake is where each connection ‘begins’ and where the technical underpinnings of SSL/TLS are established.
To help you understand the SSL handshake process, we wrote two explanations. The next section explains the handshake broadly with minimal use of technical terms. The “Step by Step” section goes in-depth into the exact workings of the handshake.
A Summary of the SSL Handshake
The ‘handshake’ is the technical name of the process that establishes an HTTPS connection. Most of the hard work involved in the SSL/TLS protocol is done here.
An HTTPS connection involves two parties: the client (who is initiating the connection, usually your web browser), and the server. These two parties are the ones that ‘shake hands.’ The purpose of the SSL handshake is to perform all the cryptographic work needed to have a secure connection. This includes authenticating the SSL certificate being used and generating an encryption key.
Every piece of software is different. So the first steps of the handshake have the client and server share their capabilities so that they can find the cryptographic features they mutually support. Web browsers are the most common client, but features vary between popular browsers like Chrome, Firefox, Internet Explorer. Likewise, on the server side, popular operating systems like Windows Server, Apache, and NGINX have very different feature support.
Once a client and server agree on the exact encryption methods they will use, the server sends the client its SSL certificate. The client will check to make sure the certificate is “authentic” – this is an extremely important step. To truly have a secure connection, you can’t just encrypt your data, you also need to know it is being sent to the right person/place. SSL certificates provide that assurance.
SSL certificates are created and signed by a Certificate Authority (CAs), which are companies that have been approved to issue certificates. You likely know some of the most popular CAs like Symantec and Comodo. Those CAs follow industry standards to make sure that you can only get a certificate for a website or company you truly own.
During the handshake, the client will perform cryptographically secure checks to make sure the certificate provided by the server is authentic. This includes checking the digital signature and making sure the certificate originates from a trusted CA.
The client will also get proof that the server owns the private key associated with the certificate. All SSL certificates contain a key pair consisting of a public and private key. The public key is used to encrypt data, and the private key is used to decrypt. This is known as “asymmetric” encryption because the two functions are performed by different keys.
With the most common type of key, RSA, the client will encrypt random data with the public key that needs to be used to generate the session key. The server will only be able to decrypt and use that data if it has the private key, which provides proof of possession. If another type of key is used this process changes, but proof of possession is always checked.
The last part of the handshake involves creating the “session key” which is the key that will actually be used for secure communication. Session keys are “symmetric,” meaning the same key is used for encryption and decryption. These keys can achieve strong encryption much more efficiently than asymmetric keys, making them appropriate for sending data back and forth in an HTTPS connection.
To end the handshake, each party lets the other know they have done all the necessary work and then they both run checks to make sure the handshake occurred without any malicious tampering or corruption.
The entire handshake takes places in a few hundred milliseconds. It’s the first thing that must happen in an HTTPS connection, even preceding the webpage loading.
Once the handshake is complete, the encrypted and authenticated HTTPS connection begins and all the data being sent and received between you and the server is protected. Every time you revisit a site, the handshake will occur again. Many servers implement a “resumption” process for efficiency and speed.
The SSL Handshake: Step by Step
The handshake involves a series of steps, which accomplish the three main tasks we summarized above: exchanging encryption capabilities, authenticating the SSL certificate, and exchanging/generating a session key.
For those looking to understand the exact process, here are the steps involved. Note that in TLS 1.3, the forthcoming protocol version, the handshake design has changed, thus these steps do not apply to TLS 1.3.
The steps are illustrated to show the client on the left and the server on the right. Each step has a directional arrow in the middle to show who is receiving the message:
- The first message is the “ClientHello,” which is sent to the server. This message lists the client’s capabilities so that the server can pick how they will communicate.
- The server responds with the “SeverHello” message. In this message it tells the client what connection parameters it has selected from the provided list. If the client and server do not share any capabilities in common, the connection terminates unsuccessfully.
- In the “Certificate” message, the Server send’s its SSL certificate chain (which includes its leaf certificate and intermediate certificates) to the client. To provide authentication to the connection, which is as important as encryption, an SSL certificate is signed by a CA which allows the client to know the certificate is legitimate. The client will then perform checks to ensure the certificate is legitimate. This includes checking the certificate’s digital signature, verifying the certificate chain, and checking for any other potential problems with the certificate data (expired certificate, wrong domain name, etc). The client will also make sure the server has possession of the certificate’s private key. This is done during the key exchange/generation process.
- This is an optional message, only needed for certain key exchange methods which require that the server provides additional data.
- The “Server Hello Done” message tells the client that it has sent over all its messages.
- The client then provides its contribution to the session key. The specifics of this step depend on the key exchange method that was decided on in the initial “Hello” messages. TLS uses two different keys: a public/private key pair (which is part of the SSL certificate), and a session key which is generated during the handshake. The session key is a “symmetric key.” It’s the key used during the HTTPS connection because its significantly faster and more efficient that using the public/private key pair, which is “asymmetric” and inherently slower. The public/private key is only used during these steps for the secure transmission of the session key.
- The “Change Cipher Spec” message lets the other party know that it has generated the session key and is going to switch to encrypted communication.
- The “Finished” message is then sent to indicate that the handshake is complete. The Finished message is encrypted, and is the first data protected by the session key. The message contains data that allows each party to make sure the handshake was not tampered with.
- Now it’s the server’s turn to do the same. It sends its “Change Cipher Spec” message to indicate it is switching to encrypted communication.
- The server sends its “Finished” message.
Original Article: https://www.thesslstore.com/blog/explaining-ssl-handshake/ by Vincent Lynch