@aws-sdk/signature-v4-crt 3.899.0 → 3.906.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist-cjs/index.js +130 -254
  2. package/package.json +9 -9
package/dist-cjs/index.js CHANGED
@@ -1,275 +1,151 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
20
2
 
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- CrtSignerV4: () => CrtSignerV4
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
- var import_signature_v4_multi_region = require("@aws-sdk/signature-v4-multi-region");
3
+ var signatureV4MultiRegion = require('@aws-sdk/signature-v4-multi-region');
4
+ var crtLoader = require('@aws-sdk/crt-loader');
5
+ var querystringParser = require('@smithy/querystring-parser');
6
+ var signatureV4 = require('@smithy/signature-v4');
7
+ var utilMiddleware = require('@smithy/util-middleware');
28
8
 
29
- // src/CrtSignerV4.ts
30
- var import_crt_loader = require("@aws-sdk/crt-loader");
31
- var import_querystring_parser = require("@smithy/querystring-parser");
32
- var import_signature_v4 = require("@smithy/signature-v4");
33
- var import_util_middleware = require("@smithy/util-middleware");
9
+ const SHA256_HEADER = "x-amz-content-sha256";
10
+ const MAX_PRESIGNED_TTL = 60 * 60 * 24 * 7;
34
11
 
35
- // src/constants.ts
36
- var AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
37
- var SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
38
- var TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
39
- var AMZ_DATE_HEADER = AMZ_DATE_QUERY_PARAM.toLowerCase();
40
- var SIGNATURE_HEADER = SIGNATURE_QUERY_PARAM.toLowerCase();
41
- var SHA256_HEADER = "x-amz-content-sha256";
42
- var TOKEN_HEADER = TOKEN_QUERY_PARAM.toLowerCase();
43
- var MAX_PRESIGNED_TTL = 60 * 60 * 24 * 7;
44
-
45
- // src/headerUtil.ts
46
12
  function deleteHeader(soughtHeader, headers) {
47
- soughtHeader = soughtHeader.toLowerCase();
48
- for (const headerName of Object.keys(headers)) {
49
- if (soughtHeader === headerName.toLowerCase()) {
50
- delete headers[headerName];
13
+ soughtHeader = soughtHeader.toLowerCase();
14
+ for (const headerName of Object.keys(headers)) {
15
+ if (soughtHeader === headerName.toLowerCase()) {
16
+ delete headers[headerName];
17
+ }
51
18
  }
52
- }
53
19
  }
54
- __name(deleteHeader, "deleteHeader");
55
20
 
56
- // src/CrtSignerV4.ts
57
21
  function sdkHttpRequest2crtHttpRequest(sdkRequest) {
58
- deleteHeader(SHA256_HEADER, sdkRequest.headers);
59
- const headersArray = Object.entries(sdkRequest.headers);
60
- const crtHttpHeaders = new import_crt_loader.http.HttpHeaders(headersArray);
61
- const queryString = (0, import_signature_v4.getCanonicalQuery)(sdkRequest);
62
- return new import_crt_loader.http.HttpRequest(sdkRequest.method, sdkRequest.path + "?" + queryString, crtHttpHeaders);
22
+ deleteHeader(SHA256_HEADER, sdkRequest.headers);
23
+ const headersArray = Object.entries(sdkRequest.headers);
24
+ const crtHttpHeaders = new crtLoader.http.HttpHeaders(headersArray);
25
+ const queryString = signatureV4.getCanonicalQuery(sdkRequest);
26
+ return new crtLoader.http.HttpRequest(sdkRequest.method, sdkRequest.path + "?" + queryString, crtHttpHeaders);
63
27
  }
64
- __name(sdkHttpRequest2crtHttpRequest, "sdkHttpRequest2crtHttpRequest");
65
- var CrtSignerV4 = class {
66
- static {
67
- __name(this, "CrtSignerV4");
68
- }
69
- service;
70
- regionProvider;
71
- credentialProvider;
72
- sha256;
73
- uriEscapePath;
74
- applyChecksum;
75
- signingAlgorithm;
76
- constructor({
77
- credentials,
78
- region,
79
- service,
80
- sha256,
81
- applyChecksum = true,
82
- uriEscapePath = true,
83
- signingAlgorithm = import_crt_loader.auth.AwsSigningAlgorithm.SigV4
84
- }) {
85
- this.service = service;
86
- this.sha256 = sha256;
87
- this.uriEscapePath = uriEscapePath;
88
- this.signingAlgorithm = signingAlgorithm;
89
- this.applyChecksum = applyChecksum;
90
- this.regionProvider = (0, import_util_middleware.normalizeProvider)(region);
91
- this.credentialProvider = (0, import_util_middleware.normalizeProvider)(credentials);
92
- import_crt_loader.io.enable_logging(import_crt_loader.io.LogLevel.ERROR);
93
- }
94
- async options2crtConfigure({
95
- signingDate = /* @__PURE__ */ new Date(),
96
- signableHeaders,
97
- unsignableHeaders,
98
- signingRegion,
99
- signingService
100
- } = {}, viaHeader, payloadHash, expiresIn, _credentials) {
101
- const credentials = _credentials ?? await this.credentialProvider();
102
- const region = signingRegion ?? await this.regionProvider();
103
- const service = signingService ?? this.service;
104
- if (signableHeaders?.has("x-amzn-trace-id") || signableHeaders?.has("user-agent")) {
105
- throw new Error("internal check (x-amzn-trace-id, user-agent) is not supported to be included to sign with CRT.");
28
+ class CrtSignerV4 {
29
+ service;
30
+ regionProvider;
31
+ credentialProvider;
32
+ sha256;
33
+ uriEscapePath;
34
+ applyChecksum;
35
+ signingAlgorithm;
36
+ constructor({ credentials, region, service, sha256, applyChecksum = true, uriEscapePath = true, signingAlgorithm = crtLoader.auth.AwsSigningAlgorithm.SigV4, }) {
37
+ this.service = service;
38
+ this.sha256 = sha256;
39
+ this.uriEscapePath = uriEscapePath;
40
+ this.signingAlgorithm = signingAlgorithm;
41
+ this.applyChecksum = applyChecksum;
42
+ this.regionProvider = utilMiddleware.normalizeProvider(region);
43
+ this.credentialProvider = utilMiddleware.normalizeProvider(credentials);
44
+ crtLoader.io.enable_logging(crtLoader.io.LogLevel.ERROR);
45
+ }
46
+ async options2crtConfigure({ signingDate = new Date(), signableHeaders, unsignableHeaders, signingRegion, signingService, } = {}, viaHeader, payloadHash, expiresIn, _credentials) {
47
+ const credentials = _credentials ?? (await this.credentialProvider());
48
+ const region = signingRegion ?? (await this.regionProvider());
49
+ const service = signingService ?? this.service;
50
+ if (signableHeaders?.has("x-amzn-trace-id") || signableHeaders?.has("user-agent")) {
51
+ throw new Error("internal check (x-amzn-trace-id, user-agent) is not supported to be included to sign with CRT.");
52
+ }
53
+ const headersUnsignable = getHeadersUnsignable(unsignableHeaders, signableHeaders);
54
+ return {
55
+ algorithm: this.signingAlgorithm,
56
+ signature_type: viaHeader
57
+ ? crtLoader.auth.AwsSignatureType.HttpRequestViaHeaders
58
+ : crtLoader.auth.AwsSignatureType.HttpRequestViaQueryParams,
59
+ provider: sdk2crtCredentialsProvider(credentials),
60
+ region: region,
61
+ service: service,
62
+ date: new Date(signingDate),
63
+ header_blacklist: headersUnsignable,
64
+ use_double_uri_encode: this.uriEscapePath,
65
+ signed_body_value: payloadHash,
66
+ signed_body_header: this.applyChecksum && viaHeader
67
+ ? crtLoader.auth.AwsSignedBodyHeaderType.XAmzContentSha256
68
+ : crtLoader.auth.AwsSignedBodyHeaderType.None,
69
+ expiration_in_seconds: expiresIn,
70
+ };
71
+ }
72
+ async presign(originalRequest, options = {}) {
73
+ if (options.expiresIn && options.expiresIn > MAX_PRESIGNED_TTL) {
74
+ return Promise.reject("Signature version 4 presigned URLs" + " must have an expiration date less than one week in" + " the future");
75
+ }
76
+ const request = signatureV4.moveHeadersToQuery(signatureV4.prepareRequest(originalRequest));
77
+ const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, false, await signatureV4.getPayloadHash(originalRequest, this.sha256), options.expiresIn ? options.expiresIn : 3600));
78
+ request.query = this.getQueryParam(crtSignedRequest.path);
79
+ return request;
80
+ }
81
+ async sign(toSign, options) {
82
+ const request = signatureV4.prepareRequest(toSign);
83
+ const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, true, await signatureV4.getPayloadHash(toSign, this.sha256)));
84
+ request.headers = crtSignedRequest.headers._flatten().reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
85
+ return request;
86
+ }
87
+ async signWithCredentials(toSign, credentials, options) {
88
+ const request = signatureV4.prepareRequest(toSign);
89
+ const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, true, await signatureV4.getPayloadHash(toSign, this.sha256), undefined, credentials));
90
+ request.headers = crtSignedRequest.headers._flatten().reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
91
+ return request;
106
92
  }
107
- const headersUnsignable = getHeadersUnsignable(unsignableHeaders, signableHeaders);
108
- return {
109
- algorithm: this.signingAlgorithm,
110
- signature_type: viaHeader ? import_crt_loader.auth.AwsSignatureType.HttpRequestViaHeaders : import_crt_loader.auth.AwsSignatureType.HttpRequestViaQueryParams,
111
- provider: sdk2crtCredentialsProvider(credentials),
112
- region,
113
- service,
114
- date: new Date(signingDate),
115
- header_blacklist: headersUnsignable,
116
- use_double_uri_encode: this.uriEscapePath,
117
- /* Always set the body value by the result from SDK */
118
- signed_body_value: payloadHash,
119
- signed_body_header: this.applyChecksum && viaHeader ? import_crt_loader.auth.AwsSignedBodyHeaderType.XAmzContentSha256 : import_crt_loader.auth.AwsSignedBodyHeaderType.None,
120
- expiration_in_seconds: expiresIn
121
- };
122
- }
123
- async presign(originalRequest, options = {}) {
124
- if (options.expiresIn && options.expiresIn > MAX_PRESIGNED_TTL) {
125
- return Promise.reject(
126
- "Signature version 4 presigned URLs must have an expiration date less than one week in the future"
127
- );
93
+ getQueryParam(crtPath) {
94
+ const start = crtPath.search(/\?/);
95
+ const startHash = crtPath.search(/\#/);
96
+ const end = startHash == -1 ? undefined : startHash;
97
+ const queryParam = {};
98
+ if (start == -1) {
99
+ return queryParam;
100
+ }
101
+ const queryString = crtPath.slice(start + 1, end);
102
+ return querystringParser.parseQueryString(queryString);
128
103
  }
129
- const request = (0, import_signature_v4.moveHeadersToQuery)((0, import_signature_v4.prepareRequest)(originalRequest));
130
- const crtSignedRequest = await this.signRequest(
131
- request,
132
- await this.options2crtConfigure(
133
- options,
134
- false,
135
- await (0, import_signature_v4.getPayloadHash)(originalRequest, this.sha256),
136
- options.expiresIn ? options.expiresIn : 3600
137
- )
138
- );
139
- request.query = this.getQueryParam(crtSignedRequest.path);
140
- return request;
141
- }
142
- async sign(toSign, options) {
143
- const request = (0, import_signature_v4.prepareRequest)(toSign);
144
- const crtSignedRequest = await this.signRequest(
145
- request,
146
- await this.options2crtConfigure(options, true, await (0, import_signature_v4.getPayloadHash)(toSign, this.sha256))
147
- );
148
- request.headers = crtSignedRequest.headers._flatten().reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
149
- return request;
150
- }
151
- /**
152
- * Sign with alternate credentials to the ones provided in the constructor.
153
- */
154
- async signWithCredentials(toSign, credentials, options) {
155
- const request = (0, import_signature_v4.prepareRequest)(toSign);
156
- const crtSignedRequest = await this.signRequest(
157
- request,
158
- await this.options2crtConfigure(
159
- options,
160
- true,
161
- await (0, import_signature_v4.getPayloadHash)(toSign, this.sha256),
162
- void 0,
163
- credentials
164
- )
165
- );
166
- request.headers = crtSignedRequest.headers._flatten().reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
167
- return request;
168
- }
169
- /* Get the query parameters from crtPath */
170
- getQueryParam(crtPath) {
171
- const start = crtPath.search(/\?/);
172
- const startHash = crtPath.search(/\#/);
173
- const end = startHash == -1 ? void 0 : startHash;
174
- const queryParam = {};
175
- if (start == -1) {
176
- return queryParam;
104
+ async signRequest(requestToSign, crtConfig) {
105
+ const request = sdkHttpRequest2crtHttpRequest(requestToSign);
106
+ try {
107
+ return await crtLoader.auth.aws_sign_request(request, crtConfig);
108
+ }
109
+ catch (error) {
110
+ throw new Error(error);
111
+ }
177
112
  }
178
- const queryString = crtPath.slice(start + 1, end);
179
- return (0, import_querystring_parser.parseQueryString)(queryString);
180
- }
181
- async signRequest(requestToSign, crtConfig) {
182
- const request = sdkHttpRequest2crtHttpRequest(requestToSign);
183
- try {
184
- return await import_crt_loader.auth.aws_sign_request(request, crtConfig);
185
- } catch (error) {
186
- throw new Error(error);
113
+ async verifySigv4aSigning(request, signature, expectedCanonicalRequest, eccPubKeyX, eccPubKeyY, options = {}) {
114
+ const sdkRequest = signatureV4.prepareRequest(request);
115
+ const crtRequest = sdkHttpRequest2crtHttpRequest(sdkRequest);
116
+ const payloadHash = await signatureV4.getPayloadHash(request, this.sha256);
117
+ const crtConfig = await this.options2crtConfigure(options, true, payloadHash);
118
+ return crtLoader.auth.aws_verify_sigv4a_signing(crtRequest, crtConfig, expectedCanonicalRequest, signature, eccPubKeyX, eccPubKeyY);
187
119
  }
188
- }
189
- /**
190
- * Test-only API used for cross-library signing verification tests. Verify sign.
191
- *
192
- * Verifies:
193
- * (1) The canonical request generated during sigv4a signing of the request matches what is passed in
194
- * (2) The signature passed in is a valid ECDSA signature of the hashed string-to-sign derived from the
195
- * canonical request
196
- *
197
- * @param request The original request used for signing
198
- * @param signature the actual signature computed from a previous signing of the signable
199
- * @param expectedCanonicalRequest expected result when building the canonical request
200
- * @param eccPubKeyX the x coordinate of the public part of the ecc key to verify the signature
201
- * @param eccPubKeyY the y coordinate of the public part of the ecc key to verify the signature
202
- * @param options the RequestSigningArguments used for signing
203
- *
204
- * @return True, if the verification succeed. Otherwise, false.
205
- */
206
- async verifySigv4aSigning(request, signature, expectedCanonicalRequest, eccPubKeyX, eccPubKeyY, options = {}) {
207
- const sdkRequest = (0, import_signature_v4.prepareRequest)(request);
208
- const crtRequest = sdkHttpRequest2crtHttpRequest(sdkRequest);
209
- const payloadHash = await (0, import_signature_v4.getPayloadHash)(request, this.sha256);
210
- const crtConfig = await this.options2crtConfigure(options, true, payloadHash);
211
- return import_crt_loader.auth.aws_verify_sigv4a_signing(
212
- crtRequest,
213
- crtConfig,
214
- expectedCanonicalRequest,
215
- signature,
216
- eccPubKeyX,
217
- eccPubKeyY
218
- );
219
- }
220
- /* Verify presign */
221
- async verifySigv4aPreSigning(request, signature, expectedCanonicalRequest, eccPubKeyX, eccPubKeyY, options = {}) {
222
- if (typeof signature != "string") {
223
- return false;
120
+ async verifySigv4aPreSigning(request, signature, expectedCanonicalRequest, eccPubKeyX, eccPubKeyY, options = {}) {
121
+ if (typeof signature != "string") {
122
+ return false;
123
+ }
124
+ const sdkRequest = signatureV4.prepareRequest(request);
125
+ const crtRequest = sdkHttpRequest2crtHttpRequest(sdkRequest);
126
+ const crtConfig = await this.options2crtConfigure(options, false, await signatureV4.getPayloadHash(request, this.sha256), options.expiresIn ? options.expiresIn : 3600);
127
+ return crtLoader.auth.aws_verify_sigv4a_signing(crtRequest, crtConfig, expectedCanonicalRequest, signature, eccPubKeyX, eccPubKeyY);
224
128
  }
225
- const sdkRequest = (0, import_signature_v4.prepareRequest)(request);
226
- const crtRequest = sdkHttpRequest2crtHttpRequest(sdkRequest);
227
- const crtConfig = await this.options2crtConfigure(
228
- options,
229
- false,
230
- await (0, import_signature_v4.getPayloadHash)(request, this.sha256),
231
- options.expiresIn ? options.expiresIn : 3600
232
- );
233
- return import_crt_loader.auth.aws_verify_sigv4a_signing(
234
- crtRequest,
235
- crtConfig,
236
- expectedCanonicalRequest,
237
- signature,
238
- eccPubKeyX,
239
- eccPubKeyY
240
- );
241
- }
242
- };
129
+ }
243
130
  function sdk2crtCredentialsProvider(credentials) {
244
- return import_crt_loader.auth.AwsCredentialsProvider.newStatic(
245
- credentials.accessKeyId,
246
- credentials.secretAccessKey,
247
- credentials.sessionToken
248
- );
131
+ return crtLoader.auth.AwsCredentialsProvider.newStatic(credentials.accessKeyId, credentials.secretAccessKey, credentials.sessionToken);
249
132
  }
250
- __name(sdk2crtCredentialsProvider, "sdk2crtCredentialsProvider");
251
133
  function getHeadersUnsignable(unsignableHeaders, signableHeaders) {
252
- if (!unsignableHeaders) {
253
- return [];
254
- }
255
- if (!signableHeaders) {
256
- return [...unsignableHeaders];
257
- }
258
- const result = /* @__PURE__ */ new Set([...unsignableHeaders]);
259
- for (let it = signableHeaders.values(), val = null; val = it.next().value; ) {
260
- if (result.has(val)) {
261
- result.delete(val);
134
+ if (!unsignableHeaders) {
135
+ return [];
136
+ }
137
+ if (!signableHeaders) {
138
+ return [...unsignableHeaders];
262
139
  }
263
- }
264
- return [...result];
140
+ const result = new Set([...unsignableHeaders]);
141
+ for (let it = signableHeaders.values(), val = null; (val = it.next().value);) {
142
+ if (result.has(val)) {
143
+ result.delete(val);
144
+ }
145
+ }
146
+ return [...result];
265
147
  }
266
- __name(getHeadersUnsignable, "getHeadersUnsignable");
267
-
268
- // src/index.ts
269
- import_signature_v4_multi_region.signatureV4CrtContainer.CrtSignerV4 = CrtSignerV4;
270
- // Annotate the CommonJS export names for ESM import in node:
271
148
 
272
- 0 && (module.exports = {
273
- CrtSignerV4
274
- });
149
+ signatureV4MultiRegion.signatureV4CrtContainer.CrtSignerV4 = CrtSignerV4;
275
150
 
151
+ exports.CrtSignerV4 = CrtSignerV4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/signature-v4-crt",
3
- "version": "3.899.0",
3
+ "version": "3.906.0",
4
4
  "description": "A revision of AWS Signature V4 request signer based on AWS Common Runtime https://github.com/awslabs/aws-crt-nodejs",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -23,18 +23,18 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
- "@aws-sdk/crt-loader": "3.899.0",
27
- "@aws-sdk/signature-v4-multi-region": "3.899.0",
28
- "@aws-sdk/types": "3.893.0",
29
- "@smithy/querystring-parser": "^4.1.1",
30
- "@smithy/signature-v4": "^5.2.1",
31
- "@smithy/types": "^4.5.0",
32
- "@smithy/util-middleware": "^4.1.1",
26
+ "@aws-sdk/crt-loader": "3.906.0",
27
+ "@aws-sdk/signature-v4-multi-region": "3.906.0",
28
+ "@aws-sdk/types": "3.901.0",
29
+ "@smithy/querystring-parser": "^4.2.0",
30
+ "@smithy/signature-v4": "^5.3.0",
31
+ "@smithy/types": "^4.6.0",
32
+ "@smithy/util-middleware": "^4.2.0",
33
33
  "tslib": "^2.6.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@aws-crypto/sha256-js": "5.2.0",
37
- "@smithy/protocol-http": "^5.2.1",
37
+ "@smithy/protocol-http": "^5.3.0",
38
38
  "@tsconfig/recommended": "1.0.1",
39
39
  "concurrently": "7.0.0",
40
40
  "downlevel-dts": "0.10.1",