@arokodev/cli 0.1.0-alpha.5 → 0.1.0-alpha.8
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/node_modules/@pairmesh/client/dist/build-info.generated.d.ts +12 -12
- package/node_modules/@pairmesh/client/dist/build-info.generated.js +6 -6
- package/node_modules/@pairmesh/client/dist/connectivity/relay/hosted-server.js +1 -1
- package/node_modules/@pairmesh/client/dist/session/schemas.d.ts +10 -10
- package/node_modules/@pairmesh/client/dist/session/schemas.d.ts.map +1 -1
- package/node_modules/@pairmesh/client/package.json +5 -5
- package/node_modules/@pairmesh/coordination/package.json +5 -5
- package/node_modules/@pairmesh/mcp/package.json +5 -5
- package/node_modules/@pairmesh/permissions/package.json +2 -2
- package/node_modules/@pairmesh/protocol/dist/action.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/inspection-execution.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/inspection-thread.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/inspection-thread.d.ts.map +1 -1
- package/node_modules/@pairmesh/protocol/dist/inspection.d.ts +2 -2
- package/node_modules/@pairmesh/protocol/dist/pairing.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/progress-event.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/progress-event.d.ts.map +1 -1
- package/node_modules/@pairmesh/protocol/package.json +2 -2
- package/node_modules/@pairmesh/shared/package.json +1 -1
- package/node_modules/body-parser/README.md +17 -13
- package/node_modules/body-parser/lib/read.js +74 -57
- package/node_modules/body-parser/lib/types/json.js +11 -11
- package/node_modules/body-parser/lib/types/urlencoded.js +5 -5
- package/node_modules/body-parser/lib/utils.js +0 -15
- package/node_modules/body-parser/package.json +7 -12
- package/node_modules/encodeurl/README.md +14 -0
- package/node_modules/encodeurl/index.js +9 -11
- package/node_modules/encodeurl/package.json +13 -6
- package/node_modules/jose/README.md +2 -2
- package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +5 -4
- package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -4
- package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +5 -4
- package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +5 -5
- package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +5 -4
- package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +5 -5
- package/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -4
- package/node_modules/jose/dist/types/jws/compact/verify.d.ts +5 -5
- package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +5 -4
- package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +6 -5
- package/node_modules/jose/dist/types/jws/general/sign.d.ts +9 -6
- package/node_modules/jose/dist/types/jws/general/verify.d.ts +7 -5
- package/node_modules/jose/dist/types/jwt/decrypt.d.ts +10 -6
- package/node_modules/jose/dist/types/jwt/encrypt.d.ts +1 -1
- package/node_modules/jose/dist/types/jwt/sign.d.ts +1 -1
- package/node_modules/jose/dist/types/jwt/unsecured.d.ts +3 -1
- package/node_modules/jose/dist/types/jwt/verify.d.ts +6 -5
- package/node_modules/jose/dist/types/key/export.d.ts +1 -1
- package/node_modules/jose/dist/types/key/generate_secret.d.ts +1 -1
- package/node_modules/jose/dist/types/key/import.d.ts +2 -2
- package/node_modules/jose/dist/types/types.d.ts +173 -107
- package/node_modules/jose/dist/types/util/decode_jwt.d.ts +3 -2
- package/node_modules/jose/dist/types/util/errors.d.ts +1 -1
- package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +3 -2
- package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +3 -3
- package/node_modules/jose/dist/webapi/jwk/thumbprint.js +8 -8
- package/node_modules/jose/dist/webapi/jwks/local.js +2 -1
- package/node_modules/jose/dist/webapi/jwks/remote.js +6 -4
- package/node_modules/jose/dist/webapi/jws/general/sign.js +3 -3
- package/node_modules/jose/dist/webapi/jws/general/verify.js +5 -11
- package/node_modules/jose/dist/webapi/jwt/encrypt.js +6 -9
- package/node_modules/jose/dist/webapi/jwt/sign.js +2 -2
- package/node_modules/jose/dist/webapi/jwt/unsecured.js +3 -3
- package/node_modules/jose/dist/webapi/key/generate_secret.js +4 -4
- package/node_modules/jose/dist/webapi/lib/asn1.js +2 -2
- package/node_modules/jose/dist/webapi/lib/buffer_utils.js +4 -4
- package/node_modules/jose/dist/webapi/lib/content_encryption.js +8 -8
- package/node_modules/jose/dist/webapi/lib/deflate.js +2 -1
- package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +26 -23
- package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +5 -5
- package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +2 -2
- package/node_modules/jose/dist/webapi/lib/jws_sign.js +11 -11
- package/node_modules/jose/dist/webapi/lib/jws_verify.js +19 -16
- package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +48 -44
- package/node_modules/jose/dist/webapi/lib/key.js +6 -4
- package/node_modules/jose/dist/webapi/lib/key_management.js +17 -18
- package/node_modules/jose/dist/webapi/lib/validate.js +10 -10
- package/node_modules/jose/dist/webapi/util/decode_jwt.js +12 -12
- package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -5
- package/node_modules/jose/package.json +1 -1
- package/node_modules/object-inspect/CHANGELOG.md +31 -0
- package/node_modules/object-inspect/index.js +326 -24
- package/node_modules/object-inspect/package.json +22 -13
- package/node_modules/object-inspect/readme.markdown +4 -1
- package/node_modules/object-inspect/stringWidth.js +68 -0
- package/node_modules/object-inspect/stringWidthRanges.js +38 -0
- package/node_modules/on-finished/index.js +14 -2
- package/node_modules/on-finished/package.json +11 -7
- package/node_modules/qs/.editorconfig +1 -1
- package/node_modules/qs/.github/THREAT_MODEL.md +4 -2
- package/node_modules/qs/CHANGELOG.md +103 -14
- package/node_modules/qs/README.md +90 -9
- package/node_modules/qs/dist/qs.js +19 -19
- package/node_modules/qs/eslint.config.mjs +61 -50
- package/node_modules/qs/lib/formats.js +7 -2
- package/node_modules/qs/lib/parse.js +121 -12
- package/node_modules/qs/lib/stringify.js +9 -7
- package/node_modules/qs/lib/utils.js +158 -15
- package/node_modules/qs/package.json +8 -8
- package/node_modules/qs/test/parse.js +509 -2
- package/node_modules/qs/test/stringify.js +485 -33
- package/node_modules/qs/test/utils.js +245 -3
- package/node_modules/router/HISTORY.md +67 -52
- package/node_modules/router/README.md +222 -2
- package/node_modules/router/index.d.ts +188 -0
- package/node_modules/router/index.js +86 -50
- package/node_modules/router/lib/layer.js +154 -47
- package/node_modules/router/lib/param.js +47 -0
- package/node_modules/router/lib/route.d.ts +118 -0
- package/node_modules/router/lib/route.js +14 -8
- package/node_modules/router/lib/symbols.js +4 -0
- package/node_modules/router/lib/tracing.js +173 -0
- package/node_modules/router/package.json +24 -9
- package/node_modules/ws/README.md +22 -31
- package/node_modules/ws/lib/buffer-util.js +13 -2
- package/node_modules/ws/lib/receiver.js +8 -0
- package/node_modules/ws/lib/sender.js +4 -1
- package/node_modules/ws/lib/websocket-server.js +3 -0
- package/node_modules/ws/lib/websocket.js +66 -16
- package/node_modules/ws/package.json +1 -1
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
- package/node_modules/zod/src/v4/core/compile.ts +9 -0
- package/node_modules/zod/src/v4/core/schemas.ts +35 -1
- package/node_modules/zod/src/v4/core/util.ts +13 -0
- package/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.d.cts +3 -1
- package/node_modules/zod/v4/core/schemas.d.ts +3 -1
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.d.cts +2 -0
- package/node_modules/zod/v4/core/util.d.ts +2 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +7 -7
- package/node_modules/object-inspect/.eslintrc +0 -53
- package/node_modules/object-inspect/.nycrc +0 -13
- package/node_modules/object-inspect/example/all.js +0 -23
- package/node_modules/object-inspect/example/circular.js +0 -6
- package/node_modules/object-inspect/example/fn.js +0 -5
- package/node_modules/object-inspect/example/inspect.js +0 -10
- package/node_modules/object-inspect/test/bigint.js +0 -58
- package/node_modules/object-inspect/test/browser/dom.js +0 -15
- package/node_modules/object-inspect/test/circular.js +0 -16
- package/node_modules/object-inspect/test/deep.js +0 -12
- package/node_modules/object-inspect/test/element.js +0 -53
- package/node_modules/object-inspect/test/err.js +0 -48
- package/node_modules/object-inspect/test/fakes.js +0 -29
- package/node_modules/object-inspect/test/fn.js +0 -76
- package/node_modules/object-inspect/test/global.js +0 -17
- package/node_modules/object-inspect/test/has.js +0 -15
- package/node_modules/object-inspect/test/holes.js +0 -15
- package/node_modules/object-inspect/test/indent-option.js +0 -271
- package/node_modules/object-inspect/test/inspect.js +0 -139
- package/node_modules/object-inspect/test/lowbyte.js +0 -12
- package/node_modules/object-inspect/test/number.js +0 -58
- package/node_modules/object-inspect/test/quoteStyle.js +0 -26
- package/node_modules/object-inspect/test/toStringTag.js +0 -40
- package/node_modules/object-inspect/test/undef.js +0 -12
- package/node_modules/object-inspect/test/values.js +0 -261
- package/node_modules/object-inspect/test-core-js.js +0 -26
- package/node_modules/on-finished/HISTORY.md +0 -98
|
@@ -31,7 +31,7 @@ class GeneralEncrypt {
|
|
|
31
31
|
#plaintext;
|
|
32
32
|
#recipients = [];
|
|
33
33
|
#protectedHeader;
|
|
34
|
-
#
|
|
34
|
+
#sharedUnprotectedHeader;
|
|
35
35
|
#aad;
|
|
36
36
|
constructor(plaintext) {
|
|
37
37
|
this.#plaintext = plaintext;
|
|
@@ -44,7 +44,7 @@ class GeneralEncrypt {
|
|
|
44
44
|
return assertNotSet(this.#protectedHeader, "setProtectedHeader"), this.#protectedHeader = protectedHeader, this;
|
|
45
45
|
}
|
|
46
46
|
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
47
|
-
return assertNotSet(this.#
|
|
47
|
+
return assertNotSet(this.#sharedUnprotectedHeader, "setSharedUnprotectedHeader"), this.#sharedUnprotectedHeader = sharedUnprotectedHeader, this;
|
|
48
48
|
}
|
|
49
49
|
setAdditionalAuthenticatedData(aad) {
|
|
50
50
|
return this.#aad = aad, this;
|
|
@@ -54,7 +54,7 @@ class GeneralEncrypt {
|
|
|
54
54
|
throw new JWEInvalid("at least one recipient must be added");
|
|
55
55
|
assertUint8Array(this.#plaintext, "plaintext");
|
|
56
56
|
const multiple = this.#recipients.length > 1;
|
|
57
|
-
let enc, protectedHeader = this.#protectedHeader, sharedUnprotectedHeader = this.#
|
|
57
|
+
let enc, protectedHeader = this.#protectedHeader, sharedUnprotectedHeader = this.#sharedUnprotectedHeader;
|
|
58
58
|
const recipients = [];
|
|
59
59
|
for (const recipient of this.#recipients) {
|
|
60
60
|
const [unprotectedHeader, keyManagementParameters, key, crit] = recipient.state, input = [
|
|
@@ -19,30 +19,30 @@ async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
|
19
19
|
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
20
20
|
if (digestAlgorithm ??= "sha256", digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512")
|
|
21
21
|
throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
|
|
22
|
-
let
|
|
22
|
+
let requiredMembers;
|
|
23
23
|
switch (jwk.kty) {
|
|
24
24
|
case "AKP":
|
|
25
|
-
check(jwk.alg, '"alg" (Algorithm) Parameter'), check(jwk.pub, '"pub" (Public key) Parameter'),
|
|
25
|
+
check(jwk.alg, '"alg" (Algorithm) Parameter'), check(jwk.pub, '"pub" (Public key) Parameter'), requiredMembers = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
|
|
26
26
|
break;
|
|
27
27
|
case "EC":
|
|
28
|
-
check(jwk.crv, '"crv" (Curve) Parameter'), check(jwk.x, '"x" (X Coordinate) Parameter'), check(jwk.y, '"y" (Y Coordinate) Parameter'),
|
|
28
|
+
check(jwk.crv, '"crv" (Curve) Parameter'), check(jwk.x, '"x" (X Coordinate) Parameter'), check(jwk.y, '"y" (Y Coordinate) Parameter'), requiredMembers = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
|
|
29
29
|
break;
|
|
30
30
|
case "OKP":
|
|
31
|
-
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter'), check(jwk.x, '"x" (Public Key) Parameter'),
|
|
31
|
+
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter'), check(jwk.x, '"x" (Public Key) Parameter'), requiredMembers = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
32
32
|
break;
|
|
33
33
|
case "RSA":
|
|
34
|
-
check(jwk.e, '"e" (Exponent) Parameter'), check(jwk.n, '"n" (Modulus) Parameter'),
|
|
34
|
+
check(jwk.e, '"e" (Exponent) Parameter'), check(jwk.n, '"n" (Modulus) Parameter'), requiredMembers = { e: jwk.e, kty: jwk.kty, n: jwk.n };
|
|
35
35
|
break;
|
|
36
36
|
case "oct":
|
|
37
37
|
if (typeof jwk.k != "string")
|
|
38
38
|
throw new JWKInvalid('"k" (Key Value) Parameter missing or invalid');
|
|
39
|
-
|
|
39
|
+
requiredMembers = { k: jwk.k, kty: jwk.kty };
|
|
40
40
|
break;
|
|
41
41
|
default:
|
|
42
42
|
throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
|
|
43
43
|
}
|
|
44
|
-
const
|
|
45
|
-
return b64u(await digest(digestAlgorithm,
|
|
44
|
+
const thumbprintInput = encode(JSON.stringify(requiredMembers));
|
|
45
|
+
return b64u(await digest(digestAlgorithm, thumbprintInput));
|
|
46
46
|
}
|
|
47
47
|
async function calculateJwkThumbprintUri(key, digestAlgorithm) {
|
|
48
48
|
digestAlgorithm ??= "sha256";
|
|
@@ -24,7 +24,8 @@ function createLocalJWKSet(jwks) {
|
|
|
24
24
|
let snapshot;
|
|
25
25
|
try {
|
|
26
26
|
snapshot = structuredClone(jwks);
|
|
27
|
-
} catch {
|
|
27
|
+
} catch (cause) {
|
|
28
|
+
throw new JWKSInvalid("JSON Web Key Set malformed", { cause });
|
|
28
29
|
}
|
|
29
30
|
if (!isJwkSet(snapshot))
|
|
30
31
|
throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
@@ -5,7 +5,7 @@ function isCloudflareWorkers() {
|
|
|
5
5
|
return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
|
|
6
6
|
}
|
|
7
7
|
let USER_AGENT;
|
|
8
|
-
(typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.
|
|
8
|
+
(typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.18");
|
|
9
9
|
const customFetch = /* @__PURE__ */ Symbol();
|
|
10
10
|
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
11
11
|
const response = await fetchImpl(url, {
|
|
@@ -14,14 +14,14 @@ async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
|
14
14
|
redirect: "manual",
|
|
15
15
|
headers
|
|
16
16
|
}).catch((err) => {
|
|
17
|
-
throw err.name === "TimeoutError" ? new JWKSTimeout() : err;
|
|
17
|
+
throw err.name === "TimeoutError" ? new JWKSTimeout(void 0, { cause: err }) : err;
|
|
18
18
|
});
|
|
19
19
|
if (response.status !== 200)
|
|
20
20
|
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
21
21
|
try {
|
|
22
22
|
return await response.json();
|
|
23
|
-
} catch {
|
|
24
|
-
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
|
|
23
|
+
} catch (cause) {
|
|
24
|
+
throw signal.aborted ? new JWKSTimeout(void 0, { cause }) : new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON", { cause });
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
const jwksCache = /* @__PURE__ */ Symbol();
|
|
@@ -31,6 +31,8 @@ function isFreshFor(timestamp, duration) {
|
|
|
31
31
|
function validateDuration(value, fallback, option) {
|
|
32
32
|
if (Number.isNaN(value))
|
|
33
33
|
throw new TypeError(`"${option}" option must not be NaN`);
|
|
34
|
+
if (typeof value == "number" && value < 0)
|
|
35
|
+
throw new TypeError(`"${option}" option must not be negative`);
|
|
34
36
|
return typeof value == "number" ? value : fallback;
|
|
35
37
|
}
|
|
36
38
|
function createRemoteJWKSet(url, options) {
|
|
@@ -40,15 +40,15 @@ class GeneralSign {
|
|
|
40
40
|
const jws = {
|
|
41
41
|
signatures: [],
|
|
42
42
|
payload: ""
|
|
43
|
-
},
|
|
43
|
+
}, encodedPayloadCache = [];
|
|
44
44
|
let b64;
|
|
45
45
|
for (const signature of this.#signatures) {
|
|
46
|
-
const [protectedHeader, unprotectedHeader, key, crit] = signature.state, [{ payload, ...
|
|
46
|
+
const [protectedHeader, unprotectedHeader, key, crit] = signature.state, [{ payload, ...signatureMembers }, signatureB64] = await createSignature([this.#payload, protectedHeader, unprotectedHeader, crit, encodedPayloadCache], key);
|
|
47
47
|
if (b64 === void 0)
|
|
48
48
|
b64 = signatureB64, jws.payload = payload;
|
|
49
49
|
else if (b64 !== signatureB64)
|
|
50
50
|
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
51
|
-
jws.signatures.push(
|
|
51
|
+
jws.signatures.push(signatureMembers);
|
|
52
52
|
}
|
|
53
53
|
return jws;
|
|
54
54
|
}
|
|
@@ -22,18 +22,12 @@ async function generalVerify(jws, key, options) {
|
|
|
22
22
|
const signatureEntries = Array.from(signatures);
|
|
23
23
|
if (!signatureEntries.every(isObject))
|
|
24
24
|
throw new JWSInvalid("JWS Signatures missing or incorrect type");
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
if (inputPayload === void 0)
|
|
28
|
-
throw new Error();
|
|
29
|
-
shared = prepareVerify(options);
|
|
30
|
-
} catch {
|
|
25
|
+
if (inputPayload === void 0)
|
|
31
26
|
throw new JWSSignatureVerificationFailed();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (modes |= mode, modes === 3)
|
|
27
|
+
const shared = prepareVerify(options), payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload, candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
|
|
28
|
+
let payloadEncodings = 0;
|
|
29
|
+
for (const [, , payloadEncoding] of candidates)
|
|
30
|
+
if (payloadEncodings |= payloadEncoding, payloadEncodings === 3)
|
|
37
31
|
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
38
32
|
for (const candidate of candidates)
|
|
39
33
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compactJWE, createJWE } from "../lib/jwe_encrypt.js";
|
|
2
|
-
import { JWTClaimsBuilder, jwtClaim,
|
|
2
|
+
import { JWTClaimsBuilder, jwtClaim, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
|
|
3
3
|
import { assertNotSet } from "../lib/validate.js";
|
|
4
4
|
const EncryptJWT_base = JWTClaimsBuilder;
|
|
5
5
|
class EncryptJWT extends EncryptJWT_base {
|
|
@@ -29,15 +29,12 @@ class EncryptJWT extends EncryptJWT_base {
|
|
|
29
29
|
return this.#replicateAudienceAsHeader = !0, this;
|
|
30
30
|
}
|
|
31
31
|
async encrypt(key, options) {
|
|
32
|
-
const plaintext = jwtData(this);
|
|
33
|
-
this.#input[1] && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader) && (this.#input[1] = {
|
|
34
|
-
...this.#input[1],
|
|
35
|
-
iss: this.#replicateIssuerAsHeader ? jwtClaim(this, "iss") : void 0,
|
|
36
|
-
sub: this.#replicateSubjectAsHeader ? jwtClaim(this, "sub") : void 0,
|
|
37
|
-
aud: this.#replicateAudienceAsHeader ? jwtClaim(this, "aud") : void 0
|
|
38
|
-
});
|
|
39
32
|
const input = [...this.#input];
|
|
40
|
-
|
|
33
|
+
if (input[0] = jwtClaimsSetBytes(this), input[1] && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader)) {
|
|
34
|
+
const header = { ...input[1] };
|
|
35
|
+
this.#replicateIssuerAsHeader && (header.iss = jwtClaim(this, "iss")), this.#replicateSubjectAsHeader && (header.sub = jwtClaim(this, "sub")), this.#replicateAudienceAsHeader && (header.aud = jwtClaim(this, "aud")), input[1] = header;
|
|
36
|
+
}
|
|
37
|
+
return compactJWE(await createJWE(input, key, options));
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createCompactSignature } from "../lib/jws_sign.js";
|
|
2
2
|
import { JWTInvalid } from "../util/errors.js";
|
|
3
|
-
import { JWTClaimsBuilder,
|
|
3
|
+
import { JWTClaimsBuilder, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
|
|
4
4
|
import { assertNotSet } from "../lib/validate.js";
|
|
5
5
|
const SignJWT_base = JWTClaimsBuilder;
|
|
6
6
|
class SignJWT extends SignJWT_base {
|
|
@@ -9,7 +9,7 @@ class SignJWT extends SignJWT_base {
|
|
|
9
9
|
return assertNotSet(this.#protectedHeader, "setProtectedHeader"), this.#protectedHeader = protectedHeader, this;
|
|
10
10
|
}
|
|
11
11
|
async sign(key, options) {
|
|
12
|
-
return createCompactSignature(
|
|
12
|
+
return createCompactSignature(jwtClaimsSetBytes(this), this.#protectedHeader, options?.crit, key, () => {
|
|
13
13
|
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
14
14
|
});
|
|
15
15
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as b64u from "../util/base64url.js";
|
|
2
2
|
import { decodeBase64url, parseJoseHeader, JWS_RECOGNIZED, validateB64, validateCrit } from "../lib/validate.js";
|
|
3
3
|
import { JWSInvalid, JWTInvalid } from "../util/errors.js";
|
|
4
|
-
import { validateClaimsSet, JWTClaimsBuilder,
|
|
4
|
+
import { validateClaimsSet, JWTClaimsBuilder, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
|
|
5
5
|
const UnsecuredJWT_base = JWTClaimsBuilder;
|
|
6
6
|
class UnsecuredJWT extends UnsecuredJWT_base {
|
|
7
7
|
encode() {
|
|
8
|
-
const
|
|
9
|
-
return `${
|
|
8
|
+
const encodedProtectedHeader = b64u.encode(JSON.stringify({ alg: "none" })), encodedPayload = b64u.encode(jwtClaimsSetBytes(this));
|
|
9
|
+
return `${encodedProtectedHeader}.${encodedPayload}.`;
|
|
10
10
|
}
|
|
11
11
|
static decode(jwt, options) {
|
|
12
12
|
if (typeof jwt != "string")
|
|
@@ -2,12 +2,12 @@ import { unsupportedAlg, algArgument } from "../lib/key_algorithm.js";
|
|
|
2
2
|
import { validateExtractableOption } from "../lib/key.js";
|
|
3
3
|
async function generateSecret(alg, options) {
|
|
4
4
|
const extractable = validateExtractableOption(options?.extractable);
|
|
5
|
-
let
|
|
5
|
+
let keyLengthBits, algorithm, keyUsages;
|
|
6
6
|
switch (alg) {
|
|
7
7
|
case "HS256":
|
|
8
8
|
case "HS384":
|
|
9
9
|
case "HS512":
|
|
10
|
-
|
|
10
|
+
keyLengthBits = +alg.slice(-3), algorithm = { name: "HMAC", hash: `SHA-${keyLengthBits}`, length: keyLengthBits }, keyUsages = ["sign", "verify"];
|
|
11
11
|
break;
|
|
12
12
|
case "A128CBC-HS256":
|
|
13
13
|
case "A192CBC-HS384":
|
|
@@ -16,7 +16,7 @@ async function generateSecret(alg, options) {
|
|
|
16
16
|
case "A128KW":
|
|
17
17
|
case "A192KW":
|
|
18
18
|
case "A256KW":
|
|
19
|
-
|
|
19
|
+
keyLengthBits = +alg.slice(1, 4), algorithm = { name: "AES-KW", length: keyLengthBits }, keyUsages = ["wrapKey", "unwrapKey"];
|
|
20
20
|
break;
|
|
21
21
|
case "A128GCMKW":
|
|
22
22
|
case "A192GCMKW":
|
|
@@ -24,7 +24,7 @@ async function generateSecret(alg, options) {
|
|
|
24
24
|
case "A128GCM":
|
|
25
25
|
case "A192GCM":
|
|
26
26
|
case "A256GCM":
|
|
27
|
-
|
|
27
|
+
keyLengthBits = +alg.slice(1, 4), algorithm = { name: "AES-GCM", length: keyLengthBits }, keyUsages = ["encrypt", "decrypt"];
|
|
28
28
|
break;
|
|
29
29
|
default:
|
|
30
30
|
unsupportedAlg(algArgument);
|
|
@@ -94,8 +94,8 @@ const parseECAlgorithmIdentifier = (state) => {
|
|
|
94
94
|
try {
|
|
95
95
|
const state = createASN1State(keyData);
|
|
96
96
|
parseKeyHeader(state, keyFormat), algorithm = entry.resolve({ crv: parseECAlgorithmIdentifier(state) });
|
|
97
|
-
} catch {
|
|
98
|
-
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
97
|
+
} catch (cause) {
|
|
98
|
+
throw new JOSENotSupported("Invalid or unsupported key format", { cause });
|
|
99
99
|
}
|
|
100
100
|
else
|
|
101
101
|
algorithm = entry.subtle;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const encoder = new TextEncoder(), decoder = new TextDecoder(), strictDecoder = new TextDecoder("utf-8", { fatal: !0 }),
|
|
1
|
+
const encoder = new TextEncoder(), decoder = new TextDecoder(), strictDecoder = new TextDecoder("utf-8", { fatal: !0 }), UINT32_RANGE = 2 ** 32;
|
|
2
2
|
function concat(...buffers) {
|
|
3
3
|
const size = buffers.reduce((acc, { length }) => acc + length, 0), buf = new Uint8Array(size);
|
|
4
4
|
let i = 0;
|
|
@@ -7,12 +7,12 @@ function concat(...buffers) {
|
|
|
7
7
|
return buf;
|
|
8
8
|
}
|
|
9
9
|
function writeUInt32BE(buf, value, offset) {
|
|
10
|
-
if (value < 0 || value >=
|
|
11
|
-
throw new RangeError(`value must be >= 0 and <= ${
|
|
10
|
+
if (value < 0 || value >= UINT32_RANGE)
|
|
11
|
+
throw new RangeError(`value must be >= 0 and <= ${UINT32_RANGE - 1}. Received ${value}`);
|
|
12
12
|
buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
|
|
13
13
|
}
|
|
14
14
|
function uint64be(value) {
|
|
15
|
-
const high = Math.floor(value /
|
|
15
|
+
const high = Math.floor(value / UINT32_RANGE), low = value % UINT32_RANGE, buf = new Uint8Array(8);
|
|
16
16
|
return writeUInt32BE(buf, high, 0), writeUInt32BE(buf, low, 4), buf;
|
|
17
17
|
}
|
|
18
18
|
function uint32be(value) {
|
|
@@ -15,20 +15,20 @@ function checkIvLength(enc, iv) {
|
|
|
15
15
|
async function cbcKeySetup(enc, cek, usage) {
|
|
16
16
|
if (!(cek instanceof Uint8Array))
|
|
17
17
|
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
18
|
-
const
|
|
19
|
-
hash: `SHA-${
|
|
18
|
+
const keyLengthBits = enc.cekBits >> 1, encKey = await crypto.subtle.importKey("raw", cek.subarray(keyLengthBits >> 3), "AES-CBC", !1, [usage]), macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keyLengthBits >> 3), {
|
|
19
|
+
hash: `SHA-${keyLengthBits << 1}`,
|
|
20
20
|
name: "HMAC"
|
|
21
21
|
}, !1, ["sign"]);
|
|
22
|
-
return [encKey, macKey,
|
|
22
|
+
return [encKey, macKey, keyLengthBits];
|
|
23
23
|
}
|
|
24
|
-
async function cbcHmacTag(macKey, macData,
|
|
25
|
-
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0,
|
|
24
|
+
async function cbcHmacTag(macKey, macData, keyLengthBits) {
|
|
25
|
+
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keyLengthBits >> 3));
|
|
26
26
|
}
|
|
27
27
|
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
28
|
-
const [encKey, macKey,
|
|
28
|
+
const [encKey, macKey, keyLengthBits] = await cbcKeySetup(enc, cek, "encrypt"), ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
29
29
|
iv,
|
|
30
30
|
name: "AES-CBC"
|
|
31
|
-
}, encKey, plaintext)), macData = concat(aad, iv, ciphertext,
|
|
31
|
+
}, encKey, plaintext)), al = uint64be(aad.length * 8), macData = concat(aad, iv, ciphertext, al), tag = await cbcHmacTag(macKey, macData, keyLengthBits);
|
|
32
32
|
return { ciphertext, tag, iv };
|
|
33
33
|
}
|
|
34
34
|
async function timingSafeEqual(a, b) {
|
|
@@ -36,7 +36,7 @@ async function timingSafeEqual(a, b) {
|
|
|
36
36
|
return crypto.subtle.verify(algorithm, key, aHmac, b);
|
|
37
37
|
}
|
|
38
38
|
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
39
|
-
const [encKey, macKey,
|
|
39
|
+
const [encKey, macKey, keyLengthBits] = await cbcKeySetup(enc, cek, "decrypt"), al = uint64be(aad.length * 8), macData = concat(aad, iv, ciphertext, al), expectedTag = await cbcHmacTag(macKey, macData, keyLengthBits);
|
|
40
40
|
try {
|
|
41
41
|
if (await timingSafeEqual(tag, expectedTag))
|
|
42
42
|
return new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
@@ -23,7 +23,8 @@ async function transform(stream, input, maxLength = 1 / 0) {
|
|
|
23
23
|
if (done)
|
|
24
24
|
break;
|
|
25
25
|
if (chunks.push(value), length += value.byteLength, maxLength !== 1 / 0 && length > maxLength)
|
|
26
|
-
throw
|
|
26
|
+
throw await reader.cancel().catch(() => {
|
|
27
|
+
}), new JWEInvalid("Decompressed plaintext exceeded the configured limit");
|
|
27
28
|
}
|
|
28
29
|
return concat(...chunks);
|
|
29
30
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { decrypt, generateCek } from "./content_encryption.js";
|
|
2
|
-
import { decodeBase64url,
|
|
2
|
+
import { decodeBase64url, encodeAsciiMember, parseJoseHeader, isDisjoint, isObject, validateCrit, validateAlgorithms, JWE_RECOGNIZED } from "./validate.js";
|
|
3
3
|
import { JOSEAlgNotAllowed, JOSENotSupported, JWEInvalid } from "../util/errors.js";
|
|
4
|
-
import { decryptKeyManagement } from "./key_management.js";
|
|
4
|
+
import { decryptKeyManagement, validateMaxPBES2Count } from "./key_management.js";
|
|
5
5
|
import { decoder } from "./buffer_utils.js";
|
|
6
6
|
import { prepareKey } from "./key.js";
|
|
7
7
|
import { JWE, isJWECEKTransport, jweAlgorithm, jweEncryption } from "./jwe_algorithms.js";
|
|
@@ -59,35 +59,40 @@ function checkRecipient(jwe) {
|
|
|
59
59
|
}
|
|
60
60
|
function shareJWE(jwe) {
|
|
61
61
|
const { protected: encodedProtected, ciphertext, iv, tag, aad } = jwe;
|
|
62
|
-
let
|
|
63
|
-
return encodedProtected !== void 0 && (
|
|
64
|
-
|
|
62
|
+
let protectedHeader;
|
|
63
|
+
return encodedProtected !== void 0 && (protectedHeader = parseJoseHeader(encodedProtected, JWEInvalid, "JWE Protected Header is invalid")), [
|
|
64
|
+
protectedHeader,
|
|
65
65
|
decodeBase64url(ciphertext, "ciphertext", JWEInvalid),
|
|
66
66
|
iv !== void 0 ? decodeBase64url(iv, "iv", JWEInvalid) : void 0,
|
|
67
67
|
tag !== void 0 ? decodeBase64url(tag, "tag", JWEInvalid) : void 0,
|
|
68
|
-
|
|
68
|
+
encodeAsciiMember((encodedProtected ?? "") + (aad !== void 0 ? `.${aad}` : ""), "aad", JWEInvalid)
|
|
69
69
|
];
|
|
70
70
|
}
|
|
71
71
|
function prepareDecrypt(options) {
|
|
72
|
+
const keyManagementAlgorithms = options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms), contentEncryptionAlgorithms = options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms), { crit, maxPBES2Count, maxDecompressedLength } = options ?? {};
|
|
73
|
+
validateMaxPBES2Count(maxPBES2Count);
|
|
74
|
+
const decompressionLimit = maxDecompressedLength ?? 25e4;
|
|
75
|
+
if (decompressionLimit !== 0 && decompressionLimit !== 1 / 0 && (!Number.isSafeInteger(decompressionLimit) || decompressionLimit < 1))
|
|
76
|
+
throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
|
|
72
77
|
return [
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
keyManagementAlgorithms,
|
|
79
|
+
contentEncryptionAlgorithms,
|
|
80
|
+
crit,
|
|
81
|
+
maxPBES2Count,
|
|
82
|
+
maxDecompressedLength
|
|
78
83
|
];
|
|
79
84
|
}
|
|
80
85
|
async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
|
|
81
|
-
const [
|
|
86
|
+
const [protectedHeader, ciphertext, iv, tag, additionalAuthenticatedData] = token, { header, unprotected, aad } = jwe;
|
|
82
87
|
let joseHeader;
|
|
83
88
|
if (header !== void 0 || unprotected !== void 0) {
|
|
84
|
-
if (!isDisjoint(
|
|
89
|
+
if (!isDisjoint(protectedHeader, header, unprotected))
|
|
85
90
|
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
86
|
-
joseHeader = { ...
|
|
91
|
+
joseHeader = { ...protectedHeader, ...header, ...unprotected };
|
|
87
92
|
} else
|
|
88
|
-
joseHeader =
|
|
93
|
+
joseHeader = protectedHeader ?? {};
|
|
89
94
|
const [keyManagementAlgorithms, contentEncryptionAlgorithms, crit, maxPBES2Count, maxDecompressedLength] = shared, { encrypted_key: encodedKey } = jwe;
|
|
90
|
-
validateCrit(JWEInvalid, JWE_RECOGNIZED, crit,
|
|
95
|
+
validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, protectedHeader, joseHeader), validateZip(joseHeader, protectedHeader);
|
|
91
96
|
const { alg, enc } = joseHeader;
|
|
92
97
|
if (typeof alg != "string" || !alg)
|
|
93
98
|
throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
|
|
@@ -122,13 +127,13 @@ async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
|
|
|
122
127
|
encryptedKey = new Uint8Array();
|
|
123
128
|
}
|
|
124
129
|
let resolvedKey = !1;
|
|
125
|
-
typeof key == "function" && (key = await key(
|
|
130
|
+
typeof key == "function" && (key = await key(protectedHeader, jwe), resolvedKey = !0);
|
|
126
131
|
const algEntry = selected ?? jweAlgorithm(alg);
|
|
127
132
|
isJWECEKTransport(algEntry) && encryptedKey === void 0 && (encryptedKey = new Uint8Array());
|
|
128
133
|
const k = await prepareKey(algEntry.mode === "direct-encryption" ? encEntry : algEntry, key, "decrypt");
|
|
129
134
|
let plaintext;
|
|
130
135
|
if (algEntry.mode === "integrated-encryption")
|
|
131
|
-
plaintext = await algEntry.decrypt(k, encryptedKey, ciphertext,
|
|
136
|
+
plaintext = await algEntry.decrypt(k, encryptedKey, ciphertext, additionalAuthenticatedData, protectedHeader, joseHeader);
|
|
132
137
|
else {
|
|
133
138
|
const encryption = encEntry;
|
|
134
139
|
let cek;
|
|
@@ -139,21 +144,19 @@ async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
|
|
|
139
144
|
throw err;
|
|
140
145
|
cek = generateCek(encryption);
|
|
141
146
|
}
|
|
142
|
-
plaintext = await decrypt(encryption, cek, ciphertext, iv, tag,
|
|
147
|
+
plaintext = await decrypt(encryption, cek, ciphertext, iv, tag, additionalAuthenticatedData);
|
|
143
148
|
}
|
|
144
149
|
if (joseHeader.zip === "DEF") {
|
|
145
150
|
const decompressionLimit = maxDecompressedLength ?? 25e4;
|
|
146
151
|
if (decompressionLimit === 0)
|
|
147
152
|
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
148
|
-
if (decompressionLimit !== 1 / 0 && (!Number.isSafeInteger(decompressionLimit) || decompressionLimit < 1))
|
|
149
|
-
throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
|
|
150
153
|
plaintext = await decompress(plaintext, decompressionLimit).catch((cause) => {
|
|
151
|
-
throw cause instanceof JWEInvalid ? cause : new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
154
|
+
throw cause instanceof JWEInvalid || cause instanceof JOSENotSupported ? cause : new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
152
155
|
});
|
|
153
156
|
}
|
|
154
157
|
return {
|
|
155
158
|
plaintext,
|
|
156
|
-
...
|
|
159
|
+
...protectedHeader && { protectedHeader },
|
|
157
160
|
...aad !== void 0 && {
|
|
158
161
|
additionalAuthenticatedData: decodeBase64url(aad, "aad", JWEInvalid)
|
|
159
162
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { encode as b64u } from "../util/base64url.js";
|
|
2
2
|
import { encrypt } from "./content_encryption.js";
|
|
3
3
|
import { encryptKeyManagement } from "./key_management.js";
|
|
4
|
-
import { JWEInvalid } from "../util/errors.js";
|
|
4
|
+
import { JOSENotSupported, JWEInvalid } from "../util/errors.js";
|
|
5
5
|
import { assertUint8Array, isDisjoint, isObject, serializeJoseHeader, validateCrit, validateCritDuplicates, JWE_RECOGNIZED } from "./validate.js";
|
|
6
6
|
import { encode } from "./buffer_utils.js";
|
|
7
7
|
import { prepareKey } from "./key.js";
|
|
@@ -48,17 +48,17 @@ async function encryptJWE(input, checked, key) {
|
|
|
48
48
|
const algEntry = selected ?? jweAlgorithm(joseHeader.alg);
|
|
49
49
|
let encryptedKey, parameters, cek;
|
|
50
50
|
algEntry.mode === "integrated-encryption" ? cek = await prepareKey(algEntry, key, "encrypt") : [cek, encryptedKey, parameters] = await encryptKeyManagement(algEntry, encEntry, key, joseHeader, providedCek, keyManagementParameters), parameters && (unprotectedParameters ? unprotectedHeader = unprotectedHeader ? { ...unprotectedHeader, ...parameters } : parameters : protectedHeader = protectedHeader ? { ...protectedHeader, ...parameters } : parameters, checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader));
|
|
51
|
-
const
|
|
51
|
+
const encodedProtectedHeader = protectedHeader ? b64u(JSON.stringify(protectedHeader)) : "", encodedAad = aad?.byteLength ? b64u(aad) : void 0, additionalAuthenticatedData = encode(encodedAad ? `${encodedProtectedHeader}.${encodedAad}` : encodedProtectedHeader);
|
|
52
52
|
let plaintext = inputPlaintext;
|
|
53
53
|
joseHeader.zip === "DEF" && (plaintext = await compress(plaintext).catch((cause) => {
|
|
54
|
-
throw new JWEInvalid("Failed to compress plaintext", { cause });
|
|
54
|
+
throw cause instanceof JOSENotSupported ? cause : new JWEInvalid("Failed to compress plaintext", { cause });
|
|
55
55
|
}));
|
|
56
56
|
let ciphertext, tag, iv;
|
|
57
|
-
algEntry.mode === "integrated-encryption" ? [encryptedKey, ciphertext] = await algEntry.encrypt(cek, plaintext,
|
|
57
|
+
algEntry.mode === "integrated-encryption" ? [encryptedKey, ciphertext] = await algEntry.encrypt(cek, plaintext, additionalAuthenticatedData, protectedHeader, joseHeader, keyManagementParameters) : { ciphertext, tag, iv } = await encrypt(encEntry, plaintext, cek, inputIv, additionalAuthenticatedData);
|
|
58
58
|
const jwe = {
|
|
59
59
|
ciphertext: b64u(ciphertext)
|
|
60
60
|
};
|
|
61
|
-
return iv && (jwe.iv = b64u(iv)), tag && (jwe.tag = b64u(tag)), encryptedKey?.byteLength && (jwe.encrypted_key = b64u(encryptedKey)),
|
|
61
|
+
return iv && (jwe.iv = b64u(iv)), tag && (jwe.tag = b64u(tag)), encryptedKey?.byteLength && (jwe.encrypted_key = b64u(encryptedKey)), encodedAad && (jwe.aad = encodedAad), protectedHeader && (jwe.protected = encodedProtectedHeader), sharedUnprotectedHeader && (jwe.unprotected = sharedUnprotectedHeader), unprotectedHeader && (jwe.header = unprotectedHeader), jwe;
|
|
62
62
|
}
|
|
63
63
|
async function createJWE(input, key, options) {
|
|
64
64
|
return encryptJWE(input, checkEncryptHeaders(input, options), key);
|
|
@@ -5,10 +5,10 @@ import { JWSInvalid } from "../util/errors.js";
|
|
|
5
5
|
import { concat, encode, encoder } from "./buffer_utils.js";
|
|
6
6
|
import { prepareKey, rawKey, checkModulusLength } from "./key.js";
|
|
7
7
|
async function createSignature(input, key, rejectUnencoded) {
|
|
8
|
-
let [payload, protectedHeader, unprotectedHeader, crit] = input,
|
|
8
|
+
let [payload, protectedHeader, unprotectedHeader, crit] = input, encodedProtectedHeader = "";
|
|
9
9
|
if (protectedHeader !== void 0) {
|
|
10
10
|
const normalized = serializeJoseHeader(JWSInvalid, protectedHeader);
|
|
11
|
-
protectedHeader = normalized[0],
|
|
11
|
+
protectedHeader = normalized[0], encodedProtectedHeader = b64u(normalized[1]);
|
|
12
12
|
}
|
|
13
13
|
if (unprotectedHeader !== void 0 && (unprotectedHeader = serializeJoseHeader(JWSInvalid, unprotectedHeader)[0]), !protectedHeader && !unprotectedHeader)
|
|
14
14
|
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
@@ -22,19 +22,19 @@ async function createSignature(input, key, rejectUnencoded) {
|
|
|
22
22
|
if (typeof alg != "string" || !alg)
|
|
23
23
|
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
24
24
|
const entry = jwsAlgorithm(alg);
|
|
25
|
-
let
|
|
25
|
+
let encodedPayload = "", signingPayload = payload, signingInput;
|
|
26
26
|
if (b64) {
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const encodedPayloadCache = input[4];
|
|
28
|
+
encodedPayloadCache ? (encodedPayload = encodedPayloadCache[0] ??= b64u(payload), signingPayload = encodedPayloadCache[1] ??= encode(encodedPayload)) : (encodedPayload = b64u(payload), signingInput = encoder.encode(`${encodedProtectedHeader}.${encodedPayload}`));
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
entry.minRsaBits && checkModulusLength(entry.alg,
|
|
30
|
+
signingInput ??= concat(encode(encodedProtectedHeader), encode("."), signingPayload);
|
|
31
|
+
const signingKey = await rawKey(await prepareKey(entry, key, "sign"), entry.subtle, "sign");
|
|
32
|
+
entry.minRsaBits && checkModulusLength(entry.alg, signingKey);
|
|
33
33
|
const jws = {
|
|
34
|
-
signature: b64u(new Uint8Array(await crypto.subtle.sign(entry.signing,
|
|
35
|
-
payload:
|
|
34
|
+
signature: b64u(new Uint8Array(await crypto.subtle.sign(entry.signing, signingKey, signingInput))),
|
|
35
|
+
payload: encodedPayload
|
|
36
36
|
};
|
|
37
|
-
return protectedHeader && (jws.protected =
|
|
37
|
+
return protectedHeader && (jws.protected = encodedProtectedHeader), unprotectedHeader && (jws.header = unprotectedHeader), [jws, b64];
|
|
38
38
|
}
|
|
39
39
|
async function createCompactSignature(payload, protectedHeader, crit, key, rejectUnencoded) {
|
|
40
40
|
const [jws] = await createSignature([payload, protectedHeader, void 0, crit], key, rejectUnencoded);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { jwsAlgorithm } from "./jws_algorithms.js";
|
|
2
2
|
import { JOSEAlgNotAllowed, JWSInvalid, JWSSignatureVerificationFailed } from "../util/errors.js";
|
|
3
3
|
import { concat, decoder, encoder, encode } from "./buffer_utils.js";
|
|
4
|
-
import { decodeBase64url,
|
|
4
|
+
import { decodeBase64url, encodeAsciiMember, parseJoseHeader, isDisjoint, isObject, validateB64, validateCrit, validateAlgorithms, JWS_RECOGNIZED } from "./validate.js";
|
|
5
5
|
import { prepareKey, rawKey, checkModulusLength } from "./key.js";
|
|
6
6
|
function snapshotJws(jws, sharedPayload) {
|
|
7
|
-
const
|
|
7
|
+
const encodedProtectedHeader = jws.protected, inputHeader = jws.header, header = isObject(inputHeader) ? { ...inputHeader } : inputHeader;
|
|
8
8
|
let payload = sharedPayload ? sharedPayload[0] : jws.payload;
|
|
9
9
|
!sharedPayload && payload instanceof Uint8Array && (payload = new Uint8Array(payload));
|
|
10
10
|
const signature = jws.signature, snapshot = { payload, signature };
|
|
11
|
-
if (
|
|
11
|
+
if (encodedProtectedHeader !== void 0 && (snapshot.protected = encodedProtectedHeader), inputHeader !== void 0 && (snapshot.header = header), encodedProtectedHeader === void 0 && header === void 0)
|
|
12
12
|
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
13
|
-
if (
|
|
13
|
+
if (encodedProtectedHeader !== void 0 && typeof encodedProtectedHeader != "string")
|
|
14
14
|
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
15
15
|
if (payload === void 0)
|
|
16
16
|
throw new JWSInvalid("JWS Payload missing");
|
|
@@ -23,8 +23,8 @@ function snapshotJws(jws, sharedPayload) {
|
|
|
23
23
|
function prepareVerify(options) {
|
|
24
24
|
return [options && validateAlgorithms("algorithms", options.algorithms), options?.crit];
|
|
25
25
|
}
|
|
26
|
-
function parseProtectedHeader(
|
|
27
|
-
return
|
|
26
|
+
function parseProtectedHeader(encodedProtectedHeader) {
|
|
27
|
+
return encodedProtectedHeader === void 0 ? {} : parseJoseHeader(encodedProtectedHeader, JWSInvalid, "JWS Protected Header is invalid");
|
|
28
28
|
}
|
|
29
29
|
function encodeJsonUnencodedPayload(payload) {
|
|
30
30
|
const invalid = /[\p{Cs}\p{Cn}]/u.exec(payload)?.[0];
|
|
@@ -35,15 +35,17 @@ function encodeJsonUnencodedPayload(payload) {
|
|
|
35
35
|
function encodeCompactUnencodedPayload(payload) {
|
|
36
36
|
try {
|
|
37
37
|
return encode(payload);
|
|
38
|
-
} catch {
|
|
39
|
-
throw new JWSInvalid("JWS Compact Serialization payload must use only ASCII characters"
|
|
38
|
+
} catch (cause) {
|
|
39
|
+
throw new JWSInvalid("JWS Compact Serialization payload must use only ASCII characters", {
|
|
40
|
+
cause
|
|
41
|
+
});
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
async function verifySignature(jws, shared, key, encodeUnencodedPayload, parsedProtected) {
|
|
43
|
-
const { protected:
|
|
44
|
-
if (!isDisjoint(
|
|
45
|
+
const { protected: encodedProtectedHeader, header, payload: inputPayload } = jws, protectedHeader = parsedProtected ?? parseProtectedHeader(encodedProtectedHeader);
|
|
46
|
+
if (!isDisjoint(protectedHeader, header))
|
|
45
47
|
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
46
|
-
const joseHeader = { ...
|
|
48
|
+
const joseHeader = { ...protectedHeader, ...header }, b64 = validateB64(protectedHeader, validateCrit(JWSInvalid, JWS_RECOGNIZED, shared[1], protectedHeader, joseHeader)), { alg } = joseHeader;
|
|
47
49
|
if (typeof alg != "string" || !alg)
|
|
48
50
|
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
49
51
|
if (shared[0] && !shared[0].has(alg))
|
|
@@ -55,18 +57,19 @@ async function verifySignature(jws, shared, key, encodeUnencodedPayload, parsedP
|
|
|
55
57
|
throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
56
58
|
const signingPayload = b64 || typeof inputPayload != "string" ? inputPayload : encodeUnencodedPayload(inputPayload);
|
|
57
59
|
let resolvedKey = !1;
|
|
58
|
-
typeof key == "function" && (key = await key(
|
|
59
|
-
const entry = jwsAlgorithm(alg),
|
|
60
|
+
typeof key == "function" && (key = await key(protectedHeader, jws), resolvedKey = !0);
|
|
61
|
+
const entry = jwsAlgorithm(alg), signingInput = concat(encodedProtectedHeader !== void 0 ? encode(encodedProtectedHeader) : new Uint8Array(), encode("."), typeof signingPayload == "string" ? shared[2] ??= encodeAsciiMember(signingPayload, "payload", JWSInvalid) : signingPayload), signature = decodeBase64url(jws.signature, "signature", JWSInvalid), verificationKey = await prepareKey(entry, key, "verify"), cryptoKey = await rawKey(verificationKey, entry.subtle, "verify");
|
|
60
62
|
entry.minRsaBits && checkModulusLength(entry.alg, cryptoKey);
|
|
61
63
|
let verified = !1;
|
|
62
64
|
try {
|
|
63
|
-
verified = await crypto.subtle.verify(entry.signing, cryptoKey, signature,
|
|
64
|
-
} catch {
|
|
65
|
+
verified = await crypto.subtle.verify(entry.signing, cryptoKey, signature, signingInput);
|
|
66
|
+
} catch (cause) {
|
|
67
|
+
throw new JWSSignatureVerificationFailed(void 0, { cause });
|
|
65
68
|
}
|
|
66
69
|
if (!verified)
|
|
67
70
|
throw new JWSSignatureVerificationFailed();
|
|
68
71
|
const result = { payload: typeof signingPayload == "string" ? decodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload };
|
|
69
|
-
return
|
|
72
|
+
return encodedProtectedHeader !== void 0 && (result.protectedHeader = protectedHeader), header !== void 0 && (result.unprotectedHeader = header), resolvedKey ? [{ ...result, key: verificationKey }, b64] : [result, b64];
|
|
70
73
|
}
|
|
71
74
|
async function verifyCompact(jws, shared, key) {
|
|
72
75
|
if (jws instanceof Uint8Array && (jws = decoder.decode(jws)), typeof jws != "string")
|