]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9054 Add support for multiple EECDH curves
authorHoward Chu <hyc@openldap.org>
Thu, 20 Aug 2020 14:07:55 +0000 (15:07 +0100)
committerHoward Chu <hyc@openldap.org>
Fri, 21 Aug 2020 06:58:07 +0000 (07:58 +0100)
Requires OpenSSL 1.0.2 or newer

doc/man/man3/ldap_get_option.3
doc/man/man5/ldap.conf.5
doc/man/man5/slapd-config.5
doc/man/man5/slapd.conf.5
libraries/libldap/init.c
libraries/libldap/tls2.c
libraries/libldap/tls_o.c

index 71bffd9cac65fa0339389e780e15070533baecbe..b10a5480f88d6777b7c4cf49e0544ffc59774ec7 100644 (file)
@@ -740,7 +740,7 @@ and its contents need to be freed by the caller using
 .BR ldap_memfree (3).
 .TP
 .B LDAP_OPT_X_TLS_ECNAME
-Gets/sets the name of the curve used for 
+Gets/sets the name of the curve(s) used for
 elliptic curve key exchanges.
 .BR invalue
 must be
index 1b8649496beae605f2fe4f67a03495d4496e2c69..c0aee8f8937de3e70b70bcc5e9ceaf7b1f83091f 100644 (file)
@@ -327,6 +327,12 @@ is always used before
 Specifies the file that contains the client certificate.
 .B This is a user-only option.
 .TP
+.B TLS_ECNAME <name>
+Specify the name of the curve(s) to use for Elliptic curve Diffie-Hellman
+ephemeral key exchange.  This option is only used for OpenSSL.
+This option is not used with GnuTLS; the curves may be
+chosen in the GnuTLS ciphersuite specification.
+.TP
 .B TLS_KEY <filename>
 Specifies the file that contains the private key that matches the certificate
 stored in the
index 1cb77421fddadc9dcc718090e2b7ed5250221751..6eca909ebb002f330c332061f41cb03406505fbc 100644 (file)
@@ -908,9 +908,9 @@ You should append "!ADH" to your cipher suites to ensure that these suites
 are not used.
 .TP
 .B olcTLSECName: <name>
-Specify the name of a curve to use for Elliptic curve Diffie-Hellman
-ephemeral key exchange.  This is required to enable ECDHE algorithms in
-OpenSSL.  This option is not used with GnuTLS; the curves may be
+Specify the name of the curve(s) to use for Elliptic curve Diffie-Hellman
+ephemeral key exchange.  This option is only used for OpenSSL.
+This option is not used with GnuTLS; the curves may be
 chosen in the GnuTLS ciphersuite specification.
 .TP
 .B olcTLSProtocolMin: <major>[.<minor>]
index 04b2fdd87b44b2ca01b7fb3d2b2e1d9f77b81541..c0957dd45468e83200330cac7abb40f0b654a95a 100644 (file)
@@ -1139,9 +1139,9 @@ You should append "!ADH" to your cipher suites to ensure that these suites
 are not used.
 .TP
 .B TLSECName <name>
-Specify the name of a curve to use for Elliptic curve Diffie-Hellman
-ephemeral key exchange.  This is required to enable ECDHE algorithms in
-OpenSSL.  This option is not used with GnuTLS; the curves may be
+Specify the name of the curve(s) to use for Elliptic curve Diffie-Hellman
+ephemeral key exchange.  This option is only used for OpenSSL.
+This option is not used with GnuTLS; the curves may be
 chosen in the GnuTLS ciphersuite specification.
 .TP
 .B TLSProtocolMin <major>[.<minor>]
index dfe1ea9da4906f00fda9c54a812144213a846e32..52b44d16e0272e9e3c3e0fdf9d035d11914c1192 100644 (file)
@@ -123,6 +123,7 @@ static const struct ol_attribute {
        {0, ATTR_TLS,   "TLS_CIPHER_SUITE",     NULL,   LDAP_OPT_X_TLS_CIPHER_SUITE},
        {0, ATTR_TLS,   "TLS_PROTOCOL_MIN",     NULL,   LDAP_OPT_X_TLS_PROTOCOL_MIN},
        {0, ATTR_TLS,   "TLS_PEERKEY_HASH",     NULL,   LDAP_OPT_X_TLS_PEERKEY_HASH},
+       {0, ATTR_TLS,   "TLS_ECNAME",           NULL,   LDAP_OPT_X_TLS_ECNAME},
 
 #ifdef HAVE_OPENSSL_CRL
        {0, ATTR_TLS,   "TLS_CRLCHECK",         NULL,   LDAP_OPT_X_TLS_CRLCHECK},
index 99f215ec1d6e09c506d03013d75581c8a3ffa0f4..ecb292514f9a751cbc9fb85a4b3e52fecc6e0a35 100644 (file)
@@ -342,7 +342,7 @@ ldap_int_tls_connect( LDAP *ld, LDAPConn *conn, const char *host )
        Sockbuf *sb = conn->lconn_sb;
        int     err;
        tls_session     *ssl = NULL;
-       char *sni = host;
+       char *sni = (char *)host;
 
        if ( HAS_TLS( sb )) {
                ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_SSL, (void *)&ssl );
@@ -580,6 +580,7 @@ ldap_pvt_tls_config( LDAP *ld, int option, const char *arg )
        case LDAP_OPT_X_TLS_CIPHER_SUITE:
        case LDAP_OPT_X_TLS_DHFILE:
        case LDAP_OPT_X_TLS_PEERKEY_HASH:
+       case LDAP_OPT_X_TLS_ECNAME:
        case LDAP_OPT_X_TLS_CRLFILE:    /* GnuTLS only */
                return ldap_pvt_tls_set_option( ld, option, (void *) arg );
 
index e6f83c795dd5e1244a800cf56d7e061f219845c1..2c8c7e3fb2f6d2df086390e6dec709e5d1a97bbe 100644 (file)
@@ -453,34 +453,30 @@ tlso_ctx_init( struct ldapoptions *lo, struct ldaptls *lt, int is_server )
                DH_free( dh );
        }
 
-       if ( is_server && lo->ldo_tls_ecname ) {
+       if ( lo->ldo_tls_ecname ) {
 #ifdef OPENSSL_NO_EC
                Debug0( LDAP_DEBUG_ANY,
                        "TLS: Elliptic Curves not supported.\n" );
                return -1;
 #else
-               EC_KEY *ecdh;
-
-               int nid = OBJ_sn2nid( lt->lt_ecname );
-               if ( nid == NID_undef ) {
+               if ( SSL_CTX_set1_curves_list( ctx, lt->lt_ecname )) {
                        Debug1( LDAP_DEBUG_ANY,
-                               "TLS: could not use EC name `%s'.\n",
+                               "TLS: could not set EC name `%s'.\n",
                                lo->ldo_tls_ecname );
                        tlso_report_error();
                        return -1;
                }
-               ecdh = EC_KEY_new_by_curve_name( nid );
-               if ( ecdh == NULL ) {
-                       Debug1( LDAP_DEBUG_ANY,
-                               "TLS: could not generate key for EC name `%s'.\n",
-                               lo->ldo_tls_ecname );
-                       tlso_report_error();
-                       return -1;
+       /*
+        * This is a NOP in OpenSSL 1.1.0 and later, where curves are always
+        * auto-negotiated.
+        */
+#if OPENSSL_VERSION_NUMBER < 0x10100000UL
+               if ( SSL_CTX_set_ecdh_auto( ctx, 1 ) <= 0 ) {
+                       Debug0( LDAP_DEBUG_ANY,
+                               "TLS: could not enable automatic EC negotiation.\n" );
                }
-               SSL_CTX_set_tmp_ecdh( ctx, ecdh );
-               SSL_CTX_set_options( ctx, SSL_OP_SINGLE_ECDH_USE );
-               EC_KEY_free( ecdh );
 #endif
+#endif /* OPENSSL_NO_EC */
        }
 
        if ( tlso_opt_trace ) {