To prevent a man-in-the-middle from obtaining the SSL/TLS key

httpsSecurityssl

As I understand it, the main reason to use HTTPS over HTTP is that the communication is encrypted so that anyone listening in is not able to view the plain text of the HTTP exchange between client/server.

Now, at the start of the session the client and server agree a master key based on the information obtained during the SSL/TLS handshake. But what is to stop someone listening in from also obtaining the key using the same cipher suite agreed by the client/server?

If there is nothing to prevent that, then how is HTTPS actually that much more secure than HTTP? All it would take for a MITM would be to engineer the key themselves using the information taken from the handshake and use it to decipher the communication between the client and server.

I must be missing something…

Best Answer

The client and server only agree on a key, they never actually send it in plain.

Most commonly, DH key exchange (2) or its ECDH variant are used – each peer only combines its DH private key with the other peer's DH public key and both obtain the same result. If you watch the traffic, you will only see both peers' public keys, which is not enough to derive the resulting session key. (The TLS handshake later verifies that an attacker hasn't injected its own pubkeys.)

Another method (nowadays rare) is "static RSA" – in this mode, the client generates the session key on its own and encrypts it using the server's public key (obtained from the SSL certificate). Although the key is sent over the net, only the server is able to decrypt it.

(While the "static RSA" method might be simpler, it is also less secure – obtaining the certificate's private key would allow one to decrypt all old and new HTTPS sessions; in other words, there is no forward secrecy. Also it requires the certificate to have a keypair capable of encryption/decryption, while DH-style key derivation only needs sign/verify.)

Related Question