Blog | G5 Cyber Security

DH Param File & Diffie-Hellman Groups

TL;DR

Yes, a DH (Diffie-Hellman) parameter .pem file can restrict the types of Diffie-Hellman key exchanges allowed. It does this by specifying only one or a limited set of prime groups that OpenSSL will use during negotiation. This enhances cyber security by reducing potential attack surfaces.

How DH Param Files Work

Diffie-Hellman (DH) relies on mathematical operations with large prime numbers. Different sets of these primes are called ‘groups’. Each group has different strengths and weaknesses. A DH parameter file contains the parameters for one or more specific groups.

Steps to Restrict Diffie-Hellman Groups

  1. Generate a DH Param File for a Specific Group: You’ll use OpenSSL to create this file. The most common group is 2, but you can choose others (e.g., 5, 14). Using only one group restricts the exchange.
    openssl dhparam -out dh_group2.pem 2048

    This command creates a file named dh_group2.pem using group number 2 and a key length of 2048 bits.

  2. Configure Your Server to Use the DH Param File: The exact method depends on your server software (e.g., Apache, Nginx). Here are examples:
    • Apache: In your virtual host configuration file (e.g., httpd.conf or vhost.conf), add or modify the following line within the <VirtualHost> block:
      DHParam /path/to/dh_group2.pem
    • Nginx: In your server configuration file (e.g., nginx.conf), add or modify the following line within the server block:
      ssl_dhparam /path/to/dh_group2.pem;
  3. Restart Your Server: After making changes to your configuration, restart the server for them to take effect.
    • Apache: sudo systemctl restart apache2 (or similar command depending on your Linux distribution)
    • Nginx: sudo systemctl restart nginx
  4. Verify the Configuration: Use an online SSL checker tool or OpenSSL to confirm that only the specified DH group is being offered.
    openssl s_client -connect yourdomain.com:443 -tls1_2

    Look for lines in the output indicating the supported Diffie-Hellman groups. You should see only group 2 (or whichever group you specified) listed.

Why Restrict DH Groups?

Important Considerations

Exit mobile version