@aws-sdk/signature-v4-crt 3.1067.0 → 3.1069.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.
- package/dist-cjs/index.js +32 -34
- package/package.json +7 -7
package/dist-cjs/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var protocols = require('@smithy/core/protocols');
|
|
7
|
-
var signatureV4 = require('@smithy/signature-v4');
|
|
1
|
+
const { signatureV4CrtContainer } = require("@aws-sdk/signature-v4-multi-region");
|
|
2
|
+
const { auth, io, http } = require("@aws-sdk/crt-loader");
|
|
3
|
+
const { normalizeProvider } = require("@smithy/core/client");
|
|
4
|
+
const { parseQueryString } = require("@smithy/core/protocols");
|
|
5
|
+
const { moveHeadersToQuery, prepareRequest, getPayloadHash, getCanonicalQuery } = require("@smithy/signature-v4");
|
|
8
6
|
|
|
9
7
|
const SHA256_HEADER = "x-amz-content-sha256";
|
|
10
8
|
const MAX_PRESIGNED_TTL = 60 * 60 * 24 * 7;
|
|
@@ -21,9 +19,9 @@ function deleteHeader(soughtHeader, headers) {
|
|
|
21
19
|
function sdkHttpRequest2crtHttpRequest(sdkRequest) {
|
|
22
20
|
deleteHeader(SHA256_HEADER, sdkRequest.headers);
|
|
23
21
|
const headersArray = Object.entries(sdkRequest.headers);
|
|
24
|
-
const crtHttpHeaders = new
|
|
25
|
-
const queryString =
|
|
26
|
-
return new
|
|
22
|
+
const crtHttpHeaders = new http.HttpHeaders(headersArray);
|
|
23
|
+
const queryString = getCanonicalQuery(sdkRequest);
|
|
24
|
+
return new http.HttpRequest(sdkRequest.method, sdkRequest.path + "?" + queryString, crtHttpHeaders);
|
|
27
25
|
}
|
|
28
26
|
class CrtSignerV4 {
|
|
29
27
|
service;
|
|
@@ -33,15 +31,15 @@ class CrtSignerV4 {
|
|
|
33
31
|
uriEscapePath;
|
|
34
32
|
applyChecksum;
|
|
35
33
|
signingAlgorithm;
|
|
36
|
-
constructor({ credentials, region, service, sha256, applyChecksum = true, uriEscapePath = true, signingAlgorithm =
|
|
34
|
+
constructor({ credentials, region, service, sha256, applyChecksum = true, uriEscapePath = true, signingAlgorithm = auth.AwsSigningAlgorithm.SigV4, }) {
|
|
37
35
|
this.service = service;
|
|
38
36
|
this.sha256 = sha256;
|
|
39
37
|
this.uriEscapePath = uriEscapePath;
|
|
40
38
|
this.signingAlgorithm = signingAlgorithm;
|
|
41
39
|
this.applyChecksum = applyChecksum;
|
|
42
|
-
this.regionProvider =
|
|
43
|
-
this.credentialProvider =
|
|
44
|
-
|
|
40
|
+
this.regionProvider = normalizeProvider(region);
|
|
41
|
+
this.credentialProvider = normalizeProvider(credentials);
|
|
42
|
+
io.enable_logging(io.LogLevel.ERROR);
|
|
45
43
|
}
|
|
46
44
|
async options2crtConfigure({ signingDate = new Date(), signableHeaders, unsignableHeaders, signingRegion, signingService, } = {}, viaHeader, payloadHash, expiresIn, _credentials) {
|
|
47
45
|
const credentials = _credentials ?? (await this.credentialProvider());
|
|
@@ -54,8 +52,8 @@ class CrtSignerV4 {
|
|
|
54
52
|
return {
|
|
55
53
|
algorithm: this.signingAlgorithm,
|
|
56
54
|
signature_type: viaHeader
|
|
57
|
-
?
|
|
58
|
-
:
|
|
55
|
+
? auth.AwsSignatureType.HttpRequestViaHeaders
|
|
56
|
+
: auth.AwsSignatureType.HttpRequestViaQueryParams,
|
|
59
57
|
provider: sdk2crtCredentialsProvider(credentials),
|
|
60
58
|
region: region,
|
|
61
59
|
service: service,
|
|
@@ -64,8 +62,8 @@ class CrtSignerV4 {
|
|
|
64
62
|
use_double_uri_encode: this.uriEscapePath,
|
|
65
63
|
signed_body_value: payloadHash,
|
|
66
64
|
signed_body_header: this.applyChecksum && viaHeader
|
|
67
|
-
?
|
|
68
|
-
:
|
|
65
|
+
? auth.AwsSignedBodyHeaderType.XAmzContentSha256
|
|
66
|
+
: auth.AwsSignedBodyHeaderType.None,
|
|
69
67
|
expiration_in_seconds: expiresIn,
|
|
70
68
|
};
|
|
71
69
|
}
|
|
@@ -73,20 +71,20 @@ class CrtSignerV4 {
|
|
|
73
71
|
if (options.expiresIn && options.expiresIn > MAX_PRESIGNED_TTL) {
|
|
74
72
|
return Promise.reject("Signature version 4 presigned URLs" + " must have an expiration date less than one week in" + " the future");
|
|
75
73
|
}
|
|
76
|
-
const request =
|
|
77
|
-
const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, false, await
|
|
74
|
+
const request = moveHeadersToQuery(prepareRequest(originalRequest));
|
|
75
|
+
const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, false, await getPayloadHash(originalRequest, this.sha256), options.expiresIn ? options.expiresIn : 3600));
|
|
78
76
|
request.query = this.getQueryParam(crtSignedRequest.path);
|
|
79
77
|
return request;
|
|
80
78
|
}
|
|
81
79
|
async sign(toSign, options) {
|
|
82
|
-
const request =
|
|
83
|
-
const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, true, await
|
|
80
|
+
const request = prepareRequest(toSign);
|
|
81
|
+
const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, true, await getPayloadHash(toSign, this.sha256)));
|
|
84
82
|
request.headers = crtSignedRequest.headers._flatten().reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
85
83
|
return request;
|
|
86
84
|
}
|
|
87
85
|
async signWithCredentials(toSign, credentials, options) {
|
|
88
|
-
const request =
|
|
89
|
-
const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, true, await
|
|
86
|
+
const request = prepareRequest(toSign);
|
|
87
|
+
const crtSignedRequest = await this.signRequest(request, await this.options2crtConfigure(options, true, await getPayloadHash(toSign, this.sha256), undefined, credentials));
|
|
90
88
|
request.headers = crtSignedRequest.headers._flatten().reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
91
89
|
return request;
|
|
92
90
|
}
|
|
@@ -99,36 +97,36 @@ class CrtSignerV4 {
|
|
|
99
97
|
return queryParam;
|
|
100
98
|
}
|
|
101
99
|
const queryString = crtPath.slice(start + 1, end);
|
|
102
|
-
return
|
|
100
|
+
return parseQueryString(queryString);
|
|
103
101
|
}
|
|
104
102
|
async signRequest(requestToSign, crtConfig) {
|
|
105
103
|
const request = sdkHttpRequest2crtHttpRequest(requestToSign);
|
|
106
104
|
try {
|
|
107
|
-
return await
|
|
105
|
+
return await auth.aws_sign_request(request, crtConfig);
|
|
108
106
|
}
|
|
109
107
|
catch (error) {
|
|
110
108
|
throw new Error(error);
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
async verifySigv4aSigning(request, signature, expectedCanonicalRequest, eccPubKeyX, eccPubKeyY, options = {}) {
|
|
114
|
-
const sdkRequest =
|
|
112
|
+
const sdkRequest = prepareRequest(request);
|
|
115
113
|
const crtRequest = sdkHttpRequest2crtHttpRequest(sdkRequest);
|
|
116
|
-
const payloadHash = await
|
|
114
|
+
const payloadHash = await getPayloadHash(request, this.sha256);
|
|
117
115
|
const crtConfig = await this.options2crtConfigure(options, true, payloadHash);
|
|
118
|
-
return
|
|
116
|
+
return auth.aws_verify_sigv4a_signing(crtRequest, crtConfig, expectedCanonicalRequest, signature, eccPubKeyX, eccPubKeyY);
|
|
119
117
|
}
|
|
120
118
|
async verifySigv4aPreSigning(request, signature, expectedCanonicalRequest, eccPubKeyX, eccPubKeyY, options = {}) {
|
|
121
119
|
if (typeof signature != "string") {
|
|
122
120
|
return false;
|
|
123
121
|
}
|
|
124
|
-
const sdkRequest =
|
|
122
|
+
const sdkRequest = prepareRequest(request);
|
|
125
123
|
const crtRequest = sdkHttpRequest2crtHttpRequest(sdkRequest);
|
|
126
|
-
const crtConfig = await this.options2crtConfigure(options, false, await
|
|
127
|
-
return
|
|
124
|
+
const crtConfig = await this.options2crtConfigure(options, false, await getPayloadHash(request, this.sha256), options.expiresIn ? options.expiresIn : 3600);
|
|
125
|
+
return auth.aws_verify_sigv4a_signing(crtRequest, crtConfig, expectedCanonicalRequest, signature, eccPubKeyX, eccPubKeyY);
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
function sdk2crtCredentialsProvider(credentials) {
|
|
131
|
-
return
|
|
129
|
+
return auth.AwsCredentialsProvider.newStatic(credentials.accessKeyId, credentials.secretAccessKey, credentials.sessionToken);
|
|
132
130
|
}
|
|
133
131
|
function getHeadersUnsignable(unsignableHeaders, signableHeaders) {
|
|
134
132
|
if (!unsignableHeaders) {
|
|
@@ -146,6 +144,6 @@ function getHeadersUnsignable(unsignableHeaders, signableHeaders) {
|
|
|
146
144
|
return [...result];
|
|
147
145
|
}
|
|
148
146
|
|
|
149
|
-
|
|
147
|
+
signatureV4CrtContainer.CrtSignerV4 = CrtSignerV4;
|
|
150
148
|
|
|
151
149
|
exports.CrtSignerV4 = CrtSignerV4;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/signature-v4-crt",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1069.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",
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
|
|
10
10
|
"build:cjs": "node ../../scripts/compilation/inline",
|
|
11
|
-
"build:es": "tsc -p tsconfig.es.json",
|
|
11
|
+
"build:es": "premove dist-es && tsc -p tsconfig.es.json",
|
|
12
12
|
"build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
|
|
13
|
-
"build:types": "tsc -p tsconfig.types.json",
|
|
13
|
+
"build:types": "premove dist-types && tsc -p tsconfig.types.json",
|
|
14
14
|
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
15
|
-
"clean": "premove dist-cjs dist-es dist-types
|
|
15
|
+
"clean": "premove dist-cjs dist-es dist-types",
|
|
16
16
|
"extract:docs": "api-extractor run --local",
|
|
17
17
|
"test": "jest"
|
|
18
18
|
},
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@aws-sdk/crt-loader": "^3.972.
|
|
27
|
-
"@aws-sdk/signature-v4-multi-region": "^3.996.
|
|
28
|
-
"@aws-sdk/types": "^3.973.
|
|
26
|
+
"@aws-sdk/crt-loader": "^3.972.51",
|
|
27
|
+
"@aws-sdk/signature-v4-multi-region": "^3.996.35",
|
|
28
|
+
"@aws-sdk/types": "^3.973.13",
|
|
29
29
|
"@smithy/core": "^3.24.6",
|
|
30
30
|
"@smithy/signature-v4": "^5.4.6",
|
|
31
31
|
"@smithy/types": "^4.14.3",
|