Diffie-Hellman & Man-in-the-Middle
- 8Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary vulnerability of Diffie-Hellman when used on its own, and how does this vulnerability manifest?
8 questions
- 1
What is the primary vulnerability of Diffie-Hellman when used on its own, and how does this vulnerability manifest?
Model answer
Diffie-Hellman, when used alone, is highly vulnerable to man-in-the-middle attacks because it lacks a mechanism for authenticating the identities of the parties exchanging keys. A malicious actor can intercept the public values exchanged and establish two separate shared secrets, one with Alice and one with Bob, without either party knowing.
Explanation
Diffie-Hellman's strength lies in establishing a shared secret over an insecure channel, but it doesn't verify who you are talking to. This absence of authentication allows a man-in-the-middle (MITM) attacker, like Sean, to sit between Alice and Bob. Sean intercepts Alice's public value (ga(modn)), generates his own private key s, and sends his public value (gs(modn)) to Alice, pretending to be Bob. Alice then calculates a shared secret (gas(modn)) with Sean. Sean then initiates a separate key exchange with Bob, sending his own public value (gs(modn)) and pretending to be Alice. Bob then calculates a shared secret (gbs(modn)) with Sean. As a result, Sean has two distinct shared secrets, one with Alice and one with Bob, and can decrypt, read, modify, and re-encrypt all traffic between them.
- 2
Describe the steps a man-in-the-middle attacker would take to compromise a Diffie-Hellman key exchange between Alice and Bob.
Model answer
The attacker intercepts Alice's public value ga(modn) and prevents it from reaching Bob. The attacker then generates their own private value s, computes gs(modn), and sends it to Alice (impersonating Bob) and also sends it to Bob (impersonating Alice). This results in two separate key exchanges, one between Alice and the attacker (gas(modn)) and one between the attacker and Bob (gbs(modn)), both of which the attacker knows.
Explanation
A man-in-the-middle attack proceeds as follows: 1. Alice sends ga(modn) to Bob. 2. The attacker (Sean) intercepts ga(modn). 3. Sean generates his own private key s. 4. Sean sends gs(modn) to Alice, pretending to be Bob. Alice calculates a shared key gas(modn). 5. Sean sends gs(modn) to Bob, pretending to be Alice. Bob calculates a shared key gbs(modn). Now, Sean can decrypt any message from Alice using the gas(modn) key, read/modify it, and then re-encrypt it with the gbs(modn) key to send to Bob, and vice-versa, without either Alice or Bob realizing the interception.
- 3
How does RSA (or other public key encryption schemes) address the man-in-the-middle problem in Diffie-Hellman key exchanges?
Model answer
RSA addresses the man-in-the-middle problem by allowing one party (e.g., Bob) to digitally sign their Diffie-Hellman public parameter with their private key. Alice can then use Bob's public key to verify this signature, confirming that only Bob, who possesses the corresponding private key, could have sent the message.
Explanation
When combined with Diffie-Hellman, RSA provides authenticity. In this scenario, Bob would send his Diffie-Hellman public value (gb(modn)) along with a digital signature of this value, signed using his RSA private key. Alice, upon receiving this, uses Bob's known RSA public key to verify the signature. If the signature is valid, Alice is assured that the gb(modn) value indeed came from Bob and not an imposter, thus preventing a man-in-the-middle from injecting their own Diffie-Hellman parameter.
- 4
Explain the role of digital signatures in securing a Diffie-Hellman key exchange against impersonation.
Model answer
Digital signatures ensure authenticity by proving that a message originated from a specific sender and has not been tampered with. In a Diffie-Hellman exchange, a party signs their public Diffie-Hellman parameter with their private key, allowing the other party to verify the sender's identity using their public key.
Explanation
A digital signature, created using a sender's private key, can only be verified with their corresponding public key. When Bob sends his Diffie-Hellman parameter (gb(modn)) along with a digital signature of this parameter (e.g., a hash of gb(modn) encrypted with his private RSA key), Alice can use Bob's public RSA key to decrypt and verify the hash. If the hashes match, Alice is confident that the gb(modn) value was indeed sent by Bob, as only Bob possesses the private key necessary to create that specific signature. This prevents an attacker from substituting their own gs(modn) and signing it as if it came from Bob.
- 5
In the context of TLS handshakes and VPN protocols like IKE, why are Diffie-Hellman and RSA often used together instead of using Diffie-Hellman alone?
Model answer
Diffie-Hellman is used to quickly establish a shared ephemeral secret key for session encryption, while RSA provides the essential authentication to ensure that the Diffie-Hellman exchange is happening with the legitimate party, preventing man-in-the-middle attacks.
Explanation
Diffie-Hellman alone is susceptible to man-in-the-middle attacks because it lacks authentication. RSA, through digital signatures, provides the necessary authentication, allowing parties to verify each other's identity. By combining them, TLS and IKE achieve both secure key exchange (Diffie-Hellman) and trusted identity verification (RSA), creating a robust secure channel.
- 6
What is 'perfect forward secrecy,' and why is it a significant advantage of using ephemeral Diffie-Hellman keys over solely relying on RSA for key establishment?
Model answer
Perfect forward secrecy means that if a long-term private key (like an RSA private key) is compromised in the future, past session keys generated via ephemeral Diffie-Hellman exchanges remain secure and cannot be decrypted. This is because the Diffie-Hellman session key is generated uniquely for each session and is not directly derived from the long-term RSA key.
Explanation
If only RSA were used to exchange a symmetric key (e.g., Alice encrypts a symmetric key with Bob's public RSA key), then if Bob's RSA private key is ever compromised, an attacker who has recorded all past traffic could decrypt all historic communication sessions. With ephemeral Diffie-Hellman, a new, temporary Diffie-Hellman key pair is generated for each session. The RSA key is only used to authenticate this ephemeral Diffie-Hellman exchange. Therefore, even if the long-term RSA private key is later compromised, the ephemeral Diffie-Hellman session keys, which are not stored or directly derivable from the RSA key, are unaffected, thus providing perfect forward secrecy.
- 7
Why is RSA generally not used for the long-term encryption of entire communication messages, even though it can be used for key establishment?
Model answer
RSA is significantly slower than symmetric encryption algorithms (like AES) and is computationally intensive, making it impractical for encrypting large volumes of data or entire communication messages.
Explanation
RSA is an asymmetric encryption algorithm, which inherently involves more complex mathematical operations compared to symmetric algorithms. This makes RSA much slower for encryption and decryption, especially when dealing with substantial amounts of data. Therefore, it is typically used for specific, smaller tasks like digitally signing information, establishing a shared symmetric key, or encrypting small amounts of sensitive data (like a session key), with the actual bulk data encryption handled by faster symmetric ciphers.
- 8
What is an 'ephemeral Diffie-Hellman key,' and how does its characteristic 'ephemeral' nature contribute to security?
Model answer
An ephemeral Diffie-Hellman key is a temporary, short-lived Diffie-Hellman key pair generated uniquely for each communication session. Its ephemeral nature contributes to security by ensuring that compromise of one session's key does not affect the security of past or future sessions, providing perfect forward secrecy.
Explanation
The term 'ephemeral' means lasting for a very short time. In the context of Diffie-Hellman, an ephemeral key is a one-time use key pair that is generated for a single session and then discarded. This ensures that a new secret key is established for every communication instance. If an attacker manages to compromise a specific session's key, it offers no information or advantage in decrypting other past or future sessions, because each session uses a different, independently generated ephemeral key. This is the core concept behind perfect forward secrecy.

Ask anything
We've read this whole study set, so questions about it get the best answers.