Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_ssl_module.c @ 1204:94774fc6620f
style fix
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 17 May 2007 18:07:28 +0000 |
parents | 8dfb3aa75de2 |
children | 86c5c9288acc |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
5 |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_http.h> |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
573 | 11 |
671 | 12 typedef ngx_int_t (*ngx_ssl_variable_handler_pt)(ngx_connection_t *c, |
13 ngx_pool_t *pool, ngx_str_t *s); | |
611 | 14 |
15 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 #define NGX_DEFLAUT_CERTIFICATE "cert.pem" |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 #define NGX_DEFLAUT_CERTIFICATE_KEY "cert.pem" |
547 | 18 #define NGX_DEFLAUT_CIPHERS "ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP" |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
671 | 21 static ngx_int_t ngx_http_ssl_static_variable(ngx_http_request_t *r, |
611 | 22 ngx_http_variable_value_t *v, uintptr_t data); |
671 | 23 static ngx_int_t ngx_http_ssl_variable(ngx_http_request_t *r, |
647 | 24 ngx_http_variable_value_t *v, uintptr_t data); |
611 | 25 |
26 static ngx_int_t ngx_http_ssl_add_variables(ngx_conf_t *cf); | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf); |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, |
501 | 29 void *parent, void *child); |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 |
973 | 31 static char *ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
32 void *conf); | |
33 | |
563 | 34 #if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) |
35 | |
36 static char *ngx_http_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, | |
37 void *conf); | |
38 | |
39 static char ngx_http_ssl_openssl097[] = "OpenSSL 0.9.7 and higher"; | |
40 | |
41 #endif | |
42 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 |
547 | 44 static ngx_conf_bitmask_t ngx_http_ssl_protocols[] = { |
45 { ngx_string("SSLv2"), NGX_SSL_SSLv2 }, | |
46 { ngx_string("SSLv3"), NGX_SSL_SSLv3 }, | |
47 { ngx_string("TLSv1"), NGX_SSL_TLSv1 }, | |
48 { ngx_null_string, 0 } | |
49 }; | |
50 | |
51 | |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
52 static ngx_command_t ngx_http_ssl_commands[] = { |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
54 { ngx_string("ssl"), |
599 | 55 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 ngx_conf_set_flag_slot, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 NGX_HTTP_SRV_CONF_OFFSET, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 offsetof(ngx_http_ssl_srv_conf_t, enable), |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 NULL }, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 { ngx_string("ssl_certificate"), |
599 | 62 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 ngx_conf_set_str_slot, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 NGX_HTTP_SRV_CONF_OFFSET, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 offsetof(ngx_http_ssl_srv_conf_t, certificate), |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 NULL }, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 { ngx_string("ssl_certificate_key"), |
599 | 69 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
70 ngx_conf_set_str_slot, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
71 NGX_HTTP_SRV_CONF_OFFSET, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 offsetof(ngx_http_ssl_srv_conf_t, certificate_key), |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 NULL }, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 |
547 | 75 { ngx_string("ssl_protocols"), |
563 | 76 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, |
547 | 77 ngx_conf_set_bitmask_slot, |
78 NGX_HTTP_SRV_CONF_OFFSET, | |
79 offsetof(ngx_http_ssl_srv_conf_t, protocols), | |
80 &ngx_http_ssl_protocols }, | |
81 | |
479 | 82 { ngx_string("ssl_ciphers"), |
563 | 83 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
479 | 84 ngx_conf_set_str_slot, |
85 NGX_HTTP_SRV_CONF_OFFSET, | |
86 offsetof(ngx_http_ssl_srv_conf_t, ciphers), | |
87 NULL }, | |
88 | |
647 | 89 { ngx_string("ssl_verify_client"), |
667 | 90 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, |
647 | 91 ngx_conf_set_flag_slot, |
92 NGX_HTTP_SRV_CONF_OFFSET, | |
93 offsetof(ngx_http_ssl_srv_conf_t, verify), | |
94 NULL }, | |
95 | |
96 { ngx_string("ssl_verify_depth"), | |
97 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, | |
98 ngx_conf_set_num_slot, | |
99 NGX_HTTP_SRV_CONF_OFFSET, | |
100 offsetof(ngx_http_ssl_srv_conf_t, verify_depth), | |
101 NULL }, | |
102 | |
103 { ngx_string("ssl_client_certificate"), | |
104 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, | |
105 ngx_conf_set_str_slot, | |
106 NGX_HTTP_SRV_CONF_OFFSET, | |
107 offsetof(ngx_http_ssl_srv_conf_t, client_certificate), | |
108 NULL }, | |
109 | |
547 | 110 { ngx_string("ssl_prefer_server_ciphers"), |
111 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, | |
563 | 112 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE |
547 | 113 ngx_conf_set_flag_slot, |
114 NGX_HTTP_SRV_CONF_OFFSET, | |
115 offsetof(ngx_http_ssl_srv_conf_t, prefer_server_ciphers), | |
116 NULL }, | |
563 | 117 #else |
118 ngx_http_ssl_nosupported, 0, 0, ngx_http_ssl_openssl097 }, | |
119 #endif | |
547 | 120 |
973 | 121 { ngx_string("ssl_session_cache"), |
122 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE12, | |
123 ngx_http_ssl_session_cache, | |
124 NGX_HTTP_SRV_CONF_OFFSET, | |
125 0, | |
126 NULL }, | |
127 | |
573 | 128 { ngx_string("ssl_session_timeout"), |
129 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, | |
130 ngx_conf_set_sec_slot, | |
131 NGX_HTTP_SRV_CONF_OFFSET, | |
132 offsetof(ngx_http_ssl_srv_conf_t, session_timeout), | |
133 NULL }, | |
134 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 ngx_null_command |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 }; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
139 static ngx_http_module_t ngx_http_ssl_module_ctx = { |
611 | 140 ngx_http_ssl_add_variables, /* preconfiguration */ |
509 | 141 NULL, /* postconfiguration */ |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
541 | 143 NULL, /* create main configuration */ |
144 NULL, /* init main configuration */ | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 ngx_http_ssl_create_srv_conf, /* create server configuration */ |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 ngx_http_ssl_merge_srv_conf, /* merge server configuration */ |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 NULL, /* create location configuration */ |
485 | 150 NULL /* merge location configuration */ |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 }; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
154 ngx_module_t ngx_http_ssl_module = { |
509 | 155 NGX_MODULE_V1, |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
156 &ngx_http_ssl_module_ctx, /* module context */ |
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
157 ngx_http_ssl_commands, /* module directives */ |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 NGX_HTTP_MODULE, /* module type */ |
541 | 159 NULL, /* init master */ |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
160 NULL, /* init module */ |
541 | 161 NULL, /* init process */ |
162 NULL, /* init thread */ | |
163 NULL, /* exit thread */ | |
164 NULL, /* exit process */ | |
165 NULL, /* exit master */ | |
166 NGX_MODULE_V1_PADDING | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 }; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
611 | 170 static ngx_http_variable_t ngx_http_ssl_vars[] = { |
171 | |
671 | 172 { ngx_string("ssl_protocol"), NULL, ngx_http_ssl_static_variable, |
611 | 173 (uintptr_t) ngx_ssl_get_protocol, NGX_HTTP_VAR_CHANGABLE, 0 }, |
174 | |
671 | 175 { ngx_string("ssl_cipher"), NULL, ngx_http_ssl_static_variable, |
611 | 176 (uintptr_t) ngx_ssl_get_cipher_name, NGX_HTTP_VAR_CHANGABLE, 0 }, |
177 | |
671 | 178 { ngx_string("ssl_client_s_dn"), NULL, ngx_http_ssl_variable, |
179 (uintptr_t) ngx_ssl_get_subject_dn, NGX_HTTP_VAR_CHANGABLE, 0 }, | |
647 | 180 |
671 | 181 { ngx_string("ssl_client_i_dn"), NULL, ngx_http_ssl_variable, |
182 (uintptr_t) ngx_ssl_get_issuer_dn, NGX_HTTP_VAR_CHANGABLE, 0 }, | |
183 | |
184 { ngx_string("ssl_client_serial"), NULL, ngx_http_ssl_variable, | |
185 (uintptr_t) ngx_ssl_get_serial_number, NGX_HTTP_VAR_CHANGABLE, 0 }, | |
647 | 186 |
637 | 187 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
611 | 188 }; |
189 | |
190 | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
191 static ngx_str_t ngx_http_ssl_sess_id_ctx = ngx_string("HTTP"); |
973 | 192 |
193 | |
194 static ngx_int_t | |
671 | 195 ngx_http_ssl_static_variable(ngx_http_request_t *r, |
611 | 196 ngx_http_variable_value_t *v, uintptr_t data) |
197 { | |
671 | 198 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data; |
611 | 199 |
671 | 200 size_t len; |
611 | 201 |
202 if (r->connection->ssl) { | |
203 | |
671 | 204 (void) handler(r->connection, NULL, (ngx_str_t *) v); |
611 | 205 |
671 | 206 for (len = 0; v->data[len]; len++) { /* void */ } |
611 | 207 |
208 v->len = len; | |
209 v->valid = 1; | |
210 v->no_cachable = 0; | |
211 v->not_found = 0; | |
212 | |
213 return NGX_OK; | |
214 } | |
215 | |
216 v->not_found = 1; | |
217 | |
218 return NGX_OK; | |
219 } | |
220 | |
221 | |
222 static ngx_int_t | |
671 | 223 ngx_http_ssl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
647 | 224 uintptr_t data) |
225 { | |
671 | 226 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data; |
647 | 227 |
228 if (r->connection->ssl) { | |
671 | 229 if (handler(r->connection, r->pool, (ngx_str_t *) v) != NGX_OK) { |
647 | 230 return NGX_ERROR; |
231 } | |
232 | |
233 if (v->len) { | |
234 v->valid = 1; | |
235 v->no_cachable = 0; | |
236 v->not_found = 0; | |
237 | |
238 return NGX_OK; | |
239 } | |
240 } | |
241 | |
242 v->not_found = 1; | |
243 | |
244 return NGX_OK; | |
245 } | |
246 | |
247 | |
248 static ngx_int_t | |
611 | 249 ngx_http_ssl_add_variables(ngx_conf_t *cf) |
250 { | |
251 ngx_http_variable_t *var, *v; | |
252 | |
253 for (v = ngx_http_ssl_vars; v->name.len; v++) { | |
254 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
255 if (var == NULL) { | |
256 return NGX_ERROR; | |
257 } | |
258 | |
637 | 259 var->get_handler = v->get_handler; |
611 | 260 var->data = v->data; |
261 } | |
262 | |
263 return NGX_OK; | |
264 } | |
265 | |
266 | |
501 | 267 static void * |
268 ngx_http_ssl_create_srv_conf(ngx_conf_t *cf) | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
269 { |
971 | 270 ngx_http_ssl_srv_conf_t *sscf; |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
271 |
971 | 272 sscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t)); |
273 if (sscf == NULL) { | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
274 return NGX_CONF_ERROR; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
275 } |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
276 |
479 | 277 /* |
278 * set by ngx_pcalloc(): | |
279 * | |
971 | 280 * sscf->protocols = 0; |
281 * sscf->certificate.len = 0; | |
282 * sscf->certificate.data = NULL; | |
283 * sscf->certificate_key.len = 0; | |
284 * sscf->certificate_key.data = NULL; | |
285 * sscf->client_certificate.len = 0; | |
286 * sscf->client_certificate.data = NULL; | |
287 * sscf->ciphers.len = 0; | |
288 * sscf->ciphers.data = NULL; | |
973 | 289 * sscf->shm_zone = NULL; |
479 | 290 */ |
291 | |
971 | 292 sscf->enable = NGX_CONF_UNSET; |
293 sscf->verify = NGX_CONF_UNSET; | |
294 sscf->verify_depth = NGX_CONF_UNSET; | |
295 sscf->prefer_server_ciphers = NGX_CONF_UNSET; | |
973 | 296 sscf->builtin_session_cache = NGX_CONF_UNSET; |
297 sscf->session_timeout = NGX_CONF_UNSET; | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
298 |
971 | 299 return sscf; |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
300 } |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
302 |
501 | 303 static char * |
304 ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
305 { |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
306 ngx_http_ssl_srv_conf_t *prev = parent; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
307 ngx_http_ssl_srv_conf_t *conf = child; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
308 |
563 | 309 ngx_pool_cleanup_t *cln; |
310 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
311 ngx_conf_merge_value(conf->enable, prev->enable, 0); |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
312 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
313 if (conf->enable == 0) { |
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
314 return NGX_CONF_OK; |
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
315 } |
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
316 |
573 | 317 ngx_conf_merge_value(conf->session_timeout, |
318 prev->session_timeout, 300); | |
319 | |
547 | 320 ngx_conf_merge_value(conf->prefer_server_ciphers, |
321 prev->prefer_server_ciphers, 0); | |
322 | |
323 ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, | |
324 (NGX_CONF_BITMASK_SET | |
325 |NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1)); | |
326 | |
647 | 327 ngx_conf_merge_value(conf->verify, prev->verify, 0); |
328 ngx_conf_merge_value(conf->verify_depth, prev->verify_depth, 1); | |
329 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
330 ngx_conf_merge_str_value(conf->certificate, prev->certificate, |
547 | 331 NGX_DEFLAUT_CERTIFICATE); |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
332 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
333 ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, |
547 | 334 NGX_DEFLAUT_CERTIFICATE_KEY); |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
335 |
647 | 336 ngx_conf_merge_str_value(conf->client_certificate, prev->client_certificate, |
337 ""); | |
338 | |
547 | 339 ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFLAUT_CIPHERS); |
479 | 340 |
341 | |
547 | 342 conf->ssl.log = cf->log; |
386
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
343 |
969 | 344 if (ngx_ssl_create(&conf->ssl, conf->protocols, conf) != NGX_OK) { |
386
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
345 return NGX_CONF_ERROR; |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
346 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
347 |
563 | 348 cln = ngx_pool_cleanup_add(cf->pool, 0); |
349 if (cln == NULL) { | |
509 | 350 return NGX_CONF_ERROR; |
351 } | |
352 | |
563 | 353 cln->handler = ngx_ssl_cleanup_ctx; |
354 cln->data = &conf->ssl; | |
355 | |
356 if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate, | |
970 | 357 &conf->certificate_key) |
358 != NGX_OK) | |
529 | 359 { |
386
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
360 return NGX_CONF_ERROR; |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
361 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
362 |
547 | 363 if (SSL_CTX_set_cipher_list(conf->ssl.ctx, |
563 | 364 (const char *) conf->ciphers.data) |
365 == 0) | |
529 | 366 { |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
367 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, |
547 | 368 "SSL_CTX_set_cipher_list(\"%V\") failed", |
369 &conf->ciphers); | |
370 } | |
371 | |
647 | 372 if (conf->verify) { |
671 | 373 if (ngx_ssl_client_certificate(cf, &conf->ssl, |
970 | 374 &conf->client_certificate, |
375 conf->verify_depth) | |
671 | 376 != NGX_OK) |
377 { | |
378 return NGX_CONF_ERROR; | |
647 | 379 } |
380 } | |
381 | |
563 | 382 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE |
383 | |
547 | 384 if (conf->prefer_server_ciphers) { |
385 SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); | |
386 } | |
387 | |
563 | 388 #endif |
389 | |
547 | 390 /* a temporary 512-bit RSA key is required for export versions of MSIE */ |
391 if (ngx_ssl_generate_rsa512_key(&conf->ssl) != NGX_OK) { | |
386
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
392 return NGX_CONF_ERROR; |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
393 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
394 |
973 | 395 ngx_conf_merge_value(conf->builtin_session_cache, |
396 prev->builtin_session_cache, | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
397 NGX_SSL_DFLT_BUILTIN_SCACHE); |
973 | 398 |
399 if (conf->shm_zone == NULL) { | |
400 conf->shm_zone = prev->shm_zone; | |
401 } | |
402 | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
403 if (ngx_ssl_session_cache(&conf->ssl, &ngx_http_ssl_sess_id_ctx, |
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
404 conf->builtin_session_cache, |
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
405 conf->shm_zone, conf->session_timeout) |
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
406 != NGX_OK) |
973 | 407 { |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
408 return NGX_CONF_ERROR; |
973 | 409 } |
573 | 410 |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
411 return NGX_CONF_OK; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
412 } |
563 | 413 |
414 | |
973 | 415 static char * |
416 ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
417 { | |
418 ngx_http_ssl_srv_conf_t *sscf = conf; | |
419 | |
420 size_t len; | |
421 ngx_str_t *value, name, size; | |
422 ngx_int_t n; | |
423 ngx_uint_t i, j; | |
424 | |
425 value = cf->args->elts; | |
426 | |
427 for (i = 1; i < cf->args->nelts; i++) { | |
428 | |
429 if (ngx_strcmp(value[i].data, "builtin") == 0) { | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
430 sscf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE; |
973 | 431 continue; |
432 } | |
433 | |
434 if (value[i].len > sizeof("builtin:") - 1 | |
435 && ngx_strncmp(value[i].data, "builtin:", sizeof("builtin:") - 1) | |
436 == 0) | |
437 { | |
438 n = ngx_atoi(value[i].data + sizeof("builtin:") - 1, | |
439 value[i].len - (sizeof("builtin:") - 1)); | |
440 | |
441 if (n == NGX_ERROR) { | |
442 goto invalid; | |
443 } | |
444 | |
445 sscf->builtin_session_cache = n; | |
446 | |
447 continue; | |
448 } | |
449 | |
450 if (value[i].len > sizeof("shared:") - 1 | |
451 && ngx_strncmp(value[i].data, "shared:", sizeof("shared:") - 1) | |
452 == 0) | |
453 { | |
454 len = 0; | |
455 | |
456 for (j = sizeof("shared:") - 1; j < value[i].len; j++) { | |
457 if (value[i].data[j] == ':') { | |
458 break; | |
459 } | |
460 | |
461 len++; | |
462 } | |
463 | |
464 if (len == 0) { | |
465 goto invalid; | |
466 } | |
467 | |
468 name.len = len; | |
469 name.data = value[i].data + sizeof("shared:") - 1; | |
470 | |
471 size.len = value[i].len - j - 1; | |
472 size.data = name.data + len + 1; | |
473 | |
474 n = ngx_parse_size(&size); | |
475 | |
476 if (n == NGX_ERROR) { | |
477 goto invalid; | |
478 } | |
479 | |
480 if (n < (ngx_int_t) (8 * ngx_pagesize)) { | |
481 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
482 "session cache \"%V\" is too small", |
973 | 483 &value[i]); |
484 | |
485 return NGX_CONF_ERROR; | |
486 } | |
487 | |
488 sscf->shm_zone = ngx_shared_memory_add(cf, &name, n, | |
489 &ngx_http_ssl_module); | |
490 if (sscf->shm_zone == NULL) { | |
491 return NGX_CONF_ERROR; | |
492 } | |
493 | |
494 continue; | |
495 } | |
496 | |
497 goto invalid; | |
498 } | |
499 | |
500 if (sscf->shm_zone && sscf->builtin_session_cache == NGX_CONF_UNSET) { | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
501 sscf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE; |
973 | 502 } |
503 | |
504 return NGX_CONF_OK; | |
505 | |
506 invalid: | |
507 | |
508 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
509 "invalid session cache \"%V\"", &value[i]); | |
510 | |
511 return NGX_CONF_ERROR; | |
512 } | |
513 | |
514 | |
563 | 515 #if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) |
516 | |
517 static char * | |
518 ngx_http_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
519 { | |
520 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
521 "\"%V\" directive is available only in %s,", | |
522 &cmd->name, cmd->post); | |
523 | |
524 return NGX_CONF_ERROR; | |
525 } | |
526 | |
527 #endif |