support space character in access key (#8335)

master
Ashish Kumar Sinha 5 years ago committed by kannappanr
parent 4f981a0b42
commit fa5a1cebd9
  1. 4
      cmd/signature-v4-parser.go
  2. 30
      cmd/signature-v4-parser_test.go

@ -250,6 +250,8 @@ func parsePreSignV4(query url.Values, region string, stype serviceType) (psv pre
// SignedHeaders=signedHeaders, Signature=signature // SignedHeaders=signedHeaders, Signature=signature
// //
func parseSignV4(v4Auth string, region string, stype serviceType) (sv signValues, aec APIErrorCode) { func parseSignV4(v4Auth string, region string, stype serviceType) (sv signValues, aec APIErrorCode) {
// credElement is fetched first to skip replacing the space in access key.
credElement := strings.TrimPrefix(strings.Split(strings.TrimSpace(v4Auth), ",")[0], signV4Algorithm)
// Replace all spaced strings, some clients can send spaced // Replace all spaced strings, some clients can send spaced
// parameters and some won't. So we pro-actively remove any spaces // parameters and some won't. So we pro-actively remove any spaces
// to make parsing easier. // to make parsing easier.
@ -275,7 +277,7 @@ func parseSignV4(v4Auth string, region string, stype serviceType) (sv signValues
var err APIErrorCode var err APIErrorCode
// Save credentail values. // Save credentail values.
signV4Values.Credential, err = parseCredentialHeader(authFields[0], region, stype) signV4Values.Credential, err = parseCredentialHeader(strings.TrimSpace(credElement), region, stype)
if err != ErrNone { if err != ErrNone {
return sv, err return sv, err
} }

@ -462,6 +462,36 @@ func TestParseSignV4(t *testing.T) {
}, },
expectedErrCode: ErrNone, expectedErrCode: ErrNone,
}, },
// Test case - 8.
{
inputV4AuthStr: signV4Algorithm +
strings.Join([]string{
// generating a valid credential.
generateCredentialStr(
"access key",
sampleTimeStr,
"us-west-1",
"s3",
"aws4_request"),
// valid SignedHeader.
"SignedHeaders=host;x-amz-content-sha256;x-amz-date",
// valid Signature field.
// a valid signature is of form "Signature="
"Signature=abcd",
}, ","),
expectedAuthField: signValues{
Credential: generateCredentials(
t,
"access key",
sampleTimeStr,
"us-west-1",
"s3",
"aws4_request"),
SignedHeaders: []string{"host", "x-amz-content-sha256", "x-amz-date"},
Signature: "abcd",
},
expectedErrCode: ErrNone,
},
} }
for i, testCase := range testCases { for i, testCase := range testCases {

Loading…
Cancel
Save