Demystifying SSL Communication
By: Lovelesh Sharma
Tags: Web Security, Ssl, Cryptography, Tls, Network Security

Demystifying SSL Communication

Understanding how SSL works and steps included in establishing a secure connection

Photo by Glenn Carstens-Peters on Unsplash

In the age of the Internet, everything is available at our fingertips where we are just one click away to get any information from anywhere in the world. This includes our sensitive data as well. This sensitive data needs to be secured so that it does not get exposed to hackers. When we surf the internet or search for any information, it gets transmitted to our browser from a server. The browser to server communication aka client-server communication happens over HTTP protocol. HTTP protocol by itself cannot protect our sensitive data. That’s where SSL comes to rescue.

What is SSL?

SSL stands for Secure Socket Layer. It was developed by Netscape to ensure that private data remains intact when it reaches the browser.

SSL is an encryption based protocol which establishes a secure and trusted connection between browser and the server over which sensitive data can be transmitted.

Once the connection is established, the data can be transmitted securely over the HTTP protocol. The HTTP protocol is now secured and becomes HTTPS protocol, which is nothing but HTTP-Secure or HTTP over SSL. To be able to establish an SSL connection, the server requires an SSL certificate.

SSL Certificate

SSL certificate is an electronic document that contains a public key used to encrypt data. It also contains information about the web site which is used to prove the ownership of the public key. In simple words, it is a document that binds the encryption key with organization details.

SSL certificate helps in establishing a secure connection between browser and server. It can be verified by seeing the green padlock 🔒which appears on the address bar of the browser. We can view the certificate by clicking the padlock.

These certificates are x509 standard certificates, and the encoding of these certificates is done in two formats, DER (Distinguished Encoding Rules) and PEM (Privacy Enhanced Mail). In the DER format, the certificate is stored in binary form, whereas in PEM format, the certificate is stored in a human-readable text form.

A typical PEM certificate looks like this:

-----BEGIN CERTIFICATE-----

MIICEjCCAXsCAg36MA0GCSqGSIb3DQEBBQUAMIGbMQswCQYDVQQGEwJKUDEOMAwG

A1UECBMFVG9reW8xEDAOBgNVBAcTB0NodW8ta3UxETAPBgNVBAoTCEZyYW5rNERE

MRgwFgYDVQQLEw9XZWJDZXJ0IFN1cHBvcnQxGDAWBgNVBAMTD0ZyYW5rNEREIFdl

YiBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBmcmFuazRkZC5jb20wHhcNMTIw

ODIyMDUyNjU0WhcNMTcwODIxMDUyNjU0WjBKMQswCQYDVQQGEwJKUDEOMAwGA1UE

CAwFVG9reW8xETAPBgNVBAoMCEZyYW5rNEREMRgwFgYDVQQDDA93d3cuZXhhbXBs

ZS5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAm/xmkHmEQrurE/0re/jeFRLl

8ZPjBop7uLHhnia7lQG/5zDtZIUC3RVpqDSwBuw/NTweGyuP+o8AG98HxqxTBwID

AQABMA0GCSqGSIb3DQEBBQUAA4GBABS2TLuBeTPmcaTaUW/LCB2NYOy8GMdzR1mx

8iBIu2H6/E2tiY3RIevV2OW61qY2/XRQg7YPxx3ffeUugX9F4J/iPnnu1zAxxyBy

2VguKv4SWjRFoRkIfIlHX0qVviMhSlNy2ioFLy7JcPZb+v3ftDGywUqcBiVDoea0

Hn+GmxZA

-----END CERTIFICATE-----

Let’s dive in and understand how this SSL communication happens.

SSL Communication

The process of SSL communication is also known as an SSL handshake. It involves several steps to establish a secure connection.

Let’s go through these steps in detail 📖

Step 1 — Client Hello

The client (browser) initiates the communication by sending the following details to the server:

Highest SSL version supported

Client Random (for generating encryption key)

Session-Id (blank in case of new session)

Compression Method

Cipher Suites (most preferred at top of the list)

Step 2 — Server Hello

The server replies to the client with the following information:

SSL version selected by the server from the list provided by the client.

Server Random

Session-Id

Compression Method (selected from client’s list)

Cipher Suites (selected from client’s list)

Server Certificate

Step 3 — Client Certificate

This step is optional and is used in 2-way SSL. In this step the client sends its SSL certificate to the server if the server has requested for it in step 2. In this way, the server authenticates the client.

Step 4 — SSL verification

Until now the server hello is done. Now the client verifies the SSL certificate provided by the server by reading the CA (Certificate Authority) from the certificate and by loading the public key of that CA from the browser’s trust store and by verifying the signature. If the certificate is not valid, the browser produces a warning, otherwise, the browser shows a green padlock at the address bar showing the authenticity of the website.

Step 5 — Key Exchange

This step aims at achieving a symmetric key which will be used for further communication. There are various algorithms for doing it. RSA & Diffie Hellman are two of those algorithms. The RSA algorithm uses the server’s public key for confidentiality while exchanging secrets. While in the Diffie Hellman algorithm, no secret key is exchanged and the server’s public key is not used. Here, the secret key of the client and the server changes for every session.

Step 6 — Change Cipherspec

In this step, the client and the server have the key and now onwards the communication happens over an encrypted channel. At this step, the client and server finalizes the cipher spec. This is the last chance to change the cipher spec. After this the key exchange phase finishes.

Step 7 — Encrypted Data Transfer

At this step, the data which is going to be transmitted, goes through a few steps:

The data is divided into small fragments.

Then, these fragments are compressed.

Then, the MAC is calculated and appended to the compressed fragment.

Then, the symmetric encryption happens.

Then, the SSL header is appended at the beginning of the encrypted fragment. This header tells about the SSL record type. For ex., Handshake type, data type, etc.

Finally

After all steps, the browser now has the secure and encrypted connection with the server and sensitive data can be transmitted over. This entire process is transparent and happens within a fraction of seconds.

Conclusion

Well thanks for reaching this far… 👍 I hope this article gave a good grasp of SSL communication and the steps involved in the SSL handshake. Please let me know what you think about this article.