comparison src/mail/ngx_mail_smtp_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 f18c285c2e59
comparison
equal deleted inserted replaced
6773:73b451d304c0 6774:bcb107bb89cd
19 19
20 static ngx_conf_bitmask_t ngx_mail_smtp_auth_methods[] = { 20 static ngx_conf_bitmask_t ngx_mail_smtp_auth_methods[] = {
21 { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED }, 21 { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED },
22 { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED }, 22 { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED },
23 { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED }, 23 { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED },
24 { ngx_string("external"), NGX_MAIL_AUTH_EXTERNAL_ENABLED },
24 { ngx_string("none"), NGX_MAIL_AUTH_NONE_ENABLED }, 25 { ngx_string("none"), NGX_MAIL_AUTH_NONE_ENABLED },
25 { ngx_null_string, 0 } 26 { ngx_null_string, 0 }
26 }; 27 };
27 28
28 29
29 static ngx_str_t ngx_mail_smtp_auth_methods_names[] = { 30 static ngx_str_t ngx_mail_smtp_auth_methods_names[] = {
30 ngx_string("PLAIN"), 31 ngx_string("PLAIN"),
31 ngx_string("LOGIN"), 32 ngx_string("LOGIN"),
32 ngx_null_string, /* APOP */ 33 ngx_null_string, /* APOP */
33 ngx_string("CRAM-MD5"), 34 ngx_string("CRAM-MD5"),
35 ngx_string("EXTERNAL"),
34 ngx_null_string /* NONE */ 36 ngx_null_string /* NONE */
35 }; 37 };
36 38
37 39
38 static ngx_mail_protocol_t ngx_mail_smtp_protocol = { 40 static ngx_mail_protocol_t ngx_mail_smtp_protocol = {
205 } 207 }
206 208
207 auth_enabled = 0; 209 auth_enabled = 0;
208 210
209 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; 211 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
210 m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED; 212 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
211 m <<= 1, i++) 213 m <<= 1, i++)
212 { 214 {
213 if (m & conf->auth_methods) { 215 if (m & conf->auth_methods) {
214 size += 1 + ngx_mail_smtp_auth_methods_names[i].len; 216 size += 1 + ngx_mail_smtp_auth_methods_names[i].len;
215 auth_enabled = 1; 217 auth_enabled = 1;
248 250
249 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' '; 251 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' ';
250 *p++ = 'A'; *p++ = 'U'; *p++ = 'T'; *p++ = 'H'; 252 *p++ = 'A'; *p++ = 'U'; *p++ = 'T'; *p++ = 'H';
251 253
252 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; 254 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
253 m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED; 255 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
254 m <<= 1, i++) 256 m <<= 1, i++)
255 { 257 {
256 if (m & conf->auth_methods) { 258 if (m & conf->auth_methods) {
257 *p++ = ' '; 259 *p++ = ' ';
258 p = ngx_cpymem(p, ngx_mail_smtp_auth_methods_names[i].data, 260 p = ngx_cpymem(p, ngx_mail_smtp_auth_methods_names[i].data,