Mercurial > hg > nginx
annotate src/http/modules/ngx_http_ssl_module.c @ 1590:8f8e0a60685f
fix segfault
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 22 Oct 2007 10:15:27 +0000 |
parents | 4c43e25d11ea |
children | 14510c3cc6cb |
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, |
1565 | 173 (uintptr_t) ngx_ssl_get_protocol, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
611 | 174 |
671 | 175 { ngx_string("ssl_cipher"), NULL, ngx_http_ssl_static_variable, |
1565 | 176 (uintptr_t) ngx_ssl_get_cipher_name, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
611 | 177 |
671 | 178 { ngx_string("ssl_client_s_dn"), NULL, ngx_http_ssl_variable, |
1565 | 179 (uintptr_t) ngx_ssl_get_subject_dn, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
647 | 180 |
671 | 181 { ngx_string("ssl_client_i_dn"), NULL, ngx_http_ssl_variable, |
1565 | 182 (uintptr_t) ngx_ssl_get_issuer_dn, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
671 | 183 |
184 { ngx_string("ssl_client_serial"), NULL, ngx_http_ssl_variable, | |
1565 | 185 (uintptr_t) ngx_ssl_get_serial_number, NGX_HTTP_VAR_CHANGEABLE, 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 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
200 size_t len; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
201 ngx_str_t s; |
611 | 202 |
203 if (r->connection->ssl) { | |
204 | |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
205 (void) handler(r->connection, NULL, &s); |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
206 |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
207 v->data = s.data; |
611 | 208 |
671 | 209 for (len = 0; v->data[len]; len++) { /* void */ } |
611 | 210 |
211 v->len = len; | |
212 v->valid = 1; | |
1565 | 213 v->no_cacheable = 0; |
611 | 214 v->not_found = 0; |
215 | |
216 return NGX_OK; | |
217 } | |
218 | |
219 v->not_found = 1; | |
220 | |
221 return NGX_OK; | |
222 } | |
223 | |
224 | |
225 static ngx_int_t | |
671 | 226 ngx_http_ssl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
647 | 227 uintptr_t data) |
228 { | |
671 | 229 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data; |
647 | 230 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
231 ngx_str_t s; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
232 |
647 | 233 if (r->connection->ssl) { |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
234 |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
235 if (handler(r->connection, r->pool, &s) != NGX_OK) { |
647 | 236 return NGX_ERROR; |
237 } | |
238 | |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
239 v->len = s.len; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
240 v->data = s.data; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
241 |
647 | 242 if (v->len) { |
243 v->valid = 1; | |
1565 | 244 v->no_cacheable = 0; |
647 | 245 v->not_found = 0; |
246 | |
247 return NGX_OK; | |
248 } | |
249 } | |
250 | |
251 v->not_found = 1; | |
252 | |
253 return NGX_OK; | |
254 } | |
255 | |
256 | |
257 static ngx_int_t | |
611 | 258 ngx_http_ssl_add_variables(ngx_conf_t *cf) |
259 { | |
260 ngx_http_variable_t *var, *v; | |
261 | |
262 for (v = ngx_http_ssl_vars; v->name.len; v++) { | |
263 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
264 if (var == NULL) { | |
265 return NGX_ERROR; | |
266 } | |
267 | |
637 | 268 var->get_handler = v->get_handler; |
611 | 269 var->data = v->data; |
270 } | |
271 | |
272 return NGX_OK; | |
273 } | |
274 | |
275 | |
501 | 276 static void * |
277 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
|
278 { |
971 | 279 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
|
280 |
971 | 281 sscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t)); |
282 if (sscf == NULL) { | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
283 return NGX_CONF_ERROR; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
284 } |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
285 |
479 | 286 /* |
287 * set by ngx_pcalloc(): | |
288 * | |
971 | 289 * sscf->protocols = 0; |
290 * sscf->certificate.len = 0; | |
291 * sscf->certificate.data = NULL; | |
292 * sscf->certificate_key.len = 0; | |
293 * sscf->certificate_key.data = NULL; | |
294 * sscf->client_certificate.len = 0; | |
295 * sscf->client_certificate.data = NULL; | |
296 * sscf->ciphers.len = 0; | |
297 * sscf->ciphers.data = NULL; | |
973 | 298 * sscf->shm_zone = NULL; |
479 | 299 */ |
300 | |
971 | 301 sscf->enable = NGX_CONF_UNSET; |
302 sscf->verify = NGX_CONF_UNSET; | |
303 sscf->verify_depth = NGX_CONF_UNSET; | |
304 sscf->prefer_server_ciphers = NGX_CONF_UNSET; | |
973 | 305 sscf->builtin_session_cache = NGX_CONF_UNSET; |
306 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
|
307 |
971 | 308 return sscf; |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
309 } |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
310 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
311 |
501 | 312 static char * |
313 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
|
314 { |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
315 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
|
316 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
|
317 |
563 | 318 ngx_pool_cleanup_t *cln; |
319 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
320 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
|
321 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
322 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
|
323 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
|
324 } |
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
325 |
573 | 326 ngx_conf_merge_value(conf->session_timeout, |
327 prev->session_timeout, 300); | |
328 | |
547 | 329 ngx_conf_merge_value(conf->prefer_server_ciphers, |
330 prev->prefer_server_ciphers, 0); | |
331 | |
332 ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, | |
333 (NGX_CONF_BITMASK_SET | |
334 |NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1)); | |
335 | |
647 | 336 ngx_conf_merge_value(conf->verify, prev->verify, 0); |
337 ngx_conf_merge_value(conf->verify_depth, prev->verify_depth, 1); | |
338 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
339 ngx_conf_merge_str_value(conf->certificate, prev->certificate, |
547 | 340 NGX_DEFLAUT_CERTIFICATE); |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
341 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
342 ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, |
547 | 343 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
|
344 |
647 | 345 ngx_conf_merge_str_value(conf->client_certificate, prev->client_certificate, |
346 ""); | |
347 | |
547 | 348 ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFLAUT_CIPHERS); |
479 | 349 |
350 | |
547 | 351 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
|
352 |
969 | 353 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
|
354 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
|
355 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
356 |
1219 | 357 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME |
358 | |
359 if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx, | |
360 ngx_http_ssl_servername) | |
361 == 0) | |
362 { | |
363 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, | |
364 "SSL_CTX_set_tlsext_servername_callback() failed"); | |
365 return NGX_CONF_ERROR; | |
366 } | |
367 | |
368 #endif | |
369 | |
563 | 370 cln = ngx_pool_cleanup_add(cf->pool, 0); |
371 if (cln == NULL) { | |
509 | 372 return NGX_CONF_ERROR; |
373 } | |
374 | |
563 | 375 cln->handler = ngx_ssl_cleanup_ctx; |
376 cln->data = &conf->ssl; | |
377 | |
378 if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate, | |
970 | 379 &conf->certificate_key) |
380 != NGX_OK) | |
529 | 381 { |
386
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
382 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
|
383 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
384 |
547 | 385 if (SSL_CTX_set_cipher_list(conf->ssl.ctx, |
563 | 386 (const char *) conf->ciphers.data) |
387 == 0) | |
529 | 388 { |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
389 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, |
547 | 390 "SSL_CTX_set_cipher_list(\"%V\") failed", |
391 &conf->ciphers); | |
392 } | |
393 | |
647 | 394 if (conf->verify) { |
671 | 395 if (ngx_ssl_client_certificate(cf, &conf->ssl, |
970 | 396 &conf->client_certificate, |
397 conf->verify_depth) | |
671 | 398 != NGX_OK) |
399 { | |
400 return NGX_CONF_ERROR; | |
647 | 401 } |
402 } | |
403 | |
563 | 404 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE |
405 | |
547 | 406 if (conf->prefer_server_ciphers) { |
407 SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); | |
408 } | |
409 | |
563 | 410 #endif |
411 | |
547 | 412 /* a temporary 512-bit RSA key is required for export versions of MSIE */ |
413 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
|
414 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
|
415 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
416 |
973 | 417 ngx_conf_merge_value(conf->builtin_session_cache, |
418 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
|
419 NGX_SSL_DFLT_BUILTIN_SCACHE); |
973 | 420 |
421 if (conf->shm_zone == NULL) { | |
422 conf->shm_zone = prev->shm_zone; | |
423 } | |
424 | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
425 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
|
426 conf->builtin_session_cache, |
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
427 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
|
428 != NGX_OK) |
973 | 429 { |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
430 return NGX_CONF_ERROR; |
973 | 431 } |
573 | 432 |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
433 return NGX_CONF_OK; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
434 } |
563 | 435 |
436 | |
973 | 437 static char * |
438 ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
439 { | |
440 ngx_http_ssl_srv_conf_t *sscf = conf; | |
441 | |
442 size_t len; | |
443 ngx_str_t *value, name, size; | |
444 ngx_int_t n; | |
445 ngx_uint_t i, j; | |
446 | |
447 value = cf->args->elts; | |
448 | |
449 for (i = 1; i < cf->args->nelts; i++) { | |
450 | |
451 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
|
452 sscf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE; |
973 | 453 continue; |
454 } | |
455 | |
456 if (value[i].len > sizeof("builtin:") - 1 | |
457 && ngx_strncmp(value[i].data, "builtin:", sizeof("builtin:") - 1) | |
458 == 0) | |
459 { | |
460 n = ngx_atoi(value[i].data + sizeof("builtin:") - 1, | |
461 value[i].len - (sizeof("builtin:") - 1)); | |
462 | |
463 if (n == NGX_ERROR) { | |
464 goto invalid; | |
465 } | |
466 | |
467 sscf->builtin_session_cache = n; | |
468 | |
469 continue; | |
470 } | |
471 | |
472 if (value[i].len > sizeof("shared:") - 1 | |
473 && ngx_strncmp(value[i].data, "shared:", sizeof("shared:") - 1) | |
474 == 0) | |
475 { | |
476 len = 0; | |
477 | |
478 for (j = sizeof("shared:") - 1; j < value[i].len; j++) { | |
479 if (value[i].data[j] == ':') { | |
480 break; | |
481 } | |
482 | |
483 len++; | |
484 } | |
485 | |
486 if (len == 0) { | |
487 goto invalid; | |
488 } | |
489 | |
490 name.len = len; | |
491 name.data = value[i].data + sizeof("shared:") - 1; | |
492 | |
493 size.len = value[i].len - j - 1; | |
494 size.data = name.data + len + 1; | |
495 | |
496 n = ngx_parse_size(&size); | |
497 | |
498 if (n == NGX_ERROR) { | |
499 goto invalid; | |
500 } | |
501 | |
502 if (n < (ngx_int_t) (8 * ngx_pagesize)) { | |
503 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
|
504 "session cache \"%V\" is too small", |
973 | 505 &value[i]); |
506 | |
507 return NGX_CONF_ERROR; | |
508 } | |
509 | |
510 sscf->shm_zone = ngx_shared_memory_add(cf, &name, n, | |
511 &ngx_http_ssl_module); | |
512 if (sscf->shm_zone == NULL) { | |
513 return NGX_CONF_ERROR; | |
514 } | |
515 | |
516 continue; | |
517 } | |
518 | |
519 goto invalid; | |
520 } | |
521 | |
522 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
|
523 sscf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE; |
973 | 524 } |
525 | |
526 return NGX_CONF_OK; | |
527 | |
528 invalid: | |
529 | |
530 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
531 "invalid session cache \"%V\"", &value[i]); | |
532 | |
533 return NGX_CONF_ERROR; | |
534 } | |
535 | |
536 | |
563 | 537 #if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) |
538 | |
539 static char * | |
540 ngx_http_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
541 { | |
542 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
543 "\"%V\" directive is available only in %s,", | |
544 &cmd->name, cmd->post); | |
545 | |
546 return NGX_CONF_ERROR; | |
547 } | |
548 | |
549 #endif |