HTTPS

HTTPS is a communication protocol composed by two phases:

  • Establishment of Secure Connection with TLS Handshake

  • Exchange of HTTP messages

    • Encryption of the HTTP request using the session key and sending of it to the server over the secure TLS connection

    • Decryption of the HTTP request on the server using the session key

    • Processing of the HTTP request on the server

    • Encryption of the HTTP response on the server using the session key

    • Sending of encrypted HTTP response

    • Decryption of HTTP response on the client with the client private key

    • Rendering/Processing of the HTTP response on the client

TLS Handshake

The TLS (Transport Layer Security) handshake is the process by which a client and server establish a secure communication channel. This process involves negotiating encryption algorithms, authenticating the server (and optionally the client), and generating shared keys for encrypting the communication.

TLS Handshake Process:

The TLS handshake consists of several steps that allow the client and server to negotiate and establish a secure connection.

  1. Client Hello:

    • The client (e.g., a web browser) sends a Client Hello message to the server to initiate the handshake. This message includes:

      • Protocol version (e.g., TLS 1.2 or TLS 1.3).

      • Cipher suites supported by the client (e.g., AES, RSA, ECC).

      • Compression methods supported (e.g., no compression or deflate).

      • Random number: A random number generated by the client, which will be used to generate session keys later.

      • Session ID: If the client wants to reuse a previous session, it includes the session ID.

    Example (simplified Client Hello in TLS 1.2):

    ClientHello
    Version: TLS 1.2
    Cipher Suites: TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA
    Compression Methods: NULL
    Random: (Client Random)
    Session ID: (Empty, as this is a new session)
  2. Server Hello:

    • The server responds with a Server Hello message, which includes:

      • Chosen protocol version: The server selects the highest protocol version that both the client and server support (e.g., TLS 1.2 or 1.3).

      • Chosen cipher suite: The server selects the strongest cipher suite from the list provided by the client.

      • Random number: Another random number generated by the server.

      • Session ID: If the server supports session resumption, it sends a session ID that allows the client to resume a previous session.

    Example (simplified Server Hello in TLS 1.2):

    ServerHello
    Version: TLS 1.2
    Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA
    Random: (Server Random)
    Session ID: (New session ID)
  3. Server Certificate:

    • The server sends its digital certificate (signed by a trusted certificate authority, CA) to the client. This certificate includes the server's public key and proves the server's identity.

    • The client verifies the server's certificate using a list of trusted certificate authorities (CAs).

    Example:

    Certificate: (Server's public certificate, signed by a CA)
  4. Server Key Exchange (Optional):

    • If the chosen cipher suite requires the server to provide additional information (e.g., Diffie-Hellman parameters for key exchange), the server will send a Server Key Exchange message. This is necessary for key exchange algorithms like ECDHE (Elliptic Curve Diffie-Hellman Ephemeral) or DHE (Diffie-Hellman Ephemeral).

  5. Server Hello Done:

    • The server signals that it has finished its part of the handshake by sending a Server Hello Done message.

  6. Client Key Exchange:

    • The client sends a Client Key Exchange message, which typically includes a pre-master secret encrypted with the server's public key. This pre-master secret will be used to generate the session key.

    For example, in RSA-based key exchange:

    ClientKeyExchange: (Pre-master secret encrypted with server's public key)
  7. Key Derivation:

    • Both the client and server independently derive the same session keys (used for encryption and integrity checks) from the pre-master secret and the random numbers exchanged earlier.

  8. Finished Messages:

    • Both the client and the server send Finished messages, which are the first messages encrypted with the session key. This confirms that the handshake is complete, and the session is now secure.

    • The message is used to verify that the handshake process has not been tampered with.

    Example (client and server send "Finished" messages):

    Finished: (Encrypted with session key)
  9. Secure Communication Begins:

    • After the handshake, both the client and server can now securely exchange application data (e.g., HTTP requests and responses) using the session key for encryption.


TLS Versions

  1. TLS 1.2:

    • Cipher Suite Negotiation: TLS 1.2 allows a wide range of cipher suites (e.g., RSA, DH, ECDHE) and hashing algorithms (SHA-1, SHA-256, etc.).

    • Server Certificate and Key Exchange: The server provides a certificate, and the client performs the key exchange using RSA or Diffie-Hellman (DH).

  2. TLS 1.3:

    • Simplified Handshake: TLS 1.3 reduces the number of messages in the handshake, speeding up the process.

      • The client and server exchange fewer messages to establish a secure connection, requiring only 1 round-trip (compared to 2 round-trips in TLS 1.2).

    • No RSA Key Exchange: TLS 1.3 removes the RSA-based key exchange in favor of forward secrecy mechanisms (e.g., ECDHE).

    • Stronger Security: It removes support for outdated algorithms (e.g., RC4, SHA-1, and DES) and mandates the use of stronger ciphers like AES-GCM and ChaCha20-Poly1305.

    Example of the ClientHello in TLS 1.3:

    ClientHello
    Version: TLS 1.3
    Cipher Suites: TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384
    Extensions: supported_versions, elliptic_curves, signature_algorithms
    Random: (Client Random)

    ServerHello in TLS 1.3:

    ServerHello
    Version: TLS 1.3
    Cipher Suite: TLS_AES_128_GCM_SHA256
    Random: (Server Random)

    Finished Message in TLS 1.3:

    Finished: (Encrypted with session key)

Summary of TLS Handshake and Versions:

  • TLS Handshake: Establishes a secure channel through a series of steps: Client Hello, Server Hello, Certificate Exchange, Key Exchange, and Finished messages.

  • TLS Versions:

    • TLS 1.0 and 1.1 are deprecated and insecure.

    • TLS 1.2 is widely used today.

    • TLS 1.3 improves security, reduces handshake latency, and mandates stronger ciphers by simplifying the handshake

Last updated