After reading the selected answer of "Diffie-Hellman Key Exchange" in plain English 5 times I can't, for the life of me, understand how it protects me from a MitM attack.
Given the following excerpt (from tylerl's answer):
- I come up with two prime numbers g and p and tell you what they are.
- You then pick a secret number (a), but you don't tell anyone. Instead you compute ga mod p and send that result back to me. (We'll call that A since it came from a).
- I do the same thing, but we'll call my secret number b and the computed number B. So I compute gb mod p and send you the result (called "B")
- Now, you take the number I sent you and do the exact same operation with it. So that's Ba mod p.
- I do the same operation with the result you sent me, so: Ab mod p.
Here are the same 5 steps with Alpha controlling the network:
- You attempt to send me
p, but Alpha intercepts and learns
- You come up with
aand attempt to send me the result of
ga mod p(
A), but Alpha intercepts and learns
- Alpha comes up with
band sends you the result of
gb mod p(
- You run
Ba mod p
- Alpha runs
Ab mod p
During this whole process Alpha pretends to be you and creates a shared secret with me using the same method.
Now, both you and Alpha, and Alpha and me each have pairs of shared secrets.
You now think it's safe to talk to me in secret, because when you send me messages encrypted with your secret Alpha decrypts them using the secret created by you and Alpha, encrypts them using the secret created by Alpha and me, then sends them to me. When I reply to you, Alpha does the same thing in reverse.
Am I missing something here?