]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-ssl-iostream: Use RSA_generate_key_ex() if it exists
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 5 Feb 2017 19:51:29 +0000 (21:51 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 6 Feb 2017 14:33:37 +0000 (16:33 +0200)
This avoids deprecation warnings about RSA_generate_key() in OpenSSL v1.1.

configure.ac
src/lib-ssl-iostream/iostream-openssl-context.c

index 18d1fe3567c669f43ecd658000bffee6ca495f4c..f223378168943925140e6bb3ed6445010911e639 100644 (file)
@@ -1756,6 +1756,9 @@ if test $want_openssl != no && test $have_ssl = no; then
     AC_CHECK_LIB(ssl, SSL_COMP_free_compression_methods, [
       AC_DEFINE(HAVE_SSL_COMP_FREE_COMPRESSION_METHODS,, [Build with SSL_COMP_free_compression_methods() support])
     ],, $SSL_LIBS)
+    AC_CHECK_LIB(ssl, RSA_generate_key_ex, [
+      AC_DEFINE(HAVE_RSA_GENERATE_KEY_EX,, [Build with RSA_generate_key_ex() support])
+    ],, $SSL_LIBS)
     AC_CHECK_LIB(ssl, [EVP_PKEY_CTX_new_id], [have_evp_pkey_ctx_new_id="yes"],, $SSL_LIBS)
     AC_CHECK_LIB(ssl, [EC_KEY_new], [have_ec_key_new="yes"],, $SSL_LIBS)
     if test "$have_evp_pkey_ctx_new_id" = "yes" && test "$have_ec_key_new" = "yes"; then
index 2b593dafe96d91c32b2f698ece888684269c20af..40d7c0efe63aa9f0bada9c32fadb864a9ec0ee7b 100644 (file)
@@ -29,7 +29,22 @@ static int ssl_iostream_init_global(const struct ssl_iostream_settings *set,
 static RSA *ssl_gen_rsa_key(SSL *ssl ATTR_UNUSED,
                            int is_export ATTR_UNUSED, int keylength)
 {
+#ifdef HAVE_RSA_GENERATE_KEY_EX
+       BIGNUM *bn = BN_new();
+       RSA *rsa = RSA_new();
+
+       if (bn != NULL && BN_set_word(bn, RSA_F4) != 0 &&
+           RSA_generate_key_ex(rsa, keylength, bn, NULL) != 0)
+               return rsa;
+
+       if (bn != NULL)
+               BN_free(bn);
+       if (rsa != NULL)
+               RSA_free(rsa);
+       return NULL;
+#else
        return RSA_generate_key(keylength, RSA_F4, NULL, NULL);
+#endif
 }
 
 static DH *ssl_tmp_dh_callback(SSL *ssl ATTR_UNUSED,