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