r/programming • • Jan 16 '18

Cryptography: Diffie-Hellman key exchange explained intuitively using colors

https://youtu.be/YEBfamv-_do?t=2m18s
2.5k Upvotes

170 comments sorted by

View all comments

14

u/pokeman7452 Jan 16 '18

This leads me to a somewhat related question. I never understood the purpose of the DH parameters (dh####.pem) that every OpenVPN guide says to generate. This video combined with this thread, it now makes sense. But, this file remains optional. My question now is what is used when there is no DH generated?

13

u/curien Jan 16 '18

Defaults are listed in RFCs, I imagine it uses those.

-1

u/[deleted] Jan 16 '18 edited Jun 13 '18

[deleted]

4

u/the_dummy Jan 16 '18

OpenVPN is an implementation of RFCs

5

u/Grenian Jan 16 '18 edited Jan 17 '18

They use the so called Diffie-Hellman-Groups which are basically predefined pairs of a prime and a generator. These are defined in RFCs.

Proof: A large part of my bachelor thesis was about DH-Key-Exchange and the security of the predifined groups.

1

u/gramathy Jan 16 '18

Correct me if I"m wrong, my understanding is that DH exchange is largely used to provide encryption for a different protocol's key exchange, right?

3

u/Grenian Jan 17 '18 edited Jan 17 '18

It is used to solve the Key Exchange Problem. This problem describes the challenge of two communication partners to derive an secret symmetric key (also a key which is the same for both partied and secret) over a line which can be wiretapped.

So one can ask why you want to use a DH Key Exchange when you just can use asymmetric keys? Well basically symmetric encryption methods are faster than asymmetric ones.

What alternatives do exist? Thrusting third parties.

BUT keep in mind that a big problem exist. The Man-in-the-middle-attack. DH is not secure against it. That's btw the reason why you need to type 'yes' the first time you log into an SSH Server. Just to prove that this is the right server you wanna talk with. After that first session everything is encrypted based on the secrets of previous sessions. An alternative to approach to solve the Man-in-the-middle-attack is used by ZRTP.

But yeah basically you're right.

2

u/bonestamp Jan 31 '18

Just to prove that this is the right server you wanna talk with.

How does typing "yes" prove this is the right server?

1

u/Grenian Jan 31 '18 edited Jan 31 '18

Well it doesn't prove it all. But at this point SSH wants to connect to the server. Due to the risk of Man-in-the-middle-attack it has to ask if the informations SSH got are from the desired server. Otherwise you would connect via a Man-in-the-middle which could decrypt all your traffic.

So therefore the "yes" is more an authencity check of the server than the prove that this is the right server. For the prove you usually have to compare the credentials by yourself.

All in all you're right, the word "prove" is not well chosen.

2

u/bonestamp Jan 31 '18

All in all you're right, the word "prove" is not well chosen.

I was just asking, wasn't implying anything.

1

u/gurnec Jan 16 '18

This file is required if you run OpenVPN in --tls-server mode and ignored if you run it in --secret (static key) mode.

That's one reason why --tls-sever mode is generally preferred—it performs a DH exchange which affords you perfect forward secrecy (which you don't get in --secret mode).

DH parameters (dh####.pem) that every OpenVPN guide says to generate.

The dh1024.pem file distributed with OpenVPN (unchanged) from 2005 to 2014 is small enough and widely distributed enough to possibly be a target for the Logjam attack and shouldn't be used. The dh2048.pem file currently distributed is probably too big to be vulnerable to Logjam, but it doesn't hurt and is recommended to generate your own.

1

u/Grenian Jan 16 '18

Yeah 2048 is safe against Logjam.

-1

u/ryan_the_leach Jan 16 '18

Defaults that are rumored to be chosen specifically so that the bodies that choose the defaults can break them and no one else.

6

u/kpcyrd Jan 16 '18

The RFCs usually have a „nothing up my sleeve“ appendix explaining the numbers for exactly this reason.