|
|
@ -59,7 +59,7 @@ func getChunkSignature(secretKey string, seedSignature string, region string, da |
|
|
|
//
|
|
|
|
// returns signature, error otherwise if the signature mismatches or any other
|
|
|
|
// error while parsing and validating.
|
|
|
|
func (iam *IdentityAccessManagement) calculateSeedSignature(r *http.Request) (cred *Credential, signature string, region string, date time.Time, errCode s3err.ErrorCode) { |
|
|
|
func (iam *IdentityAccessManagement) calculateSeedSignature(r *http.Request) (idnt *Identity, cred *Credential, signature string, region string, date time.Time, errCode s3err.ErrorCode) { |
|
|
|
|
|
|
|
// Copy request.
|
|
|
|
req := *r |
|
|
@ -70,7 +70,7 @@ func (iam *IdentityAccessManagement) calculateSeedSignature(r *http.Request) (cr |
|
|
|
// Parse signature version '4' header.
|
|
|
|
signV4Values, errCode := parseSignV4(v4Auth) |
|
|
|
if errCode != s3err.ErrNone { |
|
|
|
return nil, "", "", time.Time{}, errCode |
|
|
|
return nil, nil, "", "", time.Time{}, errCode |
|
|
|
} |
|
|
|
|
|
|
|
// Payload streaming.
|
|
|
@ -78,18 +78,18 @@ func (iam *IdentityAccessManagement) calculateSeedSignature(r *http.Request) (cr |
|
|
|
|
|
|
|
// Payload for STREAMING signature should be 'STREAMING-AWS4-HMAC-SHA256-PAYLOAD'
|
|
|
|
if payload != req.Header.Get("X-Amz-Content-Sha256") { |
|
|
|
return nil, "", "", time.Time{}, s3err.ErrContentSHA256Mismatch |
|
|
|
return nil, nil, "", "", time.Time{}, s3err.ErrContentSHA256Mismatch |
|
|
|
} |
|
|
|
|
|
|
|
// Extract all the signed headers along with its values.
|
|
|
|
extractedSignedHeaders, errCode := extractSignedHeaders(signV4Values.SignedHeaders, r) |
|
|
|
if errCode != s3err.ErrNone { |
|
|
|
return nil, "", "", time.Time{}, errCode |
|
|
|
return nil, nil, "", "", time.Time{}, errCode |
|
|
|
} |
|
|
|
// Verify if the access key id matches.
|
|
|
|
identity, cred, found := iam.lookupByAccessKey(signV4Values.Credential.accessKey) |
|
|
|
if !found { |
|
|
|
return nil, "", "", time.Time{}, s3err.ErrInvalidAccessKeyID |
|
|
|
return nil, nil, "", "", time.Time{}, s3err.ErrInvalidAccessKeyID |
|
|
|
} |
|
|
|
|
|
|
|
bucket, object := s3_constants.GetBucketAndObject(r) |
|
|
@ -105,14 +105,14 @@ func (iam *IdentityAccessManagement) calculateSeedSignature(r *http.Request) (cr |
|
|
|
var dateStr string |
|
|
|
if dateStr = req.Header.Get(http.CanonicalHeaderKey("x-amz-date")); dateStr == "" { |
|
|
|
if dateStr = r.Header.Get("Date"); dateStr == "" { |
|
|
|
return nil, "", "", time.Time{}, s3err.ErrMissingDateHeader |
|
|
|
return nil, nil, "", "", time.Time{}, s3err.ErrMissingDateHeader |
|
|
|
} |
|
|
|
} |
|
|
|
// Parse date header.
|
|
|
|
var err error |
|
|
|
date, err = time.Parse(iso8601Format, dateStr) |
|
|
|
if err != nil { |
|
|
|
return nil, "", "", time.Time{}, s3err.ErrMalformedDate |
|
|
|
return nil, nil, "", "", time.Time{}, s3err.ErrMalformedDate |
|
|
|
} |
|
|
|
|
|
|
|
// Query string.
|
|
|
@ -132,11 +132,11 @@ func (iam *IdentityAccessManagement) calculateSeedSignature(r *http.Request) (cr |
|
|
|
|
|
|
|
// Verify if signature match.
|
|
|
|
if !compareSignatureV4(newSignature, signV4Values.Signature) { |
|
|
|
return nil, "", "", time.Time{}, s3err.ErrSignatureDoesNotMatch |
|
|
|
return nil, nil, "", "", time.Time{}, s3err.ErrSignatureDoesNotMatch |
|
|
|
} |
|
|
|
|
|
|
|
// Return calculated signature.
|
|
|
|
return cred, newSignature, region, date, s3err.ErrNone |
|
|
|
return identity, cred, newSignature, region, date, s3err.ErrNone |
|
|
|
} |
|
|
|
|
|
|
|
const maxLineLength = 4 * humanize.KiByte // assumed <= bufio.defaultBufSize 4KiB
|
|
|
@ -150,20 +150,20 @@ var errMalformedEncoding = errors.New("malformed chunked encoding") |
|
|
|
// newSignV4ChunkedReader returns a new s3ChunkedReader that translates the data read from r
|
|
|
|
// out of HTTP "chunked" format before returning it.
|
|
|
|
// The s3ChunkedReader returns io.EOF when the final 0-length chunk is read.
|
|
|
|
func (iam *IdentityAccessManagement) newSignV4ChunkedReader(req *http.Request) (io.ReadCloser, s3err.ErrorCode) { |
|
|
|
ident, seedSignature, region, seedDate, errCode := iam.calculateSeedSignature(req) |
|
|
|
func (iam *IdentityAccessManagement) newSignV4ChunkedReader(req *http.Request) (io.ReadCloser, *Identity, s3err.ErrorCode) { |
|
|
|
ident, cred, seedSignature, region, seedDate, errCode := iam.calculateSeedSignature(req) |
|
|
|
if errCode != s3err.ErrNone { |
|
|
|
return nil, errCode |
|
|
|
return nil, nil, errCode |
|
|
|
} |
|
|
|
return &s3ChunkedReader{ |
|
|
|
cred: ident, |
|
|
|
cred: cred, |
|
|
|
reader: bufio.NewReader(req.Body), |
|
|
|
seedSignature: seedSignature, |
|
|
|
seedDate: seedDate, |
|
|
|
region: region, |
|
|
|
chunkSHA256Writer: sha256.New(), |
|
|
|
state: readChunkHeader, |
|
|
|
}, s3err.ErrNone |
|
|
|
}, ident, s3err.ErrNone |
|
|
|
} |
|
|
|
|
|
|
|
// Represents the overall state that is required for decoding a
|
|
|
|