Mercurial > hg > nginx
annotate src/http/modules/ngx_http_ssl_module.c @ 2213:8cc552c91cd2
bump version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 26 Aug 2008 17:23:27 +0000 |
parents | e0b424b98f24 |
children | 109849282793 |
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 | |
2124 | 16 #define NGX_DEFAULT_CERTIFICATE "cert.pem" |
17 #define NGX_DEFAULT_CERTIFICATE_KEY "cert.pem" | |
18 #define NGX_DEFAULT_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 | |
2123 | 52 static ngx_conf_enum_t ngx_http_ssl_verify[] = { |
53 { ngx_string("off"), 0 }, | |
54 { ngx_string("on"), 1 }, | |
55 { ngx_string("ask"), 2 }, | |
56 { ngx_null_string, 0 } | |
57 }; | |
58 | |
59 | |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
60 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
|
61 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
62 { ngx_string("ssl"), |
599 | 63 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
|
64 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
|
65 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
|
66 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
|
67 NULL }, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 { ngx_string("ssl_certificate"), |
599 | 70 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
|
71 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
|
72 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
|
73 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
|
74 NULL }, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 { ngx_string("ssl_certificate_key"), |
599 | 77 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
|
78 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
|
79 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
|
80 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
|
81 NULL }, |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 |
2044 | 83 { ngx_string("ssl_dhparam"), |
84 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, | |
85 ngx_conf_set_str_slot, | |
86 NGX_HTTP_SRV_CONF_OFFSET, | |
87 offsetof(ngx_http_ssl_srv_conf_t, dhparam), | |
88 NULL }, | |
89 | |
547 | 90 { ngx_string("ssl_protocols"), |
563 | 91 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, |
547 | 92 ngx_conf_set_bitmask_slot, |
93 NGX_HTTP_SRV_CONF_OFFSET, | |
94 offsetof(ngx_http_ssl_srv_conf_t, protocols), | |
95 &ngx_http_ssl_protocols }, | |
96 | |
479 | 97 { ngx_string("ssl_ciphers"), |
563 | 98 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
479 | 99 ngx_conf_set_str_slot, |
100 NGX_HTTP_SRV_CONF_OFFSET, | |
101 offsetof(ngx_http_ssl_srv_conf_t, ciphers), | |
102 NULL }, | |
103 | |
647 | 104 { ngx_string("ssl_verify_client"), |
667 | 105 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, |
2123 | 106 ngx_conf_set_enum_slot, |
647 | 107 NGX_HTTP_SRV_CONF_OFFSET, |
108 offsetof(ngx_http_ssl_srv_conf_t, verify), | |
2123 | 109 &ngx_http_ssl_verify }, |
647 | 110 |
111 { ngx_string("ssl_verify_depth"), | |
112 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, | |
113 ngx_conf_set_num_slot, | |
114 NGX_HTTP_SRV_CONF_OFFSET, | |
115 offsetof(ngx_http_ssl_srv_conf_t, verify_depth), | |
116 NULL }, | |
117 | |
118 { ngx_string("ssl_client_certificate"), | |
119 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, | |
120 ngx_conf_set_str_slot, | |
121 NGX_HTTP_SRV_CONF_OFFSET, | |
122 offsetof(ngx_http_ssl_srv_conf_t, client_certificate), | |
123 NULL }, | |
124 | |
547 | 125 { ngx_string("ssl_prefer_server_ciphers"), |
126 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, | |
563 | 127 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE |
547 | 128 ngx_conf_set_flag_slot, |
129 NGX_HTTP_SRV_CONF_OFFSET, | |
130 offsetof(ngx_http_ssl_srv_conf_t, prefer_server_ciphers), | |
131 NULL }, | |
563 | 132 #else |
133 ngx_http_ssl_nosupported, 0, 0, ngx_http_ssl_openssl097 }, | |
134 #endif | |
547 | 135 |
973 | 136 { ngx_string("ssl_session_cache"), |
137 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE12, | |
138 ngx_http_ssl_session_cache, | |
139 NGX_HTTP_SRV_CONF_OFFSET, | |
140 0, | |
141 NULL }, | |
142 | |
573 | 143 { ngx_string("ssl_session_timeout"), |
144 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, | |
145 ngx_conf_set_sec_slot, | |
146 NGX_HTTP_SRV_CONF_OFFSET, | |
147 offsetof(ngx_http_ssl_srv_conf_t, session_timeout), | |
148 NULL }, | |
149 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 ngx_null_command |
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 static ngx_http_module_t ngx_http_ssl_module_ctx = { |
611 | 155 ngx_http_ssl_add_variables, /* preconfiguration */ |
509 | 156 NULL, /* postconfiguration */ |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 |
541 | 158 NULL, /* create main configuration */ |
159 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
|
160 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 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
|
162 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
|
163 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 NULL, /* create location configuration */ |
485 | 165 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
|
166 }; |
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 |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
169 ngx_module_t ngx_http_ssl_module = { |
509 | 170 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
|
171 &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
|
172 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
|
173 NGX_HTTP_MODULE, /* module type */ |
541 | 174 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
|
175 NULL, /* init module */ |
541 | 176 NULL, /* init process */ |
177 NULL, /* init thread */ | |
178 NULL, /* exit thread */ | |
179 NULL, /* exit process */ | |
180 NULL, /* exit master */ | |
181 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
|
182 }; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 |
611 | 185 static ngx_http_variable_t ngx_http_ssl_vars[] = { |
186 | |
671 | 187 { ngx_string("ssl_protocol"), NULL, ngx_http_ssl_static_variable, |
1565 | 188 (uintptr_t) ngx_ssl_get_protocol, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
611 | 189 |
671 | 190 { ngx_string("ssl_cipher"), NULL, ngx_http_ssl_static_variable, |
1565 | 191 (uintptr_t) ngx_ssl_get_cipher_name, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
611 | 192 |
2045 | 193 { ngx_string("ssl_client_cert"), NULL, ngx_http_ssl_variable, |
194 (uintptr_t) ngx_ssl_get_certificate, NGX_HTTP_VAR_CHANGEABLE, 0 }, | |
195 | |
2123 | 196 { ngx_string("ssl_client_raw_cert"), NULL, ngx_http_ssl_variable, |
197 (uintptr_t) ngx_ssl_get_raw_certificate, | |
198 NGX_HTTP_VAR_CHANGEABLE, 0 }, | |
199 | |
671 | 200 { ngx_string("ssl_client_s_dn"), NULL, ngx_http_ssl_variable, |
1565 | 201 (uintptr_t) ngx_ssl_get_subject_dn, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
647 | 202 |
671 | 203 { ngx_string("ssl_client_i_dn"), NULL, ngx_http_ssl_variable, |
1565 | 204 (uintptr_t) ngx_ssl_get_issuer_dn, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
671 | 205 |
206 { ngx_string("ssl_client_serial"), NULL, ngx_http_ssl_variable, | |
1565 | 207 (uintptr_t) ngx_ssl_get_serial_number, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
647 | 208 |
637 | 209 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
611 | 210 }; |
211 | |
212 | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
213 static ngx_str_t ngx_http_ssl_sess_id_ctx = ngx_string("HTTP"); |
973 | 214 |
215 | |
216 static ngx_int_t | |
671 | 217 ngx_http_ssl_static_variable(ngx_http_request_t *r, |
611 | 218 ngx_http_variable_value_t *v, uintptr_t data) |
219 { | |
671 | 220 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data; |
611 | 221 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
222 size_t len; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
223 ngx_str_t s; |
611 | 224 |
225 if (r->connection->ssl) { | |
226 | |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
227 (void) handler(r->connection, NULL, &s); |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
228 |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
229 v->data = s.data; |
611 | 230 |
671 | 231 for (len = 0; v->data[len]; len++) { /* void */ } |
611 | 232 |
233 v->len = len; | |
234 v->valid = 1; | |
1565 | 235 v->no_cacheable = 0; |
611 | 236 v->not_found = 0; |
237 | |
238 return NGX_OK; | |
239 } | |
240 | |
241 v->not_found = 1; | |
242 | |
243 return NGX_OK; | |
244 } | |
245 | |
246 | |
247 static ngx_int_t | |
671 | 248 ngx_http_ssl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
647 | 249 uintptr_t data) |
250 { | |
671 | 251 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data; |
647 | 252 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
253 ngx_str_t s; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
254 |
647 | 255 if (r->connection->ssl) { |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
256 |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
257 if (handler(r->connection, r->pool, &s) != NGX_OK) { |
647 | 258 return NGX_ERROR; |
259 } | |
260 | |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
261 v->len = s.len; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
262 v->data = s.data; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
263 |
647 | 264 if (v->len) { |
265 v->valid = 1; | |
1565 | 266 v->no_cacheable = 0; |
647 | 267 v->not_found = 0; |
268 | |
269 return NGX_OK; | |
270 } | |
271 } | |
272 | |
273 v->not_found = 1; | |
274 | |
275 return NGX_OK; | |
276 } | |
277 | |
278 | |
279 static ngx_int_t | |
611 | 280 ngx_http_ssl_add_variables(ngx_conf_t *cf) |
281 { | |
282 ngx_http_variable_t *var, *v; | |
283 | |
284 for (v = ngx_http_ssl_vars; v->name.len; v++) { | |
285 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
286 if (var == NULL) { | |
287 return NGX_ERROR; | |
288 } | |
289 | |
637 | 290 var->get_handler = v->get_handler; |
611 | 291 var->data = v->data; |
292 } | |
293 | |
294 return NGX_OK; | |
295 } | |
296 | |
297 | |
501 | 298 static void * |
299 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
|
300 { |
971 | 301 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
|
302 |
971 | 303 sscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t)); |
304 if (sscf == NULL) { | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
305 return NGX_CONF_ERROR; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
306 } |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
307 |
479 | 308 /* |
309 * set by ngx_pcalloc(): | |
310 * | |
971 | 311 * sscf->protocols = 0; |
2044 | 312 * sscf->certificate = { 0, NULL }; |
313 * sscf->certificate_key = { 0, NULL }; | |
314 * sscf->dhparam = { 0, NULL }; | |
315 * sscf->client_certificate = { 0, NULL }; | |
971 | 316 * sscf->ciphers.len = 0; |
317 * sscf->ciphers.data = NULL; | |
973 | 318 * sscf->shm_zone = NULL; |
479 | 319 */ |
320 | |
971 | 321 sscf->enable = NGX_CONF_UNSET; |
2123 | 322 sscf->prefer_server_ciphers = NGX_CONF_UNSET; |
971 | 323 sscf->verify = NGX_CONF_UNSET; |
324 sscf->verify_depth = NGX_CONF_UNSET; | |
973 | 325 sscf->builtin_session_cache = NGX_CONF_UNSET; |
326 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
|
327 |
971 | 328 return sscf; |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
329 } |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
330 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
331 |
501 | 332 static char * |
333 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
|
334 { |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
335 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
|
336 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
|
337 |
563 | 338 ngx_pool_cleanup_t *cln; |
339 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
340 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
|
341 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
342 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
|
343 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
|
344 } |
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
392
diff
changeset
|
345 |
573 | 346 ngx_conf_merge_value(conf->session_timeout, |
347 prev->session_timeout, 300); | |
348 | |
547 | 349 ngx_conf_merge_value(conf->prefer_server_ciphers, |
350 prev->prefer_server_ciphers, 0); | |
351 | |
352 ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, | |
353 (NGX_CONF_BITMASK_SET | |
354 |NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1)); | |
355 | |
2123 | 356 ngx_conf_merge_uint_value(conf->verify, prev->verify, 0); |
357 ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1); | |
647 | 358 |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
359 ngx_conf_merge_str_value(conf->certificate, prev->certificate, |
2124 | 360 NGX_DEFAULT_CERTIFICATE); |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
361 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
362 ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, |
2124 | 363 NGX_DEFAULT_CERTIFICATE_KEY); |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
364 |
2044 | 365 ngx_conf_merge_str_value(conf->dhparam, prev->dhparam, ""); |
366 | |
647 | 367 ngx_conf_merge_str_value(conf->client_certificate, prev->client_certificate, |
368 ""); | |
369 | |
2124 | 370 ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFAULT_CIPHERS); |
479 | 371 |
372 | |
547 | 373 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
|
374 |
969 | 375 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
|
376 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
|
377 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
378 |
1219 | 379 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME |
380 | |
381 if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx, | |
382 ngx_http_ssl_servername) | |
383 == 0) | |
384 { | |
385 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, | |
386 "SSL_CTX_set_tlsext_servername_callback() failed"); | |
387 return NGX_CONF_ERROR; | |
388 } | |
389 | |
390 #endif | |
391 | |
563 | 392 cln = ngx_pool_cleanup_add(cf->pool, 0); |
393 if (cln == NULL) { | |
509 | 394 return NGX_CONF_ERROR; |
395 } | |
396 | |
563 | 397 cln->handler = ngx_ssl_cleanup_ctx; |
398 cln->data = &conf->ssl; | |
399 | |
400 if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate, | |
970 | 401 &conf->certificate_key) |
402 != NGX_OK) | |
529 | 403 { |
386
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
404 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
|
405 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
406 |
547 | 407 if (SSL_CTX_set_cipher_list(conf->ssl.ctx, |
563 | 408 (const char *) conf->ciphers.data) |
409 == 0) | |
529 | 410 { |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
411 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, |
547 | 412 "SSL_CTX_set_cipher_list(\"%V\") failed", |
413 &conf->ciphers); | |
414 } | |
415 | |
647 | 416 if (conf->verify) { |
2123 | 417 |
418 if (conf->client_certificate.len == 0) { | |
419 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
420 "no ssl_client_certificate for ssl_client_verify"); | |
421 return NGX_CONF_ERROR; | |
422 } | |
423 | |
671 | 424 if (ngx_ssl_client_certificate(cf, &conf->ssl, |
970 | 425 &conf->client_certificate, |
426 conf->verify_depth) | |
671 | 427 != NGX_OK) |
428 { | |
429 return NGX_CONF_ERROR; | |
647 | 430 } |
431 } | |
432 | |
563 | 433 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE |
434 | |
547 | 435 if (conf->prefer_server_ciphers) { |
436 SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); | |
437 } | |
438 | |
563 | 439 #endif |
440 | |
547 | 441 /* a temporary 512-bit RSA key is required for export versions of MSIE */ |
442 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
|
443 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
|
444 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
445 |
2044 | 446 if (ngx_ssl_dhparam(cf, &conf->ssl, &conf->dhparam) != NGX_OK) { |
447 return NGX_CONF_ERROR; | |
448 } | |
449 | |
973 | 450 ngx_conf_merge_value(conf->builtin_session_cache, |
2032 | 451 prev->builtin_session_cache, NGX_SSL_NONE_SCACHE); |
973 | 452 |
453 if (conf->shm_zone == NULL) { | |
454 conf->shm_zone = prev->shm_zone; | |
455 } | |
456 | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
457 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
|
458 conf->builtin_session_cache, |
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
459 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
|
460 != NGX_OK) |
973 | 461 { |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
462 return NGX_CONF_ERROR; |
973 | 463 } |
573 | 464 |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
465 return NGX_CONF_OK; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
466 } |
563 | 467 |
468 | |
973 | 469 static char * |
470 ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
471 { | |
472 ngx_http_ssl_srv_conf_t *sscf = conf; | |
473 | |
474 size_t len; | |
475 ngx_str_t *value, name, size; | |
476 ngx_int_t n; | |
477 ngx_uint_t i, j; | |
478 | |
479 value = cf->args->elts; | |
480 | |
481 for (i = 1; i < cf->args->nelts; i++) { | |
482 | |
1778 | 483 if (ngx_strcmp(value[i].data, "off") == 0) { |
484 sscf->builtin_session_cache = NGX_SSL_NO_SCACHE; | |
485 continue; | |
486 } | |
487 | |
2032 | 488 if (ngx_strcmp(value[i].data, "none") == 0) { |
489 sscf->builtin_session_cache = NGX_SSL_NONE_SCACHE; | |
490 continue; | |
491 } | |
492 | |
973 | 493 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
|
494 sscf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE; |
973 | 495 continue; |
496 } | |
497 | |
498 if (value[i].len > sizeof("builtin:") - 1 | |
499 && ngx_strncmp(value[i].data, "builtin:", sizeof("builtin:") - 1) | |
500 == 0) | |
501 { | |
502 n = ngx_atoi(value[i].data + sizeof("builtin:") - 1, | |
503 value[i].len - (sizeof("builtin:") - 1)); | |
504 | |
505 if (n == NGX_ERROR) { | |
506 goto invalid; | |
507 } | |
508 | |
509 sscf->builtin_session_cache = n; | |
510 | |
511 continue; | |
512 } | |
513 | |
514 if (value[i].len > sizeof("shared:") - 1 | |
515 && ngx_strncmp(value[i].data, "shared:", sizeof("shared:") - 1) | |
516 == 0) | |
517 { | |
518 len = 0; | |
519 | |
520 for (j = sizeof("shared:") - 1; j < value[i].len; j++) { | |
521 if (value[i].data[j] == ':') { | |
522 break; | |
523 } | |
524 | |
525 len++; | |
526 } | |
527 | |
528 if (len == 0) { | |
529 goto invalid; | |
530 } | |
531 | |
532 name.len = len; | |
533 name.data = value[i].data + sizeof("shared:") - 1; | |
534 | |
535 size.len = value[i].len - j - 1; | |
536 size.data = name.data + len + 1; | |
537 | |
538 n = ngx_parse_size(&size); | |
539 | |
540 if (n == NGX_ERROR) { | |
541 goto invalid; | |
542 } | |
543 | |
544 if (n < (ngx_int_t) (8 * ngx_pagesize)) { | |
545 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
|
546 "session cache \"%V\" is too small", |
973 | 547 &value[i]); |
548 | |
549 return NGX_CONF_ERROR; | |
550 } | |
551 | |
552 sscf->shm_zone = ngx_shared_memory_add(cf, &name, n, | |
553 &ngx_http_ssl_module); | |
554 if (sscf->shm_zone == NULL) { | |
555 return NGX_CONF_ERROR; | |
556 } | |
557 | |
558 continue; | |
559 } | |
560 | |
561 goto invalid; | |
562 } | |
563 | |
564 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
|
565 sscf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE; |
973 | 566 } |
567 | |
568 return NGX_CONF_OK; | |
569 | |
570 invalid: | |
571 | |
572 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
573 "invalid session cache \"%V\"", &value[i]); | |
574 | |
575 return NGX_CONF_ERROR; | |
576 } | |
577 | |
578 | |
563 | 579 #if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) |
580 | |
581 static char * | |
582 ngx_http_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
583 { | |
584 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
585 "\"%V\" directive is available only in %s,", | |
586 &cmd->name, cmd->post); | |
587 | |
588 return NGX_CONF_ERROR; | |
589 } | |
590 | |
591 #endif |