diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index 23c8818109..33b0ef2160 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -356,6 +356,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, char *spn = NULL; char *qrealm; char *qnonce; + char *quserp; /* Decode the challenge message */ CURLcode result = auth_decode_digest_md5_message(chlg, @@ -469,20 +470,22 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, for(i = 0; i < MD5_DIGEST_LEN; i++) curl_msnprintf(&resp_hash_hex[2 * i], 3, "%02x", digest[i]); - /* escape double quotes and backslashes in the realm and nonce as + /* escape double quotes and backslashes in the username, realm and nonce as necessary */ qrealm = auth_digest_string_quoted(realm); qnonce = auth_digest_string_quoted(nonce); - if(qrealm && qnonce) + quserp = auth_digest_string_quoted(userp); + if(qrealm && qnonce && quserp) /* Generate the response */ response = curl_maprintf("username=\"%s\",realm=\"%s\",nonce=\"%s\"," "cnonce=\"%s\",nc=\"%s\",digest-uri=\"%s\"," "response=%s,qop=%s", - userp, qrealm, qnonce, + quserp, qrealm, qnonce, cnonce, nonceCount, spn, resp_hash_hex, qop); curlx_free(qrealm); curlx_free(qnonce); + curlx_free(quserp); curlx_free(spn); if(!response) return CURLE_OUT_OF_MEMORY; diff --git a/tests/data/test907 b/tests/data/test907 index 73e0bd21d1..72eaf37034 100644 --- a/tests/data/test907 +++ b/tests/data/test907 @@ -15,7 +15,7 @@ RFC4954 AUTH DIGEST-MD5 REPLY AUTH 334 %b64[realm="cu\"rl",nonce="5300d17a1d695bd411e4cdf96f9548c23ced6175",algorithm=md5-sess,qop="auth"]b64% -REPLY %b64[username="user",realm="cu\"rl",nonce="5300d17a1d695bd411e4cdf96f9548c23ced6175",cnonce="34333231353332313633323137333231",nc="00000001",digest-uri="smtp/127.0.0.1",response=b7290e673d2ad888c445c9b2c7698d66,qop=auth]b64% 334 %b64[rspauth=9ea859cb9d90c37ca30d49d35378630c]b64% +REPLY %b64[username="us\"er",realm="cu\"rl",nonce="5300d17a1d695bd411e4cdf96f9548c23ced6175",cnonce="34333231353332313633323137333231",nc="00000001",digest-uri="smtp/127.0.0.1",response=53d3347e1b559d23be78934ae4a78488,qop=auth]b64% 334 %b64[rspauth=9ea859cb9d90c37ca30d49d35378630c]b64% REPLY 235 Authenticated @@ -41,7 +41,7 @@ SMTP DIGEST-MD5 authentication mail body -smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -u user:secret -T - +smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -u "us\"er:secret" -T - @@ -50,7 +50,7 @@ smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-fr EHLO %TESTNUMBER AUTH DIGEST-MD5 -%b64[username="user",realm="cu\"rl",nonce="5300d17a1d695bd411e4cdf96f9548c23ced6175",cnonce="34333231353332313633323137333231",nc="00000001",digest-uri="smtp/127.0.0.1",response=b7290e673d2ad888c445c9b2c7698d66,qop=auth]b64% +%b64[username="us\"er",realm="cu\"rl",nonce="5300d17a1d695bd411e4cdf96f9548c23ced6175",cnonce="34333231353332313633323137333231",nc="00000001",digest-uri="smtp/127.0.0.1",response=53d3347e1b559d23be78934ae4a78488,qop=auth]b64% MAIL FROM:%LTsender@example.com%GT RCPT TO:%LTrecipient@example.com%GT