diff options
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/modules/ngx_http_ssl_module.c | 69 | ||||
-rw-r--r-- | src/http/modules/ngx_http_ssl_module.h | 3 | ||||
-rw-r--r-- | src/http/ngx_http.c | 10 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.c | 12 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.h | 10 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 15 |
6 files changed, 106 insertions, 13 deletions
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c index 53e2a2157..48d40e599 100644 --- a/src/http/modules/ngx_http_ssl_module.c +++ b/src/http/modules/ngx_http_ssl_module.c @@ -13,8 +13,6 @@ typedef ngx_int_t (*ngx_ssl_variable_handler_pt)(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s); -#define NGX_DEFAULT_CERTIFICATE "cert.pem" -#define NGX_DEFAULT_CERTIFICATE_KEY "cert.pem" #define NGX_DEFAULT_CIPHERS "ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP" @@ -28,6 +26,8 @@ static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf); static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child); +static char *ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); static char *ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -61,7 +61,7 @@ static ngx_command_t ngx_http_ssl_commands[] = { { ngx_string("ssl"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, + ngx_http_ssl_enable, NGX_HTTP_SRV_CONF_OFFSET, offsetof(ngx_http_ssl_srv_conf_t, enable), NULL }, @@ -339,10 +339,6 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) ngx_conf_merge_value(conf->enable, prev->enable, 0); - if (conf->enable == 0) { - return NGX_CONF_OK; - } - ngx_conf_merge_value(conf->session_timeout, prev->session_timeout, 300); @@ -356,11 +352,8 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) ngx_conf_merge_uint_value(conf->verify, prev->verify, 0); ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1); - ngx_conf_merge_str_value(conf->certificate, prev->certificate, - NGX_DEFAULT_CERTIFICATE); - - ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, - NGX_DEFAULT_CERTIFICATE_KEY); + ngx_conf_merge_str_value(conf->certificate, prev->certificate, ""); + ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, ""); ngx_conf_merge_str_value(conf->dhparam, prev->dhparam, ""); @@ -372,6 +365,38 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) conf->ssl.log = cf->log; + if (conf->enable) { + + if (conf->certificate.len == 0) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no \"ssl_certificate\" is defined for " + "the \"ssl\" directive in %s:%ui", + conf->file, conf->line); + return NGX_CONF_ERROR; + } + + if (conf->certificate_key.len == 0) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no \"ssl_certificate_key\" is defined for " + "the \"ssl\" directive in %s:%ui", + conf->file, conf->line); + return NGX_CONF_ERROR; + } + + } else { + + if (conf->certificate.len == 0) { + return NGX_CONF_OK; + } + + if (conf->certificate_key.len == 0) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no \"ssl_certificate_key\" is defined " + "for certificate \"%V\"", &conf->certificate); + return NGX_CONF_ERROR; + } + } + if (ngx_ssl_create(&conf->ssl, conf->protocols, conf) != NGX_OK) { return NGX_CONF_ERROR; } @@ -467,6 +492,26 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) static char * +ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_http_ssl_srv_conf_t *sscf = conf; + + char *rv; + + rv = ngx_conf_set_flag_slot(cf, cmd, conf); + + if (rv != NGX_CONF_OK) { + return rv; + } + + sscf->file = cf->conf_file->file.name.data; + sscf->line = cf->conf_file->line; + + return NGX_CONF_OK; +} + + +static char * ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_ssl_srv_conf_t *sscf = conf; diff --git a/src/http/modules/ngx_http_ssl_module.h b/src/http/modules/ngx_http_ssl_module.h index 2322d90c1..da7f04736 100644 --- a/src/http/modules/ngx_http_ssl_module.h +++ b/src/http/modules/ngx_http_ssl_module.h @@ -37,6 +37,9 @@ typedef struct { ngx_str_t ciphers; ngx_shm_zone_t *shm_zone; + + u_char *file; + ngx_uint_t line; } ngx_http_ssl_srv_conf_t; diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 7b109cace..d476b5f10 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -1158,6 +1158,9 @@ ngx_http_init_server_lists(ngx_conf_t *cf, ngx_array_t *servers, in_addr[a].core_srv_conf = cscfp[s]; in_addr[a].default_server = 1; +#if (NGX_HTTP_SSL) + in_addr[a].ssl = listen[l].conf.ssl; +#endif in_addr[a].listen_conf = &listen[l].conf; } @@ -1242,6 +1245,9 @@ ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, in_addr->core_srv_conf = cscf; in_addr->default_server = listen->conf.default_server; in_addr->bind = listen->conf.bind; +#if (NGX_HTTP_SSL) + in_addr->ssl = listen->conf.ssl; +#endif in_addr->listen_conf = &listen->conf; return ngx_http_add_names(cf, cscf, in_addr); @@ -1648,6 +1654,10 @@ ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_in_port_t *in_port) hip->addrs[i].addr = in_addr[i].addr; hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf; +#if (NGX_HTTP_SSL) + hip->addrs[i].ssl = in_addr[i].ssl; +#endif + if (in_addr[i].hash.buckets == NULL && (in_addr[i].wc_head == NULL || in_addr[i].wc_head->hash.buckets == NULL) diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index c0c9e74be..dbdde6b01 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -3081,6 +3081,18 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) continue; } + if (ngx_strcmp(value[n].data, "ssl") == 0) { +#if (NGX_HTTP_SSL) + ls->conf.ssl = 1; + continue; +#else + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "the \"ssl\" parameter requires " + "ngx_http_ssl_module"); + return NGX_CONF_ERROR; +#endif + } + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "the invalid \"%V\" parameter", &value[n]); return NGX_CONF_ERROR; diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index c1ae27d2b..54e4493bc 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -35,6 +35,9 @@ typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t; typedef struct { unsigned default_server:1; unsigned bind:1; +#if (NGX_HTTP_SSL) + unsigned ssl:1; +#endif int backlog; int rcvbuf; @@ -167,6 +170,10 @@ typedef struct { ngx_http_core_srv_conf_t *core_srv_conf; ngx_http_virtual_names_t *virtual_names; + +#if (NGX_HTTP_SSL) + ngx_uint_t ssl; /* unsigned ssl:1; */ +#endif } ngx_http_in_addr_t; @@ -203,6 +210,9 @@ typedef struct { unsigned default_server:1; unsigned bind:1; +#if (NGX_HTTP_SSL) + unsigned ssl:1; +#endif ngx_http_listen_conf_t *listen_conf; } ngx_http_conf_in_addr_t; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 94f786e9a..113c5e894 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -357,9 +357,20 @@ ngx_http_init_request(ngx_event_t *rev) ngx_http_ssl_srv_conf_t *sscf; sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module); - if (sscf->enable) { + if (sscf->enable || hia[i].ssl) { if (c->ssl == NULL) { + + c->log->action = "SSL handshaking"; + + if (hia[i].ssl && sscf->ssl.ctx == NULL) { + ngx_log_error(NGX_LOG_ERR, c->log, 0, + "no \"ssl_certificate\" is defined " + "in server listening on SSL port"); + ngx_http_close_connection(c); + return; + } + if (ngx_ssl_create_connection(&sscf->ssl, c, NGX_SSL_BUFFER) == NGX_ERROR) { @@ -529,6 +540,8 @@ ngx_http_ssl_handshake(ngx_event_t *rev) } } + c->log->action = "reading client request line"; + rev->handler = ngx_http_process_request_line; ngx_http_process_request_line(rev); } |