jose 6.2.15 → 6.2.16
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.
|
@@ -13,9 +13,10 @@ async function generalDecrypt(jwe, key, options) {
|
|
|
13
13
|
throw new JWEInvalid("JWE Recipients missing or incorrect type");
|
|
14
14
|
if (!recipients.length)
|
|
15
15
|
throw new JWEInvalid("JWE Recipients has no members");
|
|
16
|
-
|
|
16
|
+
const shared = prepareDecrypt(options);
|
|
17
|
+
let sharedJwe, token;
|
|
17
18
|
try {
|
|
18
|
-
|
|
19
|
+
sharedJwe = snapshotSharedJWE(jwe), token = shareJWE(sharedJwe);
|
|
19
20
|
} catch {
|
|
20
21
|
throw new JWEDecryptionFailed();
|
|
21
22
|
}
|
|
@@ -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.16");
|
|
9
9
|
const customFetch = /* @__PURE__ */ Symbol();
|
|
10
10
|
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
11
11
|
const response = await fetchImpl(url, {
|
|
@@ -22,15 +22,9 @@ 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
|
-
const payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload, candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
|
|
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);
|
|
34
28
|
let payloadEncodings = 0;
|
|
35
29
|
for (const [, , payloadEncoding] of candidates)
|
|
36
30
|
if (payloadEncodings |= payloadEncoding, payloadEncodings === 3)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { decrypt, generateCek } from "./content_encryption.js";
|
|
2
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";
|
|
@@ -69,12 +69,17 @@ function shareJWE(jwe) {
|
|
|
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)) {
|
|
@@ -145,8 +150,6 @@ async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
|
|
|
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
154
|
throw cause instanceof JWEInvalid ? cause : new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
152
155
|
});
|
|
@@ -111,7 +111,6 @@ async function decryptKeyManagement(entry, enc, key, encryptedKey, joseHeader, m
|
|
|
111
111
|
case "PBKDF2": {
|
|
112
112
|
if (typeof joseHeader.p2c != "number")
|
|
113
113
|
throw new JWEInvalid('JOSE Header "p2c" (PBES2 Count) missing or invalid');
|
|
114
|
-
validateMaxPBES2Count(maxPBES2Count);
|
|
115
114
|
const p2cLimit = maxPBES2Count ?? 1e4;
|
|
116
115
|
if (joseHeader.p2c > p2cLimit)
|
|
117
116
|
throw new JWEInvalid('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');
|