Skip to content

Commit 9d57e50

Browse files
authored
fix: correctly compose sign v4 to compare on chunked uploads (#698)
1 parent a23c964 commit 9d57e50

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/http/plugins/signature-v4.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ function createStreamingSignatureV4Parser(opts: CreateSignatureV3ParserOpts) {
248248
'signatureReadyForVerification',
249249
(signature: string, _: number, hash: string, previousSign) => {
250250
const isValid = opts.signatureV4.validateChunkSignature(
251-
algorithm,
252251
opts.clientSignature,
253252
hash,
254253
signature,

src/storage/protocols/s3/signature-v4.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ export class SignatureV4 {
279279
}
280280

281281
public validateChunkSignature(
282-
algorithm: V4StreamingAlgorithm,
283282
clientSignature: ClientSignature,
284283
chunkHash: string,
285284
chunkSignature: string,
@@ -300,7 +299,7 @@ export class SignatureV4 {
300299
// SHA256(chunkData)
301300
const scope = `${shortDate}/${region}/${service}/aws4_request`
302301
const stringToSign = [
303-
algorithm,
302+
'AWS4-HMAC-SHA256-PAYLOAD',
304303
clientSignature.longDate,
305304
scope,
306305
prevSignature,
@@ -311,7 +310,7 @@ export class SignatureV4 {
311310
// 4) HMAC it with the derived key and compare
312311
const expected = this.hmac(signingKey, stringToSign)
313312

314-
return crypto.timingSafeEqual(expected, Buffer.from(chunkSignature))
313+
return crypto.timingSafeEqual(expected, Buffer.from(chunkSignature, 'hex'))
315314
}
316315

317316
signPostPolicy(clientSignature: ClientSignature, policy: string) {

0 commit comments

Comments
 (0)