v2.js
1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var AWS = require('../core');
var inherit = AWS.util.inherit;
/**
* @api private
*/
AWS.Signers.V2 = inherit(AWS.Signers.RequestSigner, {
addAuthorization: function addAuthorization(credentials, date) {
if (!date) date = AWS.util.date.getDate();
var r = this.request;
r.params.Timestamp = AWS.util.date.iso8601(date);
r.params.SignatureVersion = '2';
r.params.SignatureMethod = 'HmacSHA256';
r.params.AWSAccessKeyId = credentials.accessKeyId;
if (credentials.sessionToken) {
r.params.SecurityToken = credentials.sessionToken;
}
delete r.params.Signature; // delete old Signature for re-signing
r.params.Signature = this.signature(credentials);
r.body = AWS.util.queryParamsToString(r.params);
r.headers['Content-Length'] = r.body.length;
},
signature: function signature(credentials) {
return AWS.util.crypto.hmac(credentials.secretAccessKey, this.stringToSign(), 'base64');
},
stringToSign: function stringToSign() {
var parts = [];
parts.push(this.request.method);
parts.push(this.request.endpoint.host.toLowerCase());
parts.push(this.request.pathname());
parts.push(AWS.util.queryParamsToString(this.request.params));
return parts.join('\n');
}
});
/**
* @api private
*/
module.exports = AWS.Signers.V2;