INN commit: trunk (doc/pod/news.pod nnrpd/tls.c)

INN Commit rra at isc.org
Fri May 31 22:34:34 UTC 2019


    Date: Friday, May 31, 2019 @ 15:34:34
  Author: iulius
Revision: 10343

nnrpd:  Use DH parameters from RFC 7919

Adapt the length of the DH parameter to use depending on the security
level expected by OpenSSL.

Modified:
  trunk/doc/pod/news.pod
  trunk/nnrpd/tls.c

------------------+
 doc/pod/news.pod |    6 +-
 nnrpd/tls.c      |  118 ++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 97 insertions(+), 27 deletions(-)

Modified: doc/pod/news.pod
===================================================================
--- doc/pod/news.pod	2019-05-30 14:18:48 UTC (rev 10342)
+++ doc/pod/news.pod	2019-05-31 22:34:34 UTC (rev 10343)
@@ -4,9 +4,9 @@
 
 =item *
 
-B<nnrpd> now always uses 4096-bit parameters for DH keys.  When OpenSSL
-is configured with a security level beyond 1, shorter parameters might not
-be accepted.  Thanks to Michael Baeuerle for the patch.
+B<nnrpd> now adapts the length of the DH parameter used during a DHE
+key exchange so that to comply with the security level S<OpenSSL 1.1.0>
+or later expects.   Thanks to Michael Baeuerle for the bug report.
 
 =back
 

Modified: nnrpd/tls.c
===================================================================
--- nnrpd/tls.c	2019-05-30 14:18:48 UTC (rev 10342)
+++ nnrpd/tls.c	2019-05-31 22:34:34 UTC (rev 10343)
@@ -95,27 +95,63 @@
 
 
 /*
-**  Hardcoded DH parameter file, from OpenSSL.
-**  For information on how that file was generated, see
-**  "Assigned Number for SKIP Protocols" 
-**  <http://www.skip-vpn.org/spec/numbers.html>.
+**  Hardcoded DH parameter files.
+**  These are pre-defined DH groups recommended by RFC 7919 (Appendix A),
+**  that have been audited and therefore supposed to be more
+**  resistant to attacks than ones randomly generated.
 */
-static const char file_dh4096[] =
+static const char file_ffdhe2048[] = \
 "-----BEGIN DH PARAMETERS-----\n\
-MIICCAKCAgEA+hRyUsFN4VpJ1O8JLcCo/VWr19k3BCgJ4uk+d+KhehjdRqNDNyOQ\n\
-l/MOyQNQfWXPeGKmOmIig6Ev/nm6Nf9Z2B1h3R4hExf+zTiHnvVPeRBhjdQi81rt\n\
-Xeoh6TNrSBIKIHfUJWBh3va0TxxjQIs6IZOLeVNRLMqzeylWqMf49HsIXqbcokUS\n\
-Vt1BkvLdW48j8PPv5DsKRN3tloTxqDJGo9tKvj1Fuk74A+Xda1kNhB7KFlqMyN98\n\
-VETEJ6c7KpfOo30mnK30wqw3S8OtaIR/maYX72tGOno2ehFDkq3pnPtEbD2CScxc\n\
-alJC+EL7RPk5c/tgeTvCngvc1KZn92Y//EI7G9tPZtylj2b56sHtMftIoYJ9+ODM\n\
-sccD5Piz/rejE3Ome8EOOceUSCYAhXn8b3qvxVI1ddd1pED6FHRhFvLrZxFvBEM9\n\
-ERRMp5QqOaHJkM+Dxv8Cj6MqrCbfC4u+ZErxodzuusgDgvZiLF22uxMZbobFWyte\n\
-OvOzKGtwcTqO/1wV5gKkzu1ZVswVUQd5Gg8lJicwqRWyyNRczDDoG9jVDxmogKTH\n\
-AaqLulO7R8Ifa1SwF2DteSGVtgWEN8gDpN3RBmmPTDngyF2DHb5qmpnznwtFKdTL\n\
-KWbuHn491xNO25CQWMtem80uKw+pTnisBRF/454n1Jnhub144YRBoN8CAQI=\n\
+MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz\n\
++8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a\n\
+87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7\n\
+YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi\n\
+7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD\n\
+ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==\n\
 -----END DH PARAMETERS-----\n";
 
+static const char file_ffdhe4096[] = \
+"-----BEGIN DH PARAMETERS-----\n\
+MIICCAKCAgEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz\n\
++8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a\n\
+87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7\n\
+YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi\n\
+7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD\n\
+ssbzSibBsu/6iGtCOGEfz9zeNVs7ZRkDW7w09N75nAI4YbRvydbmyQd62R0mkff3\n\
+7lmMsPrBhtkcrv4TCYUTknC0EwyTvEN5RPT9RFLi103TZPLiHnH1S/9croKrnJ32\n\
+nuhtK8UiNjoNq8Uhl5sN6todv5pC1cRITgq80Gv6U93vPBsg7j/VnXwl5B0rZp4e\n\
+8W5vUsMWTfT7eTDp5OWIV7asfV9C1p9tGHdjzx1VA0AEh/VbpX4xzHpxNciG77Qx\n\
+iu1qHgEtnmgyqQdgCpGBMMRtx3j5ca0AOAkpmaMzy4t6Gh25PXFAADwqTs6p+Y0K\n\
+zAqCkc3OyX3Pjsm1Wn+IpGtNtahR9EGC4caKAH5eZV9q//////////8CAQI=\n\
+-----END DH PARAMETERS-----\n";
 
+static const char file_ffdhe8192[] = \
+"-----BEGIN DH PARAMETERS-----\n\
+MIIECAKCBAEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz\n\
++8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a\n\
+87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7\n\
+YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4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lIjZwKCh/jB1pXfiMYP4HUo/L6RXHvyM4LqKT+i2hV3+crCm\n\
+bt7S+6v75Yow+vq+HF1xqH4vdB74wf6G/qa7/eUwZ38Nl9EdSfeoRD0IIuUGqfRh\n\
+TgEeKpSDj/iM1oyLt8XGQkz//////////wIBAg==\n\
+-----END DH PARAMETERS-----\n";
+
+
 /*
 **  Load hardcoded DH parameters.
 */
@@ -137,10 +173,11 @@
 
 
 /*
-**  Generate empheral DH key.  Because this can take a long
-**  time to compute, we use a precomputed parameter of 4096 bits.
-**  Shorter DH parameters are considered less secure, and no longer
-**  allowed by OpenSSL with Security Level 2:
+**  Generate ephemeral DH key.  Because this can take a long
+**  time to compute, we use precomputed parameters of the common
+**  key sizes.
+**  Depending on OpenSSL Security Level, a minimal length for
+**  DH parameters is required:
 **  <https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_security_level.html>
 **
 **  These values can be static (once loaded or computed) since
@@ -157,11 +194,44 @@
 tmp_dh_cb(SSL *s UNUSED, int export UNUSED, int keylength UNUSED)
 {
     DH *r = NULL;
-    static DH *dh4096 = NULL;
 
-    if (dh4096 == NULL) {
-        dh4096 = load_dh_buffer(file_dh4096, sizeof(file_dh4096));
-        r = dh4096;
+    static DH *ffdhe2048 = NULL;
+    static DH *ffdhe4096 = NULL;
+    static DH *ffdhe8192 = NULL;
+    int level = 2; /* Default security level. */
+
+    /* Security levels have been introduced in OpenSSL 1.1.0. */
+#if OPENSSL_VERSION_NUMBER >= 0x010100000L && !defined(LIBRESSL_VERSION_NUMBER)
+    level = SSL_get_security_level(s);
+#endif
+
+    switch(level)
+    {
+        case 0: /* Everything is permitted. */
+        case 1: /* DH keys shorter than 1024 bits are prohibited. */
+        case 2: /* DH keys shorter than 2048 bits are prohibited. */
+            if (ffdhe2048 == NULL) {
+                ffdhe2048 = load_dh_buffer(file_ffdhe2048,
+                                           sizeof(file_ffdhe2048));
+                r = ffdhe2048;
+            }
+            break;
+
+        case 3: /* DH keys shorter than 3072 bits are prohibited. */
+            if (ffdhe4096 == NULL) {
+                ffdhe4096 = load_dh_buffer(file_ffdhe4096,
+                                           sizeof(file_ffdhe4096));
+                r = ffdhe4096;
+            }
+            break;
+
+        case 4: /* DH keys shorter than 7680 bits are prohibited. */
+        default:
+            if (ffdhe8192 == NULL) {
+                ffdhe8192 = load_dh_buffer(file_ffdhe8192,
+                                           sizeof(file_ffdhe8192));
+                r = ffdhe8192;
+            }
     }
 
     return r;



More information about the inn-committers mailing list