Skip to content

Commit 657ad6e

Browse files
committed
digest: pass over leading spaces in qop values
When parsing the "qop=" parameter of the digest authentication, and the value is provided within quotes, the list of values can have leading white space which the parser previously did not handle correctly. Add test case 388 to verify. Reported-by: vlubart on github Fixes #9264 Closes #
1 parent 3fe24ea commit 657ad6e

File tree

3 files changed

+160
-1
lines changed

3 files changed

+160
-1
lines changed

lib/vauth/digest.c

+3
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
560560

561561
token = strtok_r(tmp, ",", &tok_buf);
562562
while(token) {
563+
/* Pass additional spaces here */
564+
while(*token && ISSPACE(*token))
565+
token++;
563566
if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH)) {
564567
foundAuth = TRUE;
565568
}

tests/data/Makefile.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test343 test344 test345 test346 test347 test348 test349 test350 test351 \
6464
test352 test353 test354 test355 test356 test357 test358 test359 test360 \
6565
test361 test362 test363 test364 test365 test366 test367 test368 test369 \
6666
test370 test371 test372 test373 test374 test375 test376 test378 test379 \
67-
test380 test381 test383 test384 test385 test386 test387 \
67+
test380 test381 test383 test384 test385 test386 test387 test388 \
6868
\
6969
test390 test391 test392 test393 test394 test395 test396 test397 test398 \
7070
\

tests/data/test388

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<testcase>
2+
<info>
3+
<keywords>
4+
HTTP
5+
HTTP GET
6+
HTTP Digest auth
7+
</keywords>
8+
</info>
9+
10+
# Server-side
11+
<reply>
12+
# First reply back and ask for Digest auth
13+
<data1>
14+
HTTP/1.1 401 Authorization Required swsclose
15+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
16+
WWW-Authenticate: Digest realm="testrealm", nonce="1053604145"
17+
Content-Type: text/html; charset=iso-8859-1
18+
Content-Length: 26
19+
20+
This is not the real page
21+
</data1>
22+
23+
# second reply back
24+
<data2>
25+
HTTP/1.1 401 Authorization Required swsclose
26+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
27+
WWW-Authenticate: Digest realm="testrealm", nonce="1053604145"
28+
Content-Type: text/html; charset=iso-8859-1
29+
Content-Length: 26
30+
31+
This is not the real page
32+
</data2>
33+
34+
# This is supposed to be returned when the server gets a
35+
# Authorization: Digest line passed-in from the client
36+
<data1001>
37+
HTTP/1.1 200 OK
38+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
39+
Content-Type: text/html; charset=iso-8859-1
40+
Content-Length: 23
41+
42+
This IS the real page!
43+
</data1001>
44+
45+
#
46+
# This is the second request, and this sends back a response saying that
47+
# the request contained stale data. We want an update. Set swsbounce to
48+
# bounce on to data1003 on the second request.
49+
<data1002>
50+
HTTP/1.1 401 Authorization re-negotiation please swsbounce
51+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
52+
WWW-Authenticate: Digest realm="testrealm", algorithm=MD5, nonce="999999", stale=true, qop="crazy, auth"
53+
Content-Type: text/html; charset=iso-8859-1
54+
Content-Length: 26
55+
56+
This is not the real page
57+
</data1002>
58+
59+
# The second request to the 1002 section will bounce this one back instead
60+
# thanks to the swsbounce keyword up there
61+
<data1003>
62+
HTTP/1.1 200 OK
63+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
64+
Content-Type: text/html; charset=iso-8859-1
65+
Content-Length: 30
66+
67+
This IS the second real page!
68+
</data1003>
69+
</reply>
70+
71+
# Client-side
72+
<client>
73+
<server>
74+
http
75+
</server>
76+
<features>
77+
!SSPI
78+
crypto
79+
</features>
80+
<name>
81+
HTTP with Digest and multiple qop values with leading space
82+
</name>
83+
<command>
84+
http://%HOSTIP:%HTTPPORT/%TESTNUMBER0001 -u testuser:testpass --digest http://%HOSTIP:%HTTPPORT/%TESTNUMBER0002
85+
</command>
86+
</client>
87+
88+
# Verify data after the test has been "shot"
89+
<verify>
90+
<strip>
91+
^Authorization.*cnonce
92+
</strip>
93+
<protocol>
94+
GET /%TESTNUMBER0001 HTTP/1.1
95+
Host: %HOSTIP:%HTTPPORT
96+
User-Agent: curl/%VERSION
97+
Accept: */*
98+
99+
GET /%TESTNUMBER0001 HTTP/1.1
100+
Host: %HOSTIP:%HTTPPORT
101+
Authorization: Digest username="testuser", realm="testrealm", nonce="1053604145", uri="/%TESTNUMBER0001", response="ea598bbfdb5c54b7352c977e3885e44d"
102+
User-Agent: curl/%VERSION
103+
Accept: */*
104+
105+
GET /%TESTNUMBER0002 HTTP/1.1
106+
Host: %HOSTIP:%HTTPPORT
107+
User-Agent: curl/%VERSION
108+
Accept: */*
109+
110+
GET /%TESTNUMBER0002 HTTP/1.1
111+
Host: %HOSTIP:%HTTPPORT
112+
Authorization: Digest username="testuser", realm="testrealm", nonce="1053604145", uri="/%TESTNUMBER0002", response="921a8e6db782d6359db1f40d9ed7e6a6"
113+
User-Agent: curl/%VERSION
114+
Accept: */*
115+
116+
GET /%TESTNUMBER0002 HTTP/1.1
117+
Host: %HOSTIP:%HTTPPORT
118+
Authorization: Digest username="testuser", realm="testrealm", nonce="999999", uri="/%TESTNUMBER0002", cnonce="MTA4MzIy", nc="00000001", qop="auth", response="25291c357671604a16c0242f56721c07", algorithm=MD5
119+
User-Agent: curl/%VERSION
120+
Accept: */*
121+
122+
</protocol>
123+
<stdout>
124+
HTTP/1.1 401 Authorization Required swsclose
125+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
126+
WWW-Authenticate: Digest realm="testrealm", nonce="1053604145"
127+
Content-Type: text/html; charset=iso-8859-1
128+
Content-Length: 26
129+
130+
HTTP/1.1 200 OK
131+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
132+
Content-Type: text/html; charset=iso-8859-1
133+
Content-Length: 23
134+
135+
This IS the real page!
136+
HTTP/1.1 401 Authorization Required swsclose
137+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
138+
WWW-Authenticate: Digest realm="testrealm", nonce="1053604145"
139+
Content-Type: text/html; charset=iso-8859-1
140+
Content-Length: 26
141+
142+
HTTP/1.1 401 Authorization re-negotiation please swsbounce
143+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
144+
WWW-Authenticate: Digest realm="testrealm", algorithm=MD5, nonce="999999", stale=true, qop="crazy, auth"
145+
Content-Type: text/html; charset=iso-8859-1
146+
Content-Length: 26
147+
148+
HTTP/1.1 200 OK
149+
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
150+
Content-Type: text/html; charset=iso-8859-1
151+
Content-Length: 30
152+
153+
This IS the second real page!
154+
</stdout>
155+
</verify>
156+
</testcase>

0 commit comments

Comments
 (0)