0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10
|
122
|
11
|
220
|
12 typedef ngx_int_t (*ngx_ssl_variable_handler_pt)(ngx_connection_t *c,
|
|
13 ngx_pool_t *pool, ngx_str_t *s);
|
160
|
14
|
|
15
|
632
|
16 #define NGX_DEFAULT_CIPHERS "HIGH:!aNULL:!MD5"
|
|
17 #define NGX_DEFAULT_ECDH_CURVE "prime256v1"
|
0
|
18
|
|
19
|
220
|
20 static ngx_int_t ngx_http_ssl_static_variable(ngx_http_request_t *r,
|
160
|
21 ngx_http_variable_value_t *v, uintptr_t data);
|
220
|
22 static ngx_int_t ngx_http_ssl_variable(ngx_http_request_t *r,
|
196
|
23 ngx_http_variable_value_t *v, uintptr_t data);
|
160
|
24
|
|
25 static ngx_int_t ngx_http_ssl_add_variables(ngx_conf_t *cf);
|
0
|
26 static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf);
|
|
27 static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
|
50
|
28 void *parent, void *child);
|
0
|
29
|
404
|
30 static char *ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
31 void *conf);
|
272
|
32 static char *ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
33 void *conf);
|
|
34
|
0
|
35
|
96
|
36 static ngx_conf_bitmask_t ngx_http_ssl_protocols[] = {
|
|
37 { ngx_string("SSLv2"), NGX_SSL_SSLv2 },
|
|
38 { ngx_string("SSLv3"), NGX_SSL_SSLv3 },
|
|
39 { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
|
658
|
40 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
|
|
41 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
|
96
|
42 { ngx_null_string, 0 }
|
|
43 };
|
|
44
|
|
45
|
390
|
46 static ngx_conf_enum_t ngx_http_ssl_verify[] = {
|
|
47 { ngx_string("off"), 0 },
|
|
48 { ngx_string("on"), 1 },
|
510
|
49 { ngx_string("optional"), 2 },
|
390
|
50 { ngx_null_string, 0 }
|
|
51 };
|
|
52
|
|
53
|
0
|
54 static ngx_command_t ngx_http_ssl_commands[] = {
|
|
55
|
|
56 { ngx_string("ssl"),
|
148
|
57 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
404
|
58 ngx_http_ssl_enable,
|
0
|
59 NGX_HTTP_SRV_CONF_OFFSET,
|
|
60 offsetof(ngx_http_ssl_srv_conf_t, enable),
|
|
61 NULL },
|
|
62
|
|
63 { ngx_string("ssl_certificate"),
|
148
|
64 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
0
|
65 ngx_conf_set_str_slot,
|
|
66 NGX_HTTP_SRV_CONF_OFFSET,
|
|
67 offsetof(ngx_http_ssl_srv_conf_t, certificate),
|
|
68 NULL },
|
|
69
|
|
70 { ngx_string("ssl_certificate_key"),
|
148
|
71 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
0
|
72 ngx_conf_set_str_slot,
|
|
73 NGX_HTTP_SRV_CONF_OFFSET,
|
|
74 offsetof(ngx_http_ssl_srv_conf_t, certificate_key),
|
|
75 NULL },
|
|
76
|
380
|
77 { ngx_string("ssl_dhparam"),
|
|
78 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
79 ngx_conf_set_str_slot,
|
|
80 NGX_HTTP_SRV_CONF_OFFSET,
|
|
81 offsetof(ngx_http_ssl_srv_conf_t, dhparam),
|
|
82 NULL },
|
|
83
|
632
|
84 { ngx_string("ssl_ecdh_curve"),
|
|
85 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
86 ngx_conf_set_str_slot,
|
|
87 NGX_HTTP_SRV_CONF_OFFSET,
|
|
88 offsetof(ngx_http_ssl_srv_conf_t, ecdh_curve),
|
|
89 NULL },
|
|
90
|
96
|
91 { ngx_string("ssl_protocols"),
|
112
|
92 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
96
|
93 ngx_conf_set_bitmask_slot,
|
|
94 NGX_HTTP_SRV_CONF_OFFSET,
|
|
95 offsetof(ngx_http_ssl_srv_conf_t, protocols),
|
|
96 &ngx_http_ssl_protocols },
|
|
97
|
28
|
98 { ngx_string("ssl_ciphers"),
|
112
|
99 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
28
|
100 ngx_conf_set_str_slot,
|
|
101 NGX_HTTP_SRV_CONF_OFFSET,
|
|
102 offsetof(ngx_http_ssl_srv_conf_t, ciphers),
|
|
103 NULL },
|
|
104
|
196
|
105 { ngx_string("ssl_verify_client"),
|
648
|
106 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
390
|
107 ngx_conf_set_enum_slot,
|
196
|
108 NGX_HTTP_SRV_CONF_OFFSET,
|
|
109 offsetof(ngx_http_ssl_srv_conf_t, verify),
|
390
|
110 &ngx_http_ssl_verify },
|
196
|
111
|
|
112 { ngx_string("ssl_verify_depth"),
|
|
113 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
|
114 ngx_conf_set_num_slot,
|
|
115 NGX_HTTP_SRV_CONF_OFFSET,
|
|
116 offsetof(ngx_http_ssl_srv_conf_t, verify_depth),
|
|
117 NULL },
|
|
118
|
|
119 { ngx_string("ssl_client_certificate"),
|
|
120 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
121 ngx_conf_set_str_slot,
|
|
122 NGX_HTTP_SRV_CONF_OFFSET,
|
|
123 offsetof(ngx_http_ssl_srv_conf_t, client_certificate),
|
|
124 NULL },
|
|
125
|
96
|
126 { ngx_string("ssl_prefer_server_ciphers"),
|
|
127 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
128 ngx_conf_set_flag_slot,
|
|
129 NGX_HTTP_SRV_CONF_OFFSET,
|
|
130 offsetof(ngx_http_ssl_srv_conf_t, prefer_server_ciphers),
|
|
131 NULL },
|
|
132
|
272
|
133 { ngx_string("ssl_session_cache"),
|
|
134 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE12,
|
|
135 ngx_http_ssl_session_cache,
|
|
136 NGX_HTTP_SRV_CONF_OFFSET,
|
|
137 0,
|
|
138 NULL },
|
|
139
|
122
|
140 { ngx_string("ssl_session_timeout"),
|
|
141 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
142 ngx_conf_set_sec_slot,
|
|
143 NGX_HTTP_SRV_CONF_OFFSET,
|
|
144 offsetof(ngx_http_ssl_srv_conf_t, session_timeout),
|
|
145 NULL },
|
|
146
|
510
|
147 { ngx_string("ssl_crl"),
|
|
148 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
149 ngx_conf_set_str_slot,
|
|
150 NGX_HTTP_SRV_CONF_OFFSET,
|
|
151 offsetof(ngx_http_ssl_srv_conf_t, crl),
|
|
152 NULL },
|
|
153
|
0
|
154 ngx_null_command
|
|
155 };
|
|
156
|
|
157
|
|
158 static ngx_http_module_t ngx_http_ssl_module_ctx = {
|
160
|
159 ngx_http_ssl_add_variables, /* preconfiguration */
|
58
|
160 NULL, /* postconfiguration */
|
0
|
161
|
90
|
162 NULL, /* create main configuration */
|
|
163 NULL, /* init main configuration */
|
0
|
164
|
|
165 ngx_http_ssl_create_srv_conf, /* create server configuration */
|
|
166 ngx_http_ssl_merge_srv_conf, /* merge server configuration */
|
|
167
|
|
168 NULL, /* create location configuration */
|
34
|
169 NULL /* merge location configuration */
|
0
|
170 };
|
|
171
|
|
172
|
|
173 ngx_module_t ngx_http_ssl_module = {
|
58
|
174 NGX_MODULE_V1,
|
0
|
175 &ngx_http_ssl_module_ctx, /* module context */
|
|
176 ngx_http_ssl_commands, /* module directives */
|
|
177 NGX_HTTP_MODULE, /* module type */
|
90
|
178 NULL, /* init master */
|
0
|
179 NULL, /* init module */
|
90
|
180 NULL, /* init process */
|
|
181 NULL, /* init thread */
|
|
182 NULL, /* exit thread */
|
|
183 NULL, /* exit process */
|
|
184 NULL, /* exit master */
|
|
185 NGX_MODULE_V1_PADDING
|
0
|
186 };
|
|
187
|
|
188
|
160
|
189 static ngx_http_variable_t ngx_http_ssl_vars[] = {
|
|
190
|
220
|
191 { ngx_string("ssl_protocol"), NULL, ngx_http_ssl_static_variable,
|
340
|
192 (uintptr_t) ngx_ssl_get_protocol, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
160
|
193
|
220
|
194 { ngx_string("ssl_cipher"), NULL, ngx_http_ssl_static_variable,
|
340
|
195 (uintptr_t) ngx_ssl_get_cipher_name, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
160
|
196
|
530
|
197 { ngx_string("ssl_session_id"), NULL, ngx_http_ssl_variable,
|
|
198 (uintptr_t) ngx_ssl_get_session_id, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
|
199
|
380
|
200 { ngx_string("ssl_client_cert"), NULL, ngx_http_ssl_variable,
|
|
201 (uintptr_t) ngx_ssl_get_certificate, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
|
202
|
390
|
203 { ngx_string("ssl_client_raw_cert"), NULL, ngx_http_ssl_variable,
|
|
204 (uintptr_t) ngx_ssl_get_raw_certificate,
|
|
205 NGX_HTTP_VAR_CHANGEABLE, 0 },
|
|
206
|
220
|
207 { ngx_string("ssl_client_s_dn"), NULL, ngx_http_ssl_variable,
|
340
|
208 (uintptr_t) ngx_ssl_get_subject_dn, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
196
|
209
|
220
|
210 { ngx_string("ssl_client_i_dn"), NULL, ngx_http_ssl_variable,
|
340
|
211 (uintptr_t) ngx_ssl_get_issuer_dn, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
220
|
212
|
|
213 { ngx_string("ssl_client_serial"), NULL, ngx_http_ssl_variable,
|
340
|
214 (uintptr_t) ngx_ssl_get_serial_number, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
196
|
215
|
510
|
216 { ngx_string("ssl_client_verify"), NULL, ngx_http_ssl_variable,
|
|
217 (uintptr_t) ngx_ssl_get_client_verify, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
|
218
|
186
|
219 { ngx_null_string, NULL, NULL, 0, 0, 0 }
|
160
|
220 };
|
|
221
|
|
222
|
272
|
223 static ngx_str_t ngx_http_ssl_sess_id_ctx = ngx_string("HTTP");
|
92
|
224
|
|
225
|
160
|
226 static ngx_int_t
|
220
|
227 ngx_http_ssl_static_variable(ngx_http_request_t *r,
|
160
|
228 ngx_http_variable_value_t *v, uintptr_t data)
|
|
229 {
|
220
|
230 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data;
|
160
|
231
|
320
|
232 size_t len;
|
|
233 ngx_str_t s;
|
160
|
234
|
|
235 if (r->connection->ssl) {
|
|
236
|
320
|
237 (void) handler(r->connection, NULL, &s);
|
|
238
|
|
239 v->data = s.data;
|
160
|
240
|
220
|
241 for (len = 0; v->data[len]; len++) { /* void */ }
|
160
|
242
|
|
243 v->len = len;
|
|
244 v->valid = 1;
|
340
|
245 v->no_cacheable = 0;
|
160
|
246 v->not_found = 0;
|
|
247
|
|
248 return NGX_OK;
|
|
249 }
|
|
250
|
|
251 v->not_found = 1;
|
|
252
|
|
253 return NGX_OK;
|
|
254 }
|
|
255
|
|
256
|
|
257 static ngx_int_t
|
220
|
258 ngx_http_ssl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
196
|
259 uintptr_t data)
|
|
260 {
|
220
|
261 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data;
|
196
|
262
|
320
|
263 ngx_str_t s;
|
|
264
|
196
|
265 if (r->connection->ssl) {
|
320
|
266
|
|
267 if (handler(r->connection, r->pool, &s) != NGX_OK) {
|
196
|
268 return NGX_ERROR;
|
|
269 }
|
|
270
|
320
|
271 v->len = s.len;
|
|
272 v->data = s.data;
|
|
273
|
196
|
274 if (v->len) {
|
|
275 v->valid = 1;
|
340
|
276 v->no_cacheable = 0;
|
196
|
277 v->not_found = 0;
|
|
278
|
|
279 return NGX_OK;
|
|
280 }
|
|
281 }
|
|
282
|
|
283 v->not_found = 1;
|
|
284
|
|
285 return NGX_OK;
|
|
286 }
|
|
287
|
|
288
|
|
289 static ngx_int_t
|
160
|
290 ngx_http_ssl_add_variables(ngx_conf_t *cf)
|
|
291 {
|
|
292 ngx_http_variable_t *var, *v;
|
|
293
|
|
294 for (v = ngx_http_ssl_vars; v->name.len; v++) {
|
|
295 var = ngx_http_add_variable(cf, &v->name, v->flags);
|
|
296 if (var == NULL) {
|
|
297 return NGX_ERROR;
|
|
298 }
|
|
299
|
186
|
300 var->get_handler = v->get_handler;
|
160
|
301 var->data = v->data;
|
|
302 }
|
|
303
|
|
304 return NGX_OK;
|
|
305 }
|
|
306
|
|
307
|
50
|
308 static void *
|
|
309 ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
|
0
|
310 {
|
272
|
311 ngx_http_ssl_srv_conf_t *sscf;
|
0
|
312
|
272
|
313 sscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t));
|
|
314 if (sscf == NULL) {
|
496
|
315 return NULL;
|
0
|
316 }
|
|
317
|
28
|
318 /*
|
|
319 * set by ngx_pcalloc():
|
|
320 *
|
272
|
321 * sscf->protocols = 0;
|
380
|
322 * sscf->certificate = { 0, NULL };
|
|
323 * sscf->certificate_key = { 0, NULL };
|
|
324 * sscf->dhparam = { 0, NULL };
|
632
|
325 * sscf->ecdh_curve = { 0, NULL };
|
380
|
326 * sscf->client_certificate = { 0, NULL };
|
510
|
327 * sscf->crl = { 0, NULL };
|
570
|
328 * sscf->ciphers = { 0, NULL };
|
272
|
329 * sscf->shm_zone = NULL;
|
28
|
330 */
|
|
331
|
272
|
332 sscf->enable = NGX_CONF_UNSET;
|
390
|
333 sscf->prefer_server_ciphers = NGX_CONF_UNSET;
|
480
|
334 sscf->verify = NGX_CONF_UNSET_UINT;
|
|
335 sscf->verify_depth = NGX_CONF_UNSET_UINT;
|
272
|
336 sscf->builtin_session_cache = NGX_CONF_UNSET;
|
|
337 sscf->session_timeout = NGX_CONF_UNSET;
|
0
|
338
|
272
|
339 return sscf;
|
0
|
340 }
|
|
341
|
|
342
|
50
|
343 static char *
|
|
344 ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
345 {
|
|
346 ngx_http_ssl_srv_conf_t *prev = parent;
|
|
347 ngx_http_ssl_srv_conf_t *conf = child;
|
|
348
|
112
|
349 ngx_pool_cleanup_t *cln;
|
|
350
|
646
|
351 if (conf->enable == NGX_CONF_UNSET) {
|
|
352 if (prev->enable == NGX_CONF_UNSET) {
|
|
353 conf->enable = 0;
|
|
354
|
|
355 } else {
|
|
356 conf->enable = prev->enable;
|
|
357 conf->file = prev->file;
|
|
358 conf->line = prev->line;
|
|
359 }
|
|
360 }
|
0
|
361
|
122
|
362 ngx_conf_merge_value(conf->session_timeout,
|
|
363 prev->session_timeout, 300);
|
|
364
|
96
|
365 ngx_conf_merge_value(conf->prefer_server_ciphers,
|
|
366 prev->prefer_server_ciphers, 0);
|
|
367
|
|
368 ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
|
658
|
369 (NGX_CONF_BITMASK_SET|NGX_SSL_SSLv3|NGX_SSL_TLSv1
|
|
370 |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
|
96
|
371
|
390
|
372 ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
|
|
373 ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);
|
196
|
374
|
404
|
375 ngx_conf_merge_str_value(conf->certificate, prev->certificate, "");
|
|
376 ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, "");
|
0
|
377
|
380
|
378 ngx_conf_merge_str_value(conf->dhparam, prev->dhparam, "");
|
|
379
|
196
|
380 ngx_conf_merge_str_value(conf->client_certificate, prev->client_certificate,
|
|
381 "");
|
510
|
382 ngx_conf_merge_str_value(conf->crl, prev->crl, "");
|
196
|
383
|
632
|
384 ngx_conf_merge_str_value(conf->ecdh_curve, prev->ecdh_curve,
|
|
385 NGX_DEFAULT_ECDH_CURVE);
|
|
386
|
390
|
387 ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFAULT_CIPHERS);
|
28
|
388
|
|
389
|
96
|
390 conf->ssl.log = cf->log;
|
0
|
391
|
404
|
392 if (conf->enable) {
|
|
393
|
|
394 if (conf->certificate.len == 0) {
|
|
395 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
396 "no \"ssl_certificate\" is defined for "
|
|
397 "the \"ssl\" directive in %s:%ui",
|
|
398 conf->file, conf->line);
|
|
399 return NGX_CONF_ERROR;
|
|
400 }
|
|
401
|
|
402 if (conf->certificate_key.len == 0) {
|
|
403 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
404 "no \"ssl_certificate_key\" is defined for "
|
|
405 "the \"ssl\" directive in %s:%ui",
|
|
406 conf->file, conf->line);
|
|
407 return NGX_CONF_ERROR;
|
|
408 }
|
|
409
|
|
410 } else {
|
|
411
|
|
412 if (conf->certificate.len == 0) {
|
|
413 return NGX_CONF_OK;
|
|
414 }
|
|
415
|
|
416 if (conf->certificate_key.len == 0) {
|
|
417 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
418 "no \"ssl_certificate_key\" is defined "
|
|
419 "for certificate \"%V\"", &conf->certificate);
|
|
420 return NGX_CONF_ERROR;
|
|
421 }
|
|
422 }
|
|
423
|
272
|
424 if (ngx_ssl_create(&conf->ssl, conf->protocols, conf) != NGX_OK) {
|
0
|
425 return NGX_CONF_ERROR;
|
|
426 }
|
|
427
|
306
|
428 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
|
|
429
|
|
430 if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx,
|
|
431 ngx_http_ssl_servername)
|
|
432 == 0)
|
|
433 {
|
528
|
434 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
|
538
|
435 "nginx was built with SNI support, however, now it is linked "
|
528
|
436 "dynamically to an OpenSSL library which has no tlsext support, "
|
|
437 "therefore SNI is not available");
|
306
|
438 }
|
|
439
|
|
440 #endif
|
|
441
|
112
|
442 cln = ngx_pool_cleanup_add(cf->pool, 0);
|
|
443 if (cln == NULL) {
|
58
|
444 return NGX_CONF_ERROR;
|
|
445 }
|
|
446
|
112
|
447 cln->handler = ngx_ssl_cleanup_ctx;
|
|
448 cln->data = &conf->ssl;
|
|
449
|
|
450 if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate,
|
272
|
451 &conf->certificate_key)
|
|
452 != NGX_OK)
|
78
|
453 {
|
0
|
454 return NGX_CONF_ERROR;
|
|
455 }
|
|
456
|
96
|
457 if (SSL_CTX_set_cipher_list(conf->ssl.ctx,
|
112
|
458 (const char *) conf->ciphers.data)
|
|
459 == 0)
|
78
|
460 {
|
0
|
461 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0,
|
96
|
462 "SSL_CTX_set_cipher_list(\"%V\") failed",
|
|
463 &conf->ciphers);
|
|
464 }
|
|
465
|
196
|
466 if (conf->verify) {
|
390
|
467
|
|
468 if (conf->client_certificate.len == 0) {
|
|
469 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
470 "no ssl_client_certificate for ssl_client_verify");
|
|
471 return NGX_CONF_ERROR;
|
|
472 }
|
|
473
|
220
|
474 if (ngx_ssl_client_certificate(cf, &conf->ssl,
|
272
|
475 &conf->client_certificate,
|
|
476 conf->verify_depth)
|
220
|
477 != NGX_OK)
|
|
478 {
|
|
479 return NGX_CONF_ERROR;
|
196
|
480 }
|
510
|
481
|
|
482 if (ngx_ssl_crl(cf, &conf->ssl, &conf->crl) != NGX_OK) {
|
|
483 return NGX_CONF_ERROR;
|
|
484 }
|
196
|
485 }
|
|
486
|
96
|
487 if (conf->prefer_server_ciphers) {
|
|
488 SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
|
|
489 }
|
|
490
|
|
491 /* a temporary 512-bit RSA key is required for export versions of MSIE */
|
632
|
492 SSL_CTX_set_tmp_rsa_callback(conf->ssl.ctx, ngx_ssl_rsa512_key_callback);
|
|
493
|
|
494 if (ngx_ssl_dhparam(cf, &conf->ssl, &conf->dhparam) != NGX_OK) {
|
0
|
495 return NGX_CONF_ERROR;
|
|
496 }
|
|
497
|
632
|
498 if (ngx_ssl_ecdh_curve(cf, &conf->ssl, &conf->ecdh_curve) != NGX_OK) {
|
380
|
499 return NGX_CONF_ERROR;
|
|
500 }
|
|
501
|
272
|
502 ngx_conf_merge_value(conf->builtin_session_cache,
|
378
|
503 prev->builtin_session_cache, NGX_SSL_NONE_SCACHE);
|
272
|
504
|
|
505 if (conf->shm_zone == NULL) {
|
|
506 conf->shm_zone = prev->shm_zone;
|
|
507 }
|
92
|
508
|
272
|
509 if (ngx_ssl_session_cache(&conf->ssl, &ngx_http_ssl_sess_id_ctx,
|
|
510 conf->builtin_session_cache,
|
|
511 conf->shm_zone, conf->session_timeout)
|
|
512 != NGX_OK)
|
|
513 {
|
|
514 return NGX_CONF_ERROR;
|
|
515 }
|
122
|
516
|
0
|
517 return NGX_CONF_OK;
|
|
518 }
|
112
|
519
|
|
520
|
272
|
521 static char *
|
404
|
522 ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
523 {
|
|
524 ngx_http_ssl_srv_conf_t *sscf = conf;
|
|
525
|
|
526 char *rv;
|
|
527
|
|
528 rv = ngx_conf_set_flag_slot(cf, cmd, conf);
|
|
529
|
|
530 if (rv != NGX_CONF_OK) {
|
|
531 return rv;
|
|
532 }
|
|
533
|
|
534 sscf->file = cf->conf_file->file.name.data;
|
|
535 sscf->line = cf->conf_file->line;
|
|
536
|
|
537 return NGX_CONF_OK;
|
|
538 }
|
|
539
|
|
540
|
|
541 static char *
|
272
|
542 ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
543 {
|
|
544 ngx_http_ssl_srv_conf_t *sscf = conf;
|
|
545
|
|
546 size_t len;
|
|
547 ngx_str_t *value, name, size;
|
|
548 ngx_int_t n;
|
|
549 ngx_uint_t i, j;
|
|
550
|
|
551 value = cf->args->elts;
|
|
552
|
|
553 for (i = 1; i < cf->args->nelts; i++) {
|
|
554
|
358
|
555 if (ngx_strcmp(value[i].data, "off") == 0) {
|
|
556 sscf->builtin_session_cache = NGX_SSL_NO_SCACHE;
|
|
557 continue;
|
|
558 }
|
|
559
|
378
|
560 if (ngx_strcmp(value[i].data, "none") == 0) {
|
|
561 sscf->builtin_session_cache = NGX_SSL_NONE_SCACHE;
|
|
562 continue;
|
|
563 }
|
|
564
|
272
|
565 if (ngx_strcmp(value[i].data, "builtin") == 0) {
|
|
566 sscf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE;
|
|
567 continue;
|
|
568 }
|
|
569
|
|
570 if (value[i].len > sizeof("builtin:") - 1
|
|
571 && ngx_strncmp(value[i].data, "builtin:", sizeof("builtin:") - 1)
|
|
572 == 0)
|
|
573 {
|
|
574 n = ngx_atoi(value[i].data + sizeof("builtin:") - 1,
|
|
575 value[i].len - (sizeof("builtin:") - 1));
|
|
576
|
|
577 if (n == NGX_ERROR) {
|
|
578 goto invalid;
|
|
579 }
|
|
580
|
|
581 sscf->builtin_session_cache = n;
|
|
582
|
|
583 continue;
|
|
584 }
|
|
585
|
|
586 if (value[i].len > sizeof("shared:") - 1
|
|
587 && ngx_strncmp(value[i].data, "shared:", sizeof("shared:") - 1)
|
|
588 == 0)
|
|
589 {
|
|
590 len = 0;
|
|
591
|
|
592 for (j = sizeof("shared:") - 1; j < value[i].len; j++) {
|
|
593 if (value[i].data[j] == ':') {
|
480
|
594 value[i].data[j] = '\0';
|
272
|
595 break;
|
|
596 }
|
|
597
|
|
598 len++;
|
|
599 }
|
|
600
|
|
601 if (len == 0) {
|
|
602 goto invalid;
|
|
603 }
|
|
604
|
|
605 name.len = len;
|
|
606 name.data = value[i].data + sizeof("shared:") - 1;
|
|
607
|
|
608 size.len = value[i].len - j - 1;
|
|
609 size.data = name.data + len + 1;
|
|
610
|
|
611 n = ngx_parse_size(&size);
|
|
612
|
|
613 if (n == NGX_ERROR) {
|
|
614 goto invalid;
|
|
615 }
|
|
616
|
|
617 if (n < (ngx_int_t) (8 * ngx_pagesize)) {
|
|
618 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
619 "session cache \"%V\" is too small",
|
|
620 &value[i]);
|
|
621
|
|
622 return NGX_CONF_ERROR;
|
|
623 }
|
|
624
|
|
625 sscf->shm_zone = ngx_shared_memory_add(cf, &name, n,
|
|
626 &ngx_http_ssl_module);
|
|
627 if (sscf->shm_zone == NULL) {
|
|
628 return NGX_CONF_ERROR;
|
|
629 }
|
|
630
|
642
|
631 sscf->shm_zone->init = ngx_ssl_session_cache_init;
|
|
632
|
272
|
633 continue;
|
|
634 }
|
|
635
|
|
636 goto invalid;
|
|
637 }
|
|
638
|
|
639 if (sscf->shm_zone && sscf->builtin_session_cache == NGX_CONF_UNSET) {
|
|
640 sscf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE;
|
|
641 }
|
|
642
|
|
643 return NGX_CONF_OK;
|
|
644
|
|
645 invalid:
|
|
646
|
|
647 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
648 "invalid session cache \"%V\"", &value[i]);
|
|
649
|
|
650 return NGX_CONF_ERROR;
|
|
651 }
|