comparison src/mail/ngx_mail_imap_module.c @ 6774:bcb107bb89cd

Mail: support SASL EXTERNAL (RFC 4422). This is needed to allow TLS client certificate auth to work. With ssl_verify_client configured, the auth daemon can choose to allow the connection to proceed based on the certificate data. This has been tested with Thunderbird for IMAP only. I've not yet found a client that will do client certificate auth for POP3 or SMTP, and the method is not really documented anywhere that I can find. That said, its simple enough that the way I've done is probably right.
author Rob N ★ <robn@fastmail.com>
date Sat, 08 Oct 2016 18:05:00 +1100
parents ec01b1d1fff1
children dc955d274130
comparison
equal deleted inserted replaced
6773:73b451d304c0 6774:bcb107bb89cd
27 27
28 static ngx_conf_bitmask_t ngx_mail_imap_auth_methods[] = { 28 static ngx_conf_bitmask_t ngx_mail_imap_auth_methods[] = {
29 { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED }, 29 { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED },
30 { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED }, 30 { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED },
31 { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED }, 31 { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED },
32 { ngx_string("external"), NGX_MAIL_AUTH_EXTERNAL_ENABLED },
32 { ngx_null_string, 0 } 33 { ngx_null_string, 0 }
33 }; 34 };
34 35
35 36
36 static ngx_str_t ngx_mail_imap_auth_methods_names[] = { 37 static ngx_str_t ngx_mail_imap_auth_methods_names[] = {
37 ngx_string("AUTH=PLAIN"), 38 ngx_string("AUTH=PLAIN"),
38 ngx_string("AUTH=LOGIN"), 39 ngx_string("AUTH=LOGIN"),
39 ngx_null_string, /* APOP */ 40 ngx_null_string, /* APOP */
40 ngx_string("AUTH=CRAM-MD5"), 41 ngx_string("AUTH=CRAM-MD5"),
42 ngx_string("AUTH=EXTERNAL"),
41 ngx_null_string /* NONE */ 43 ngx_null_string /* NONE */
42 }; 44 };
43 45
44 46
45 static ngx_mail_protocol_t ngx_mail_imap_protocol = { 47 static ngx_mail_protocol_t ngx_mail_imap_protocol = {
177 for (i = 0; i < conf->capabilities.nelts; i++) { 179 for (i = 0; i < conf->capabilities.nelts; i++) {
178 size += 1 + c[i].len; 180 size += 1 + c[i].len;
179 } 181 }
180 182
181 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; 183 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
182 m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED; 184 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
183 m <<= 1, i++) 185 m <<= 1, i++)
184 { 186 {
185 if (m & conf->auth_methods) { 187 if (m & conf->auth_methods) {
186 size += 1 + ngx_mail_imap_auth_methods_names[i].len; 188 size += 1 + ngx_mail_imap_auth_methods_names[i].len;
187 } 189 }
203 } 205 }
204 206
205 auth = p; 207 auth = p;
206 208
207 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; 209 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
208 m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED; 210 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
209 m <<= 1, i++) 211 m <<= 1, i++)
210 { 212 {
211 if (m & conf->auth_methods) { 213 if (m & conf->auth_methods) {
212 *p++ = ' '; 214 *p++ = ' ';
213 p = ngx_cpymem(p, ngx_mail_imap_auth_methods_names[i].data, 215 p = ngx_cpymem(p, ngx_mail_imap_auth_methods_names[i].data,