Skip to content
Glossary 7 Connection Type: 2 views

TLS Handshake

Explore the TLS handshake process when using a proxy. Learn how GProxy secures your connection, ensuring data integrity and privacy.

Security

A secure connection is established through a proxy via the TLS handshake, where the client and the ultimate server (either the origin or the proxy itself, depending on configuration) authenticate identities and negotiate cryptographic parameters to create an encrypted communication channel. This process ensures data confidentiality, integrity, and authenticity for applications communicating across networks.

Understanding the TLS Handshake

The Transport Layer Security (TLS) protocol is fundamental for securing internet communications. It operates above the transport layer (TCP) and provides end-to-end encryption and authentication. The TLS handshake is the initial negotiation phase where the client and server agree on the cryptographic parameters and establish a secure session before application data is exchanged.

The primary goals of the TLS handshake are:
* Authentication: Verifying the identity of the server (and optionally the client) using digital certificates.
* Key Exchange: Securely agreeing on a shared secret key for symmetric encryption.
* Cipher Suite Negotiation: Selecting the algorithms for encryption, hashing, and key exchange.

Direct TLS Handshake Steps

In a direct connection without a proxy, the TLS handshake proceeds as follows:

  1. Client Hello: The client initiates the handshake by sending a Client Hello message. This message includes:
    • Supported TLS versions.
    • A list of supported cipher suites.
    • A random byte string (Client Random).
    • Supported compression methods.
    • Server Name Indication (SNI) for virtual hosting.
  2. Server Hello: The server responds with a Server Hello message, selecting:
    • The TLS version to use.
    • A chosen cipher suite from the client's list.
    • A random byte string (Server Random).
  3. Certificate: The server sends its digital certificate, which contains its public key and is signed by a Certificate Authority (CA). The client verifies this certificate.
  4. Server Key Exchange (Optional): If the chosen cipher suite requires it (e.g., for Diffie-Hellman ephemeral), the server sends parameters for key exchange.
  5. Server Hello Done: The server indicates it has completed its part of the initial handshake.
  6. Client Key Exchange: The client generates a pre-master secret, encrypts it with the server's public key (from its certificate), and sends it to the server.
  7. Change Cipher Spec (Client): The client sends a Change Cipher Spec message, indicating that all subsequent messages will be encrypted using the negotiated keys and cipher suite.
  8. Encrypted Handshake Message (Client): The client sends a Finished message, encrypted with the newly established symmetric key, to verify the handshake integrity.
  9. Change Cipher Spec (Server): The server sends its own Change Cipher Spec message.
  10. Encrypted Handshake Message (Server): The server sends its Finished message, also encrypted.
  11. Application Data: Both parties can now exchange encrypted application data.

Proxy Types and TLS Handshake Interaction

Proxies modify how the TLS handshake is initiated and processed based on their operational mode.

Forward Proxy (Non-Intercepting)

A forward proxy acts as an intermediary for clients seeking to access external resources. For HTTPS traffic, a non-intercepting forward proxy typically operates as a TCP tunnel. The client explicitly configures itself to use the proxy.

Mechanism:
The client sends an HTTP CONNECT request to the proxy to establish a TCP tunnel to the origin server. Once the tunnel is established, the client and origin server perform the TLS handshake directly through this tunnel. The proxy forwards encrypted bytes without decrypting them.

TLS Handshake Flow:
1. Client to Proxy (TCP): Client establishes a TCP connection to the proxy.
2. Client CONNECT Request: Client sends an HTTP CONNECT request to the proxy, specifying the origin server's hostname and port (e.g., CONNECT example.com:443 HTTP/1.1).
3. Proxy to Origin (TCP): The proxy establishes a TCP connection to the specified origin server.
4. Proxy 200 OK: If the connection to the origin server is successful, the proxy responds to the client with HTTP/1.1 200 Connection established.
5. Client to Origin (TLS via Tunnel): The client, upon receiving the 200 OK, initiates the standard TLS handshake directly with the origin server through the established TCP tunnel.
6. Proxy Forwarding: The proxy transparently forwards all subsequent encrypted bytes between the client and the origin server. It does not participate in the TLS handshake, nor does it decrypt the traffic.

Code Example: Client CONNECT Request

CONNECT www.example.com:443 HTTP/1.1
Host: www.example.com:443
Proxy-Connection: Keep-Alive

Proxy Response

HTTP/1.1 200 Connection established

Reverse Proxy (TLS Termination)

A reverse proxy sits in front of one or more origin servers and intercepts client requests destined for those servers. For HTTPS traffic, a reverse proxy often performs TLS termination.

Mechanism:
The reverse proxy receives the client's HTTPS request, terminates the TLS connection, decrypts the traffic, and then establishes a new connection (which may or may not be TLS-encrypted) to the backend origin server.

TLS Handshake Flow:
1. Client to Reverse Proxy (TLS Handshake 1):
* The client performs a standard TLS handshake directly with the reverse proxy.
* The reverse proxy presents its own digital certificate to the client.
* A secure, encrypted channel is established between the client and the reverse proxy.
2. Reverse Proxy Decryption: The reverse proxy decrypts the client's request.
3. Reverse Proxy to Origin (TLS Handshake 2 or HTTP):
* The reverse proxy then initiates a new connection to the appropriate backend origin server.
* This connection may be plain HTTP (common in trusted internal networks) or another TLS-encrypted connection (for end-to-end encryption).
* If TLS is used, the reverse proxy acts as a client and performs a second TLS handshake with the origin server, which presents its own certificate.
4. Origin Processing: The origin server processes the request and sends the response back to the reverse proxy.
5. Reverse Proxy Encryption: If the connection to the client was TLS, the reverse proxy re-encrypts the response using the client-facing TLS session keys.
6. Reverse Proxy to Client: The encrypted response is sent back to the client.

Transparent Proxy (MITM TLS Interception)

A transparent proxy intercepts traffic without the client being explicitly configured to use it. For HTTPS, this typically involves a Man-in-the-Middle (MITM) approach.

Mechanism:
When a client attempts to connect to an HTTPS site, the transparent proxy intercepts the connection. It generates a fake certificate for the requested domain, signed by its own root CA. The client performs a TLS handshake with the proxy, which then performs another TLS handshake with the origin server. This allows the proxy to decrypt, inspect, and potentially modify traffic. For this to work without certificate errors, the proxy's root CA certificate must be trusted by the client. This is common in enterprise environments for security monitoring.

Comparison of Proxy Types and TLS Interaction

Feature Direct TLS Connection Forward Proxy (Non-Intercepting) Reverse Proxy (TLS Termination) Transparent Proxy (MITM)
TLS Handshake Location Client ↔ Origin Server Client ↔ Origin Server (via tunnel) Client ↔ Proxy; Proxy ↔ Origin Server Client ↔ Proxy; Proxy ↔ Origin Server
Proxy Decryption N/A No Yes (client-side connection) Yes
Proxy Certificate N/A N/A Proxy's certificate Proxy's dynamically generated certificate
End-to-End Encryption Yes Yes No (Proxy sees plaintext) No (Proxy sees plaintext)
Client Awareness Direct Explicitly configured Unaware (sees proxy as origin) Unaware (transparent redirection)
Primary Use Case Standard web browsing Client-side access control, caching Load balancing, WAF, API gateway Enterprise security, content filtering

Security Considerations

When establishing secure connections through a proxy, several security implications arise:

  • Trust in the Proxy:
    • Forward Proxy: Since the proxy only tunnels encrypted data, trust requirements are minimal regarding data confidentiality. However, the proxy could potentially log connection metadata (IPs, domains).
    • Reverse Proxy / Transparent Proxy (MITM): These proxies decrypt traffic. Trust in the proxy operator becomes paramount, as they have access to decrypted sensitive data. For transparent MITM proxies, the client must explicitly trust the proxy's root CA, typically by installing it in the system's trust store.
  • Certificate Pinning: Applications that use certificate pinning might fail when connecting through a reverse proxy or transparent MITM proxy, as the proxy presents a different certificate than the expected origin server's certificate. This is a security feature designed to prevent MITM attacks.
  • TLS Version and Cipher Suite Enforcement: Proxies can be configured to enforce specific TLS versions and cipher suites, enhancing security by disallowing deprecated or weak cryptographic protocols, even if the client or origin server supports them.
  • Logging and Auditing: Proxies, especially reverse and transparent types, can provide extensive logging capabilities for decrypted traffic, aiding in security audits and incident response.
  • Performance Overhead: TLS termination at a proxy introduces computational overhead for encryption and decryption, which needs to be considered in high-traffic environments. Hardware acceleration (e.g., SSL offloading) is commonly used to mitigate this.
Auto-update: 03.03.2026
All Categories

Advantages of our proxies

25,000+ proxies from 120+ countries