Skip to content

Commit

Permalink
Merge pull request #6 from badslug/sign-other-amz-headers
Browse files Browse the repository at this point in the history
Add code to include arbitrary extra `x-amz-` headers
  • Loading branch information
badslug authored Jan 17, 2017
2 parents a7f2889 + 47f5324 commit 8347b8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions AWSSignature4DynamicValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,28 @@ var AWSSignature4DynamicValue = function() {
daytime = day + 'T' + amzTime(now)
}
var bodyHash = hash256(request.body || '')

// Step 1
// Search for other signed headers to include. We will assume any headers that begin with X-Amz-<*> will be included
var signedHeaders = 'host;x-amz-date'
var headers = '' // The actual headers to sign
var names = request.getHeaderNames()
if (names) {
names.forEach(function(name) {
var lower = name.toLowerCase()
if (lower !== 'x-amz-date' && lower.startsWith('x-amz-') {
signedHeaders += ';'+lower
headers += lower + ':' + request.getHeaderByName(name, false) + '\n'
}
})
}

// Step 1
var canonical = request.method + '\n' +
uri.pathname + '\n' +
getParametersString(request, uri.search) + '\n' +
'host:' + uri.hostname.toLowerCase() + '\n' +
'x-amz-date:' + daytime + '\n' +
headers +
'\n' +
signedHeaders + '\n' +
bodyHash
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected using IAM.

TBD

To support AWS Signature 3 authentication please follow these steps:
To support AWS Signature 4 authentication please follow these steps:

* Install this extension. For now, you should install by using the Makefile
(see Development section below).
Expand Down

0 comments on commit 8347b8a

Please sign in to comment.