Mercurial > hg > nginx
annotate src/http/modules/ngx_http_ssl_module.c @ 2994:f33c48457d0c
*) $ssl_client_verify
*) "ssl_verify_client ask" was changed to "ssl_verify_client optional"
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 22 Jul 2009 17:41:42 +0000 |
parents | c7d57b539248 |
children | cc07d164f0dc |
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_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
|
17 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
18 |
671 | 19 static ngx_int_t ngx_http_ssl_static_variable(ngx_http_request_t *r, |
611 | 20 ngx_http_variable_value_t *v, uintptr_t data); |
671 | 21 static ngx_int_t ngx_http_ssl_variable(ngx_http_request_t *r, |
647 | 22 ngx_http_variable_value_t *v, uintptr_t data); |
611 | 23 |
24 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
|
25 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
|
26 static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, |
501 | 27 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
|
28 |
2224 | 29 static char *ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, |
30 void *conf); | |
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 }, | |
2994 | 55 { ngx_string("optional"), 2 }, |
2123 | 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, |
2224 | 64 ngx_http_ssl_enable, |
383
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 |
2994 | 209 { ngx_string("ssl_client_verify"), NULL, ngx_http_ssl_variable, |
210 (uintptr_t) ngx_ssl_get_client_verify, NGX_HTTP_VAR_CHANGEABLE, 0 }, | |
211 | |
637 | 212 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
611 | 213 }; |
214 | |
215 | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
216 static ngx_str_t ngx_http_ssl_sess_id_ctx = ngx_string("HTTP"); |
973 | 217 |
218 | |
219 static ngx_int_t | |
671 | 220 ngx_http_ssl_static_variable(ngx_http_request_t *r, |
611 | 221 ngx_http_variable_value_t *v, uintptr_t data) |
222 { | |
671 | 223 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data; |
611 | 224 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
225 size_t len; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
226 ngx_str_t s; |
611 | 227 |
228 if (r->connection->ssl) { | |
229 | |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
230 (void) handler(r->connection, NULL, &s); |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
231 |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
232 v->data = s.data; |
611 | 233 |
671 | 234 for (len = 0; v->data[len]; len++) { /* void */ } |
611 | 235 |
236 v->len = len; | |
237 v->valid = 1; | |
1565 | 238 v->no_cacheable = 0; |
611 | 239 v->not_found = 0; |
240 | |
241 return NGX_OK; | |
242 } | |
243 | |
244 v->not_found = 1; | |
245 | |
246 return NGX_OK; | |
247 } | |
248 | |
249 | |
250 static ngx_int_t | |
671 | 251 ngx_http_ssl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
647 | 252 uintptr_t data) |
253 { | |
671 | 254 ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data; |
647 | 255 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
256 ngx_str_t s; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
257 |
647 | 258 if (r->connection->ssl) { |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
259 |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
260 if (handler(r->connection, r->pool, &s) != NGX_OK) { |
647 | 261 return NGX_ERROR; |
262 } | |
263 | |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
264 v->len = s.len; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
265 v->data = s.data; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1219
diff
changeset
|
266 |
647 | 267 if (v->len) { |
268 v->valid = 1; | |
1565 | 269 v->no_cacheable = 0; |
647 | 270 v->not_found = 0; |
271 | |
272 return NGX_OK; | |
273 } | |
274 } | |
275 | |
276 v->not_found = 1; | |
277 | |
278 return NGX_OK; | |
279 } | |
280 | |
281 | |
282 static ngx_int_t | |
611 | 283 ngx_http_ssl_add_variables(ngx_conf_t *cf) |
284 { | |
285 ngx_http_variable_t *var, *v; | |
286 | |
287 for (v = ngx_http_ssl_vars; v->name.len; v++) { | |
288 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
289 if (var == NULL) { | |
290 return NGX_ERROR; | |
291 } | |
292 | |
637 | 293 var->get_handler = v->get_handler; |
611 | 294 var->data = v->data; |
295 } | |
296 | |
297 return NGX_OK; | |
298 } | |
299 | |
300 | |
501 | 301 static void * |
302 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
|
303 { |
971 | 304 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
|
305 |
971 | 306 sscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t)); |
307 if (sscf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
308 return NULL; |
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 |
479 | 311 /* |
312 * set by ngx_pcalloc(): | |
313 * | |
971 | 314 * sscf->protocols = 0; |
2044 | 315 * sscf->certificate = { 0, NULL }; |
316 * sscf->certificate_key = { 0, NULL }; | |
317 * sscf->dhparam = { 0, NULL }; | |
318 * sscf->client_certificate = { 0, NULL }; | |
971 | 319 * sscf->ciphers.len = 0; |
320 * sscf->ciphers.data = NULL; | |
973 | 321 * sscf->shm_zone = NULL; |
479 | 322 */ |
323 | |
971 | 324 sscf->enable = NGX_CONF_UNSET; |
2123 | 325 sscf->prefer_server_ciphers = NGX_CONF_UNSET; |
2710 | 326 sscf->verify = NGX_CONF_UNSET_UINT; |
327 sscf->verify_depth = NGX_CONF_UNSET_UINT; | |
973 | 328 sscf->builtin_session_cache = NGX_CONF_UNSET; |
329 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
|
330 |
971 | 331 return sscf; |
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 |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
334 |
501 | 335 static char * |
336 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
|
337 { |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
338 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
|
339 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
|
340 |
563 | 341 ngx_pool_cleanup_t *cln; |
342 | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
343 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
|
344 |
573 | 345 ngx_conf_merge_value(conf->session_timeout, |
346 prev->session_timeout, 300); | |
347 | |
547 | 348 ngx_conf_merge_value(conf->prefer_server_ciphers, |
349 prev->prefer_server_ciphers, 0); | |
350 | |
351 ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, | |
352 (NGX_CONF_BITMASK_SET | |
353 |NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1)); | |
354 | |
2123 | 355 ngx_conf_merge_uint_value(conf->verify, prev->verify, 0); |
356 ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1); | |
647 | 357 |
2224 | 358 ngx_conf_merge_str_value(conf->certificate, prev->certificate, ""); |
359 ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, ""); | |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
360 |
2044 | 361 ngx_conf_merge_str_value(conf->dhparam, prev->dhparam, ""); |
362 | |
647 | 363 ngx_conf_merge_str_value(conf->client_certificate, prev->client_certificate, |
364 ""); | |
365 | |
2124 | 366 ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFAULT_CIPHERS); |
479 | 367 |
368 | |
547 | 369 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
|
370 |
2224 | 371 if (conf->enable) { |
372 | |
373 if (conf->certificate.len == 0) { | |
374 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
375 "no \"ssl_certificate\" is defined for " | |
376 "the \"ssl\" directive in %s:%ui", | |
377 conf->file, conf->line); | |
378 return NGX_CONF_ERROR; | |
379 } | |
380 | |
381 if (conf->certificate_key.len == 0) { | |
382 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
383 "no \"ssl_certificate_key\" is defined for " | |
384 "the \"ssl\" directive in %s:%ui", | |
385 conf->file, conf->line); | |
386 return NGX_CONF_ERROR; | |
387 } | |
388 | |
389 } else { | |
390 | |
391 if (conf->certificate.len == 0) { | |
392 return NGX_CONF_OK; | |
393 } | |
394 | |
395 if (conf->certificate_key.len == 0) { | |
396 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
397 "no \"ssl_certificate_key\" is defined " | |
398 "for certificate \"%V\"", &conf->certificate); | |
399 return NGX_CONF_ERROR; | |
400 } | |
401 } | |
402 | |
969 | 403 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
|
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 |
1219 | 407 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME |
408 | |
409 if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx, | |
410 ngx_http_ssl_servername) | |
411 == 0) | |
412 { | |
413 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, | |
414 "SSL_CTX_set_tlsext_servername_callback() failed"); | |
415 return NGX_CONF_ERROR; | |
416 } | |
417 | |
418 #endif | |
419 | |
563 | 420 cln = ngx_pool_cleanup_add(cf->pool, 0); |
421 if (cln == NULL) { | |
509 | 422 return NGX_CONF_ERROR; |
423 } | |
424 | |
563 | 425 cln->handler = ngx_ssl_cleanup_ctx; |
426 cln->data = &conf->ssl; | |
427 | |
428 if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate, | |
970 | 429 &conf->certificate_key) |
430 != NGX_OK) | |
529 | 431 { |
386
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
432 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
|
433 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
434 |
547 | 435 if (SSL_CTX_set_cipher_list(conf->ssl.ctx, |
563 | 436 (const char *) conf->ciphers.data) |
437 == 0) | |
529 | 438 { |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
439 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, |
547 | 440 "SSL_CTX_set_cipher_list(\"%V\") failed", |
441 &conf->ciphers); | |
442 } | |
443 | |
647 | 444 if (conf->verify) { |
2123 | 445 |
446 if (conf->client_certificate.len == 0) { | |
447 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
448 "no ssl_client_certificate for ssl_client_verify"); | |
449 return NGX_CONF_ERROR; | |
450 } | |
451 | |
671 | 452 if (ngx_ssl_client_certificate(cf, &conf->ssl, |
970 | 453 &conf->client_certificate, |
454 conf->verify_depth) | |
671 | 455 != NGX_OK) |
456 { | |
457 return NGX_CONF_ERROR; | |
647 | 458 } |
459 } | |
460 | |
563 | 461 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE |
462 | |
547 | 463 if (conf->prefer_server_ciphers) { |
464 SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); | |
465 } | |
466 | |
563 | 467 #endif |
468 | |
547 | 469 /* a temporary 512-bit RSA key is required for export versions of MSIE */ |
470 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
|
471 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
|
472 } |
fa72605e7089
nginx-0.0.7-2004-07-12-01:03:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
385
diff
changeset
|
473 |
2044 | 474 if (ngx_ssl_dhparam(cf, &conf->ssl, &conf->dhparam) != NGX_OK) { |
475 return NGX_CONF_ERROR; | |
476 } | |
477 | |
973 | 478 ngx_conf_merge_value(conf->builtin_session_cache, |
2032 | 479 prev->builtin_session_cache, NGX_SSL_NONE_SCACHE); |
973 | 480 |
481 if (conf->shm_zone == NULL) { | |
482 conf->shm_zone = prev->shm_zone; | |
483 } | |
484 | |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
485 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
|
486 conf->builtin_session_cache, |
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
487 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
|
488 != NGX_OK) |
973 | 489 { |
974
8dfb3aa75de2
move the session cache callbacks to the ngx_openssl_module
Igor Sysoev <igor@sysoev.ru>
parents:
973
diff
changeset
|
490 return NGX_CONF_ERROR; |
973 | 491 } |
573 | 492 |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
493 return NGX_CONF_OK; |
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
494 } |
563 | 495 |
496 | |
973 | 497 static char * |
2224 | 498 ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
499 { | |
500 ngx_http_ssl_srv_conf_t *sscf = conf; | |
501 | |
502 char *rv; | |
503 | |
504 rv = ngx_conf_set_flag_slot(cf, cmd, conf); | |
505 | |
506 if (rv != NGX_CONF_OK) { | |
507 return rv; | |
508 } | |
509 | |
510 sscf->file = cf->conf_file->file.name.data; | |
511 sscf->line = cf->conf_file->line; | |
512 | |
513 return NGX_CONF_OK; | |
514 } | |
515 | |
516 | |
517 static char * | |
973 | 518 ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
519 { | |
520 ngx_http_ssl_srv_conf_t *sscf = conf; | |
521 | |
522 size_t len; | |
523 ngx_str_t *value, name, size; | |
524 ngx_int_t n; | |
525 ngx_uint_t i, j; | |
526 | |
527 value = cf->args->elts; | |
528 | |
529 for (i = 1; i < cf->args->nelts; i++) { | |
530 | |
1778 | 531 if (ngx_strcmp(value[i].data, "off") == 0) { |
532 sscf->builtin_session_cache = NGX_SSL_NO_SCACHE; | |
533 continue; | |
534 } | |
535 | |
2032 | 536 if (ngx_strcmp(value[i].data, "none") == 0) { |
537 sscf->builtin_session_cache = NGX_SSL_NONE_SCACHE; | |
538 continue; | |
539 } | |
540 | |
973 | 541 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
|
542 sscf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE; |
973 | 543 continue; |
544 } | |
545 | |
546 if (value[i].len > sizeof("builtin:") - 1 | |
547 && ngx_strncmp(value[i].data, "builtin:", sizeof("builtin:") - 1) | |
548 == 0) | |
549 { | |
550 n = ngx_atoi(value[i].data + sizeof("builtin:") - 1, | |
551 value[i].len - (sizeof("builtin:") - 1)); | |
552 | |
553 if (n == NGX_ERROR) { | |
554 goto invalid; | |
555 } | |
556 | |
557 sscf->builtin_session_cache = n; | |
558 | |
559 continue; | |
560 } | |
561 | |
562 if (value[i].len > sizeof("shared:") - 1 | |
563 && ngx_strncmp(value[i].data, "shared:", sizeof("shared:") - 1) | |
564 == 0) | |
565 { | |
566 len = 0; | |
567 | |
568 for (j = sizeof("shared:") - 1; j < value[i].len; j++) { | |
569 if (value[i].data[j] == ':') { | |
2716
d5896f6608e8
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2710
diff
changeset
|
570 value[i].data[j] = '\0'; |
973 | 571 break; |
572 } | |
573 | |
574 len++; | |
575 } | |
576 | |
577 if (len == 0) { | |
578 goto invalid; | |
579 } | |
580 | |
581 name.len = len; | |
582 name.data = value[i].data + sizeof("shared:") - 1; | |
583 | |
584 size.len = value[i].len - j - 1; | |
585 size.data = name.data + len + 1; | |
586 | |
587 n = ngx_parse_size(&size); | |
588 | |
589 if (n == NGX_ERROR) { | |
590 goto invalid; | |
591 } | |
592 | |
593 if (n < (ngx_int_t) (8 * ngx_pagesize)) { | |
594 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
|
595 "session cache \"%V\" is too small", |
973 | 596 &value[i]); |
597 | |
598 return NGX_CONF_ERROR; | |
599 } | |
600 | |
601 sscf->shm_zone = ngx_shared_memory_add(cf, &name, n, | |
602 &ngx_http_ssl_module); | |
603 if (sscf->shm_zone == NULL) { | |
604 return NGX_CONF_ERROR; | |
605 } | |
606 | |
607 continue; | |
608 } | |
609 | |
610 goto invalid; | |
611 } | |
612 | |
613 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
|
614 sscf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE; |
973 | 615 } |
616 | |
617 return NGX_CONF_OK; | |
618 | |
619 invalid: | |
620 | |
621 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
622 "invalid session cache \"%V\"", &value[i]); | |
623 | |
624 return NGX_CONF_ERROR; | |
625 } | |
626 | |
627 | |
563 | 628 #if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) |
629 | |
630 static char * | |
631 ngx_http_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
632 { | |
633 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
634 "\"%V\" directive is available only in %s,", | |
635 &cmd->name, cmd->post); | |
636 | |
637 return NGX_CONF_ERROR; | |
638 } | |
639 | |
640 #endif |