Blog | G5 Cyber Security

Diffie-Hellman & SSL: One-Way Authentication

TL;DR

While Diffie-Hellman key exchange can be part of an SSL/TLS handshake, it cannot directly replace the cipher used for encrypting data. It’s excellent for establishing a shared secret, but you still need a symmetric cipher (like AES) to actually secure communication. For one-way certificate-based authentication, Diffie-Hellman can be used to establish a key, which then secures the session using a standard cipher.

Understanding the Components

Let’s break down what each part does:

Why Diffie-Hellman Alone Isn’t Enough

Diffie-Hellman is vulnerable to man-in-the-middle attacks if not authenticated. Without authentication, an attacker can intercept the key exchange and establish their own shared secret with both parties, allowing them to decrypt and modify traffic.

How Diffie-Hellman Fits into SSL/TLS for One-Way Authentication

  1. ClientHello: The client initiates the connection by sending a ClientHello message.
  2. ServerHello & Certificate: The server responds with a ServerHello and presents its certificate to the client. This is where one-way authentication happens – the client verifies the server’s identity using the certificate.
  3. Key Exchange (Diffie-Hellman): The server proposes Diffie-Hellman parameters for key exchange. The client generates an ephemeral Diffie-Hellman key and sends it to the server.
  4. Shared Secret Calculation: Both the client and server use their private keys and the exchanged public values to calculate a shared secret.
  5. Cipher Suite Negotiation: A cipher suite is selected, which determines the encryption algorithm (e.g., AES-256-GCM), hashing function, and key derivation method.
  6. Encryption Begins: The shared secret is used to derive session keys for encrypting all subsequent communication using the chosen cipher.

Example Scenario

Imagine a website (server) wants you (client) to connect securely.

  1. The server shows you its ID card (certificate). You check it’s valid and from someone you trust.
  2. You both agree on a secret code-making method (Diffie-Hellman).
  3. You each create part of the code, exchange them, and combine them to make a unique shared key.
  4. Now all messages between you are scrambled using that key with a strong encryption algorithm like AES.

Code Example (Conceptual – OpenSSL)

This is a simplified illustration; actual SSL/TLS implementations are far more complex.

# Server-side (simplified)
openssl genrsa -out server.key 2048  # Generate private key
openssl req -new -key server.key -out server.csr # Create certificate signing request
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt # Self-sign (for testing only!)
# Client-side (simplified)
openssl s_client -connect example.com:443  # Connect to the server and verify certificate

Important Considerations

Exit mobile version