aboutsummaryrefslogtreecommitdiff
path: root/src/stream/ngx_stream_proxy_module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stream/ngx_stream_proxy_module.c')
-rw-r--r--src/stream/ngx_stream_proxy_module.c68
1 files changed, 58 insertions, 10 deletions
diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c
index 7f8bfc4e0..6e51585f6 100644
--- a/src/stream/ngx_stream_proxy_module.c
+++ b/src/stream/ngx_stream_proxy_module.c
@@ -108,6 +108,8 @@ static ngx_int_t ngx_stream_proxy_ssl_name(ngx_stream_session_t *s);
static ngx_int_t ngx_stream_proxy_ssl_certificate(ngx_stream_session_t *s);
static ngx_int_t ngx_stream_proxy_merge_ssl(ngx_conf_t *cf,
ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev);
+static ngx_int_t ngx_stream_proxy_merge_ssl_passwords(ngx_conf_t *cf,
+ ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev);
static ngx_int_t ngx_stream_proxy_set_ssl(ngx_conf_t *cf,
ngx_stream_proxy_srv_conf_t *pscf);
@@ -2315,7 +2317,9 @@ ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_ptr_value(conf->ssl_certificate_cache,
prev->ssl_certificate_cache, NULL);
- ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL);
+ if (ngx_stream_proxy_merge_ssl_passwords(cf, conf, prev) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
ngx_conf_merge_ptr_value(conf->ssl_conf_commands,
prev->ssl_conf_commands, NULL);
@@ -2382,6 +2386,57 @@ ngx_stream_proxy_merge_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *conf,
static ngx_int_t
+ngx_stream_proxy_merge_ssl_passwords(ngx_conf_t *cf,
+ ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev)
+{
+ ngx_uint_t preserve;
+
+ ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL);
+
+ if (conf->ssl_certificate == NULL
+ || conf->ssl_certificate->value.len == 0
+ || conf->ssl_certificate_key == NULL)
+ {
+ return NGX_OK;
+ }
+
+ if (conf->ssl_certificate->lengths == NULL
+ && conf->ssl_certificate_key->lengths == NULL)
+ {
+ if (conf->ssl_passwords && conf->ssl_passwords->pool == NULL) {
+ /* un-preserve empty password list */
+ conf->ssl_passwords = NULL;
+ }
+
+ return NGX_OK;
+ }
+
+ if (conf->ssl_passwords && conf->ssl_passwords->pool != cf->temp_pool) {
+ /* already preserved */
+ return NGX_OK;
+ }
+
+ preserve = (conf->ssl_passwords == prev->ssl_passwords) ? 1 : 0;
+
+ conf->ssl_passwords = ngx_ssl_preserve_passwords(cf, conf->ssl_passwords);
+ if (conf->ssl_passwords == NULL) {
+ return NGX_ERROR;
+ }
+
+ /*
+ * special handling to keep a preserved ssl_passwords copy
+ * in the previous configuration to inherit it to all children
+ */
+
+ if (preserve) {
+ prev->ssl_passwords = conf->ssl_passwords;
+ }
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_stream_proxy_set_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *pscf)
{
ngx_pool_cleanup_t *cln;
@@ -2418,16 +2473,9 @@ ngx_stream_proxy_set_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *pscf)
return NGX_ERROR;
}
- if (pscf->ssl_certificate->lengths
- || pscf->ssl_certificate_key->lengths)
+ if (pscf->ssl_certificate->lengths == NULL
+ && pscf->ssl_certificate_key->lengths == NULL)
{
- pscf->ssl_passwords =
- ngx_ssl_preserve_passwords(cf, pscf->ssl_passwords);
- if (pscf->ssl_passwords == NULL) {
- return NGX_ERROR;
- }
-
- } else {
if (ngx_ssl_certificate(cf, pscf->ssl,
&pscf->ssl_certificate->value,
&pscf->ssl_certificate_key->value,