Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) Igor Sysoev |
Maxim Konovalov | f8d59e3 | 2012-01-18 15:07:43 +0000 | [diff] [blame] | 4 | * Copyright (C) Nginx, Inc. |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | |
| 8 | #include <ngx_config.h> |
| 9 | #include <ngx_core.h> |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 10 | #include <ngx_mail.h> |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 11 | |
| 12 | |
Igor Sysoev | f39642a | 2011-07-20 15:42:40 +0000 | [diff] [blame] | 13 | #define NGX_DEFAULT_CIPHERS "HIGH:!aNULL:!MD5" |
| 14 | #define NGX_DEFAULT_ECDH_CURVE "prime256v1" |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 15 | |
| 16 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 17 | static void *ngx_mail_ssl_create_conf(ngx_conf_t *cf); |
| 18 | static char *ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child); |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 19 | |
| 20 | static char *ngx_mail_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, |
| 21 | void *conf); |
| 22 | static char *ngx_mail_ssl_starttls(ngx_conf_t *cf, ngx_command_t *cmd, |
| 23 | void *conf); |
Valentin Bartenev | 9f8785a | 2014-06-16 19:43:25 +0400 | [diff] [blame] | 24 | static char *ngx_mail_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, |
| 25 | void *conf); |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 26 | static char *ngx_mail_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 27 | void *conf); |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 28 | |
| 29 | |
Piotr Sikora | c3d20f5 | 2013-05-21 18:43:43 -0700 | [diff] [blame] | 30 | static ngx_conf_enum_t ngx_mail_starttls_state[] = { |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 31 | { ngx_string("off"), NGX_MAIL_STARTTLS_OFF }, |
| 32 | { ngx_string("on"), NGX_MAIL_STARTTLS_ON }, |
| 33 | { ngx_string("only"), NGX_MAIL_STARTTLS_ONLY }, |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 34 | { ngx_null_string, 0 } |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 39 | static ngx_conf_bitmask_t ngx_mail_ssl_protocols[] = { |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 40 | { ngx_string("SSLv2"), NGX_SSL_SSLv2 }, |
| 41 | { ngx_string("SSLv3"), NGX_SSL_SSLv3 }, |
| 42 | { ngx_string("TLSv1"), NGX_SSL_TLSv1 }, |
Maxim Dounin | 4efcbce | 2012-01-11 11:15:00 +0000 | [diff] [blame] | 43 | { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 }, |
| 44 | { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 }, |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 45 | { ngx_null_string, 0 } |
| 46 | }; |
| 47 | |
| 48 | |
Maxim Dounin | cbc9f4d | 2015-02-25 17:48:05 +0300 | [diff] [blame] | 49 | static ngx_conf_enum_t ngx_mail_ssl_verify[] = { |
| 50 | { ngx_string("off"), 0 }, |
| 51 | { ngx_string("on"), 1 }, |
| 52 | { ngx_string("optional"), 2 }, |
| 53 | { ngx_string("optional_no_ca"), 3 }, |
| 54 | { ngx_null_string, 0 } |
| 55 | }; |
| 56 | |
| 57 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 58 | static ngx_command_t ngx_mail_ssl_commands[] = { |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 59 | |
| 60 | { ngx_string("ssl"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 61 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 62 | ngx_mail_ssl_enable, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 63 | NGX_MAIL_SRV_CONF_OFFSET, |
| 64 | offsetof(ngx_mail_ssl_conf_t, enable), |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 65 | NULL }, |
| 66 | |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 67 | { ngx_string("starttls"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 68 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 69 | ngx_mail_ssl_starttls, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 70 | NGX_MAIL_SRV_CONF_OFFSET, |
| 71 | offsetof(ngx_mail_ssl_conf_t, starttls), |
Piotr Sikora | c3d20f5 | 2013-05-21 18:43:43 -0700 | [diff] [blame] | 72 | ngx_mail_starttls_state }, |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 73 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 74 | { ngx_string("ssl_certificate"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 75 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 76 | ngx_conf_set_str_slot, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 77 | NGX_MAIL_SRV_CONF_OFFSET, |
| 78 | offsetof(ngx_mail_ssl_conf_t, certificate), |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 79 | NULL }, |
| 80 | |
| 81 | { ngx_string("ssl_certificate_key"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 82 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 83 | ngx_conf_set_str_slot, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 84 | NGX_MAIL_SRV_CONF_OFFSET, |
| 85 | offsetof(ngx_mail_ssl_conf_t, certificate_key), |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 86 | NULL }, |
| 87 | |
Valentin Bartenev | 9f8785a | 2014-06-16 19:43:25 +0400 | [diff] [blame] | 88 | { ngx_string("ssl_password_file"), |
| 89 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 90 | ngx_mail_ssl_password_file, |
| 91 | NGX_MAIL_SRV_CONF_OFFSET, |
| 92 | 0, |
| 93 | NULL }, |
| 94 | |
Igor Sysoev | df83e6f | 2008-06-16 05:51:32 +0000 | [diff] [blame] | 95 | { ngx_string("ssl_dhparam"), |
| 96 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 97 | ngx_conf_set_str_slot, |
| 98 | NGX_MAIL_SRV_CONF_OFFSET, |
| 99 | offsetof(ngx_mail_ssl_conf_t, dhparam), |
| 100 | NULL }, |
| 101 | |
Igor Sysoev | f39642a | 2011-07-20 15:42:40 +0000 | [diff] [blame] | 102 | { ngx_string("ssl_ecdh_curve"), |
| 103 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 104 | ngx_conf_set_str_slot, |
| 105 | NGX_MAIL_SRV_CONF_OFFSET, |
| 106 | offsetof(ngx_mail_ssl_conf_t, ecdh_curve), |
| 107 | NULL }, |
| 108 | |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 109 | { ngx_string("ssl_protocols"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 110 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 111 | ngx_conf_set_bitmask_slot, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 112 | NGX_MAIL_SRV_CONF_OFFSET, |
| 113 | offsetof(ngx_mail_ssl_conf_t, protocols), |
| 114 | &ngx_mail_ssl_protocols }, |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 115 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 116 | { ngx_string("ssl_ciphers"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 117 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 118 | ngx_conf_set_str_slot, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 119 | NGX_MAIL_SRV_CONF_OFFSET, |
| 120 | offsetof(ngx_mail_ssl_conf_t, ciphers), |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 121 | NULL }, |
| 122 | |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 123 | { ngx_string("ssl_prefer_server_ciphers"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 124 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 125 | ngx_conf_set_flag_slot, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 126 | NGX_MAIL_SRV_CONF_OFFSET, |
| 127 | offsetof(ngx_mail_ssl_conf_t, prefer_server_ciphers), |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 128 | NULL }, |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 129 | |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 130 | { ngx_string("ssl_session_cache"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 131 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE12, |
| 132 | ngx_mail_ssl_session_cache, |
| 133 | NGX_MAIL_SRV_CONF_OFFSET, |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 134 | 0, |
| 135 | NULL }, |
| 136 | |
Dirkjan Bussink | 58a240d | 2014-01-10 16:12:40 +0100 | [diff] [blame] | 137 | { ngx_string("ssl_session_tickets"), |
| 138 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
| 139 | ngx_conf_set_flag_slot, |
| 140 | NGX_MAIL_SRV_CONF_OFFSET, |
| 141 | offsetof(ngx_mail_ssl_conf_t, session_tickets), |
| 142 | NULL }, |
| 143 | |
Piotr Sikora | 79be6a5 | 2013-10-11 16:05:24 -0700 | [diff] [blame] | 144 | { ngx_string("ssl_session_ticket_key"), |
| 145 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 146 | ngx_conf_set_str_array_slot, |
| 147 | NGX_MAIL_SRV_CONF_OFFSET, |
| 148 | offsetof(ngx_mail_ssl_conf_t, session_ticket_keys), |
| 149 | NULL }, |
| 150 | |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 151 | { ngx_string("ssl_session_timeout"), |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 152 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 153 | ngx_conf_set_sec_slot, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 154 | NGX_MAIL_SRV_CONF_OFFSET, |
| 155 | offsetof(ngx_mail_ssl_conf_t, session_timeout), |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 156 | NULL }, |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 157 | |
Maxim Dounin | cbc9f4d | 2015-02-25 17:48:05 +0300 | [diff] [blame] | 158 | { ngx_string("ssl_verify_client"), |
| 159 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 160 | ngx_conf_set_enum_slot, |
| 161 | NGX_MAIL_SRV_CONF_OFFSET, |
| 162 | offsetof(ngx_mail_ssl_conf_t, verify), |
| 163 | &ngx_mail_ssl_verify }, |
| 164 | |
| 165 | { ngx_string("ssl_verify_depth"), |
| 166 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 167 | ngx_conf_set_num_slot, |
| 168 | NGX_MAIL_SRV_CONF_OFFSET, |
| 169 | offsetof(ngx_mail_ssl_conf_t, verify_depth), |
| 170 | NULL }, |
| 171 | |
| 172 | { ngx_string("ssl_client_certificate"), |
| 173 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 174 | ngx_conf_set_str_slot, |
| 175 | NGX_MAIL_SRV_CONF_OFFSET, |
| 176 | offsetof(ngx_mail_ssl_conf_t, client_certificate), |
| 177 | NULL }, |
| 178 | |
| 179 | { ngx_string("ssl_trusted_certificate"), |
| 180 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 181 | ngx_conf_set_str_slot, |
| 182 | NGX_MAIL_SRV_CONF_OFFSET, |
| 183 | offsetof(ngx_mail_ssl_conf_t, trusted_certificate), |
| 184 | NULL }, |
| 185 | |
| 186 | { ngx_string("ssl_crl"), |
| 187 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 188 | ngx_conf_set_str_slot, |
| 189 | NGX_MAIL_SRV_CONF_OFFSET, |
| 190 | offsetof(ngx_mail_ssl_conf_t, crl), |
| 191 | NULL }, |
| 192 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 193 | ngx_null_command |
| 194 | }; |
| 195 | |
| 196 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 197 | static ngx_mail_module_t ngx_mail_ssl_module_ctx = { |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 198 | NULL, /* protocol */ |
| 199 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 200 | NULL, /* create main configuration */ |
| 201 | NULL, /* init main configuration */ |
| 202 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 203 | ngx_mail_ssl_create_conf, /* create server configuration */ |
| 204 | ngx_mail_ssl_merge_conf /* merge server configuration */ |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 208 | ngx_module_t ngx_mail_ssl_module = { |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 209 | NGX_MODULE_V1, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 210 | &ngx_mail_ssl_module_ctx, /* module context */ |
| 211 | ngx_mail_ssl_commands, /* module directives */ |
| 212 | NGX_MAIL_MODULE, /* module type */ |
Igor Sysoev | e573380 | 2005-09-08 14:36:09 +0000 | [diff] [blame] | 213 | NULL, /* init master */ |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 214 | NULL, /* init module */ |
Igor Sysoev | e573380 | 2005-09-08 14:36:09 +0000 | [diff] [blame] | 215 | NULL, /* init process */ |
| 216 | NULL, /* init thread */ |
| 217 | NULL, /* exit thread */ |
| 218 | NULL, /* exit process */ |
| 219 | NULL, /* exit master */ |
| 220 | NGX_MODULE_V1_PADDING |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 224 | static ngx_str_t ngx_mail_ssl_sess_id_ctx = ngx_string("MAIL"); |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 225 | |
| 226 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 227 | static void * |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 228 | ngx_mail_ssl_create_conf(ngx_conf_t *cf) |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 229 | { |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 230 | ngx_mail_ssl_conf_t *scf; |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 231 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 232 | scf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_ssl_conf_t)); |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 233 | if (scf == NULL) { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 234 | return NULL; |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 238 | * set by ngx_pcalloc(): |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 239 | * |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 240 | * scf->protocols = 0; |
Igor Sysoev | df83e6f | 2008-06-16 05:51:32 +0000 | [diff] [blame] | 241 | * scf->certificate = { 0, NULL }; |
| 242 | * scf->certificate_key = { 0, NULL }; |
| 243 | * scf->dhparam = { 0, NULL }; |
Igor Sysoev | f39642a | 2011-07-20 15:42:40 +0000 | [diff] [blame] | 244 | * scf->ecdh_curve = { 0, NULL }; |
Maxim Dounin | cbc9f4d | 2015-02-25 17:48:05 +0300 | [diff] [blame] | 245 | * scf->client_certificate = { 0, NULL }; |
| 246 | * scf->trusted_certificate = { 0, NULL }; |
| 247 | * scf->crl = { 0, NULL }; |
Igor Sysoev | 05b1a8f | 2010-05-14 09:56:37 +0000 | [diff] [blame] | 248 | * scf->ciphers = { 0, NULL }; |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 249 | * scf->shm_zone = NULL; |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 250 | */ |
| 251 | |
| 252 | scf->enable = NGX_CONF_UNSET; |
Igor Sysoev | 2ac565f | 2009-04-27 11:33:34 +0000 | [diff] [blame] | 253 | scf->starttls = NGX_CONF_UNSET_UINT; |
Valentin Bartenev | 9f8785a | 2014-06-16 19:43:25 +0400 | [diff] [blame] | 254 | scf->passwords = NGX_CONF_UNSET_PTR; |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 255 | scf->prefer_server_ciphers = NGX_CONF_UNSET; |
Maxim Dounin | cbc9f4d | 2015-02-25 17:48:05 +0300 | [diff] [blame] | 256 | scf->verify = NGX_CONF_UNSET_UINT; |
| 257 | scf->verify_depth = NGX_CONF_UNSET_UINT; |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 258 | scf->builtin_session_cache = NGX_CONF_UNSET; |
| 259 | scf->session_timeout = NGX_CONF_UNSET; |
Dirkjan Bussink | 58a240d | 2014-01-10 16:12:40 +0100 | [diff] [blame] | 260 | scf->session_tickets = NGX_CONF_UNSET; |
Piotr Sikora | 79be6a5 | 2013-10-11 16:05:24 -0700 | [diff] [blame] | 261 | scf->session_ticket_keys = NGX_CONF_UNSET_PTR; |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 262 | |
| 263 | return scf; |
| 264 | } |
| 265 | |
| 266 | |
| 267 | static char * |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 268 | ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 269 | { |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 270 | ngx_mail_ssl_conf_t *prev = parent; |
| 271 | ngx_mail_ssl_conf_t *conf = child; |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 272 | |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 273 | char *mode; |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 274 | ngx_pool_cleanup_t *cln; |
| 275 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 276 | ngx_conf_merge_value(conf->enable, prev->enable, 0); |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 277 | ngx_conf_merge_uint_value(conf->starttls, prev->starttls, |
| 278 | NGX_MAIL_STARTTLS_OFF); |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 279 | |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 280 | ngx_conf_merge_value(conf->session_timeout, |
| 281 | prev->session_timeout, 300); |
| 282 | |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 283 | ngx_conf_merge_value(conf->prefer_server_ciphers, |
| 284 | prev->prefer_server_ciphers, 0); |
| 285 | |
| 286 | ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, |
Maxim Dounin | ae0d1e5 | 2015-05-25 17:58:20 +0300 | [diff] [blame] | 287 | (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1 |
Maxim Dounin | 4efcbce | 2012-01-11 11:15:00 +0000 | [diff] [blame] | 288 | |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2)); |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 289 | |
Maxim Dounin | cbc9f4d | 2015-02-25 17:48:05 +0300 | [diff] [blame] | 290 | ngx_conf_merge_uint_value(conf->verify, prev->verify, 0); |
| 291 | ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1); |
| 292 | |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 293 | ngx_conf_merge_str_value(conf->certificate, prev->certificate, ""); |
| 294 | ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key, ""); |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 295 | |
Valentin Bartenev | 9f8785a | 2014-06-16 19:43:25 +0400 | [diff] [blame] | 296 | ngx_conf_merge_ptr_value(conf->passwords, prev->passwords, NULL); |
| 297 | |
Igor Sysoev | df83e6f | 2008-06-16 05:51:32 +0000 | [diff] [blame] | 298 | ngx_conf_merge_str_value(conf->dhparam, prev->dhparam, ""); |
| 299 | |
Igor Sysoev | f39642a | 2011-07-20 15:42:40 +0000 | [diff] [blame] | 300 | ngx_conf_merge_str_value(conf->ecdh_curve, prev->ecdh_curve, |
| 301 | NGX_DEFAULT_ECDH_CURVE); |
| 302 | |
Maxim Dounin | cbc9f4d | 2015-02-25 17:48:05 +0300 | [diff] [blame] | 303 | ngx_conf_merge_str_value(conf->client_certificate, |
| 304 | prev->client_certificate, ""); |
| 305 | ngx_conf_merge_str_value(conf->trusted_certificate, |
| 306 | prev->trusted_certificate, ""); |
| 307 | ngx_conf_merge_str_value(conf->crl, prev->crl, ""); |
| 308 | |
Igor Sysoev | 4c756c4 | 2008-07-29 14:31:03 +0000 | [diff] [blame] | 309 | ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFAULT_CIPHERS); |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 310 | |
| 311 | |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 312 | conf->ssl.log = cf->log; |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 313 | |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 314 | if (conf->enable) { |
Ruslan Ermilov | 2161d8a | 2016-03-30 11:52:16 +0300 | [diff] [blame] | 315 | mode = "ssl"; |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 316 | |
| 317 | } else if (conf->starttls != NGX_MAIL_STARTTLS_OFF) { |
Ruslan Ermilov | 2161d8a | 2016-03-30 11:52:16 +0300 | [diff] [blame] | 318 | mode = "starttls"; |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 319 | |
| 320 | } else { |
Ruslan Ermilov | 2161d8a | 2016-03-30 11:52:16 +0300 | [diff] [blame] | 321 | mode = ""; |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Maxim Dounin | ef8c64a | 2013-09-30 22:10:13 +0400 | [diff] [blame] | 324 | if (conf->file == NULL) { |
| 325 | conf->file = prev->file; |
| 326 | conf->line = prev->line; |
| 327 | } |
| 328 | |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 329 | if (*mode) { |
| 330 | |
| 331 | if (conf->certificate.len == 0) { |
| 332 | ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
| 333 | "no \"ssl_certificate\" is defined for " |
| 334 | "the \"%s\" directive in %s:%ui", |
| 335 | mode, conf->file, conf->line); |
| 336 | return NGX_CONF_ERROR; |
| 337 | } |
| 338 | |
| 339 | if (conf->certificate_key.len == 0) { |
| 340 | ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
| 341 | "no \"ssl_certificate_key\" is defined for " |
| 342 | "the \"%s\" directive in %s:%ui", |
| 343 | mode, conf->file, conf->line); |
| 344 | return NGX_CONF_ERROR; |
| 345 | } |
| 346 | |
| 347 | } else { |
| 348 | |
| 349 | if (conf->certificate.len == 0) { |
| 350 | return NGX_CONF_OK; |
| 351 | } |
| 352 | |
| 353 | if (conf->certificate_key.len == 0) { |
| 354 | ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
| 355 | "no \"ssl_certificate_key\" is defined " |
| 356 | "for certificate \"%V\"", |
| 357 | &conf->certificate); |
| 358 | return NGX_CONF_ERROR; |
| 359 | } |
| 360 | } |
| 361 | |
Igor Sysoev | ebf2bbc | 2007-01-02 23:37:25 +0000 | [diff] [blame] | 362 | if (ngx_ssl_create(&conf->ssl, conf->protocols, NULL) != NGX_OK) { |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 363 | return NGX_CONF_ERROR; |
| 364 | } |
| 365 | |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 366 | cln = ngx_pool_cleanup_add(cf->pool, 0); |
| 367 | if (cln == NULL) { |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 368 | return NGX_CONF_ERROR; |
| 369 | } |
| 370 | |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 371 | cln->handler = ngx_ssl_cleanup_ctx; |
| 372 | cln->data = &conf->ssl; |
| 373 | |
| 374 | if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate, |
Valentin Bartenev | 9f8785a | 2014-06-16 19:43:25 +0400 | [diff] [blame] | 375 | &conf->certificate_key, conf->passwords) |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 376 | != NGX_OK) |
Igor Sysoev | 9fa5a82 | 2005-09-30 14:41:25 +0000 | [diff] [blame] | 377 | { |
| 378 | return NGX_CONF_ERROR; |
| 379 | } |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 380 | |
Maxim Dounin | cbc9f4d | 2015-02-25 17:48:05 +0300 | [diff] [blame] | 381 | if (conf->verify) { |
| 382 | |
| 383 | if (conf->client_certificate.len == 0 && conf->verify != 3) { |
| 384 | ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
| 385 | "no ssl_client_certificate for ssl_client_verify"); |
| 386 | return NGX_CONF_ERROR; |
| 387 | } |
| 388 | |
| 389 | if (ngx_ssl_client_certificate(cf, &conf->ssl, |
| 390 | &conf->client_certificate, |
| 391 | conf->verify_depth) |
| 392 | != NGX_OK) |
| 393 | { |
| 394 | return NGX_CONF_ERROR; |
| 395 | } |
| 396 | |
| 397 | if (ngx_ssl_trusted_certificate(cf, &conf->ssl, |
| 398 | &conf->trusted_certificate, |
| 399 | conf->verify_depth) |
| 400 | != NGX_OK) |
| 401 | { |
| 402 | return NGX_CONF_ERROR; |
| 403 | } |
| 404 | |
| 405 | if (ngx_ssl_crl(cf, &conf->ssl, &conf->crl) != NGX_OK) { |
| 406 | return NGX_CONF_ERROR; |
| 407 | } |
| 408 | } |
| 409 | |
Piotr Sikora | f52a2c7 | 2013-09-22 22:36:11 -0700 | [diff] [blame] | 410 | if (SSL_CTX_set_cipher_list(conf->ssl.ctx, |
| 411 | (const char *) conf->ciphers.data) |
| 412 | == 0) |
| 413 | { |
| 414 | ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, |
| 415 | "SSL_CTX_set_cipher_list(\"%V\") failed", |
| 416 | &conf->ciphers); |
| 417 | return NGX_CONF_ERROR; |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 420 | if (conf->prefer_server_ciphers) { |
| 421 | SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); |
| 422 | } |
| 423 | |
Maxim Dounin | 38ea0eb | 2016-03-31 23:38:34 +0300 | [diff] [blame] | 424 | #if (OPENSSL_VERSION_NUMBER < 0x10100001L && !defined LIBRESSL_VERSION_NUMBER) |
Igor Sysoev | e61ba26 | 2011-07-20 12:59:24 +0000 | [diff] [blame] | 425 | SSL_CTX_set_tmp_rsa_callback(conf->ssl.ctx, ngx_ssl_rsa512_key_callback); |
Maxim Dounin | 9628901 | 2015-03-23 02:42:34 +0300 | [diff] [blame] | 426 | #endif |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 427 | |
Igor Sysoev | df83e6f | 2008-06-16 05:51:32 +0000 | [diff] [blame] | 428 | if (ngx_ssl_dhparam(cf, &conf->ssl, &conf->dhparam) != NGX_OK) { |
| 429 | return NGX_CONF_ERROR; |
| 430 | } |
| 431 | |
F. da Silva | 2b1779b | 2013-05-10 16:53:45 +0200 | [diff] [blame] | 432 | if (ngx_ssl_ecdh_curve(cf, &conf->ssl, &conf->ecdh_curve) != NGX_OK) { |
| 433 | return NGX_CONF_ERROR; |
| 434 | } |
| 435 | |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 436 | ngx_conf_merge_value(conf->builtin_session_cache, |
Igor Sysoev | d6548fa | 2008-05-26 07:14:13 +0000 | [diff] [blame] | 437 | prev->builtin_session_cache, NGX_SSL_NONE_SCACHE); |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 438 | |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 439 | if (conf->shm_zone == NULL) { |
| 440 | conf->shm_zone = prev->shm_zone; |
| 441 | } |
Igor Sysoev | e573380 | 2005-09-08 14:36:09 +0000 | [diff] [blame] | 442 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 443 | if (ngx_ssl_session_cache(&conf->ssl, &ngx_mail_ssl_sess_id_ctx, |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 444 | conf->builtin_session_cache, |
| 445 | conf->shm_zone, conf->session_timeout) |
| 446 | != NGX_OK) |
| 447 | { |
| 448 | return NGX_CONF_ERROR; |
| 449 | } |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 450 | |
Dirkjan Bussink | 58a240d | 2014-01-10 16:12:40 +0100 | [diff] [blame] | 451 | ngx_conf_merge_value(conf->session_tickets, |
| 452 | prev->session_tickets, 1); |
| 453 | |
| 454 | #ifdef SSL_OP_NO_TICKET |
| 455 | if (!conf->session_tickets) { |
| 456 | SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_NO_TICKET); |
| 457 | } |
| 458 | #endif |
| 459 | |
Piotr Sikora | 79be6a5 | 2013-10-11 16:05:24 -0700 | [diff] [blame] | 460 | ngx_conf_merge_ptr_value(conf->session_ticket_keys, |
| 461 | prev->session_ticket_keys, NULL); |
| 462 | |
| 463 | if (ngx_ssl_session_ticket_keys(cf, &conf->ssl, conf->session_ticket_keys) |
| 464 | != NGX_OK) |
| 465 | { |
| 466 | return NGX_CONF_ERROR; |
| 467 | } |
| 468 | |
Igor Sysoev | ceb9929 | 2005-09-06 16:09:32 +0000 | [diff] [blame] | 469 | return NGX_CONF_OK; |
| 470 | } |
Igor Sysoev | c2068d0 | 2005-10-19 12:33:58 +0000 | [diff] [blame] | 471 | |
Igor Sysoev | 0e5dc5c | 2005-11-15 13:30:52 +0000 | [diff] [blame] | 472 | |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 473 | static char * |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 474 | ngx_mail_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 475 | { |
| 476 | ngx_mail_ssl_conf_t *scf = conf; |
| 477 | |
| 478 | char *rv; |
| 479 | |
| 480 | rv = ngx_conf_set_flag_slot(cf, cmd, conf); |
| 481 | |
| 482 | if (rv != NGX_CONF_OK) { |
| 483 | return rv; |
| 484 | } |
| 485 | |
| 486 | if (scf->enable && (ngx_int_t) scf->starttls > NGX_MAIL_STARTTLS_OFF) { |
| 487 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 488 | "\"starttls\" directive conflicts with \"ssl on\""); |
| 489 | return NGX_CONF_ERROR; |
| 490 | } |
| 491 | |
| 492 | scf->file = cf->conf_file->file.name.data; |
| 493 | scf->line = cf->conf_file->line; |
| 494 | |
| 495 | return NGX_CONF_OK; |
| 496 | } |
| 497 | |
| 498 | |
| 499 | static char * |
| 500 | ngx_mail_ssl_starttls(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 501 | { |
| 502 | ngx_mail_ssl_conf_t *scf = conf; |
| 503 | |
| 504 | char *rv; |
| 505 | |
| 506 | rv = ngx_conf_set_enum_slot(cf, cmd, conf); |
| 507 | |
| 508 | if (rv != NGX_CONF_OK) { |
| 509 | return rv; |
| 510 | } |
| 511 | |
| 512 | if (scf->enable == 1 && (ngx_int_t) scf->starttls > NGX_MAIL_STARTTLS_OFF) { |
| 513 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 514 | "\"ssl\" directive conflicts with \"starttls\""); |
| 515 | return NGX_CONF_ERROR; |
| 516 | } |
| 517 | |
| 518 | scf->file = cf->conf_file->file.name.data; |
| 519 | scf->line = cf->conf_file->line; |
| 520 | |
| 521 | return NGX_CONF_OK; |
| 522 | } |
| 523 | |
| 524 | |
| 525 | static char * |
Valentin Bartenev | 9f8785a | 2014-06-16 19:43:25 +0400 | [diff] [blame] | 526 | ngx_mail_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 527 | { |
| 528 | ngx_mail_ssl_conf_t *scf = conf; |
| 529 | |
| 530 | ngx_str_t *value; |
| 531 | |
| 532 | if (scf->passwords != NGX_CONF_UNSET_PTR) { |
| 533 | return "is duplicate"; |
| 534 | } |
| 535 | |
| 536 | value = cf->args->elts; |
| 537 | |
| 538 | scf->passwords = ngx_ssl_read_password_file(cf, &value[1]); |
| 539 | |
| 540 | if (scf->passwords == NULL) { |
| 541 | return NGX_CONF_ERROR; |
| 542 | } |
| 543 | |
| 544 | return NGX_CONF_OK; |
| 545 | } |
| 546 | |
| 547 | |
| 548 | static char * |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 549 | ngx_mail_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 550 | { |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 551 | ngx_mail_ssl_conf_t *scf = conf; |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 552 | |
| 553 | size_t len; |
| 554 | ngx_str_t *value, name, size; |
| 555 | ngx_int_t n; |
| 556 | ngx_uint_t i, j; |
| 557 | |
| 558 | value = cf->args->elts; |
| 559 | |
| 560 | for (i = 1; i < cf->args->nelts; i++) { |
| 561 | |
Igor Sysoev | 6ff850b | 2007-12-26 20:27:22 +0000 | [diff] [blame] | 562 | if (ngx_strcmp(value[i].data, "off") == 0) { |
| 563 | scf->builtin_session_cache = NGX_SSL_NO_SCACHE; |
| 564 | continue; |
| 565 | } |
| 566 | |
Igor Sysoev | d6548fa | 2008-05-26 07:14:13 +0000 | [diff] [blame] | 567 | if (ngx_strcmp(value[i].data, "none") == 0) { |
| 568 | scf->builtin_session_cache = NGX_SSL_NONE_SCACHE; |
| 569 | continue; |
| 570 | } |
| 571 | |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 572 | if (ngx_strcmp(value[i].data, "builtin") == 0) { |
| 573 | scf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE; |
| 574 | continue; |
| 575 | } |
| 576 | |
| 577 | if (value[i].len > sizeof("builtin:") - 1 |
| 578 | && ngx_strncmp(value[i].data, "builtin:", sizeof("builtin:") - 1) |
| 579 | == 0) |
| 580 | { |
| 581 | n = ngx_atoi(value[i].data + sizeof("builtin:") - 1, |
| 582 | value[i].len - (sizeof("builtin:") - 1)); |
| 583 | |
| 584 | if (n == NGX_ERROR) { |
| 585 | goto invalid; |
| 586 | } |
| 587 | |
| 588 | scf->builtin_session_cache = n; |
| 589 | |
| 590 | continue; |
| 591 | } |
| 592 | |
| 593 | if (value[i].len > sizeof("shared:") - 1 |
| 594 | && ngx_strncmp(value[i].data, "shared:", sizeof("shared:") - 1) |
| 595 | == 0) |
| 596 | { |
| 597 | len = 0; |
| 598 | |
| 599 | for (j = sizeof("shared:") - 1; j < value[i].len; j++) { |
| 600 | if (value[i].data[j] == ':') { |
| 601 | break; |
| 602 | } |
| 603 | |
| 604 | len++; |
| 605 | } |
| 606 | |
| 607 | if (len == 0) { |
| 608 | goto invalid; |
| 609 | } |
| 610 | |
| 611 | name.len = len; |
| 612 | name.data = value[i].data + sizeof("shared:") - 1; |
| 613 | |
| 614 | size.len = value[i].len - j - 1; |
| 615 | size.data = name.data + len + 1; |
| 616 | |
| 617 | n = ngx_parse_size(&size); |
| 618 | |
| 619 | if (n == NGX_ERROR) { |
| 620 | goto invalid; |
| 621 | } |
| 622 | |
| 623 | if (n < (ngx_int_t) (8 * ngx_pagesize)) { |
| 624 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 625 | "session cache \"%V\" is too small", |
| 626 | &value[i]); |
| 627 | |
| 628 | return NGX_CONF_ERROR; |
| 629 | } |
| 630 | |
| 631 | scf->shm_zone = ngx_shared_memory_add(cf, &name, n, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 632 | &ngx_mail_ssl_module); |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 633 | if (scf->shm_zone == NULL) { |
| 634 | return NGX_CONF_ERROR; |
| 635 | } |
| 636 | |
Maxim Dounin | 554768d | 2011-09-27 12:06:07 +0000 | [diff] [blame] | 637 | scf->shm_zone->init = ngx_ssl_session_cache_init; |
| 638 | |
Igor Sysoev | a4c84c5 | 2007-01-03 16:11:53 +0000 | [diff] [blame] | 639 | continue; |
| 640 | } |
| 641 | |
| 642 | goto invalid; |
| 643 | } |
| 644 | |
| 645 | if (scf->shm_zone && scf->builtin_session_cache == NGX_CONF_UNSET) { |
| 646 | scf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE; |
| 647 | } |
| 648 | |
| 649 | return NGX_CONF_OK; |
| 650 | |
| 651 | invalid: |
| 652 | |
| 653 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 654 | "invalid session cache \"%V\"", &value[i]); |
| 655 | |
| 656 | return NGX_CONF_ERROR; |
| 657 | } |