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
|
638
|
349 if (conf->enable == NGX_CONF_UNSET) {
|
|
350 if (prev->enable == NGX_CONF_UNSET) {
|
|
351 conf->enable = 0;
|
|
352
|
|
353 } else {
|
|
354 conf->enable = prev->enable;
|
|
355 conf->file = prev->file;
|
|
356 conf->line = prev->line;
|
|
357 }
|
|
358 }
|
0
|
359
|
122
|
360 ngx_conf_merge_value(conf->session_timeout,
|
|
361 prev->session_timeout, 300);
|
|
362
|
96
|
363 ngx_conf_merge_value(conf->prefer_server_ciphers,
|
|
364 prev->prefer_server_ciphers, 0);
|
|
365
|
|
366 ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
|
534
|
367 (NGX_CONF_BITMASK_SET|NGX_SSL_SSLv3|NGX_SSL_TLSv1));
|
96
|
368
|
390
|
369 ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
|
|
370 ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);
|
196
|
371
|
404
|
372 ngx_conf_merge_str_value(conf->certificate, prev->certificate, "");
|
|
373 ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, "");
|
0
|
374
|
380
|
375 ngx_conf_merge_str_value(conf->dhparam, prev->dhparam, "");
|
|
376
|
196
|
377 ngx_conf_merge_str_value(conf->client_certificate, prev->client_certificate,
|
|
378 "");
|
510
|
379 ngx_conf_merge_str_value(conf->crl, prev->crl, "");
|
196
|
380
|
632
|
381 ngx_conf_merge_str_value(conf->ecdh_curve, prev->ecdh_curve,
|
|
382 NGX_DEFAULT_ECDH_CURVE);
|
|
383
|
390
|
384 ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFAULT_CIPHERS);
|
28
|
385
|
|
386
|
96
|
387 conf->ssl.log = cf->log;
|
0
|
388
|
404
|
389 if (conf->enable) {
|
|
390
|
|
391 if (conf->certificate.len == 0) {
|
|
392 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
393 "no \"ssl_certificate\" is defined for "
|
|
394 "the \"ssl\" directive in %s:%ui",
|
|
395 conf->file, conf->line);
|
|
396 return NGX_CONF_ERROR;
|
|
397 }
|
|
398
|
|
399 if (conf->certificate_key.len == 0) {
|
|
400 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
401 "no \"ssl_certificate_key\" is defined for "
|
|
402 "the \"ssl\" directive in %s:%ui",
|
|
403 conf->file, conf->line);
|
|
404 return NGX_CONF_ERROR;
|
|
405 }
|
|
406
|
|
407 } else {
|
|
408
|
|
409 if (conf->certificate.len == 0) {
|
|
410 return NGX_CONF_OK;
|
|
411 }
|
|
412
|
|
413 if (conf->certificate_key.len == 0) {
|
|
414 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
415 "no \"ssl_certificate_key\" is defined "
|
|
416 "for certificate \"%V\"", &conf->certificate);
|
|
417 return NGX_CONF_ERROR;
|
|
418 }
|
|
419 }
|
|
420
|
272
|
421 if (ngx_ssl_create(&conf->ssl, conf->protocols, conf) != NGX_OK) {
|
0
|
422 return NGX_CONF_ERROR;
|
|
423 }
|
|
424
|
306
|
425 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
|
|
426
|
|
427 if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx,
|
|
428 ngx_http_ssl_servername)
|
|
429 == 0)
|
|
430 {
|
528
|
431 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
|
538
|
432 "nginx was built with SNI support, however, now it is linked "
|
528
|
433 "dynamically to an OpenSSL library which has no tlsext support, "
|
|
434 "therefore SNI is not available");
|
306
|
435 }
|
|
436
|
|
437 #endif
|
|
438
|
112
|
439 cln = ngx_pool_cleanup_add(cf->pool, 0);
|
|
440 if (cln == NULL) {
|
58
|
441 return NGX_CONF_ERROR;
|
|
442 }
|
|
443
|
112
|
444 cln->handler = ngx_ssl_cleanup_ctx;
|
|
445 cln->data = &conf->ssl;
|
|
446
|
|
447 if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate,
|
272
|
448 &conf->certificate_key)
|
|
449 != NGX_OK)
|
78
|
450 {
|
0
|
451 return NGX_CONF_ERROR;
|
|
452 }
|
|
453
|
96
|
454 if (SSL_CTX_set_cipher_list(conf->ssl.ctx,
|
112
|
455 (const char *) conf->ciphers.data)
|
|
456 == 0)
|
78
|
457 {
|
0
|
458 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0,
|
96
|
459 "SSL_CTX_set_cipher_list(\"%V\") failed",
|
|
460 &conf->ciphers);
|
|
461 }
|
|
462
|
196
|
463 if (conf->verify) {
|
390
|
464
|
|
465 if (conf->client_certificate.len == 0) {
|
|
466 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
467 "no ssl_client_certificate for ssl_client_verify");
|
|
468 return NGX_CONF_ERROR;
|
|
469 }
|
|
470
|
220
|
471 if (ngx_ssl_client_certificate(cf, &conf->ssl,
|
272
|
472 &conf->client_certificate,
|
|
473 conf->verify_depth)
|
220
|
474 != NGX_OK)
|
|
475 {
|
|
476 return NGX_CONF_ERROR;
|
196
|
477 }
|
510
|
478
|
|
479 if (ngx_ssl_crl(cf, &conf->ssl, &conf->crl) != NGX_OK) {
|
|
480 return NGX_CONF_ERROR;
|
|
481 }
|
196
|
482 }
|
|
483
|
96
|
484 if (conf->prefer_server_ciphers) {
|
|
485 SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
|
|
486 }
|
|
487
|
|
488 /* a temporary 512-bit RSA key is required for export versions of MSIE */
|
632
|
489 SSL_CTX_set_tmp_rsa_callback(conf->ssl.ctx, ngx_ssl_rsa512_key_callback);
|
|
490
|
|
491 if (ngx_ssl_dhparam(cf, &conf->ssl, &conf->dhparam) != NGX_OK) {
|
0
|
492 return NGX_CONF_ERROR;
|
|
493 }
|
|
494
|
632
|
495 if (ngx_ssl_ecdh_curve(cf, &conf->ssl, &conf->ecdh_curve) != NGX_OK) {
|
380
|
496 return NGX_CONF_ERROR;
|
|
497 }
|
|
498
|
272
|
499 ngx_conf_merge_value(conf->builtin_session_cache,
|
378
|
500 prev->builtin_session_cache, NGX_SSL_NONE_SCACHE);
|
272
|
501
|
|
502 if (conf->shm_zone == NULL) {
|
|
503 conf->shm_zone = prev->shm_zone;
|
|
504 }
|
92
|
505
|
272
|
506 if (ngx_ssl_session_cache(&conf->ssl, &ngx_http_ssl_sess_id_ctx,
|
|
507 conf->builtin_session_cache,
|
|
508 conf->shm_zone, conf->session_timeout)
|
|
509 != NGX_OK)
|
|
510 {
|
|
511 return NGX_CONF_ERROR;
|
|
512 }
|
122
|
513
|
0
|
514 return NGX_CONF_OK;
|
|
515 }
|
112
|
516
|
|
517
|
272
|
518 static char *
|
404
|
519 ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
520 {
|
|
521 ngx_http_ssl_srv_conf_t *sscf = conf;
|
|
522
|
|
523 char *rv;
|
|
524
|
|
525 rv = ngx_conf_set_flag_slot(cf, cmd, conf);
|
|
526
|
|
527 if (rv != NGX_CONF_OK) {
|
|
528 return rv;
|
|
529 }
|
|
530
|
|
531 sscf->file = cf->conf_file->file.name.data;
|
|
532 sscf->line = cf->conf_file->line;
|
|
533
|
|
534 return NGX_CONF_OK;
|
|
535 }
|
|
536
|
|
537
|
|
538 static char *
|
272
|
539 ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
540 {
|
|
541 ngx_http_ssl_srv_conf_t *sscf = conf;
|
|
542
|
|
543 size_t len;
|
|
544 ngx_str_t *value, name, size;
|
|
545 ngx_int_t n;
|
|
546 ngx_uint_t i, j;
|
|
547
|
|
548 value = cf->args->elts;
|
|
549
|
|
550 for (i = 1; i < cf->args->nelts; i++) {
|
|
551
|
358
|
552 if (ngx_strcmp(value[i].data, "off") == 0) {
|
|
553 sscf->builtin_session_cache = NGX_SSL_NO_SCACHE;
|
|
554 continue;
|
|
555 }
|
|
556
|
378
|
557 if (ngx_strcmp(value[i].data, "none") == 0) {
|
|
558 sscf->builtin_session_cache = NGX_SSL_NONE_SCACHE;
|
|
559 continue;
|
|
560 }
|
|
561
|
272
|
562 if (ngx_strcmp(value[i].data, "builtin") == 0) {
|
|
563 sscf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE;
|
|
564 continue;
|
|
565 }
|
|
566
|
|
567 if (value[i].len > sizeof("builtin:") - 1
|
|
568 && ngx_strncmp(value[i].data, "builtin:", sizeof("builtin:") - 1)
|
|
569 == 0)
|
|
570 {
|
|
571 n = ngx_atoi(value[i].data + sizeof("builtin:") - 1,
|
|
572 value[i].len - (sizeof("builtin:") - 1));
|
|
573
|
|
574 if (n == NGX_ERROR) {
|
|
575 goto invalid;
|
|
576 }
|
|
577
|
|
578 sscf->builtin_session_cache = n;
|
|
579
|
|
580 continue;
|
|
581 }
|
|
582
|
|
583 if (value[i].len > sizeof("shared:") - 1
|
|
584 && ngx_strncmp(value[i].data, "shared:", sizeof("shared:") - 1)
|
|
585 == 0)
|
|
586 {
|
|
587 len = 0;
|
|
588
|
|
589 for (j = sizeof("shared:") - 1; j < value[i].len; j++) {
|
|
590 if (value[i].data[j] == ':') {
|
480
|
591 value[i].data[j] = '\0';
|
272
|
592 break;
|
|
593 }
|
|
594
|
|
595 len++;
|
|
596 }
|
|
597
|
|
598 if (len == 0) {
|
|
599 goto invalid;
|
|
600 }
|
|
601
|
|
602 name.len = len;
|
|
603 name.data = value[i].data + sizeof("shared:") - 1;
|
|
604
|
|
605 size.len = value[i].len - j - 1;
|
|
606 size.data = name.data + len + 1;
|
|
607
|
|
608 n = ngx_parse_size(&size);
|
|
609
|
|
610 if (n == NGX_ERROR) {
|
|
611 goto invalid;
|
|
612 }
|
|
613
|
|
614 if (n < (ngx_int_t) (8 * ngx_pagesize)) {
|
|
615 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
616 "session cache \"%V\" is too small",
|
|
617 &value[i]);
|
|
618
|
|
619 return NGX_CONF_ERROR;
|
|
620 }
|
|
621
|
|
622 sscf->shm_zone = ngx_shared_memory_add(cf, &name, n,
|
|
623 &ngx_http_ssl_module);
|
|
624 if (sscf->shm_zone == NULL) {
|
|
625 return NGX_CONF_ERROR;
|
|
626 }
|
|
627
|
634
|
628 sscf->shm_zone->init = ngx_ssl_session_cache_init;
|
|
629
|
272
|
630 continue;
|
|
631 }
|
|
632
|
|
633 goto invalid;
|
|
634 }
|
|
635
|
|
636 if (sscf->shm_zone && sscf->builtin_session_cache == NGX_CONF_UNSET) {
|
|
637 sscf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE;
|
|
638 }
|
|
639
|
|
640 return NGX_CONF_OK;
|
|
641
|
|
642 invalid:
|
|
643
|
|
644 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
645 "invalid session cache \"%V\"", &value[i]);
|
|
646
|
|
647 return NGX_CONF_ERROR;
|
|
648 }
|