Commit
48a8332a introduce SSL_CTX_get0_privatekey in openssl-compat.h but
SSL_CTX_get0_privatekey access internal structure and can't be a candidate
to openssl-compat.h. The workaround with openssl < 1.0.2 is to use SSL_new
then SSL_get_privatekey.
}
#endif
-#if (OPENSSL_VERSION_NUMBER < 0x10002000L) || defined(LIBRESSL_VERSION_NUMBER)
-/*
- * Functions introduced in OpenSSL 1.0.2 and not yet present in LibreSSL
- */
-EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx)
-{
- if (ctx->cert != NULL)
- return ctx->cert->key->privatekey;
- else
- return NULL;
-}
-#endif
-
#if (OPENSSL_VERSION_NUMBER < 0x1010000fL) || defined(LIBRESSL_VERSION_NUMBER)
/*
* Functions introduced in OpenSSL 1.1.0 and not yet present in LibreSSL
SSL_CTX *ssl_ctx = NULL;
X509 *newcrt = NULL;
EVP_PKEY *pkey = NULL;
+ SSL *tmp_ssl = NULL;
X509_NAME *name;
const EVP_MD *digest;
X509V3_CTX ctx;
int key_type;
/* Get the private key of the default certificate and use it */
- if (!(pkey = SSL_CTX_get0_privatekey(bind_conf->default_ctx)))
+#if (OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined LIBRESSL_VERSION_NUMBER)
+ pkey = SSL_CTX_get0_privatekey(bind_conf->default_ctx);
+#else
+ tmp_ssl = SSL_new(bind_conf->default_ctx);
+ if (tmp_ssl)
+ pkey = SSL_get_privatekey(tmp_ssl);
+#endif
+ if (!pkey)
goto mkcert_error;
/* Create the certificate */
return ssl_ctx;
mkcert_error:
+ if (tmp_ssl) SSL_free(tmp_ssl);
if (ssl_ctx) SSL_CTX_free(ssl_ctx);
if (newcrt) X509_free(newcrt);
return NULL;