Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imap: Provide method to disable SASL if it is advertised #10041

Merged
merged 1 commit into from Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/cmdline-opts/login-options.d
Expand Up @@ -16,3 +16,9 @@ You can use login options to specify protocol specific options that may be
used during authentication. At present only IMAP, POP3 and SMTP support
login options. For more information about login options please see RFC
2384, RFC 5092 and IETF draft draft-earhart-url-smtp-00.txt

Since 8.2.0, IMAP supports the login option "AUTH=+LOGIN". With this option,
curl uses the plain (not SASL) LOGIN IMAP command even if the server advertises
SASL authentication. Care should be taken in using this option, as it will send
out your password in plain text. This will not work if the IMAP server disables
the plain LOGIN (e.g. to prevent password snooping).
6 changes: 6 additions & 0 deletions docs/libcurl/opts/CURLOPT_LOGIN_OPTIONS.3
Expand Up @@ -43,6 +43,12 @@ options, such as the preferred authentication mechanism via "AUTH=NTLM" or
"AUTH=*", and should be used in conjunction with the \fICURLOPT_USERNAME(3)\fP
option.

Since 8.2.0, IMAP supports the login option "AUTH=+LOGIN". With this option,
curl uses the plain (not SASL) LOGIN IMAP command even if the server advertises
SASL authentication. Care should be taken in using this option, as it will send
out your password in plain text. This will not work if the IMAP server disables
the plain LOGIN (e.g. to prevent password snooping).

The application does not have to keep the string around after setting this
option.
.SH DEFAULT
Expand Down
38 changes: 26 additions & 12 deletions lib/imap.c
Expand Up @@ -1925,6 +1925,7 @@ static CURLcode imap_parse_url_options(struct connectdata *conn)
CURLcode result = CURLE_OK;
struct imap_conn *imapc = &conn->proto.imapc;
const char *ptr = conn->options;
bool prefer_login = false;

while(!result && ptr && *ptr) {
const char *key = ptr;
Expand All @@ -1938,26 +1939,39 @@ static CURLcode imap_parse_url_options(struct connectdata *conn)
while(*ptr && *ptr != ';')
ptr++;

if(strncasecompare(key, "AUTH=", 5))
if(strncasecompare(key, "AUTH=+LOGIN", 11)) {
/* User prefers plaintext LOGIN over any SASL, including SASL LOGIN */
prefer_login = true;
imapc->sasl.prefmech = SASL_AUTH_NONE;
}
else if(strncasecompare(key, "AUTH=", 5)) {
prefer_login = false;
result = Curl_sasl_parse_url_auth_option(&imapc->sasl,
value, ptr - value);
else
}
else {
prefer_login = false;
result = CURLE_URL_MALFORMAT;
}

if(*ptr == ';')
ptr++;
}

switch(imapc->sasl.prefmech) {
case SASL_AUTH_NONE:
imapc->preftype = IMAP_TYPE_NONE;
break;
case SASL_AUTH_DEFAULT:
imapc->preftype = IMAP_TYPE_ANY;
break;
default:
imapc->preftype = IMAP_TYPE_SASL;
break;
if(prefer_login)
imapc->preftype = IMAP_TYPE_CLEARTEXT;
else {
switch(imapc->sasl.prefmech) {
case SASL_AUTH_NONE:
imapc->preftype = IMAP_TYPE_NONE;
break;
case SASL_AUTH_DEFAULT:
imapc->preftype = IMAP_TYPE_ANY;
break;
default:
imapc->preftype = IMAP_TYPE_SASL;
break;
}
}

return result;
Expand Down
1 change: 1 addition & 0 deletions tests/data/Makefile.inc
Expand Up @@ -102,6 +102,7 @@ test700 test701 test702 test703 test704 test705 test706 test707 test708 \
test709 test710 test711 test712 test713 test714 test715 test716 test717 \
test718 test719 test720 test721 \
\
test799 \
test800 test801 test802 test803 test804 test805 test806 test807 test808 \
test809 test810 test811 test812 test813 test814 test815 test816 test817 \
test818 test819 test820 test821 test822 test823 test824 test825 test826 \
Expand Down
53 changes: 53 additions & 0 deletions tests/data/test799
@@ -0,0 +1,53 @@
<testcase>
<info>
<keywords>
IMAP
Clear Text
SASL AUTH +LOGIN
</keywords>
</info>

#
# Server-side
<reply>
<servercmd>
AUTH PLAIN
REPLY LOGIN A002 OK LOGIN completed
</servercmd>
<data>
From: me@somewhere
To: fake@nowhere

body

--
yours sincerely
</data>
</reply>

#
# Client-side
<client>
<server>
imap
</server>
<name>
IMAP with --login-options 'AUTH=+LOGIN'
</name>
<command>
'imap://%HOSTIP:%IMAPPORT/%TESTNUMBER/;MAILINDEX=1' -u user:secret --login-options AUTH=+LOGIN
</command>
</client>

#
# Verify data after the test has been "shot"
<verify>
<protocol>
A001 CAPABILITY
A002 LOGIN user secret
A003 SELECT %TESTNUMBER
A004 FETCH 1 BODY[]
A005 LOGOUT
</protocol>
</verify>
</testcase>