diff options
author | Rob N ★ <robn@fastmail.com> | 2016-10-08 18:05:00 +1100 |
---|---|---|
committer | Rob N ★ <robn@fastmail.com> | 2016-10-08 18:05:00 +1100 |
commit | 66c23edf6308867572d5c4b8341e7a3fe7e97864 (patch) | |
tree | ef7915e431e44d1394d27d3fb70cdcb0d893e467 /src/mail/ngx_mail_handler.c | |
parent | a747089a1dd63f323111c82000debfd83a5e6719 (diff) | |
download | nginx-66c23edf6308867572d5c4b8341e7a3fe7e97864.tar.gz nginx-66c23edf6308867572d5c4b8341e7a3fe7e97864.zip |
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.
Diffstat (limited to 'src/mail/ngx_mail_handler.c')
-rw-r--r-- | src/mail/ngx_mail_handler.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mail/ngx_mail_handler.c b/src/mail/ngx_mail_handler.c index 901bb8f15..9d4ef561b 100644 --- a/src/mail/ngx_mail_handler.c +++ b/src/mail/ngx_mail_handler.c @@ -612,6 +612,40 @@ ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c) } +ngx_int_t +ngx_mail_auth_external(ngx_mail_session_t *s, ngx_connection_t *c, + ngx_uint_t n) +{ + ngx_str_t *arg, external; + + arg = s->args.elts; + + ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, + "mail auth external: \"%V\"", &arg[n]); + + external.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len)); + if (external.data == NULL) { + return NGX_ERROR; + } + + if (ngx_decode_base64(&external, &arg[n]) != NGX_OK) { + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "client sent invalid base64 encoding in AUTH EXTERNAL command"); + return NGX_MAIL_PARSE_INVALID_COMMAND; + } + + s->login.len = external.len; + s->login.data = external.data; + + ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, + "mail auth external: \"%V\"", &s->login); + + s->auth_method = NGX_MAIL_AUTH_EXTERNAL; + + return NGX_DONE; +} + + void ngx_mail_send(ngx_event_t *wev) { |