}
}
if (!node) {
+ /* Nothing more to look up in the tree, and
+ * ssl_sock_generate_certificate() takes this same lock in read
+ * mode, which must not be done recursively.
+ */
+ HA_RWLOCK_RDUNLOCK(SNI_LOCK, &s->sni_lock);
#if (!defined SSL_NO_GENERATE_CERTIFICATES)
if (s->options & BC_O_GENERATE_CERTS && ssl_sock_generate_certificate(servername, s, ssl)) {
/* switch ctx done in ssl_sock_generate_certificate */
- HA_RWLOCK_RDUNLOCK(SNI_LOCK, &s->sni_lock);
TRACE_STATE("No context found, generate certificate", SSL_EV_CONN_SWITCHCTX_CB, NULL, ssl, servername);
return SSL_TLSEXT_ERR_OK;
}
#endif
- HA_RWLOCK_RDUNLOCK(SNI_LOCK, &s->sni_lock);
if (!(s->ssl_options & BC_SSL_O_STRICT_SNI) && !default_lookup) {
/* we didn't find a SNI, and we didn't look for a default
if (!ssl_sock_sni_is_valid(servername))
goto mkcert_error;
+ HA_RWLOCK_RDLOCK(SNI_LOCK, &bind_conf->sni_lock);
sni_ctx = ssl_sock_choose_sni_ctx(bind_conf, NULL, "", 1, 1);
- if (!sni_ctx)
+ if (!sni_ctx) {
+ HA_RWLOCK_RDUNLOCK(SNI_LOCK, &bind_conf->sni_lock);
goto mkcert_error;
+ }
/* Get the private key of the default certificate and use it */
#ifdef HAVE_SSL_CTX_get0_privatekey
if (tmp_ssl)
pkey = SSL_get_privatekey(tmp_ssl);
#endif
- if (!pkey)
+ if (!pkey) {
+ HA_RWLOCK_RDUNLOCK(SNI_LOCK, &bind_conf->sni_lock);
goto mkcert_error;
+ }
+ EVP_PKEY_up_ref(pkey);
+ HA_RWLOCK_RDUNLOCK(SNI_LOCK, &bind_conf->sni_lock);
/* Create the certificate */
if (!(newcrt = X509_new()))
end:
if (ctmp) NCONF_free(ctmp);
if (tmp_ssl) SSL_free(tmp_ssl);
+ EVP_PKEY_free(pkey);
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);
+ EVP_PKEY_free(pkey);
return NULL;
}
struct sni_ctx *sni_ctx;
/* if we use the generate-certificates option, look for the first default cert available */
+ HA_RWLOCK_RDLOCK(SNI_LOCK, &bind_conf->sni_lock);
sni_ctx = ssl_sock_choose_sni_ctx(bind_conf, NULL, "", 1, 1);
if (!sni_ctx) {
+ HA_RWLOCK_RDUNLOCK(SNI_LOCK, &bind_conf->sni_lock);
ha_alert("Proxy '%s': no SSL certificate specified for bind '%s' and 'generate-certificates' option at [%s:%d] (use 'crt').\n",
px->id, bind_conf->arg, bind_conf->file, bind_conf->line);
return -1;
}
+ HA_RWLOCK_RDUNLOCK(SNI_LOCK, &bind_conf->sni_lock);
}
if (!ssl_shctx && global.tune.sslcachesize) {