ngx_ssl_get_server_conf()
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c index 2c6d445..c5389e3 100644 --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c
@@ -84,7 +84,8 @@ }; -int ngx_connection_index; +int ngx_ssl_connection_index; +int ngx_ssl_server_conf_index; ngx_int_t @@ -101,19 +102,27 @@ ENGINE_load_builtin_engines(); #endif - ngx_connection_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); + ngx_ssl_connection_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); - if (ngx_connection_index == -1) { + if (ngx_ssl_connection_index == -1) { ngx_ssl_error(NGX_LOG_ALERT, log, 0, "SSL_get_ex_new_index() failed"); return NGX_ERROR; } + ngx_ssl_server_conf_index = SSL_CTX_get_ex_new_index(0, NULL, NULL, NULL, + NULL); + if (ngx_ssl_server_conf_index == -1) { + ngx_ssl_error(NGX_LOG_ALERT, log, 0, + "SSL_CTX_get_ex_new_index() failed"); + return NGX_ERROR; + } + return NGX_OK; } ngx_int_t -ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols) +ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data) { ssl->ctx = SSL_CTX_new(SSLv23_method()); @@ -122,6 +131,12 @@ return NGX_ERROR; } + if (SSL_CTX_set_ex_data(ssl->ctx, ngx_ssl_server_conf_index, data) == 0) { + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, + "SSL_CTX_set_ex_data() failed"); + return NGX_ERROR; + } + /* client side options */ SSL_CTX_set_options(ssl->ctx, SSL_OP_MICROSOFT_SESS_ID_BUG); @@ -336,7 +351,7 @@ SSL_set_accept_state(sc->connection); } - if (SSL_set_ex_data(sc->connection, ngx_connection_index, c) == 0) { + if (SSL_set_ex_data(sc->connection, ngx_ssl_connection_index, c) == 0) { ngx_ssl_error(NGX_LOG_ALERT, c->log, 0, "SSL_set_ex_data() failed"); return NGX_ERROR; }
diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h index 7247fd2..758f579 100644 --- a/src/event/ngx_event_openssl.h +++ b/src/event/ngx_event_openssl.h
@@ -63,7 +63,7 @@ ngx_int_t ngx_ssl_init(ngx_log_t *log); -ngx_int_t ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols); +ngx_int_t ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data); ngx_int_t ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert, ngx_str_t *key); ngx_int_t ngx_ssl_client_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, @@ -75,7 +75,10 @@ ngx_int_t ngx_ssl_set_session(ngx_connection_t *c, ngx_ssl_session_t *session); #define ngx_ssl_get_session(c) SSL_get1_session(c->ssl->connection) #define ngx_ssl_free_session SSL_SESSION_free -#define ngx_ssl_get_connection(sc) SSL_get_ex_data(sc, ngx_connection_index) +#define ngx_ssl_get_connection(ssl_conn) \ + SSL_get_ex_data(ssl_conn, ngx_ssl_connection_index) +#define ngx_ssl_get_server_conf(ssl_ctx) \ + SSL_CTX_get_ex_data(ssl_ctx, ngx_ssl_server_conf_index) ngx_int_t ngx_ssl_get_protocol(ngx_connection_t *c, ngx_pool_t *pool, @@ -104,7 +107,8 @@ void ngx_ssl_cleanup_ctx(void *data); -extern int ngx_connection_index; +extern int ngx_ssl_connection_index; +extern int ngx_ssl_server_conf_index; #endif /* _NGX_EVENT_OPENSSL_H_INCLUDED_ */
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index 9083ee8..63ee8fd 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c
@@ -2130,7 +2130,7 @@ plcf->upstream.ssl->log = cf->log; if (ngx_ssl_create(plcf->upstream.ssl, - NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1) + NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1, NULL) != NGX_OK) { return NGX_CONF_ERROR;
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c index 30c2d11..39e3eab 100644 --- a/src/http/modules/ngx_http_ssl_module.c +++ b/src/http/modules/ngx_http_ssl_module.c
@@ -330,7 +330,7 @@ conf->ssl.log = cf->log; - if (ngx_ssl_create(&conf->ssl, conf->protocols) != NGX_OK) { + if (ngx_ssl_create(&conf->ssl, conf->protocols, conf) != NGX_OK) { return NGX_CONF_ERROR; }
diff --git a/src/imap/ngx_imap_ssl_module.c b/src/imap/ngx_imap_ssl_module.c index cb2b8ca..5836574 100644 --- a/src/imap/ngx_imap_ssl_module.c +++ b/src/imap/ngx_imap_ssl_module.c
@@ -206,7 +206,7 @@ conf->ssl.log = cf->log; - if (ngx_ssl_create(&conf->ssl, conf->protocols) != NGX_OK) { + if (ngx_ssl_create(&conf->ssl, conf->protocols, NULL) != NGX_OK) { return NGX_CONF_ERROR; }