Skip to content

Commit 48159ac

Browse files
authored
Fixes a bug that could cause the SigV4 payload hash to be incorrectly encoded, leading to signing errors. (#1684)
1 parent 14b97ee commit 48159ac

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "96bcadc5-352b-4729-806e-07feee9091d0",
3+
"type": "bugfix",
4+
"description": "Fixes a bug that could cause the SigV4 payload hash to be incorrectly encoded, leading to signing errors.",
5+
"modules": [
6+
"service/internal/checksum"
7+
]
8+
}

service/internal/checksum/middleware_compute_input_checksum.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func computeStreamChecksum(algorithm Algorithm, stream io.Reader, computePayload
422422
if algorithm != AlgorithmSHA256 {
423423
sha256Checksum = string(hexEncodeHashSum(sha256Hasher))
424424
} else {
425-
sha256Checksum = checksum
425+
sha256Checksum = string(hexEncodeHashSum(hasher))
426426
}
427427
}
428428

service/internal/checksum/middleware_compute_input_checksum_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,29 @@ func TestComputeInputPayloadChecksum(t *testing.T) {
369369
"CRC32": "DUoRhQ==",
370370
},
371371
},
372+
"http seekable checksum matches payload hash": {
373+
initContext: func(ctx context.Context) context.Context {
374+
return setContextInputAlgorithm(ctx, string(AlgorithmSHA256))
375+
},
376+
buildInput: middleware.BuildInput{
377+
Request: func() *smithyhttp.Request {
378+
r := smithyhttp.NewStackRequest().(*smithyhttp.Request)
379+
r.URL, _ = url.Parse("http://example.aws")
380+
r.ContentLength = 11
381+
r = requestMust(r.SetStream(bytes.NewReader([]byte("hello world"))))
382+
return r
383+
}(),
384+
},
385+
expectHeader: http.Header{
386+
"X-Amz-Checksum-Sha256": []string{"uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="},
387+
},
388+
expectContentLength: 11,
389+
expectPayload: []byte("hello world"),
390+
expectPayloadHash: "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9",
391+
expectChecksumMetadata: map[string]string{
392+
"SHA256": "uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=",
393+
},
394+
},
372395
"http payload hash disabled": {
373396
initContext: func(ctx context.Context) context.Context {
374397
return setContextInputAlgorithm(ctx, string(AlgorithmCRC32))

0 commit comments

Comments
 (0)