Latest update - 9224
This commit is contained in:
+286
-124
@@ -40,12 +40,12 @@ static ngx_int_t ngx_stream_ssl_variable(ngx_stream_session_t *s,
|
||||
ngx_stream_variable_value_t *v, uintptr_t data);
|
||||
|
||||
static ngx_int_t ngx_stream_ssl_add_variables(ngx_conf_t *cf);
|
||||
static void *ngx_stream_ssl_create_conf(ngx_conf_t *cf);
|
||||
static char *ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent,
|
||||
static void *ngx_stream_ssl_create_srv_conf(ngx_conf_t *cf);
|
||||
static char *ngx_stream_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent,
|
||||
void *child);
|
||||
|
||||
static ngx_int_t ngx_stream_ssl_compile_certificates(ngx_conf_t *cf,
|
||||
ngx_stream_ssl_conf_t *conf);
|
||||
ngx_stream_ssl_srv_conf_t *conf);
|
||||
|
||||
static char *ngx_stream_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
@@ -90,21 +90,21 @@ static ngx_command_t ngx_stream_ssl_commands[] = {
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_msec_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, handshake_timeout),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, handshake_timeout),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_certificate"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_array_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, certificates),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, certificates),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_certificate_key"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_array_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, certificate_keys),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, certificate_keys),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_password_file"),
|
||||
@@ -118,63 +118,63 @@ static ngx_command_t ngx_stream_ssl_commands[] = {
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, dhparam),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, dhparam),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_ecdh_curve"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, ecdh_curve),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, ecdh_curve),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_protocols"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE,
|
||||
ngx_conf_set_bitmask_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, protocols),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, protocols),
|
||||
&ngx_stream_ssl_protocols },
|
||||
|
||||
{ ngx_string("ssl_ciphers"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, ciphers),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, ciphers),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_verify_client"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_enum_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, verify),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, verify),
|
||||
&ngx_stream_ssl_verify },
|
||||
|
||||
{ ngx_string("ssl_verify_depth"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_num_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, verify_depth),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, verify_depth),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_client_certificate"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, client_certificate),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, client_certificate),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_trusted_certificate"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, trusted_certificate),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, trusted_certificate),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_prefer_server_ciphers"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, prefer_server_ciphers),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, prefer_server_ciphers),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_session_cache"),
|
||||
@@ -188,37 +188,44 @@ static ngx_command_t ngx_stream_ssl_commands[] = {
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, session_tickets),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, session_tickets),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_session_ticket_key"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_array_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, session_ticket_keys),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, session_ticket_keys),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_session_timeout"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_sec_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, session_timeout),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, session_timeout),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_crl"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, crl),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, crl),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_conf_command"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE2,
|
||||
ngx_conf_set_keyval_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_conf_t, conf_commands),
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, conf_commands),
|
||||
&ngx_stream_ssl_conf_command_post },
|
||||
|
||||
{ ngx_string("ssl_reject_handshake"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_ssl_srv_conf_t, reject_handshake),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssl_alpn"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE,
|
||||
ngx_stream_ssl_alpn,
|
||||
@@ -237,8 +244,8 @@ static ngx_stream_module_t ngx_stream_ssl_module_ctx = {
|
||||
NULL, /* create main configuration */
|
||||
NULL, /* init main configuration */
|
||||
|
||||
ngx_stream_ssl_create_conf, /* create server configuration */
|
||||
ngx_stream_ssl_merge_conf /* merge server configuration */
|
||||
ngx_stream_ssl_create_srv_conf, /* create server configuration */
|
||||
ngx_stream_ssl_merge_srv_conf /* merge server configuration */
|
||||
};
|
||||
|
||||
|
||||
@@ -332,11 +339,11 @@ static ngx_str_t ngx_stream_ssl_sess_id_ctx = ngx_string("STREAM");
|
||||
static ngx_int_t
|
||||
ngx_stream_ssl_handler(ngx_stream_session_t *s)
|
||||
{
|
||||
long rc;
|
||||
X509 *cert;
|
||||
ngx_int_t rv;
|
||||
ngx_connection_t *c;
|
||||
ngx_stream_ssl_conf_t *sslcf;
|
||||
long rc;
|
||||
X509 *cert;
|
||||
ngx_int_t rv;
|
||||
ngx_connection_t *c;
|
||||
ngx_stream_ssl_srv_conf_t *sscf;
|
||||
|
||||
if (!s->ssl) {
|
||||
return NGX_OK;
|
||||
@@ -344,23 +351,23 @@ ngx_stream_ssl_handler(ngx_stream_session_t *s)
|
||||
|
||||
c = s->connection;
|
||||
|
||||
sslcf = ngx_stream_get_module_srv_conf(s, ngx_stream_ssl_module);
|
||||
sscf = ngx_stream_get_module_srv_conf(s, ngx_stream_ssl_module);
|
||||
|
||||
if (c->ssl == NULL) {
|
||||
c->log->action = "SSL handshaking";
|
||||
|
||||
rv = ngx_stream_ssl_init_connection(&sslcf->ssl, c);
|
||||
rv = ngx_stream_ssl_init_connection(&sscf->ssl, c);
|
||||
|
||||
if (rv != NGX_OK) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (sslcf->verify) {
|
||||
if (sscf->verify) {
|
||||
rc = SSL_get_verify_result(c->ssl->connection);
|
||||
|
||||
if (rc != X509_V_OK
|
||||
&& (sslcf->verify != 3 || !ngx_ssl_verify_error_optional(rc)))
|
||||
&& (sscf->verify != 3 || !ngx_ssl_verify_error_optional(rc)))
|
||||
{
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, 0,
|
||||
"client SSL certificate verify error: (%l:%s)",
|
||||
@@ -371,7 +378,7 @@ ngx_stream_ssl_handler(ngx_stream_session_t *s)
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (sslcf->verify == 1) {
|
||||
if (sscf->verify == 1) {
|
||||
cert = SSL_get_peer_certificate(c->ssl->connection);
|
||||
|
||||
if (cert == NULL) {
|
||||
@@ -396,7 +403,7 @@ ngx_stream_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c)
|
||||
{
|
||||
ngx_int_t rc;
|
||||
ngx_stream_session_t *s;
|
||||
ngx_stream_ssl_conf_t *sslcf;
|
||||
ngx_stream_ssl_srv_conf_t *sscf;
|
||||
ngx_stream_core_srv_conf_t *cscf;
|
||||
|
||||
s = c->data;
|
||||
@@ -418,9 +425,9 @@ ngx_stream_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c)
|
||||
}
|
||||
|
||||
if (rc == NGX_AGAIN) {
|
||||
sslcf = ngx_stream_get_module_srv_conf(s, ngx_stream_ssl_module);
|
||||
sscf = ngx_stream_get_module_srv_conf(s, ngx_stream_ssl_module);
|
||||
|
||||
ngx_add_timer(c->read, sslcf->handshake_timeout);
|
||||
ngx_add_timer(c->read, sscf->handshake_timeout);
|
||||
|
||||
c->ssl->handler = ngx_stream_ssl_handshake_handler;
|
||||
|
||||
@@ -458,7 +465,112 @@ ngx_stream_ssl_handshake_handler(ngx_connection_t *c)
|
||||
static int
|
||||
ngx_stream_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
|
||||
{
|
||||
ngx_int_t rc;
|
||||
ngx_str_t host;
|
||||
const char *servername;
|
||||
ngx_connection_t *c;
|
||||
ngx_stream_session_t *s;
|
||||
ngx_stream_ssl_srv_conf_t *sscf;
|
||||
ngx_stream_core_srv_conf_t *cscf;
|
||||
|
||||
c = ngx_ssl_get_connection(ssl_conn);
|
||||
|
||||
if (c->ssl->handshaked) {
|
||||
*ad = SSL_AD_NO_RENEGOTIATION;
|
||||
return SSL_TLSEXT_ERR_ALERT_FATAL;
|
||||
}
|
||||
|
||||
s = c->data;
|
||||
|
||||
servername = SSL_get_servername(ssl_conn, TLSEXT_NAMETYPE_host_name);
|
||||
|
||||
if (servername == NULL) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0,
|
||||
"SSL server name: null");
|
||||
goto done;
|
||||
}
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0,
|
||||
"SSL server name: \"%s\"", servername);
|
||||
|
||||
host.len = ngx_strlen(servername);
|
||||
|
||||
if (host.len == 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
host.data = (u_char *) servername;
|
||||
|
||||
rc = ngx_stream_validate_host(&host, c->pool, 1);
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (rc == NGX_DECLINED) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
rc = ngx_stream_find_virtual_server(s, &host, &cscf);
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (rc == NGX_DECLINED) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
s->srv_conf = cscf->ctx->srv_conf;
|
||||
|
||||
ngx_set_connection_log(c, cscf->error_log);
|
||||
|
||||
sscf = ngx_stream_get_module_srv_conf(s, ngx_stream_ssl_module);
|
||||
|
||||
if (sscf->ssl.ctx) {
|
||||
if (SSL_set_SSL_CTX(ssl_conn, sscf->ssl.ctx) == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* SSL_set_SSL_CTX() only changes certs as of 1.0.0d
|
||||
* adjust other things we care about
|
||||
*/
|
||||
|
||||
SSL_set_verify(ssl_conn, SSL_CTX_get_verify_mode(sscf->ssl.ctx),
|
||||
SSL_CTX_get_verify_callback(sscf->ssl.ctx));
|
||||
|
||||
SSL_set_verify_depth(ssl_conn, SSL_CTX_get_verify_depth(sscf->ssl.ctx));
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x009080dfL
|
||||
/* only in 0.9.8m+ */
|
||||
SSL_clear_options(ssl_conn, SSL_get_options(ssl_conn) &
|
||||
~SSL_CTX_get_options(sscf->ssl.ctx));
|
||||
#endif
|
||||
|
||||
SSL_set_options(ssl_conn, SSL_CTX_get_options(sscf->ssl.ctx));
|
||||
|
||||
#ifdef SSL_OP_NO_RENEGOTIATION
|
||||
SSL_set_options(ssl_conn, SSL_OP_NO_RENEGOTIATION);
|
||||
#endif
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
sscf = ngx_stream_get_module_srv_conf(s, ngx_stream_ssl_module);
|
||||
|
||||
if (sscf->reject_handshake) {
|
||||
c->ssl->handshake_rejected = 1;
|
||||
*ad = SSL_AD_UNRECOGNIZED_NAME;
|
||||
return SSL_TLSEXT_ERR_ALERT_FATAL;
|
||||
}
|
||||
|
||||
return SSL_TLSEXT_ERR_OK;
|
||||
|
||||
error:
|
||||
|
||||
*ad = SSL_AD_INTERNAL_ERROR;
|
||||
return SSL_TLSEXT_ERR_ALERT_FATAL;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -513,7 +625,7 @@ ngx_stream_ssl_certificate(ngx_ssl_conn_t *ssl_conn, void *arg)
|
||||
ngx_uint_t i, nelts;
|
||||
ngx_connection_t *c;
|
||||
ngx_stream_session_t *s;
|
||||
ngx_stream_ssl_conf_t *sslcf;
|
||||
ngx_stream_ssl_srv_conf_t *sscf;
|
||||
ngx_stream_complex_value_t *certs, *keys;
|
||||
|
||||
c = ngx_ssl_get_connection(ssl_conn);
|
||||
@@ -524,11 +636,11 @@ ngx_stream_ssl_certificate(ngx_ssl_conn_t *ssl_conn, void *arg)
|
||||
|
||||
s = c->data;
|
||||
|
||||
sslcf = arg;
|
||||
sscf = arg;
|
||||
|
||||
nelts = sslcf->certificate_values->nelts;
|
||||
certs = sslcf->certificate_values->elts;
|
||||
keys = sslcf->certificate_key_values->elts;
|
||||
nelts = sscf->certificate_values->nelts;
|
||||
certs = sscf->certificate_values->elts;
|
||||
keys = sscf->certificate_key_values->elts;
|
||||
|
||||
for (i = 0; i < nelts; i++) {
|
||||
|
||||
@@ -547,7 +659,7 @@ ngx_stream_ssl_certificate(ngx_ssl_conn_t *ssl_conn, void *arg)
|
||||
"ssl key: \"%s\"", key.data);
|
||||
|
||||
if (ngx_ssl_connection_certificate(c, c->pool, &cert, &key,
|
||||
sslcf->passwords)
|
||||
sscf->passwords)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return 0;
|
||||
@@ -643,53 +755,53 @@ ngx_stream_ssl_add_variables(ngx_conf_t *cf)
|
||||
|
||||
|
||||
static void *
|
||||
ngx_stream_ssl_create_conf(ngx_conf_t *cf)
|
||||
ngx_stream_ssl_create_srv_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_stream_ssl_conf_t *scf;
|
||||
ngx_stream_ssl_srv_conf_t *sscf;
|
||||
|
||||
scf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_ssl_conf_t));
|
||||
if (scf == NULL) {
|
||||
sscf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_ssl_srv_conf_t));
|
||||
if (sscf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* set by ngx_pcalloc():
|
||||
*
|
||||
* scf->listen = 0;
|
||||
* scf->protocols = 0;
|
||||
* scf->certificate_values = NULL;
|
||||
* scf->dhparam = { 0, NULL };
|
||||
* scf->ecdh_curve = { 0, NULL };
|
||||
* scf->client_certificate = { 0, NULL };
|
||||
* scf->trusted_certificate = { 0, NULL };
|
||||
* scf->crl = { 0, NULL };
|
||||
* scf->alpn = { 0, NULL };
|
||||
* scf->ciphers = { 0, NULL };
|
||||
* scf->shm_zone = NULL;
|
||||
* sscf->protocols = 0;
|
||||
* sscf->certificate_values = NULL;
|
||||
* sscf->dhparam = { 0, NULL };
|
||||
* sscf->ecdh_curve = { 0, NULL };
|
||||
* sscf->client_certificate = { 0, NULL };
|
||||
* sscf->trusted_certificate = { 0, NULL };
|
||||
* sscf->crl = { 0, NULL };
|
||||
* sscf->alpn = { 0, NULL };
|
||||
* sscf->ciphers = { 0, NULL };
|
||||
* sscf->shm_zone = NULL;
|
||||
*/
|
||||
|
||||
scf->handshake_timeout = NGX_CONF_UNSET_MSEC;
|
||||
scf->certificates = NGX_CONF_UNSET_PTR;
|
||||
scf->certificate_keys = NGX_CONF_UNSET_PTR;
|
||||
scf->passwords = NGX_CONF_UNSET_PTR;
|
||||
scf->conf_commands = NGX_CONF_UNSET_PTR;
|
||||
scf->prefer_server_ciphers = NGX_CONF_UNSET;
|
||||
scf->verify = NGX_CONF_UNSET_UINT;
|
||||
scf->verify_depth = NGX_CONF_UNSET_UINT;
|
||||
scf->builtin_session_cache = NGX_CONF_UNSET;
|
||||
scf->session_timeout = NGX_CONF_UNSET;
|
||||
scf->session_tickets = NGX_CONF_UNSET;
|
||||
scf->session_ticket_keys = NGX_CONF_UNSET_PTR;
|
||||
sscf->handshake_timeout = NGX_CONF_UNSET_MSEC;
|
||||
sscf->certificates = NGX_CONF_UNSET_PTR;
|
||||
sscf->certificate_keys = NGX_CONF_UNSET_PTR;
|
||||
sscf->passwords = NGX_CONF_UNSET_PTR;
|
||||
sscf->conf_commands = NGX_CONF_UNSET_PTR;
|
||||
sscf->prefer_server_ciphers = NGX_CONF_UNSET;
|
||||
sscf->reject_handshake = NGX_CONF_UNSET;
|
||||
sscf->verify = NGX_CONF_UNSET_UINT;
|
||||
sscf->verify_depth = NGX_CONF_UNSET_UINT;
|
||||
sscf->builtin_session_cache = NGX_CONF_UNSET;
|
||||
sscf->session_timeout = NGX_CONF_UNSET;
|
||||
sscf->session_tickets = NGX_CONF_UNSET;
|
||||
sscf->session_ticket_keys = NGX_CONF_UNSET_PTR;
|
||||
|
||||
return scf;
|
||||
return sscf;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
ngx_stream_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
{
|
||||
ngx_stream_ssl_conf_t *prev = parent;
|
||||
ngx_stream_ssl_conf_t *conf = child;
|
||||
ngx_stream_ssl_srv_conf_t *prev = parent;
|
||||
ngx_stream_ssl_srv_conf_t *conf = child;
|
||||
|
||||
ngx_pool_cleanup_t *cln;
|
||||
|
||||
@@ -702,6 +814,8 @@ ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
ngx_conf_merge_value(conf->prefer_server_ciphers,
|
||||
prev->prefer_server_ciphers, 1);
|
||||
|
||||
ngx_conf_merge_value(conf->reject_handshake, prev->reject_handshake, 0);
|
||||
|
||||
ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
|
||||
(NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
|
||||
@@ -733,37 +847,23 @@ ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
|
||||
conf->ssl.log = cf->log;
|
||||
|
||||
if (!conf->listen) {
|
||||
if (conf->certificates) {
|
||||
|
||||
if (conf->certificate_keys == NULL
|
||||
|| conf->certificate_keys->nelts < conf->certificates->nelts)
|
||||
{
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate_key\" is defined "
|
||||
"for certificate \"%V\"",
|
||||
((ngx_str_t *) conf->certificates->elts)
|
||||
+ conf->certificates->nelts - 1);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
} else if (!conf->reject_handshake) {
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
if (conf->certificates == NULL) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate\" is defined for "
|
||||
"the \"listen ... ssl\" directive in %s:%ui",
|
||||
conf->file, conf->line);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (conf->certificate_keys == NULL) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate_key\" is defined for "
|
||||
"the \"listen ... ssl\" directive in %s:%ui",
|
||||
conf->file, conf->line);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (conf->certificate_keys->nelts < conf->certificates->nelts) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate_key\" is defined "
|
||||
"for certificate \"%V\" and "
|
||||
"the \"listen ... ssl\" directive in %s:%ui",
|
||||
((ngx_str_t *) conf->certificates->elts)
|
||||
+ conf->certificates->nelts - 1,
|
||||
conf->file, conf->line);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (ngx_ssl_create(&conf->ssl, conf->protocols, NULL) != NGX_OK) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
@@ -816,7 +916,7 @@ ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
return NGX_CONF_ERROR;
|
||||
#endif
|
||||
|
||||
} else {
|
||||
} else if (conf->certificates) {
|
||||
|
||||
/* configure certificates */
|
||||
|
||||
@@ -908,13 +1008,17 @@ ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
|
||||
static ngx_int_t
|
||||
ngx_stream_ssl_compile_certificates(ngx_conf_t *cf,
|
||||
ngx_stream_ssl_conf_t *conf)
|
||||
ngx_stream_ssl_srv_conf_t *conf)
|
||||
{
|
||||
ngx_str_t *cert, *key;
|
||||
ngx_uint_t i, nelts;
|
||||
ngx_stream_complex_value_t *cv;
|
||||
ngx_stream_compile_complex_value_t ccv;
|
||||
|
||||
if (conf->certificates == NULL) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
cert = conf->certificates->elts;
|
||||
key = conf->certificate_keys->elts;
|
||||
nelts = conf->certificates->nelts;
|
||||
@@ -993,19 +1097,19 @@ found:
|
||||
static char *
|
||||
ngx_stream_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_stream_ssl_conf_t *scf = conf;
|
||||
ngx_stream_ssl_srv_conf_t *sscf = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
|
||||
if (scf->passwords != NGX_CONF_UNSET_PTR) {
|
||||
if (sscf->passwords != NGX_CONF_UNSET_PTR) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
scf->passwords = ngx_ssl_read_password_file(cf, &value[1]);
|
||||
sscf->passwords = ngx_ssl_read_password_file(cf, &value[1]);
|
||||
|
||||
if (scf->passwords == NULL) {
|
||||
if (sscf->passwords == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
@@ -1016,7 +1120,7 @@ ngx_stream_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
static char *
|
||||
ngx_stream_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_stream_ssl_conf_t *scf = conf;
|
||||
ngx_stream_ssl_srv_conf_t *sscf = conf;
|
||||
|
||||
size_t len;
|
||||
ngx_str_t *value, name, size;
|
||||
@@ -1028,17 +1132,17 @@ ngx_stream_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
for (i = 1; i < cf->args->nelts; i++) {
|
||||
|
||||
if (ngx_strcmp(value[i].data, "off") == 0) {
|
||||
scf->builtin_session_cache = NGX_SSL_NO_SCACHE;
|
||||
sscf->builtin_session_cache = NGX_SSL_NO_SCACHE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_strcmp(value[i].data, "none") == 0) {
|
||||
scf->builtin_session_cache = NGX_SSL_NONE_SCACHE;
|
||||
sscf->builtin_session_cache = NGX_SSL_NONE_SCACHE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_strcmp(value[i].data, "builtin") == 0) {
|
||||
scf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE;
|
||||
sscf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1053,7 +1157,7 @@ ngx_stream_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
scf->builtin_session_cache = n;
|
||||
sscf->builtin_session_cache = n;
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -1096,13 +1200,13 @@ ngx_stream_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
scf->shm_zone = ngx_shared_memory_add(cf, &name, n,
|
||||
sscf->shm_zone = ngx_shared_memory_add(cf, &name, n,
|
||||
&ngx_stream_ssl_module);
|
||||
if (scf->shm_zone == NULL) {
|
||||
if (sscf->shm_zone == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
scf->shm_zone->init = ngx_ssl_session_cache_init;
|
||||
sscf->shm_zone->init = ngx_ssl_session_cache_init;
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -1110,8 +1214,8 @@ ngx_stream_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
if (scf->shm_zone && scf->builtin_session_cache == NGX_CONF_UNSET) {
|
||||
scf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE;
|
||||
if (sscf->shm_zone && sscf->builtin_session_cache == NGX_CONF_UNSET) {
|
||||
sscf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE;
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
@@ -1130,14 +1234,14 @@ ngx_stream_ssl_alpn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
|
||||
|
||||
ngx_stream_ssl_conf_t *scf = conf;
|
||||
ngx_stream_ssl_srv_conf_t *sscf = conf;
|
||||
|
||||
u_char *p;
|
||||
size_t len;
|
||||
ngx_str_t *value;
|
||||
ngx_uint_t i;
|
||||
|
||||
if (scf->alpn.len) {
|
||||
if (sscf->alpn.len) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
@@ -1154,19 +1258,19 @@ ngx_stream_ssl_alpn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
len += value[i].len + 1;
|
||||
}
|
||||
|
||||
scf->alpn.data = ngx_pnalloc(cf->pool, len);
|
||||
if (scf->alpn.data == NULL) {
|
||||
sscf->alpn.data = ngx_pnalloc(cf->pool, len);
|
||||
if (sscf->alpn.data == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
p = scf->alpn.data;
|
||||
p = sscf->alpn.data;
|
||||
|
||||
for (i = 1; i < cf->args->nelts; i++) {
|
||||
*p++ = value[i].len;
|
||||
p = ngx_cpymem(p, value[i].data, value[i].len);
|
||||
}
|
||||
|
||||
scf->alpn.len = len;
|
||||
sscf->alpn.len = len;
|
||||
|
||||
return NGX_CONF_OK;
|
||||
|
||||
@@ -1193,8 +1297,13 @@ ngx_stream_ssl_conf_command_check(ngx_conf_t *cf, void *post, void *data)
|
||||
static ngx_int_t
|
||||
ngx_stream_ssl_init(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_stream_handler_pt *h;
|
||||
ngx_stream_core_main_conf_t *cmcf;
|
||||
ngx_uint_t a, p, s;
|
||||
ngx_stream_handler_pt *h;
|
||||
ngx_stream_conf_addr_t *addr;
|
||||
ngx_stream_conf_port_t *port;
|
||||
ngx_stream_ssl_srv_conf_t *sscf;
|
||||
ngx_stream_core_srv_conf_t **cscfp, *cscf;
|
||||
ngx_stream_core_main_conf_t *cmcf;
|
||||
|
||||
cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module);
|
||||
|
||||
@@ -1205,5 +1314,58 @@ ngx_stream_ssl_init(ngx_conf_t *cf)
|
||||
|
||||
*h = ngx_stream_ssl_handler;
|
||||
|
||||
if (cmcf->ports == NULL) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
port = cmcf->ports->elts;
|
||||
for (p = 0; p < cmcf->ports->nelts; p++) {
|
||||
|
||||
addr = port[p].addrs.elts;
|
||||
for (a = 0; a < port[p].addrs.nelts; a++) {
|
||||
|
||||
if (!addr[a].opt.ssl) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cscf = addr[a].default_server;
|
||||
sscf = cscf->ctx->srv_conf[ngx_stream_ssl_module.ctx_index];
|
||||
|
||||
if (sscf->certificates) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!sscf->reject_handshake) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate\" is defined for "
|
||||
"the \"listen ... ssl\" directive in %s:%ui",
|
||||
cscf->file_name, cscf->line);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* if no certificates are defined in the default server,
|
||||
* check all non-default server blocks
|
||||
*/
|
||||
|
||||
cscfp = addr[a].servers.elts;
|
||||
for (s = 0; s < addr[a].servers.nelts; s++) {
|
||||
|
||||
cscf = cscfp[s];
|
||||
sscf = cscf->ctx->srv_conf[ngx_stream_ssl_module.ctx_index];
|
||||
|
||||
if (sscf->certificates || sscf->reject_handshake) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate\" is defined for "
|
||||
"the \"listen ... ssl\" directive in %s:%ui",
|
||||
cscf->file_name, cscf->line);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user