aws_sigv4: fix canon order for headers with same prefix

If a request containing two headers that have equivalent prefixes (ex.
"x-amz-meta-test:test" and "x-amz-meta-test-two:test2") AWS expects the
header with the shorter name to come first. The previous implementation
used `strcmp` on the full header. Using the example, this would result
in a comparison between the ':' and '-' chars and sort
"x-amz-meta-test-two" before "x-amz-meta-test", which produces a
different "StringToSign" than the one calculated by AWS.

Test 1976 verifies

Closes #14370
This commit is contained in:
Austin Moore 2024-08-03 23:43:45 -04:00 committed by Daniel Stenberg
parent f3e07e5c55
commit cf3e3d93d1
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 94 additions and 3 deletions

View file

@ -233,7 +233,7 @@ test1916 test1917 test1918 test1919 \
test1933 test1934 test1935 test1936 test1937 test1938 test1939 test1940 \
test1941 test1942 test1943 test1944 test1945 test1946 test1947 test1948 \
test1955 test1956 test1957 test1958 test1959 test1960 test1964 \
test1970 test1971 test1972 test1973 test1974 test1975 \
test1970 test1971 test1972 test1973 test1974 test1975 test1976 \
\
test2000 test2001 test2002 test2003 test2004 \
\

60
tests/data/test1976 Normal file
View file

@ -0,0 +1,60 @@
<testcase>
<info>
<keywords>
HTTP
CURLOPT_AWS_SIGV4
</keywords>
</info>
# Server-side
<reply>
<data>
HTTP/1.1 200 OK
Date: Thu, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
Content-Length: 0
</data>
</reply>
# Client-side
<client>
<server>
http
</server>
<features>
SSL
Debug
crypto
</features>
<name>
HTTP AWS_SIGV4 canonical request header sorting test
</name>
<command>
-X PUT -H "X-Amz-Meta-Test-Two: test2" -H "x-amz-meta-test: test" --aws-sigv4 "aws:amz:us-east-1:s3" -u "xxx:yyy" http://%HOSTIP:%HTTPPORT/%TESTNUMBER
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<strip>
^User-Agent:.*
^Content-Length:.*
^Accept:.*
</strip>
<strippart>
# Strip the actual signature. We only care about header order in this test
s/Signature=[a-f0-9]{64}/Signature=stripped/
</strippart>
<protocol crlf="yes">
PUT /%TESTNUMBER HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Authorization: AWS4-HMAC-SHA256 Credential=xxx/19700101/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-meta-test;x-amz-meta-test-two, Signature=stripped
X-Amz-Date: 19700101T000000Z
x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Meta-Test-Two: test2
x-amz-meta-test: test
</protocol>
</verify>
</testcase>