Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLS: allow support for different protocols on different hosts (same m… #1863

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/event/ngx_event_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert,
sk_X509_pop_free(chain, X509_free);
return NGX_ERROR;
}

} else if (cert_tag == SSL_SIGN_CERT) {
if (SSL_CTX_use_sign_certificate(ssl->ctx, x509) == 0) {
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
Expand All @@ -726,7 +725,6 @@ ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert,
sk_X509_pop_free(chain, X509_free);
return NGX_ERROR;
}

} else
#endif
if (SSL_CTX_use_certificate(ssl->ctx, x509) == 0) {
Expand Down Expand Up @@ -826,7 +824,6 @@ ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert,
EVP_PKEY_free(pkey);
return NGX_ERROR;
}

} else if (cert_tag == SSL_SIGN_CERT) {
if (SSL_CTX_use_sign_PrivateKey(ssl->ctx, pkey) == 0) {
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
Expand All @@ -835,7 +832,6 @@ ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert,
EVP_PKEY_free(pkey);
return NGX_ERROR;
}

} else
#endif
if (SSL_CTX_use_PrivateKey(ssl->ctx, pkey) == 0) {
Expand Down Expand Up @@ -2286,6 +2282,28 @@ ngx_ssl_handshake(ngx_connection_t *c)
}
#endif

#ifdef T_INGRESS_SHARED_MEMORY_PB
if (0
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
|| sslerr == SSL_ERROR_WANT_CLIENT_HELLO_CB
#endif
)
{
c->read->handler = ngx_ssl_handshake_handler;
c->write->handler = ngx_ssl_handshake_handler;

if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
return NGX_ERROR;
}

if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
return NGX_ERROR;
}

return NGX_AGAIN;
}
#endif

err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;

c->ssl->no_wait_shutdown = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/event/ngx_event_openssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ struct ngx_ssl_connection_s {
unsigned early_preread:1;
unsigned write_blocked:1;

#if defined(T_INGRESS_SHARED_MEMORY_PB) && OPENSSL_VERSION_NUMBER >= 0x10101000L
unsigned client_hello_retry:1;
#endif

#if (T_NGX_HAVE_DTLS)
unsigned bio_changed:1;
unsigned dtls_send:1;
Expand Down
5 changes: 5 additions & 0 deletions src/http/modules/ngx_http_ssl_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,11 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
cln->handler = ngx_ssl_cleanup_ctx;
cln->data = &conf->ssl;

#if defined(T_INGRESS_SHARED_MEMORY_PB) && OPENSSL_VERSION_NUMBER >= 0x10101000L
SSL_CTX_set_client_hello_cb(conf->ssl.ctx,
ngx_http_ssl_client_hello_callback, NULL);
#endif

#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME

if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx,
Expand Down
3 changes: 3 additions & 0 deletions src/http/ngx_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ int ngx_http_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg);
int ngx_http_ssl_certificate(ngx_ssl_conn_t *ssl_conn, void *arg);
#endif

#if defined(T_INGRESS_SHARED_MEMORY_PB) && OPENSSL_VERSION_NUMBER >= 0x10101000L
int ngx_http_ssl_client_hello_callback(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg);
#endif

ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b);
ngx_int_t ngx_http_parse_uri(ngx_http_request_t *r);
Expand Down
Loading