Describe in detail a maninthemiddle attack on the DiffieHell
Describe in detail a man-in-the-middle attack on the Diffie-Hellman key-exchange protocol whereby the adversary ends up sharing a key kA with Alice and a different key kB with Bob, and Alice and Bob cannot detect that anything has gone wrong.
What happens if Alice and Bob try to detect the presence of a man-in-the-middle adversary by sending each other (encrypted) questions that only the other party would know how to answer?
Solution
In man-in-the-middle attack, an Eavesdropper interprets public key KA of Alice and sends his own public key as KA to Bob. When Bob sends his public key KB, Eavesdropper changes it with his own public key and sends it as KB to Alice. This way Alice and Eavesdropper allow to share one key and, Bob and Eavesdropper allow to share another key. After this exchange of the keys, Eavesdropper easily decrypts every messages sent by any of Alice or Bob, and he can even read and also alter the messages before re-encrypting with the suitable key and sending the messages to the other person. This risk is present all the time because Diffie-Hellman key exchange does not authenticate the participants.
These type of attackes can be blocked by using digital signatures and other cryptographic schemes.
Encryption should be in such a way that any message encrypted by Bob, only Alice will be able to decrypt it, with no prior communication between them other than Bob having trusted knowledge of public key of Alice.
Puble key of Alice is gKA mod p. For sending a message to Alice, Bob will select a random KB and then he will send Alice gKB mod p together with the message encrypted with (gKA)KB mod p symmetric key. Now only Alice will be able to determine the symmetric key and then she will decrypt the message because she has KA.
