Basics of SSL/TLS secure connection

SSL (Secure Sockets Layer) and TLS (Transport Layer Security) are cryptographic protocols designed to provide a secure communication channel over the Internet. While SSL is the older of the two, TLS is the more modern and secure protocol; however, the term "SSL" is still commonly used to refer to either protocol. These protocols are used to secure data transmissions, ensuring privacy, data integrity, and authentication in applications like web browsers, email, and VoIP services.

Why it was invented?

SSL/TLS was invented to address the inherent security vulnerabilities in the transmission of data over the internet, particularly when it is transmitted in plain text. Before SSL/TLS, data exchanged between the client and server could be easily intercepted, read, modified, or stolen by attackers due to the lack of encryption. Here’s a deeper look into the reasons behind the invention of SSL/TLS:

1. Privacy and Confidentiality:

  • To ensure that sensitive information such as passwords, credit card numbers, and personal details are not exposed to eavesdroppers or unauthorized entities during transmission.

2. Data Integrity:

  • To ensure that the data sent between two parties is not tampered with or altered during transit by malicious actors.

3. Authentication:

  • To authenticate the identity of the parties involved in the communication, primarily the server, and in some cases, the client. This is crucial to avoid man-in-the-middle attacks where an attacker could impersonate the server or client.

4. Secure E-Commerce Transactions:

  • With the rise of the internet, there was a growing need for secure online transactions. SSL/TLS provided a way for users to verify the authenticity of a website and ensure the confidentiality and integrity of the financial and personal information exchanged during online transactions.

History and Evolution:

  • SSL: Developed by Netscape in the mid-1990s, SSL was one of the first protocols to secure communications on the internet.

  • TLS: Developed as a successor to SSL, TLS was standardized by the Internet Engineering Task Force (IETF) to address various vulnerabilities and shortcomings in the SSL protocol.

Development of the Protocols:

  • SSL 1.0: Developed internally by Netscape and was never publicly released due to serious security flaws.

  • SSL 2.0: The first public release of SSL by Netscape in 1995 but was quickly found to have several security flaws.

  • SSL 3.0: Released by Netscape in 1996 to address the vulnerabilities in SSL 2.0.

  • TLS 1.0: Published by IETF in 1999 as an upgrade to SSL 3.0 and included numerous improvements and enhancements for security and performance.

  • Subsequent TLS Versions: TLS 1.1, TLS 1.2, and TLS 1.3 were released to continually address new vulnerabilities and enhance the security and performance of the protocol.

SSL/TLS remains crucial for the security of communications over the internet, and its invention has been pivotal in enabling the growth of e-commerce and secure communications online.

Basic Working:

  1. Handshake Phase:

    • The client and server establish a connection, and the client requests a secure session.

    • The server responds by sending a digital certificate, including its public key.

    • The client verifies the server's certificate and generates a pre-master secret.

    • The client encrypts the pre-master secret using the server’s public key and sends it back to the server.

    • Both the client and the server use the pre-master secret to generate a session-specific symmetric key, called the session key.

  2. Data Transfer Phase:

    • After the secure connection is established, the client and the server use the session key to encrypt and decrypt the data exchanged between them.
  3. Closure Phase:

    • Once the session is completed, the session key is discarded, ensuring that each session has unique encryption, which helps in protecting against certain types of attacks.

TLS Handshake process

The handshake phase of TLS is a crucial step where the client and the server agree on various parameters to establish a secure connection. Below are the detailed steps of the TLS handshake phase:

1. ClientHello Message:

  • Client Sends:

    • Supported TLS versions.

    • List of supported cipher suites (combinations of cryptographic algorithms).

    • Supported compression methods.

    • Randomly generated data, called the Client Random.

    • Other extensions (e.g., SNI to specify which host it is trying to connect to).

2. ServerHello Message:

  • Server Responds With:

    • Chosen TLS version from the list provided by the client.

    • Chosen cipher suite from the list provided by the client.

    • Randomly generated data, called the Server Random.

    • Other negotiated parameters and extensions.

3. Server Certificate:

  • Server Sends:

    • Its digital certificate, containing the public key and information about the server’s identity.

    • The certificate chain if intermediate certificates are present.

  • Client Does:

    • Verifies the server's certificate against its list of trusted certificate authorities (CAs).

    • Checks if the certificate is expired, revoked, or if it matches the server's hostname.

  • Note: If the client cannot verify the server's certificate, it terminates the connection.

4. Key Exchange:

  • Client Generates:

    • Pre-master secret.
  • Client Sends:

    • Pre-master secret encrypted with the server's public key (in RSA key exchange).
  • Or alternatively, in the case of Diffie-Hellman key exchange:

    • Both client and server independently generate public-private key pairs and exchange the public keys, keeping their private keys confidential.

5. Deriving the Session Key:

  • Both the client and the server independently use the pre-master secret and the Client and Server Random values to derive the symmetric session key.

  • The session key is used for encrypting and decrypting the application data during the secured session.

6. Finalizing Handshake:

  • Client Sends:

    • A "Finished" message, encrypted with the derived symmetric key, indicating that it is switching to encrypted mode.
  • Server Responds With:

    • Its "Finished" message, also encrypted, indicating it is switching to encrypted mode as well.
  • At this point, the “Change Cipher Spec” protocol is activated, and subsequent communication is encrypted using the derived keys.

7. Data Transfer:

  • Once the handshake is completed, the client and the server can securely exchange application data over the established secure connection.

8. Session Resumption:

  • To avoid the overhead of repeating the full handshake in future connections, both parties can agree to resume the previous session by using session identifiers or session tickets.

The handshake phase is a complex but integral part of TLS, enabling the client and server to agree on how to securely communicate, authenticate each other, and establish encryption keys, thus ensuring the confidentiality and integrity of the transmitted data.

TLS/SSL in Web Browsing:

In the context of web browsing, when you visit a website that uses HTTPS, the communication between your browser and the server is secured using TLS/SSL, ensuring that any sensitive information you share is secure.


  • Security: TLS includes improved security features over SSL.

  • Algorithm Flexibility: TLS is more flexible in terms of supporting newer and more secure cryptographic algorithms.

  • Performance: TLS can be more efficient due to the support for more efficient cryptographic algorithms.


TLS/SSL is implemented in various layers of the tech stack, such as:

  • Web servers (e.g., Apache, Nginx)

  • Load balancers

  • Content Delivery Networks (CDN)

  • Browsers

  • Email servers

  • Database connections


  • SSL has three versions: SSL 1.0, SSL 2.0, and SSL 3.0.

  • TLS has several versions: TLS 1.0, TLS 1.1, TLS 1.2, and TLS 1.3, with TLS 1.3 being the most recent and secure.

TLS session parameters

Several parameters are crucial in the TLS protocol to ensure the secure transmission of data. These parameters are exchanged or negotiated during the TLS handshake process between the client and the server.

1. Protocol Version:

  • Determines the TLS version to be used for the session. It is important to use the most secure and updated version of TLS (currently TLS 1.3) to avoid vulnerabilities present in older versions.

2. Cipher Suites:

  • A set of cryptographic algorithms that are used for securing the communication session. It includes algorithms for key exchange, authentication, encryption, and Message Authentication Code (MAC). Choosing strong and secure cipher suites is essential for the security of the communication.

3. Public and Private Keys:

  • The server’s public and private keys are critical for establishing a secure connection. The public key is shared with the client during the handshake, while the private key remains confidential and is used by the server to decrypt messages received from the client.

4. Certificates:

  • Digital certificates are used to authenticate the entities involved in the communication and establish trust. They contain the public key and information about the entity’s identity, and they are signed by a trusted Certificate Authority (CA).

5. Random Values:

  • Both the client and the server generate random values during the handshake, which are used, along with the Pre-Master Secret, to derive the symmetric session key.

6. Pre-Master Secret:

  • A secret value generated by the client and securely transmitted to the server during the handshake. It is used, along with the random values, to derive the symmetric session key.

7. Session Key:

  • A symmetric key derived from the Pre-Master Secret and random values, used to encrypt and decrypt the data exchanged during the session.

8. Extensions:

  • These are used to negotiate additional functionalities and features between the client and server, such as Server Name Indication (SNI) for hosting multiple domains on a single IP address, or Application-Layer Protocol Negotiation (ALPN) for negotiating the application-layer protocol.

9. Compression Methods:

  • While older TLS versions supported compression methods to reduce the amount of data transmitted, they have been found to be insecure and are generally not used in modern TLS versions due to vulnerabilities like CRIME.

10. Session Identifiers and Tickets:

  • These are used to resume previous sessions without performing a full handshake, improving the performance of the secure connection.


  • The proper selection and management of these parameters are crucial for maintaining the security and integrity of the data transmitted between the client and the server.

  • Utilizing updated protocol versions, secure cipher suites, and proper key management practices are essential to safeguard against vulnerabilities and attacks.

Bash script to get info about TLS connection parameters

When a client establishes a TLS connection, it can view several parameters related to the connection, including:

  • The SSL/TLS version being used.

  • The cipher suite negotiated between the client and the server.

  • The server’s digital certificate, which includes the public key and information about the server’s identity.

You can use OpenSSL to view these parameters for a given website from the command line. Here’s a simple Bash script that takes a domain name as an argument and displays the SSL/TLS connection parameters:


if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <domain>"
    exit 1


echo "Connecting to $domain on port 443..."

# Extracting Certificate Information and Cipher and Protocol Information.
certificate_info=$(echo | openssl s_client -connect "$domain:443" -servername "$domain" 2>/dev/null | openssl x509 -noout -text)

# Extracting and Displaying Desired Certificate Parameters.
echo "$certificate_info" | grep -E 'Subject:|Issuer:|Not Before:|Not After :|Public Key Algorithm:|RSA Public-Key:|Signature Algorithm:'

echo "Cipher and Protocol Information:"
echo | openssl s_client -connect "$domain:443" -servername "$domain" 2>/dev/null | grep -E 'Cipher|Protocol'

Example usage with domain:

Code is available at:


SSL/TLS protocols are crucial in maintaining the confidentiality and integrity of data transmitted over the Internet by encrypting the data and providing secure communication channels. Transitioning to more modern versions, like TLS 1.3, is recommended for enhanced security and performance.


  1. Transport Layer Security (TLS) - Computerphile

  2. Secure Web Browsing - Computerphile

  3. TLS Handshake Explained - Computerphile

  4. What Is An SSL/TLS Certificate?

  5. TLS vs SSL: What’s the Difference? Which One Should You Use?


  7. TLS 1.3, the new and more efficient version of secure web