Your Diffie-Hellman Makes a Difference

I think it's safe to say that all of us in the tech community are familiar with the Snowden leaks.  Most of the information deals with programs or tactics the average person can't do much about, except for the obvious of trying to vote in people willing to change them.  Some would argue that might not even be possible, but I digress.  One of the vulnerabilities that we could potentially counter involves the prime number used in the Diffie Hellman key exchange.

So what is the Diffie Hellman key exchange?  The two most common types of key encryption are symmetric and asymmetric key encryption.  Symmetric involves both parties using the same key, your data is potentially harder to crack, but the problem lies with, how do both parties get the key?  If it's your buddy or coworker it'd be trivial to swap a USB key.  But what if you are an e-commerce website that needs to encrypt payment requests?  There is no good way for customers to get a symmetric key.  This is where asymmetric keys become a necessity.   This works by having each party use their own private key and then they both share a public key.  The data can then be encrypted and decrypted by both parties using the combo of the private and public keys.  This does involve some fairly complicated math that is beyond the scope of this article, but in short it is based on the use of a very large prime number and modular arithmetic.  Here is a link if you are interested in further explanation.

https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange#Cryptographic_explanation

Alright so lets get to the problem.  I included a link to a fascinating paper that provides detail and analysis of the potential vulnerability.

https://weakdh.org/imperfect-forward-secrecy-ccs15.pdf

So here is the TLDR summary, it is theoretically possible that an entity with a large enough budget could harness enough computing power to break a 1024 prime.  In case you didn't read the paper I linked, they estimate it would cost a few hundred million dollars to supply the hardware to crack one Diffie Hellman prime a year.  This figure is certainly feasible for quite a few countries cyber intelligence budget. 

So they can crack one prime a year?  Is that really a big deal? Yes! And here is why. A lot of platforms use common primes. To the layman, this might seem silly, but if you understand the math behind it, this was a safe practice being the technology and infrastructure to crack a prime of this size wasn't feasible.  According to the linked paper, breaking a single, common 1024-bit prime would allow an entity to passively decrypt connections to two-thirds of VPNs and a quarter of all SSH servers globally. Breaking a second 1024-bit prime would allow passive eavesdropping on connections to nearly 20% of the top million HTTPS websites. In other words, a one-time investment in massive computation would make it possible to eavesdrop on trillions of encrypted connections.

 So what can we do?  Well, if you maintain a server that provides SSL support it's actually pretty easy to change the Diffie Hellman key.  I recommend you spend time looking at your server settings before running any of the following commands. My goal is to shed light on the process, not necessarily provide a step by step tutorial.  I feel better mentioning that disclaimer!  Below is the general process for changing your Diffie Hellman key for the two most common Linux webservers: Apache and Nginx. 

First, we need generate a new Diffie Hellman key with openssl in addition to generating a new key. It is recommended the size is upped from 1024 to 2048.  Theoretically a 2048 bit key is 10^9 times harder to break.  That should be safe for quite a few years!  Here is the command.

openssl dhparam -out dhparam.pem 2048

Next point your server at the new key.

For Nginx

ssl_dhparam /path/to/dhparam.pem;

Prior to Apache 2.4.7, the Diffie Hellman key was always set to 1024 bits and not user configurable. If you are on Redhat/CentOS the fix has been back ported to Apache 2.2.15-32.  Here is the command for Apache.

SSLOpenSSLConfCmd DHParameters "/path/to/dhparams.pem"

Again, please spend some time researching these settings before making these changes. In the end generating your own custom Diffie Hellman key is a good step to keeping your information safer than it currently is.

Want to Learn More?

This is just a sample of what we can do. We have 15 years of experience working in nearly every technology and industry. Whatever you are doing, we've done it and are prepared to tackle your project. Reach out and we will discuss it with you.