@aws-sdk/signature-v4
Advanced tools
Comparing version 1.0.0-gamma.1 to 1.0.0-gamma.2
176
CHANGELOG.md
@@ -6,2 +6,178 @@ # Change Log | ||
# [1.0.0-gamma.2](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/signature-v4@0.1.0-preview.3...@aws-sdk/signature-v4@1.0.0-gamma.2) (2020-07-08) | ||
### Features | ||
* use a common tsconfig for the monorepo ([#1297](https://github.com/aws/aws-sdk-js-v3/issues/1297)) ([16aea66](https://github.com/aws/aws-sdk-js-v3/commit/16aea66d1fc5386680d3e6da9b7dcde78e178bd3)) | ||
# 1.0.0-gamma.1 (2020-05-21) | ||
### Features | ||
* bump up to gamma version ([#1192](https://github.com/aws/aws-sdk-js-v3/issues/1192)) ([a609075](https://github.com/aws/aws-sdk-js-v3/commit/a6090754f2a6c21e5b70bf0c8782cc0fbe59ee12)) | ||
# 1.0.0-beta.4 (2020-04-25) | ||
# 1.0.0-beta.2 (2020-03-28) | ||
# 1.0.0-beta.1 (2020-03-25) | ||
### Features | ||
* bump packages to beta ([#1050](https://github.com/aws/aws-sdk-js-v3/issues/1050)) ([40501d4](https://github.com/aws/aws-sdk-js-v3/commit/40501d4394d04bc1bc91c10136fa48b1d3a67d8f)) | ||
# 1.0.0-alpha.28 (2020-03-20) | ||
### Features | ||
* **signature-v4:** update EventSigner signature API to sign ([#1016](https://github.com/aws/aws-sdk-js-v3/issues/1016)) ([bce853a](https://github.com/aws/aws-sdk-js-v3/commit/bce853aa67f744b548198f9e20f7bfd3ad0bd894)) | ||
# 1.0.0-alpha.26 (2020-03-12) | ||
### Bug Fixes | ||
* **signature-v4:** make x-amz-user-agent signable ([#997](https://github.com/aws/aws-sdk-js-v3/issues/997)) ([2785d2f](https://github.com/aws/aws-sdk-js-v3/commit/2785d2f9b9391350a4fdaba0093e6a64944d0949)), closes [/github.com/aws/aws-sdk-js/blob/999ebda726224a67f0fe207702bf5b03609775a4/lib/signers/v4.js#L191-L199](https://github.com//github.com/aws/aws-sdk-js/blob/999ebda726224a67f0fe207702bf5b03609775a4/lib/signers/v4.js/issues/L191-L199) | ||
# 1.0.0-alpha.24 (2020-02-19) | ||
### Bug Fixes | ||
* consistently encode query ([#935](https://github.com/aws/aws-sdk-js-v3/issues/935)) ([251dd57](https://github.com/aws/aws-sdk-js-v3/commit/251dd57dfdf082ef66d8fb7346e2fdf6e7195a42)) | ||
### Features | ||
* **signature-v4:** unsign x-amz-user-agent header ([#928](https://github.com/aws/aws-sdk-js-v3/issues/928)) ([082567e](https://github.com/aws/aws-sdk-js-v3/commit/082567ebc7fc18fa66fcc8db675b047ca239c0d4)) | ||
* remove suite script ([#927](https://github.com/aws/aws-sdk-js-v3/issues/927)) ([a8414f2](https://github.com/aws/aws-sdk-js-v3/commit/a8414f29eccef4d8c10f7d345b884bb928924cfe)) | ||
# 1.0.0-alpha.21 (2020-02-11) | ||
# 1.0.0-alpha.20 (2020-02-09) | ||
### Bug Fixes | ||
* remove test suite fixture ([#890](https://github.com/aws/aws-sdk-js-v3/issues/890)) ([2a9a897](https://github.com/aws/aws-sdk-js-v3/commit/2a9a897680733deec669257db9f48041f06d1cda)) | ||
# 1.0.0-alpha.18 (2020-02-06) | ||
### Features | ||
* remove protocol-timestamp package ([#816](https://github.com/aws/aws-sdk-js-v3/issues/816)) ([9913924](https://github.com/aws/aws-sdk-js-v3/commit/9913924e78d6cdfd5e0dfacc440403e3eebe5dfd)) | ||
# 1.0.0-alpha.13 (2020-01-24) | ||
# 1.0.0-alpha.12 (2020-01-22) | ||
# 1.0.0-alpha.9 (2020-01-17) | ||
# 1.0.0-alpha.8 (2020-01-16) | ||
# 1.0.0-alpha.4 (2020-01-14) | ||
### Bug Fixes | ||
* **signature-v4:** use correct main entry point ([#712](https://github.com/aws/aws-sdk-js-v3/issues/712)) ([16e233a](https://github.com/aws/aws-sdk-js-v3/commit/16e233ac1ae2722cf49c31ad7270a9ada9e0f916)) | ||
# 1.0.0-alpha.1 (2020-01-10) | ||
# 0.9.0 (2020-01-09) | ||
### Bug Fixes | ||
* update updated types ([#474](https://github.com/aws/aws-sdk-js-v3/issues/474)) ([9efac3e](https://github.com/aws/aws-sdk-js-v3/commit/9efac3e1eb2370fb11b10b3d005369ec1a307e3a)) | ||
* use httpRequestOptions in signature-v4 ([#623](https://github.com/aws/aws-sdk-js-v3/issues/623)) ([4548971](https://github.com/aws/aws-sdk-js-v3/commit/454897124d995e992f3515475237359bb98bec92)) | ||
### Features | ||
* start endpoint resolver generation ([#472](https://github.com/aws/aws-sdk-js-v3/issues/472)) ([d0f9250](https://github.com/aws/aws-sdk-js-v3/commit/d0f9250fde6f51418640ea897cc29359243257f1)) | ||
# 0.7.0 (2019-11-19) | ||
# 0.6.0 (2019-10-30) | ||
### Features | ||
* **signature-v4:** add support to override the set of unsignableHeaders ([#420](https://github.com/aws/aws-sdk-js-v3/issues/420)) ([8d6b27a](https://github.com/aws/aws-sdk-js-v3/commit/8d6b27a97cf7f256b35986a305b27180e933f459)) | ||
# 0.4.0 (2019-09-19) | ||
# 0.3.0 (2019-09-09) | ||
### Features | ||
* commit all clients ([#324](https://github.com/aws/aws-sdk-js-v3/issues/324)) ([cb268ed](https://github.com/aws/aws-sdk-js-v3/commit/cb268ed45fd5580ef9633da78f13aaa6aa472805)) | ||
# 0.2.0 (2019-07-12) | ||
### Features | ||
* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10cb6b0ebc32004b797556bfc171c96bbf16)) | ||
* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab4ac5343058eaf7d448a428d8c4b72c844)) | ||
# 0.1.0 (2019-04-19) | ||
# [1.0.0-gamma.1](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/signature-v4@0.1.0-preview.3...@aws-sdk/signature-v4@1.0.0-gamma.1) (2020-05-21) | ||
@@ -8,0 +184,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
var tslib_1 = require("tslib"); | ||
/** | ||
@@ -8,12 +8,13 @@ * @internal | ||
function cloneRequest(_a) { | ||
var { headers, query } = _a, rest = tslib_1.__rest(_a, ["headers", "query"]); | ||
return Object.assign(Object.assign({}, rest), { headers: Object.assign({}, headers), query: query ? cloneQuery(query) : undefined }); | ||
var headers = _a.headers, query = _a.query, rest = tslib_1.__rest(_a, ["headers", "query"]); | ||
return tslib_1.__assign(tslib_1.__assign({}, rest), { headers: tslib_1.__assign({}, headers), query: query ? cloneQuery(query) : undefined }); | ||
} | ||
exports.cloneRequest = cloneRequest; | ||
function cloneQuery(query) { | ||
return Object.keys(query).reduce((carry, paramName) => { | ||
const param = query[paramName]; | ||
return Object.assign(Object.assign({}, carry), { [paramName]: Array.isArray(param) ? [...param] : param }); | ||
return Object.keys(query).reduce(function (carry, paramName) { | ||
var _a; | ||
var param = query[paramName]; | ||
return tslib_1.__assign(tslib_1.__assign({}, carry), (_a = {}, _a[paramName] = Array.isArray(param) ? tslib_1.__spread(param) : param, _a)); | ||
}, {}); | ||
} | ||
//# sourceMappingURL=cloneRequest.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const constants_1 = require("./constants"); | ||
const signingKeyCache = {}; | ||
const cacheQueue = []; | ||
var tslib_1 = require("tslib"); | ||
var constants_1 = require("./constants"); | ||
var signingKeyCache = {}; | ||
var cacheQueue = []; | ||
/** | ||
@@ -14,3 +15,3 @@ * Create a string describing the scope of credentials used to sign a request. | ||
function createScope(shortDate, region, service) { | ||
return `${shortDate}/${region}/${service}/${constants_1.KEY_TYPE_IDENTIFIER}`; | ||
return shortDate + "/" + region + "/" + service + "/" + constants_1.KEY_TYPE_IDENTIFIER; | ||
} | ||
@@ -31,4 +32,4 @@ exports.createScope = createScope; | ||
function getSigningKey(sha256Constructor, credentials, shortDate, region, service) { | ||
const cacheKey = `${shortDate}:${region}:${service}:` + | ||
`${credentials.accessKeyId}:${credentials.sessionToken}`; | ||
var cacheKey = shortDate + ":" + region + ":" + service + ":" + | ||
(credentials.accessKeyId + ":" + credentials.sessionToken); | ||
if (cacheKey in signingKeyCache) { | ||
@@ -41,9 +42,25 @@ return signingKeyCache[cacheKey]; | ||
} | ||
return (signingKeyCache[cacheKey] = new Promise((resolve, reject) => { | ||
let keyPromise = Promise.resolve(`AWS4${credentials.secretAccessKey}`); | ||
for (let signable of [shortDate, region, service, constants_1.KEY_TYPE_IDENTIFIER]) { | ||
keyPromise = keyPromise.then(intermediateKey => hmac(sha256Constructor, intermediateKey, signable)); | ||
keyPromise.catch(() => { }); | ||
return (signingKeyCache[cacheKey] = new Promise(function (resolve, reject) { | ||
var e_1, _a; | ||
var keyPromise = Promise.resolve("AWS4" + credentials.secretAccessKey); | ||
var _loop_1 = function (signable) { | ||
keyPromise = keyPromise.then(function (intermediateKey) { | ||
return hmac(sha256Constructor, intermediateKey, signable); | ||
}); | ||
keyPromise.catch(function () { }); | ||
}; | ||
try { | ||
for (var _b = tslib_1.__values([shortDate, region, service, constants_1.KEY_TYPE_IDENTIFIER]), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var signable = _c.value; | ||
_loop_1(signable); | ||
} | ||
} | ||
keyPromise.then(resolve, reason => { | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
keyPromise.then(resolve, function (reason) { | ||
delete signingKeyCache[cacheKey]; | ||
@@ -60,3 +77,3 @@ reject(reason); | ||
cacheQueue.length = 0; | ||
Object.keys(signingKeyCache).forEach(cacheKey => { | ||
Object.keys(signingKeyCache).forEach(function (cacheKey) { | ||
delete signingKeyCache[cacheKey]; | ||
@@ -67,3 +84,3 @@ }); | ||
function hmac(ctor, secret, data) { | ||
const hash = new ctor(secret); | ||
var hash = new ctor(secret); | ||
hash.update(data); | ||
@@ -70,0 +87,0 @@ return hash.digest(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const constants_1 = require("./constants"); | ||
var tslib_1 = require("tslib"); | ||
var constants_1 = require("./constants"); | ||
/** | ||
* @internal | ||
*/ | ||
function getCanonicalHeaders({ headers }, unsignableHeaders, signableHeaders) { | ||
const canonical = {}; | ||
for (let headerName of Object.keys(headers).sort()) { | ||
const canonicalHeaderName = headerName.toLowerCase(); | ||
if (canonicalHeaderName in constants_1.ALWAYS_UNSIGNABLE_HEADERS || (unsignableHeaders === null || unsignableHeaders === void 0 ? void 0 : unsignableHeaders.has(canonicalHeaderName)) || | ||
constants_1.PROXY_HEADER_PATTERN.test(canonicalHeaderName) || | ||
constants_1.SEC_HEADER_PATTERN.test(canonicalHeaderName)) { | ||
if (!signableHeaders || | ||
(signableHeaders && !signableHeaders.has(canonicalHeaderName))) { | ||
continue; | ||
function getCanonicalHeaders(_a, unsignableHeaders, signableHeaders) { | ||
var e_1, _b; | ||
var headers = _a.headers; | ||
var canonical = {}; | ||
try { | ||
for (var _c = tslib_1.__values(Object.keys(headers).sort()), _d = _c.next(); !_d.done; _d = _c.next()) { | ||
var headerName = _d.value; | ||
var canonicalHeaderName = headerName.toLowerCase(); | ||
if (canonicalHeaderName in constants_1.ALWAYS_UNSIGNABLE_HEADERS || (unsignableHeaders === null || unsignableHeaders === void 0 ? void 0 : unsignableHeaders.has(canonicalHeaderName)) || | ||
constants_1.PROXY_HEADER_PATTERN.test(canonicalHeaderName) || | ||
constants_1.SEC_HEADER_PATTERN.test(canonicalHeaderName)) { | ||
if (!signableHeaders || | ||
(signableHeaders && !signableHeaders.has(canonicalHeaderName))) { | ||
continue; | ||
} | ||
} | ||
canonical[canonicalHeaderName] = headers[headerName] | ||
.trim() | ||
.replace(/\s+/g, " "); | ||
} | ||
canonical[canonicalHeaderName] = headers[headerName] | ||
.trim() | ||
.replace(/\s+/g, " "); | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_d && !_d.done && (_b = _c.return)) _b.call(_c); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return canonical; | ||
@@ -24,0 +37,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const constants_1 = require("./constants"); | ||
const util_uri_escape_1 = require("@aws-sdk/util-uri-escape"); | ||
var tslib_1 = require("tslib"); | ||
var constants_1 = require("./constants"); | ||
var util_uri_escape_1 = require("@aws-sdk/util-uri-escape"); | ||
/** | ||
* @internal | ||
*/ | ||
function getCanonicalQuery({ query = {} }) { | ||
const keys = []; | ||
const serialized = {}; | ||
for (let key of Object.keys(query).sort()) { | ||
function getCanonicalQuery(_a) { | ||
var e_1, _b; | ||
var _c = _a.query, query = _c === void 0 ? {} : _c; | ||
var keys = []; | ||
var serialized = {}; | ||
var _loop_1 = function (key) { | ||
if (key.toLowerCase() === constants_1.SIGNATURE_HEADER) { | ||
continue; | ||
return "continue"; | ||
} | ||
keys.push(key); | ||
const value = query[key]; | ||
var value = query[key]; | ||
if (typeof value === "string") { | ||
serialized[key] = `${util_uri_escape_1.escapeUri(key)}=${util_uri_escape_1.escapeUri(value)}`; | ||
serialized[key] = util_uri_escape_1.escapeUri(key) + "=" + util_uri_escape_1.escapeUri(value); | ||
} | ||
@@ -24,9 +27,24 @@ else if (Array.isArray(value)) { | ||
.sort() | ||
.reduce((encoded, value) => encoded.concat([`${util_uri_escape_1.escapeUri(key)}=${util_uri_escape_1.escapeUri(value)}`]), []) | ||
.reduce(function (encoded, value) { | ||
return encoded.concat([util_uri_escape_1.escapeUri(key) + "=" + util_uri_escape_1.escapeUri(value)]); | ||
}, []) | ||
.join("&"); | ||
} | ||
}; | ||
try { | ||
for (var _d = tslib_1.__values(Object.keys(query).sort()), _e = _d.next(); !_e.done; _e = _d.next()) { | ||
var key = _e.value; | ||
_loop_1(key); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_e && !_e.done && (_b = _d.return)) _b.call(_d); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return keys | ||
.map(key => serialized[key]) | ||
.filter(serialized => serialized) // omit any falsy values | ||
.map(function (key) { return serialized[key]; }) | ||
.filter(function (serialized) { return serialized; }) // omit any falsy values | ||
.join("&"); | ||
@@ -33,0 +51,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const constants_1 = require("./constants"); | ||
const is_array_buffer_1 = require("@aws-sdk/is-array-buffer"); | ||
const util_hex_encoding_1 = require("@aws-sdk/util-hex-encoding"); | ||
var tslib_1 = require("tslib"); | ||
var constants_1 = require("./constants"); | ||
var is_array_buffer_1 = require("@aws-sdk/is-array-buffer"); | ||
var util_hex_encoding_1 = require("@aws-sdk/util-hex-encoding"); | ||
/** | ||
* @internal | ||
*/ | ||
async function getPayloadHash({ headers, body }, hashConstructor) { | ||
for (const headerName of Object.keys(headers)) { | ||
if (headerName.toLowerCase() === constants_1.SHA256_HEADER) { | ||
return headers[headerName]; | ||
} | ||
} | ||
if (body == undefined) { | ||
return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; | ||
} | ||
else if (typeof body === "string" || | ||
ArrayBuffer.isView(body) || | ||
is_array_buffer_1.isArrayBuffer(body)) { | ||
const hashCtor = new hashConstructor(); | ||
hashCtor.update(body); | ||
return util_hex_encoding_1.toHex(await hashCtor.digest()); | ||
} | ||
// As any defined body that is not a string or binary data is a stream, this | ||
// body is unsignable. Attempt to send the request with an unsigned payload, | ||
// which may or may not be accepted by the service. | ||
return constants_1.UNSIGNED_PAYLOAD; | ||
function getPayloadHash(_a, hashConstructor) { | ||
var headers = _a.headers, body = _a.body; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _b, _c, headerName, hashCtor, _d; | ||
var e_1, _e; | ||
return tslib_1.__generator(this, function (_f) { | ||
switch (_f.label) { | ||
case 0: | ||
try { | ||
for (_b = tslib_1.__values(Object.keys(headers)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
headerName = _c.value; | ||
if (headerName.toLowerCase() === constants_1.SHA256_HEADER) { | ||
return [2 /*return*/, headers[headerName]]; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_e = _b.return)) _e.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
if (!(body == undefined)) return [3 /*break*/, 1]; | ||
return [2 /*return*/, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"]; | ||
case 1: | ||
if (!(typeof body === "string" || | ||
ArrayBuffer.isView(body) || | ||
is_array_buffer_1.isArrayBuffer(body))) return [3 /*break*/, 3]; | ||
hashCtor = new hashConstructor(); | ||
hashCtor.update(body); | ||
_d = util_hex_encoding_1.toHex; | ||
return [4 /*yield*/, hashCtor.digest()]; | ||
case 2: return [2 /*return*/, _d.apply(void 0, [_f.sent()])]; | ||
case 3: | ||
// As any defined body that is not a string or binary data is a stream, this | ||
// body is unsignable. Attempt to send the request with an unsigned payload, | ||
// which may or may not be accepted by the service. | ||
return [2 /*return*/, constants_1.UNSIGNED_PAYLOAD]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.getPayloadHash = getPayloadHash; | ||
//# sourceMappingURL=getPayloadHash.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
function hasHeader(soughtHeader, headers) { | ||
var e_1, _a; | ||
soughtHeader = soughtHeader.toLowerCase(); | ||
for (const headerName of Object.keys(headers)) { | ||
if (soughtHeader === headerName.toLowerCase()) { | ||
return true; | ||
try { | ||
for (var _b = tslib_1.__values(Object.keys(headers)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var headerName = _c.value; | ||
if (soughtHeader === headerName.toLowerCase()) { | ||
return true; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return false; | ||
@@ -11,0 +23,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./credentialDerivation"), exports); | ||
tslib_1.__exportStar(require("./SignatureV4"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const cloneRequest_1 = require("./cloneRequest"); | ||
var tslib_1 = require("tslib"); | ||
var cloneRequest_1 = require("./cloneRequest"); | ||
/** | ||
@@ -8,16 +9,27 @@ * @internal | ||
function moveHeadersToQuery(request) { | ||
const { headers, query = {} } = typeof request.clone === "function" | ||
var e_1, _a; | ||
var _b = typeof request.clone === "function" | ||
? request.clone() | ||
: cloneRequest_1.cloneRequest(request); | ||
for (let name of Object.keys(headers)) { | ||
const lname = name.toLowerCase(); | ||
if (lname.substr(0, 6) === "x-amz-") { | ||
query[name] = headers[name]; | ||
delete headers[name]; | ||
: cloneRequest_1.cloneRequest(request), headers = _b.headers, _c = _b.query, query = _c === void 0 ? {} : _c; | ||
try { | ||
for (var _d = tslib_1.__values(Object.keys(headers)), _e = _d.next(); !_e.done; _e = _d.next()) { | ||
var name_1 = _e.value; | ||
var lname = name_1.toLowerCase(); | ||
if (lname.substr(0, 6) === "x-amz-") { | ||
query[name_1] = headers[name_1]; | ||
delete headers[name_1]; | ||
} | ||
} | ||
} | ||
return Object.assign(Object.assign({}, request), { headers, | ||
query }); | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_e && !_e.done && (_a = _d.return)) _a.call(_d); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return tslib_1.__assign(tslib_1.__assign({}, request), { headers: headers, | ||
query: query }); | ||
} | ||
exports.moveHeadersToQuery = moveHeadersToQuery; | ||
//# sourceMappingURL=moveHeadersToQuery.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const cloneRequest_1 = require("./cloneRequest"); | ||
const constants_1 = require("./constants"); | ||
var tslib_1 = require("tslib"); | ||
var cloneRequest_1 = require("./cloneRequest"); | ||
var constants_1 = require("./constants"); | ||
/** | ||
@@ -9,2 +10,3 @@ * @internal | ||
function prepareRequest(request) { | ||
var e_1, _a; | ||
// Create a clone of the request object that does not clone the body | ||
@@ -15,7 +17,17 @@ request = | ||
: cloneRequest_1.cloneRequest(request); | ||
for (let headerName of Object.keys(request.headers)) { | ||
if (constants_1.GENERATED_HEADERS.indexOf(headerName.toLowerCase()) > -1) { | ||
delete request.headers[headerName]; | ||
try { | ||
for (var _b = tslib_1.__values(Object.keys(request.headers)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var headerName = _c.value; | ||
if (constants_1.GENERATED_HEADERS.indexOf(headerName.toLowerCase()) > -1) { | ||
delete request.headers[headerName]; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return request; | ||
@@ -22,0 +34,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const credentialDerivation_1 = require("./credentialDerivation"); | ||
const getCanonicalHeaders_1 = require("./getCanonicalHeaders"); | ||
const getCanonicalQuery_1 = require("./getCanonicalQuery"); | ||
const getPayloadHash_1 = require("./getPayloadHash"); | ||
const prepareRequest_1 = require("./prepareRequest"); | ||
const moveHeadersToQuery_1 = require("./moveHeadersToQuery"); | ||
const constants_1 = require("./constants"); | ||
const util_hex_encoding_1 = require("@aws-sdk/util-hex-encoding"); | ||
const hasHeader_1 = require("./hasHeader"); | ||
const utilDate_1 = require("./utilDate"); | ||
class SignatureV4 { | ||
constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath = true }) { | ||
var tslib_1 = require("tslib"); | ||
var credentialDerivation_1 = require("./credentialDerivation"); | ||
var getCanonicalHeaders_1 = require("./getCanonicalHeaders"); | ||
var getCanonicalQuery_1 = require("./getCanonicalQuery"); | ||
var getPayloadHash_1 = require("./getPayloadHash"); | ||
var prepareRequest_1 = require("./prepareRequest"); | ||
var moveHeadersToQuery_1 = require("./moveHeadersToQuery"); | ||
var constants_1 = require("./constants"); | ||
var util_hex_encoding_1 = require("@aws-sdk/util-hex-encoding"); | ||
var hasHeader_1 = require("./hasHeader"); | ||
var utilDate_1 = require("./utilDate"); | ||
var SignatureV4 = /** @class */ (function () { | ||
function SignatureV4(_a) { | ||
var applyChecksum = _a.applyChecksum, credentials = _a.credentials, region = _a.region, service = _a.service, sha256 = _a.sha256, _b = _a.uriEscapePath, uriEscapePath = _b === void 0 ? true : _b; | ||
this.service = service; | ||
@@ -22,4 +24,4 @@ this.sha256 = sha256; | ||
if (typeof region === "string") { | ||
const promisified = Promise.resolve(region); | ||
this.regionProvider = () => promisified; | ||
var promisified_1 = Promise.resolve(region); | ||
this.regionProvider = function () { return promisified_1; }; | ||
} | ||
@@ -30,4 +32,4 @@ else { | ||
if (typeof credentials === "object") { | ||
const promisified = Promise.resolve(credentials); | ||
this.credentialProvider = () => promisified; | ||
var promisified_2 = Promise.resolve(credentials); | ||
this.credentialProvider = function () { return promisified_2; }; | ||
} | ||
@@ -38,136 +40,225 @@ else { | ||
} | ||
async presign(originalRequest, options = {}) { | ||
const [region, credentials] = await Promise.all([ | ||
this.regionProvider(), | ||
this.credentialProvider() | ||
]); | ||
const { signingDate = new Date(), expiresIn = 3600, unsignableHeaders, signableHeaders } = options; | ||
const { longDate, shortDate } = formatDate(signingDate); | ||
if (expiresIn > constants_1.MAX_PRESIGNED_TTL) { | ||
return Promise.reject("Signature version 4 presigned URLs" + | ||
" must have an expiration date less than one week in" + | ||
" the future"); | ||
} | ||
const scope = credentialDerivation_1.createScope(shortDate, region, this.service); | ||
const request = moveHeadersToQuery_1.moveHeadersToQuery(prepareRequest_1.prepareRequest(originalRequest)); | ||
if (credentials.sessionToken) { | ||
request.query[constants_1.TOKEN_QUERY_PARAM] = credentials.sessionToken; | ||
} | ||
request.query[constants_1.ALGORITHM_QUERY_PARAM] = constants_1.ALGORITHM_IDENTIFIER; | ||
request.query[constants_1.CREDENTIAL_QUERY_PARAM] = `${credentials.accessKeyId}/${scope}`; | ||
request.query[constants_1.AMZ_DATE_QUERY_PARAM] = longDate; | ||
request.query[constants_1.EXPIRES_QUERY_PARAM] = expiresIn.toString(10); | ||
const canonicalHeaders = getCanonicalHeaders_1.getCanonicalHeaders(request, unsignableHeaders, signableHeaders); | ||
request.query[constants_1.SIGNED_HEADERS_QUERY_PARAM] = getCanonicalHeaderList(canonicalHeaders); | ||
request.query[constants_1.SIGNATURE_QUERY_PARAM] = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate), this.createCanonicalRequest(request, canonicalHeaders, await getPayloadHash_1.getPayloadHash(originalRequest, this.sha256))); | ||
return request; | ||
} | ||
async sign(toSign, options) { | ||
if (typeof toSign === "string") { | ||
return this.signString(toSign, options); | ||
} | ||
else if (toSign.headers && toSign.payload) { | ||
return this.signEvent(toSign, options); | ||
} | ||
else { | ||
return this.signRequest(toSign, options); | ||
} | ||
} | ||
async signEvent({ headers, payload }, { signingDate = new Date(), priorSignature }) { | ||
const [region] = await Promise.all([ | ||
this.regionProvider(), | ||
this.credentialProvider() | ||
]); | ||
const { shortDate, longDate } = formatDate(signingDate); | ||
const scope = credentialDerivation_1.createScope(shortDate, region, this.service); | ||
const hashedPayload = await getPayloadHash_1.getPayloadHash({ headers: {}, body: payload }, this.sha256); | ||
const hash = new this.sha256(); | ||
hash.update(headers); | ||
const hashedHeaders = util_hex_encoding_1.toHex(await hash.digest()); | ||
const stringToSign = [ | ||
constants_1.EVENT_ALGORITHM_IDENTIFIER, | ||
longDate, | ||
scope, | ||
priorSignature, | ||
hashedHeaders, | ||
hashedPayload | ||
].join("\n"); | ||
return this.signString(stringToSign, { signingDate }); | ||
} | ||
async signString(stringToSign, { signingDate = new Date() } = {}) { | ||
const [region, credentials] = await Promise.all([ | ||
this.regionProvider(), | ||
this.credentialProvider() | ||
]); | ||
const { shortDate } = formatDate(signingDate); | ||
const hash = new this.sha256(await this.getSigningKey(credentials, region, shortDate)); | ||
hash.update(stringToSign); | ||
return util_hex_encoding_1.toHex(await hash.digest()); | ||
} | ||
async signRequest(requestToSign, { signingDate = new Date(), signableHeaders, unsignableHeaders } = {}) { | ||
const [region, credentials] = await Promise.all([ | ||
this.regionProvider(), | ||
this.credentialProvider() | ||
]); | ||
const request = prepareRequest_1.prepareRequest(requestToSign); | ||
const { longDate, shortDate } = formatDate(signingDate); | ||
const scope = credentialDerivation_1.createScope(shortDate, region, this.service); | ||
request.headers[constants_1.AMZ_DATE_HEADER] = longDate; | ||
if (credentials.sessionToken) { | ||
request.headers[constants_1.TOKEN_HEADER] = credentials.sessionToken; | ||
} | ||
const payloadHash = await getPayloadHash_1.getPayloadHash(request, this.sha256); | ||
if (!hasHeader_1.hasHeader(constants_1.SHA256_HEADER, request.headers) && this.applyChecksum) { | ||
request.headers[constants_1.SHA256_HEADER] = payloadHash; | ||
} | ||
const canonicalHeaders = getCanonicalHeaders_1.getCanonicalHeaders(request, unsignableHeaders, signableHeaders); | ||
const signature = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate), this.createCanonicalRequest(request, canonicalHeaders, payloadHash)); | ||
request.headers[constants_1.AUTH_HEADER] = | ||
`${constants_1.ALGORITHM_IDENTIFIER} ` + | ||
`Credential=${credentials.accessKeyId}/${scope}, ` + | ||
`SignedHeaders=${getCanonicalHeaderList(canonicalHeaders)}, ` + | ||
`Signature=${signature}`; | ||
return request; | ||
} | ||
createCanonicalRequest(request, canonicalHeaders, payloadHash) { | ||
const sortedHeaders = Object.keys(canonicalHeaders).sort(); | ||
return `${request.method} | ||
${this.getCanonicalPath(request)} | ||
${getCanonicalQuery_1.getCanonicalQuery(request)} | ||
${sortedHeaders.map(name => `${name}:${canonicalHeaders[name]}`).join("\n")} | ||
${sortedHeaders.join(";")} | ||
${payloadHash}`; | ||
} | ||
async createStringToSign(longDate, credentialScope, canonicalRequest) { | ||
const hash = new this.sha256(); | ||
hash.update(canonicalRequest); | ||
const hashedRequest = await hash.digest(); | ||
return `${constants_1.ALGORITHM_IDENTIFIER} | ||
${longDate} | ||
${credentialScope} | ||
${util_hex_encoding_1.toHex(hashedRequest)}`; | ||
} | ||
getCanonicalPath({ path }) { | ||
SignatureV4.prototype.presign = function (originalRequest, options) { | ||
if (options === void 0) { options = {}; } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, region, credentials, _b, signingDate, _c, expiresIn, unsignableHeaders, signableHeaders, _d, longDate, shortDate, scope, request, canonicalHeaders, _e, _f, _g, _h, _j, _k; | ||
return tslib_1.__generator(this, function (_l) { | ||
switch (_l.label) { | ||
case 0: return [4 /*yield*/, Promise.all([ | ||
this.regionProvider(), | ||
this.credentialProvider() | ||
])]; | ||
case 1: | ||
_a = tslib_1.__read.apply(void 0, [_l.sent(), 2]), region = _a[0], credentials = _a[1]; | ||
_b = options.signingDate, signingDate = _b === void 0 ? new Date() : _b, _c = options.expiresIn, expiresIn = _c === void 0 ? 3600 : _c, unsignableHeaders = options.unsignableHeaders, signableHeaders = options.signableHeaders; | ||
_d = formatDate(signingDate), longDate = _d.longDate, shortDate = _d.shortDate; | ||
if (expiresIn > constants_1.MAX_PRESIGNED_TTL) { | ||
return [2 /*return*/, Promise.reject("Signature version 4 presigned URLs" + | ||
" must have an expiration date less than one week in" + | ||
" the future")]; | ||
} | ||
scope = credentialDerivation_1.createScope(shortDate, region, this.service); | ||
request = moveHeadersToQuery_1.moveHeadersToQuery(prepareRequest_1.prepareRequest(originalRequest)); | ||
if (credentials.sessionToken) { | ||
request.query[constants_1.TOKEN_QUERY_PARAM] = credentials.sessionToken; | ||
} | ||
request.query[constants_1.ALGORITHM_QUERY_PARAM] = constants_1.ALGORITHM_IDENTIFIER; | ||
request.query[constants_1.CREDENTIAL_QUERY_PARAM] = credentials.accessKeyId + "/" + scope; | ||
request.query[constants_1.AMZ_DATE_QUERY_PARAM] = longDate; | ||
request.query[constants_1.EXPIRES_QUERY_PARAM] = expiresIn.toString(10); | ||
canonicalHeaders = getCanonicalHeaders_1.getCanonicalHeaders(request, unsignableHeaders, signableHeaders); | ||
request.query[constants_1.SIGNED_HEADERS_QUERY_PARAM] = getCanonicalHeaderList(canonicalHeaders); | ||
_e = request.query; | ||
_f = constants_1.SIGNATURE_QUERY_PARAM; | ||
_g = this.getSignature; | ||
_h = [longDate, | ||
scope, | ||
this.getSigningKey(credentials, region, shortDate)]; | ||
_j = this.createCanonicalRequest; | ||
_k = [request, | ||
canonicalHeaders]; | ||
return [4 /*yield*/, getPayloadHash_1.getPayloadHash(originalRequest, this.sha256)]; | ||
case 2: return [4 /*yield*/, _g.apply(this, _h.concat([_j.apply(this, _k.concat([_l.sent()]))]))]; | ||
case 3: | ||
_e[_f] = _l.sent(); | ||
return [2 /*return*/, request]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SignatureV4.prototype.sign = function (toSign, options) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
if (typeof toSign === "string") { | ||
return [2 /*return*/, this.signString(toSign, options)]; | ||
} | ||
else if (toSign.headers && toSign.payload) { | ||
return [2 /*return*/, this.signEvent(toSign, options)]; | ||
} | ||
else { | ||
return [2 /*return*/, this.signRequest(toSign, options)]; | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
SignatureV4.prototype.signEvent = function (_a, _b) { | ||
var headers = _a.headers, payload = _a.payload; | ||
var _c = _b.signingDate, signingDate = _c === void 0 ? new Date() : _c, priorSignature = _b.priorSignature; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _d, region, _e, shortDate, longDate, scope, hashedPayload, hash, hashedHeaders, _f, stringToSign; | ||
return tslib_1.__generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: return [4 /*yield*/, Promise.all([ | ||
this.regionProvider(), | ||
this.credentialProvider() | ||
])]; | ||
case 1: | ||
_d = tslib_1.__read.apply(void 0, [_g.sent(), 1]), region = _d[0]; | ||
_e = formatDate(signingDate), shortDate = _e.shortDate, longDate = _e.longDate; | ||
scope = credentialDerivation_1.createScope(shortDate, region, this.service); | ||
return [4 /*yield*/, getPayloadHash_1.getPayloadHash({ headers: {}, body: payload }, this.sha256)]; | ||
case 2: | ||
hashedPayload = _g.sent(); | ||
hash = new this.sha256(); | ||
hash.update(headers); | ||
_f = util_hex_encoding_1.toHex; | ||
return [4 /*yield*/, hash.digest()]; | ||
case 3: | ||
hashedHeaders = _f.apply(void 0, [_g.sent()]); | ||
stringToSign = [ | ||
constants_1.EVENT_ALGORITHM_IDENTIFIER, | ||
longDate, | ||
scope, | ||
priorSignature, | ||
hashedHeaders, | ||
hashedPayload | ||
].join("\n"); | ||
return [2 /*return*/, this.signString(stringToSign, { signingDate: signingDate })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SignatureV4.prototype.signString = function (stringToSign, _a) { | ||
var _b = (_a === void 0 ? {} : _a).signingDate, signingDate = _b === void 0 ? new Date() : _b; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _c, region, credentials, shortDate, hash, _d, _e, _f; | ||
return tslib_1.__generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: return [4 /*yield*/, Promise.all([ | ||
this.regionProvider(), | ||
this.credentialProvider() | ||
])]; | ||
case 1: | ||
_c = tslib_1.__read.apply(void 0, [_g.sent(), 2]), region = _c[0], credentials = _c[1]; | ||
shortDate = formatDate(signingDate).shortDate; | ||
_e = (_d = this.sha256).bind; | ||
return [4 /*yield*/, this.getSigningKey(credentials, region, shortDate)]; | ||
case 2: | ||
hash = new (_e.apply(_d, [void 0, _g.sent()]))(); | ||
hash.update(stringToSign); | ||
_f = util_hex_encoding_1.toHex; | ||
return [4 /*yield*/, hash.digest()]; | ||
case 3: return [2 /*return*/, _f.apply(void 0, [_g.sent()])]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SignatureV4.prototype.signRequest = function (requestToSign, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.signingDate, signingDate = _c === void 0 ? new Date() : _c, signableHeaders = _b.signableHeaders, unsignableHeaders = _b.unsignableHeaders; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _d, region, credentials, request, _e, longDate, shortDate, scope, payloadHash, canonicalHeaders, signature; | ||
return tslib_1.__generator(this, function (_f) { | ||
switch (_f.label) { | ||
case 0: return [4 /*yield*/, Promise.all([ | ||
this.regionProvider(), | ||
this.credentialProvider() | ||
])]; | ||
case 1: | ||
_d = tslib_1.__read.apply(void 0, [_f.sent(), 2]), region = _d[0], credentials = _d[1]; | ||
request = prepareRequest_1.prepareRequest(requestToSign); | ||
_e = formatDate(signingDate), longDate = _e.longDate, shortDate = _e.shortDate; | ||
scope = credentialDerivation_1.createScope(shortDate, region, this.service); | ||
request.headers[constants_1.AMZ_DATE_HEADER] = longDate; | ||
if (credentials.sessionToken) { | ||
request.headers[constants_1.TOKEN_HEADER] = credentials.sessionToken; | ||
} | ||
return [4 /*yield*/, getPayloadHash_1.getPayloadHash(request, this.sha256)]; | ||
case 2: | ||
payloadHash = _f.sent(); | ||
if (!hasHeader_1.hasHeader(constants_1.SHA256_HEADER, request.headers) && this.applyChecksum) { | ||
request.headers[constants_1.SHA256_HEADER] = payloadHash; | ||
} | ||
canonicalHeaders = getCanonicalHeaders_1.getCanonicalHeaders(request, unsignableHeaders, signableHeaders); | ||
return [4 /*yield*/, this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate), this.createCanonicalRequest(request, canonicalHeaders, payloadHash))]; | ||
case 3: | ||
signature = _f.sent(); | ||
request.headers[constants_1.AUTH_HEADER] = | ||
constants_1.ALGORITHM_IDENTIFIER + " " + | ||
("Credential=" + credentials.accessKeyId + "/" + scope + ", ") + | ||
("SignedHeaders=" + getCanonicalHeaderList(canonicalHeaders) + ", ") + | ||
("Signature=" + signature); | ||
return [2 /*return*/, request]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SignatureV4.prototype.createCanonicalRequest = function (request, canonicalHeaders, payloadHash) { | ||
var sortedHeaders = Object.keys(canonicalHeaders).sort(); | ||
return request.method + "\n" + this.getCanonicalPath(request) + "\n" + getCanonicalQuery_1.getCanonicalQuery(request) + "\n" + sortedHeaders.map(function (name) { return name + ":" + canonicalHeaders[name]; }).join("\n") + "\n\n" + sortedHeaders.join(";") + "\n" + payloadHash; | ||
}; | ||
SignatureV4.prototype.createStringToSign = function (longDate, credentialScope, canonicalRequest) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var hash, hashedRequest; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
hash = new this.sha256(); | ||
hash.update(canonicalRequest); | ||
return [4 /*yield*/, hash.digest()]; | ||
case 1: | ||
hashedRequest = _a.sent(); | ||
return [2 /*return*/, constants_1.ALGORITHM_IDENTIFIER + "\n" + longDate + "\n" + credentialScope + "\n" + util_hex_encoding_1.toHex(hashedRequest)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SignatureV4.prototype.getCanonicalPath = function (_a) { | ||
var path = _a.path; | ||
if (this.uriEscapePath) { | ||
const doubleEncoded = encodeURIComponent(path.replace(/^\//, "")); | ||
return `/${doubleEncoded.replace(/%2F/g, "/")}`; | ||
var doubleEncoded = encodeURIComponent(path.replace(/^\//, "")); | ||
return "/" + doubleEncoded.replace(/%2F/g, "/"); | ||
} | ||
return path; | ||
} | ||
async getSignature(longDate, credentialScope, keyPromise, canonicalRequest) { | ||
const stringToSign = await this.createStringToSign(longDate, credentialScope, canonicalRequest); | ||
const hash = new this.sha256(await keyPromise); | ||
hash.update(stringToSign); | ||
return util_hex_encoding_1.toHex(await hash.digest()); | ||
} | ||
getSigningKey(credentials, region, shortDate) { | ||
}; | ||
SignatureV4.prototype.getSignature = function (longDate, credentialScope, keyPromise, canonicalRequest) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var stringToSign, hash, _a, _b, _c; | ||
return tslib_1.__generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: return [4 /*yield*/, this.createStringToSign(longDate, credentialScope, canonicalRequest)]; | ||
case 1: | ||
stringToSign = _d.sent(); | ||
_b = (_a = this.sha256).bind; | ||
return [4 /*yield*/, keyPromise]; | ||
case 2: | ||
hash = new (_b.apply(_a, [void 0, _d.sent()]))(); | ||
hash.update(stringToSign); | ||
_c = util_hex_encoding_1.toHex; | ||
return [4 /*yield*/, hash.digest()]; | ||
case 3: return [2 /*return*/, _c.apply(void 0, [_d.sent()])]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SignatureV4.prototype.getSigningKey = function (credentials, region, shortDate) { | ||
return credentialDerivation_1.getSigningKey(this.sha256, credentials, shortDate, region, this.service); | ||
} | ||
} | ||
}; | ||
return SignatureV4; | ||
}()); | ||
exports.SignatureV4 = SignatureV4; | ||
function formatDate(now) { | ||
const longDate = utilDate_1.iso8601(now).replace(/[\-:]/g, ""); | ||
var longDate = utilDate_1.iso8601(now).replace(/[\-:]/g, ""); | ||
return { | ||
longDate, | ||
longDate: longDate, | ||
shortDate: longDate.substr(0, 8) | ||
@@ -174,0 +265,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { __assign, __rest, __spreadArrays } from "tslib"; | ||
import { __assign, __read, __rest, __spread } from "tslib"; | ||
/** | ||
@@ -13,5 +13,5 @@ * @internal | ||
var param = query[paramName]; | ||
return __assign(__assign({}, carry), (_a = {}, _a[paramName] = Array.isArray(param) ? __spreadArrays(param) : param, _a)); | ||
return __assign(__assign({}, carry), (_a = {}, _a[paramName] = Array.isArray(param) ? __spread(param) : param, _a)); | ||
}, {}); | ||
} | ||
//# sourceMappingURL=cloneRequest.js.map |
@@ -0,1 +1,2 @@ | ||
import { __values } from "tslib"; | ||
import { KEY_TYPE_IDENTIFIER, MAX_CACHE_SIZE } from "./constants"; | ||
@@ -37,2 +38,3 @@ var signingKeyCache = {}; | ||
return (signingKeyCache[cacheKey] = new Promise(function (resolve, reject) { | ||
var e_1, _a; | ||
var keyPromise = Promise.resolve("AWS4" + credentials.secretAccessKey); | ||
@@ -45,6 +47,15 @@ var _loop_1 = function (signable) { | ||
}; | ||
for (var _i = 0, _a = [shortDate, region, service, KEY_TYPE_IDENTIFIER]; _i < _a.length; _i++) { | ||
var signable = _a[_i]; | ||
_loop_1(signable); | ||
try { | ||
for (var _b = __values([shortDate, region, service, KEY_TYPE_IDENTIFIER]), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var signable = _c.value; | ||
_loop_1(signable); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
keyPromise.then(resolve, function (reason) { | ||
@@ -51,0 +62,0 @@ delete signingKeyCache[cacheKey]; |
@@ -0,1 +1,2 @@ | ||
import { __values } from "tslib"; | ||
import { ALWAYS_UNSIGNABLE_HEADERS, PROXY_HEADER_PATTERN, SEC_HEADER_PATTERN } from "./constants"; | ||
@@ -6,21 +7,31 @@ /** | ||
export function getCanonicalHeaders(_a, unsignableHeaders, signableHeaders) { | ||
var e_1, _b; | ||
var headers = _a.headers; | ||
var canonical = {}; | ||
for (var _i = 0, _b = Object.keys(headers).sort(); _i < _b.length; _i++) { | ||
var headerName = _b[_i]; | ||
var canonicalHeaderName = headerName.toLowerCase(); | ||
if (canonicalHeaderName in ALWAYS_UNSIGNABLE_HEADERS || (unsignableHeaders === null || unsignableHeaders === void 0 ? void 0 : unsignableHeaders.has(canonicalHeaderName)) || | ||
PROXY_HEADER_PATTERN.test(canonicalHeaderName) || | ||
SEC_HEADER_PATTERN.test(canonicalHeaderName)) { | ||
if (!signableHeaders || | ||
(signableHeaders && !signableHeaders.has(canonicalHeaderName))) { | ||
continue; | ||
try { | ||
for (var _c = __values(Object.keys(headers).sort()), _d = _c.next(); !_d.done; _d = _c.next()) { | ||
var headerName = _d.value; | ||
var canonicalHeaderName = headerName.toLowerCase(); | ||
if (canonicalHeaderName in ALWAYS_UNSIGNABLE_HEADERS || (unsignableHeaders === null || unsignableHeaders === void 0 ? void 0 : unsignableHeaders.has(canonicalHeaderName)) || | ||
PROXY_HEADER_PATTERN.test(canonicalHeaderName) || | ||
SEC_HEADER_PATTERN.test(canonicalHeaderName)) { | ||
if (!signableHeaders || | ||
(signableHeaders && !signableHeaders.has(canonicalHeaderName))) { | ||
continue; | ||
} | ||
} | ||
canonical[canonicalHeaderName] = headers[headerName] | ||
.trim() | ||
.replace(/\s+/g, " "); | ||
} | ||
canonical[canonicalHeaderName] = headers[headerName] | ||
.trim() | ||
.replace(/\s+/g, " "); | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_d && !_d.done && (_b = _c.return)) _b.call(_c); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return canonical; | ||
} | ||
//# sourceMappingURL=getCanonicalHeaders.js.map |
@@ -0,1 +1,2 @@ | ||
import { __values } from "tslib"; | ||
import { SIGNATURE_HEADER } from "./constants"; | ||
@@ -7,3 +8,4 @@ import { escapeUri } from "@aws-sdk/util-uri-escape"; | ||
export function getCanonicalQuery(_a) { | ||
var _b = _a.query, query = _b === void 0 ? {} : _b; | ||
var e_1, _b; | ||
var _c = _a.query, query = _c === void 0 ? {} : _c; | ||
var keys = []; | ||
@@ -30,6 +32,15 @@ var serialized = {}; | ||
}; | ||
for (var _i = 0, _c = Object.keys(query).sort(); _i < _c.length; _i++) { | ||
var key = _c[_i]; | ||
_loop_1(key); | ||
try { | ||
for (var _d = __values(Object.keys(query).sort()), _e = _d.next(); !_e.done; _e = _d.next()) { | ||
var key = _e.value; | ||
_loop_1(key); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_e && !_e.done && (_b = _d.return)) _b.call(_d); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return keys | ||
@@ -36,0 +47,0 @@ .map(function (key) { return serialized[key]; }) |
@@ -1,2 +0,2 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { __awaiter, __generator, __values } from "tslib"; | ||
import { SHA256_HEADER, UNSIGNED_PAYLOAD } from "./constants"; | ||
@@ -11,12 +11,22 @@ import { isArrayBuffer } from "@aws-sdk/is-array-buffer"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _i, _b, headerName, hashCtor, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
var _b, _c, headerName, hashCtor, _d; | ||
var e_1, _e; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
case 0: | ||
for (_i = 0, _b = Object.keys(headers); _i < _b.length; _i++) { | ||
headerName = _b[_i]; | ||
if (headerName.toLowerCase() === SHA256_HEADER) { | ||
return [2 /*return*/, headers[headerName]]; | ||
try { | ||
for (_b = __values(Object.keys(headers)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
headerName = _c.value; | ||
if (headerName.toLowerCase() === SHA256_HEADER) { | ||
return [2 /*return*/, headers[headerName]]; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_e = _b.return)) _e.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
if (!(body == undefined)) return [3 /*break*/, 1]; | ||
@@ -30,5 +40,5 @@ return [2 /*return*/, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"]; | ||
hashCtor.update(body); | ||
_c = toHex; | ||
_d = toHex; | ||
return [4 /*yield*/, hashCtor.digest()]; | ||
case 2: return [2 /*return*/, _c.apply(void 0, [_d.sent()])]; | ||
case 2: return [2 /*return*/, _d.apply(void 0, [_f.sent()])]; | ||
case 3: | ||
@@ -35,0 +45,0 @@ // As any defined body that is not a string or binary data is a stream, this |
@@ -0,11 +1,22 @@ | ||
import { __values } from "tslib"; | ||
export function hasHeader(soughtHeader, headers) { | ||
var e_1, _a; | ||
soughtHeader = soughtHeader.toLowerCase(); | ||
for (var _i = 0, _a = Object.keys(headers); _i < _a.length; _i++) { | ||
var headerName = _a[_i]; | ||
if (soughtHeader === headerName.toLowerCase()) { | ||
return true; | ||
try { | ||
for (var _b = __values(Object.keys(headers)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var headerName = _c.value; | ||
if (soughtHeader === headerName.toLowerCase()) { | ||
return true; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return false; | ||
} | ||
//# sourceMappingURL=hasHeader.js.map |
@@ -1,2 +0,2 @@ | ||
import { __assign } from "tslib"; | ||
import { __assign, __values } from "tslib"; | ||
import { cloneRequest } from "./cloneRequest"; | ||
@@ -7,13 +7,23 @@ /** | ||
export function moveHeadersToQuery(request) { | ||
var _a = typeof request.clone === "function" | ||
var e_1, _a; | ||
var _b = typeof request.clone === "function" | ||
? request.clone() | ||
: cloneRequest(request), headers = _a.headers, _b = _a.query, query = _b === void 0 ? {} : _b; | ||
for (var _i = 0, _c = Object.keys(headers); _i < _c.length; _i++) { | ||
var name = _c[_i]; | ||
var lname = name.toLowerCase(); | ||
if (lname.substr(0, 6) === "x-amz-") { | ||
query[name] = headers[name]; | ||
delete headers[name]; | ||
: cloneRequest(request), headers = _b.headers, _c = _b.query, query = _c === void 0 ? {} : _c; | ||
try { | ||
for (var _d = __values(Object.keys(headers)), _e = _d.next(); !_e.done; _e = _d.next()) { | ||
var name = _e.value; | ||
var lname = name.toLowerCase(); | ||
if (lname.substr(0, 6) === "x-amz-") { | ||
query[name] = headers[name]; | ||
delete headers[name]; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_e && !_e.done && (_a = _d.return)) _a.call(_d); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return __assign(__assign({}, request), { headers: headers, | ||
@@ -20,0 +30,0 @@ query: query }); |
@@ -0,1 +1,2 @@ | ||
import { __values } from "tslib"; | ||
import { cloneRequest } from "./cloneRequest"; | ||
@@ -7,2 +8,3 @@ import { GENERATED_HEADERS } from "./constants"; | ||
export function prepareRequest(request) { | ||
var e_1, _a; | ||
// Create a clone of the request object that does not clone the body | ||
@@ -13,10 +15,19 @@ request = | ||
: cloneRequest(request); | ||
for (var _i = 0, _a = Object.keys(request.headers); _i < _a.length; _i++) { | ||
var headerName = _a[_i]; | ||
if (GENERATED_HEADERS.indexOf(headerName.toLowerCase()) > -1) { | ||
delete request.headers[headerName]; | ||
try { | ||
for (var _b = __values(Object.keys(request.headers)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var headerName = _c.value; | ||
if (GENERATED_HEADERS.indexOf(headerName.toLowerCase()) > -1) { | ||
delete request.headers[headerName]; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return request; | ||
} | ||
//# sourceMappingURL=prepareRequest.js.map |
@@ -1,2 +0,2 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { __awaiter, __generator, __read } from "tslib"; | ||
import { createScope, getSigningKey } from "./credentialDerivation"; | ||
@@ -47,3 +47,3 @@ import { getCanonicalHeaders } from "./getCanonicalHeaders"; | ||
case 1: | ||
_a = _l.sent(), region = _a[0], credentials = _a[1]; | ||
_a = __read.apply(void 0, [_l.sent(), 2]), region = _a[0], credentials = _a[1]; | ||
_b = options.signingDate, signingDate = _b === void 0 ? new Date() : _b, _c = options.expiresIn, expiresIn = _c === void 0 ? 3600 : _c, unsignableHeaders = options.unsignableHeaders, signableHeaders = options.signableHeaders; | ||
@@ -105,5 +105,5 @@ _d = formatDate(signingDate), longDate = _d.longDate, shortDate = _d.shortDate; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var region, _d, shortDate, longDate, scope, hashedPayload, hash, hashedHeaders, _e, stringToSign; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
var _d, region, _e, shortDate, longDate, scope, hashedPayload, hash, hashedHeaders, _f, stringToSign; | ||
return __generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: return [4 /*yield*/, Promise.all([ | ||
@@ -114,14 +114,14 @@ this.regionProvider(), | ||
case 1: | ||
region = (_f.sent())[0]; | ||
_d = formatDate(signingDate), shortDate = _d.shortDate, longDate = _d.longDate; | ||
_d = __read.apply(void 0, [_g.sent(), 1]), region = _d[0]; | ||
_e = formatDate(signingDate), shortDate = _e.shortDate, longDate = _e.longDate; | ||
scope = createScope(shortDate, region, this.service); | ||
return [4 /*yield*/, getPayloadHash({ headers: {}, body: payload }, this.sha256)]; | ||
case 2: | ||
hashedPayload = _f.sent(); | ||
hashedPayload = _g.sent(); | ||
hash = new this.sha256(); | ||
hash.update(headers); | ||
_e = toHex; | ||
_f = toHex; | ||
return [4 /*yield*/, hash.digest()]; | ||
case 3: | ||
hashedHeaders = _e.apply(void 0, [_f.sent()]); | ||
hashedHeaders = _f.apply(void 0, [_g.sent()]); | ||
stringToSign = [ | ||
@@ -151,3 +151,3 @@ EVENT_ALGORITHM_IDENTIFIER, | ||
case 1: | ||
_c = _g.sent(), region = _c[0], credentials = _c[1]; | ||
_c = __read.apply(void 0, [_g.sent(), 2]), region = _c[0], credentials = _c[1]; | ||
shortDate = formatDate(signingDate).shortDate; | ||
@@ -177,3 +177,3 @@ _e = (_d = this.sha256).bind; | ||
case 1: | ||
_d = _f.sent(), region = _d[0], credentials = _d[1]; | ||
_d = __read.apply(void 0, [_f.sent(), 2]), region = _d[0], credentials = _d[1]; | ||
request = prepareRequest(requestToSign); | ||
@@ -180,0 +180,0 @@ _e = formatDate(signingDate), longDate = _e.longDate, shortDate = _e.shortDate; |
{ | ||
"name": "@aws-sdk/signature-v4", | ||
"version": "1.0.0-gamma.1", | ||
"version": "1.0.0-gamma.2", | ||
"description": "A standalone implementation of the AWS Signature V4 request signing algorithm", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/es/index.js", | ||
"types": "./dist/cjs/index.d.ts", | ||
"scripts": { | ||
"build:cjs": "tsc -p tsconfig.json", | ||
"build:cjs": "tsc -p tsconfig.cjs.json", | ||
"build:es": "tsc -p tsconfig.es.json", | ||
@@ -21,6 +22,6 @@ "build": "yarn build:es && yarn build:cjs", | ||
"dependencies": { | ||
"@aws-sdk/is-array-buffer": "1.0.0-gamma.1", | ||
"@aws-sdk/types": "1.0.0-gamma.1", | ||
"@aws-sdk/util-hex-encoding": "1.0.0-gamma.1", | ||
"@aws-sdk/util-uri-escape": "1.0.0-gamma.1", | ||
"@aws-sdk/is-array-buffer": "1.0.0-gamma.2", | ||
"@aws-sdk/types": "1.0.0-gamma.2", | ||
"@aws-sdk/util-hex-encoding": "1.0.0-gamma.2", | ||
"@aws-sdk/util-uri-escape": "1.0.0-gamma.2", | ||
"tslib": "^1.8.0" | ||
@@ -30,9 +31,8 @@ }, | ||
"@aws-crypto/sha256-js": "^1.0.0-alpha.0", | ||
"@aws-sdk/protocol-http": "1.0.0-gamma.1", | ||
"@aws-sdk/util-buffer-from": "1.0.0-gamma.1", | ||
"@types/jest": "^25.1.4", | ||
"jest": "^25.1.0", | ||
"@aws-sdk/protocol-http": "1.0.0-gamma.2", | ||
"@aws-sdk/util-buffer-from": "1.0.0-gamma.2", | ||
"@types/jest": "^26.0.4", | ||
"jest": "^26.1.0", | ||
"typescript": "~3.8.3" | ||
}, | ||
"types": "./dist/cjs/index.d.ts" | ||
} | ||
} |
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "esNext", | ||
"moduleResolution": "node", | ||
"lib": ["es5", "es2015.promise", "es2015.collection"], | ||
"declaration": true, | ||
@@ -17,4 +12,11 @@ "sourceMap": true, | ||
"noUnusedLocals": true, | ||
"baseUrl": ".", | ||
"target": "es5", | ||
"module": "esNext", | ||
"moduleResolution": "node", | ||
"lib": ["es5", "es2015.promise", "es2015.collection"], | ||
"incremental": true | ||
} | ||
}, | ||
"extends": "../../tsconfig.es.json", | ||
"include": ["src/"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
229552
2449
+ Added@aws-sdk/is-array-buffer@1.0.0-gamma.2(transitive)
+ Added@aws-sdk/types@1.0.0-gamma.2(transitive)
+ Added@aws-sdk/util-hex-encoding@1.0.0-gamma.2(transitive)
+ Added@aws-sdk/util-uri-escape@1.0.0-gamma.2(transitive)
- Removed@aws-sdk/is-array-buffer@1.0.0-gamma.1(transitive)
- Removed@aws-sdk/types@1.0.0-gamma.1(transitive)
- Removed@aws-sdk/util-hex-encoding@1.0.0-gamma.1(transitive)
- Removed@aws-sdk/util-uri-escape@1.0.0-gamma.1(transitive)
Updated@aws-sdk/types@1.0.0-gamma.2