@zuplo/cli 6.73.27 → 6.73.28
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/@modelcontextprotocol/sdk/node_modules/jose/README.md +13 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/index.d.ts +6 -5
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +7 -19
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +7 -19
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +20 -21
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/encrypt.d.ts +10 -34
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/export.d.ts +0 -14
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/import.d.ts +18 -28
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/types.d.ts +242 -223
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/errors.d.ts +128 -121
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +3 -21
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/decrypt.js +15 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/encrypt.js +33 -48
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/local.js +27 -47
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/remote.js +3 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/verify.js +3 -15
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -57
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/sign.js +18 -5
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/verify.js +21 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/decrypt.js +4 -4
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/verify.js +5 -5
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/export.js +34 -1
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/generate_key_pair.js +32 -82
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/import.js +8 -8
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/asn1.js +29 -65
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/content_encryption.js +20 -77
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/crypto_key.js +13 -127
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +143 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +181 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +109 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwk_to_key.js +11 -96
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_algorithms.js +74 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_sign.js +68 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_verify.js +108 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +9 -8
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key.js +170 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_algorithm.js +16 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_management.js +186 -29
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/{validate_crit.js → options.js} +18 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/signing.js +20 -52
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/base64url.js +11 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/errors.js +1 -1
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/package.json +2 -4
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/package.json +6 -6
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
- package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
|
@@ -1,52 +1,18 @@
|
|
|
1
1
|
import { concat, uint64be } from './buffer_utils.js';
|
|
2
|
-
import {
|
|
2
|
+
import { checkCryptoKey } from './crypto_key.js';
|
|
3
3
|
import { invalidKeyInput } from './invalid_key_input.js';
|
|
4
|
-
import {
|
|
4
|
+
import { JWEDecryptionFailed, JWEInvalid } from '../util/errors.js';
|
|
5
5
|
import { isCryptoKey } from './is_key_like.js';
|
|
6
|
-
export
|
|
7
|
-
switch (alg) {
|
|
8
|
-
case 'A128GCM':
|
|
9
|
-
return 128;
|
|
10
|
-
case 'A192GCM':
|
|
11
|
-
return 192;
|
|
12
|
-
case 'A256GCM':
|
|
13
|
-
case 'A128CBC-HS256':
|
|
14
|
-
return 256;
|
|
15
|
-
case 'A192CBC-HS384':
|
|
16
|
-
return 384;
|
|
17
|
-
case 'A256CBC-HS512':
|
|
18
|
-
return 512;
|
|
19
|
-
default:
|
|
20
|
-
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export const generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
|
|
6
|
+
export const generateCek = (enc) => crypto.getRandomValues(new Uint8Array(enc.cekBits >> 3));
|
|
24
7
|
function checkCekLength(cek, expected) {
|
|
25
8
|
const actual = cek.byteLength << 3;
|
|
26
9
|
if (actual !== expected) {
|
|
27
10
|
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
28
11
|
}
|
|
29
12
|
}
|
|
30
|
-
|
|
31
|
-
switch (alg) {
|
|
32
|
-
case 'A128GCM':
|
|
33
|
-
case 'A128GCMKW':
|
|
34
|
-
case 'A192GCM':
|
|
35
|
-
case 'A192GCMKW':
|
|
36
|
-
case 'A256GCM':
|
|
37
|
-
case 'A256GCMKW':
|
|
38
|
-
return 96;
|
|
39
|
-
case 'A128CBC-HS256':
|
|
40
|
-
case 'A192CBC-HS384':
|
|
41
|
-
case 'A256CBC-HS512':
|
|
42
|
-
return 128;
|
|
43
|
-
default:
|
|
44
|
-
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export const generateIv = (alg) => crypto.getRandomValues(new Uint8Array(ivBitLength(alg) >> 3));
|
|
13
|
+
export const generateIv = (enc) => crypto.getRandomValues(new Uint8Array(enc.ivBits >> 3));
|
|
48
14
|
export function checkIvLength(enc, iv) {
|
|
49
|
-
if (iv.length << 3 !==
|
|
15
|
+
if (iv.length << 3 !== enc.ivBits) {
|
|
50
16
|
throw new JWEInvalid('Invalid Initialization Vector length');
|
|
51
17
|
}
|
|
52
18
|
}
|
|
@@ -54,7 +20,7 @@ async function cbcKeySetup(enc, cek, usage) {
|
|
|
54
20
|
if (!(cek instanceof Uint8Array)) {
|
|
55
21
|
throw new TypeError(invalidKeyInput(cek, 'Uint8Array'));
|
|
56
22
|
}
|
|
57
|
-
const keySize =
|
|
23
|
+
const keySize = enc.cekBits >> 1;
|
|
58
24
|
const encKey = await crypto.subtle.importKey('raw', cek.subarray(keySize >> 3), 'AES-CBC', false, [usage]);
|
|
59
25
|
const macKey = await crypto.subtle.importKey('raw', cek.subarray(0, keySize >> 3), {
|
|
60
26
|
hash: `SHA-${keySize << 1}`,
|
|
@@ -71,7 +37,7 @@ async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
|
71
37
|
iv: iv,
|
|
72
38
|
name: 'AES-CBC',
|
|
73
39
|
}, encKey, plaintext));
|
|
74
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length
|
|
40
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
|
|
75
41
|
const tag = await cbcHmacTag(macKey, macData, keySize);
|
|
76
42
|
return { ciphertext, tag, iv };
|
|
77
43
|
}
|
|
@@ -95,7 +61,7 @@ async function timingSafeEqual(a, b) {
|
|
|
95
61
|
}
|
|
96
62
|
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
97
63
|
const { encKey, macKey, keySize } = await cbcKeySetup(enc, cek, 'decrypt');
|
|
98
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length
|
|
64
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
|
|
99
65
|
const expectedTag = await cbcHmacTag(macKey, macData, keySize);
|
|
100
66
|
let macCheckPassed;
|
|
101
67
|
try {
|
|
@@ -123,7 +89,7 @@ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
|
123
89
|
encKey = await crypto.subtle.importKey('raw', cek, 'AES-GCM', false, ['encrypt']);
|
|
124
90
|
}
|
|
125
91
|
else {
|
|
126
|
-
|
|
92
|
+
checkCryptoKey(cek, enc.subtle, 'encrypt');
|
|
127
93
|
encKey = cek;
|
|
128
94
|
}
|
|
129
95
|
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
@@ -142,7 +108,7 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
142
108
|
encKey = await crypto.subtle.importKey('raw', cek, 'AES-GCM', false, ['decrypt']);
|
|
143
109
|
}
|
|
144
110
|
else {
|
|
145
|
-
|
|
111
|
+
checkCryptoKey(cek, enc.subtle, 'decrypt');
|
|
146
112
|
encKey = cek;
|
|
147
113
|
}
|
|
148
114
|
try {
|
|
@@ -157,7 +123,6 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
157
123
|
throw new JWEDecryptionFailed();
|
|
158
124
|
}
|
|
159
125
|
}
|
|
160
|
-
const unsupportedEnc = 'Unsupported JWE Content Encryption Algorithm';
|
|
161
126
|
export async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
162
127
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
163
128
|
throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'KeyObject', 'Uint8Array', 'JSON Web Key'));
|
|
@@ -168,24 +133,12 @@ export async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
|
168
133
|
else {
|
|
169
134
|
iv = generateIv(enc);
|
|
170
135
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
case 'A192CBC-HS384':
|
|
174
|
-
case 'A256CBC-HS512':
|
|
175
|
-
if (cek instanceof Uint8Array) {
|
|
176
|
-
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
177
|
-
}
|
|
178
|
-
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
179
|
-
case 'A128GCM':
|
|
180
|
-
case 'A192GCM':
|
|
181
|
-
case 'A256GCM':
|
|
182
|
-
if (cek instanceof Uint8Array) {
|
|
183
|
-
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
184
|
-
}
|
|
185
|
-
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
186
|
-
default:
|
|
187
|
-
throw new JOSENotSupported(unsupportedEnc);
|
|
136
|
+
if (cek instanceof Uint8Array) {
|
|
137
|
+
checkCekLength(cek, enc.cekBits);
|
|
188
138
|
}
|
|
139
|
+
return enc.cbc
|
|
140
|
+
? cbcEncrypt(enc, plaintext, cek, iv, aad)
|
|
141
|
+
: gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
189
142
|
}
|
|
190
143
|
export async function decrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
191
144
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
@@ -198,20 +151,10 @@ export async function decrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
198
151
|
throw new JWEInvalid('JWE Authentication Tag missing');
|
|
199
152
|
}
|
|
200
153
|
checkIvLength(enc, iv);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
case 'A192CBC-HS384':
|
|
204
|
-
case 'A256CBC-HS512':
|
|
205
|
-
if (cek instanceof Uint8Array)
|
|
206
|
-
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
207
|
-
return cbcDecrypt(enc, cek, ciphertext, iv, tag, aad);
|
|
208
|
-
case 'A128GCM':
|
|
209
|
-
case 'A192GCM':
|
|
210
|
-
case 'A256GCM':
|
|
211
|
-
if (cek instanceof Uint8Array)
|
|
212
|
-
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
213
|
-
return gcmDecrypt(enc, cek, ciphertext, iv, tag, aad);
|
|
214
|
-
default:
|
|
215
|
-
throw new JOSENotSupported(unsupportedEnc);
|
|
154
|
+
if (cek instanceof Uint8Array) {
|
|
155
|
+
checkCekLength(cek, enc.cekBits);
|
|
216
156
|
}
|
|
157
|
+
return enc.cbc
|
|
158
|
+
? cbcDecrypt(enc, cek, ciphertext, iv, tag, aad)
|
|
159
|
+
: gcmDecrypt(enc, cek, ciphertext, iv, tag, aad);
|
|
217
160
|
}
|
package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/crypto_key.js
CHANGED
|
@@ -1,136 +1,22 @@
|
|
|
1
1
|
const unusable = (name, prop = 'algorithm.name') => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
2
|
-
|
|
3
|
-
function getHashLength(hash) {
|
|
4
|
-
return parseInt(hash.name.slice(4), 10);
|
|
5
|
-
}
|
|
6
|
-
function checkHashLength(algorithm, expected) {
|
|
7
|
-
const actual = getHashLength(algorithm.hash);
|
|
8
|
-
if (actual !== expected)
|
|
9
|
-
throw unusable(`SHA-${expected}`, 'algorithm.hash');
|
|
10
|
-
}
|
|
11
|
-
function getNamedCurve(alg) {
|
|
12
|
-
switch (alg) {
|
|
13
|
-
case 'ES256':
|
|
14
|
-
return 'P-256';
|
|
15
|
-
case 'ES384':
|
|
16
|
-
return 'P-384';
|
|
17
|
-
case 'ES512':
|
|
18
|
-
return 'P-521';
|
|
19
|
-
default:
|
|
20
|
-
throw new Error('unreachable');
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function checkUsage(key, usage) {
|
|
2
|
+
export function checkUsage(key, usage) {
|
|
24
3
|
if (usage && !key.usages.includes(usage)) {
|
|
25
4
|
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
26
5
|
}
|
|
27
6
|
}
|
|
28
|
-
export function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
case 'HS512': {
|
|
33
|
-
if (!isAlgorithm(key.algorithm, 'HMAC'))
|
|
34
|
-
throw unusable('HMAC');
|
|
35
|
-
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 'RS256':
|
|
39
|
-
case 'RS384':
|
|
40
|
-
case 'RS512': {
|
|
41
|
-
if (!isAlgorithm(key.algorithm, 'RSASSA-PKCS1-v1_5'))
|
|
42
|
-
throw unusable('RSASSA-PKCS1-v1_5');
|
|
43
|
-
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
case 'PS256':
|
|
47
|
-
case 'PS384':
|
|
48
|
-
case 'PS512': {
|
|
49
|
-
if (!isAlgorithm(key.algorithm, 'RSA-PSS'))
|
|
50
|
-
throw unusable('RSA-PSS');
|
|
51
|
-
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case 'Ed25519':
|
|
55
|
-
case 'EdDSA': {
|
|
56
|
-
if (!isAlgorithm(key.algorithm, 'Ed25519'))
|
|
57
|
-
throw unusable('Ed25519');
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
case 'ML-DSA-44':
|
|
61
|
-
case 'ML-DSA-65':
|
|
62
|
-
case 'ML-DSA-87': {
|
|
63
|
-
if (!isAlgorithm(key.algorithm, alg))
|
|
64
|
-
throw unusable(alg);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
case 'ES256':
|
|
68
|
-
case 'ES384':
|
|
69
|
-
case 'ES512': {
|
|
70
|
-
if (!isAlgorithm(key.algorithm, 'ECDSA'))
|
|
71
|
-
throw unusable('ECDSA');
|
|
72
|
-
const expected = getNamedCurve(alg);
|
|
73
|
-
const actual = key.algorithm.namedCurve;
|
|
74
|
-
if (actual !== expected)
|
|
75
|
-
throw unusable(expected, 'algorithm.namedCurve');
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
default:
|
|
79
|
-
throw new TypeError('CryptoKey does not support this operation');
|
|
7
|
+
export function checkCryptoKey(key, expected, usage) {
|
|
8
|
+
const algorithm = key.algorithm;
|
|
9
|
+
if (algorithm.name !== expected.name) {
|
|
10
|
+
throw unusable(expected.name);
|
|
80
11
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
throw unusable('AES-GCM');
|
|
90
|
-
const expected = parseInt(alg.slice(1, 4), 10);
|
|
91
|
-
const actual = key.algorithm.length;
|
|
92
|
-
if (actual !== expected)
|
|
93
|
-
throw unusable(expected, 'algorithm.length');
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
case 'A128KW':
|
|
97
|
-
case 'A192KW':
|
|
98
|
-
case 'A256KW': {
|
|
99
|
-
if (!isAlgorithm(key.algorithm, 'AES-KW'))
|
|
100
|
-
throw unusable('AES-KW');
|
|
101
|
-
const expected = parseInt(alg.slice(1, 4), 10);
|
|
102
|
-
const actual = key.algorithm.length;
|
|
103
|
-
if (actual !== expected)
|
|
104
|
-
throw unusable(expected, 'algorithm.length');
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
case 'ECDH': {
|
|
108
|
-
switch (key.algorithm.name) {
|
|
109
|
-
case 'ECDH':
|
|
110
|
-
case 'X25519':
|
|
111
|
-
break;
|
|
112
|
-
default:
|
|
113
|
-
throw unusable('ECDH or X25519');
|
|
114
|
-
}
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
case 'PBES2-HS256+A128KW':
|
|
118
|
-
case 'PBES2-HS384+A192KW':
|
|
119
|
-
case 'PBES2-HS512+A256KW':
|
|
120
|
-
if (!isAlgorithm(key.algorithm, 'PBKDF2'))
|
|
121
|
-
throw unusable('PBKDF2');
|
|
122
|
-
break;
|
|
123
|
-
case 'RSA-OAEP':
|
|
124
|
-
case 'RSA-OAEP-256':
|
|
125
|
-
case 'RSA-OAEP-384':
|
|
126
|
-
case 'RSA-OAEP-512': {
|
|
127
|
-
if (!isAlgorithm(key.algorithm, 'RSA-OAEP'))
|
|
128
|
-
throw unusable('RSA-OAEP');
|
|
129
|
-
checkHashLength(key.algorithm, parseInt(alg.slice(9), 10) || 1);
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
default:
|
|
133
|
-
throw new TypeError('CryptoKey does not support this operation');
|
|
12
|
+
if (expected.hash && algorithm.hash?.name !== expected.hash) {
|
|
13
|
+
throw unusable(expected.hash, 'algorithm.hash');
|
|
14
|
+
}
|
|
15
|
+
if (expected.namedCurve && algorithm.namedCurve !== expected.namedCurve) {
|
|
16
|
+
throw unusable(expected.namedCurve, 'algorithm.namedCurve');
|
|
17
|
+
}
|
|
18
|
+
if (expected.length !== undefined && algorithm.length !== expected.length) {
|
|
19
|
+
throw unusable(expected.length, 'algorithm.length');
|
|
134
20
|
}
|
|
135
21
|
checkUsage(key, usage);
|
|
136
22
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { decode } from '../util/base64url.js';
|
|
2
|
+
import { encode, strictDecoder } from './buffer_utils.js';
|
|
3
|
+
import { isObject } from './type_checks.js';
|
|
2
4
|
export const unprotected = Symbol();
|
|
3
5
|
export function assertNotSet(value, name) {
|
|
4
6
|
if (value) {
|
|
@@ -13,7 +15,28 @@ export function decodeBase64url(value, label, ErrorClass) {
|
|
|
13
15
|
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
14
16
|
}
|
|
15
17
|
}
|
|
18
|
+
export function encodeBase64url(value, label, ErrorClass) {
|
|
19
|
+
try {
|
|
20
|
+
return encode(value);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new ErrorClass(`The ${label} is not a valid base64url string`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
16
26
|
export async function digest(algorithm, data) {
|
|
17
27
|
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
18
28
|
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
19
29
|
}
|
|
30
|
+
export function parseJoseHeader(b64, ErrorClass, message) {
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = JSON.parse(strictDecoder.decode(decode(b64)));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new ErrorClass(message);
|
|
37
|
+
}
|
|
38
|
+
if (!isObject(parsed)) {
|
|
39
|
+
throw new ErrorClass(message);
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_algorithms.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { JOSENotSupported } from '../util/errors.js';
|
|
2
|
+
import { table } from './key_descriptor.js';
|
|
3
|
+
const wrap = {
|
|
4
|
+
public: ['encrypt', 'wrapKey'],
|
|
5
|
+
private: ['decrypt', 'unwrapKey'],
|
|
6
|
+
};
|
|
7
|
+
const derive = { public: [], private: ['deriveBits'] };
|
|
8
|
+
const none = { public: [], private: [] };
|
|
9
|
+
function rsaes(bits) {
|
|
10
|
+
return {
|
|
11
|
+
kty: ['RSA'],
|
|
12
|
+
subtle: { name: 'RSA-OAEP', hash: `SHA-${bits}` },
|
|
13
|
+
usages: wrap,
|
|
14
|
+
minModulusLength: 2048,
|
|
15
|
+
keyOps: { encrypt: 'wrapKey', decrypt: 'unwrapKey' },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function ecdh(kwBits) {
|
|
19
|
+
return {
|
|
20
|
+
kty: ['EC', 'OKP'],
|
|
21
|
+
subtle: { name: 'ECDH' },
|
|
22
|
+
subtleFor: ({ kty, crv, asymmetricKeyType }) => {
|
|
23
|
+
if (crv === 'X25519' || asymmetricKeyType === 'x25519') {
|
|
24
|
+
return { name: 'X25519' };
|
|
25
|
+
}
|
|
26
|
+
if (kty === 'OKP') {
|
|
27
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
28
|
+
}
|
|
29
|
+
return { name: 'ECDH', namedCurve: crv };
|
|
30
|
+
},
|
|
31
|
+
usages: derive,
|
|
32
|
+
kwBits,
|
|
33
|
+
keyOps: { decrypt: 'deriveBits' },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function aeskw(bits) {
|
|
37
|
+
return {
|
|
38
|
+
kty: ['oct'],
|
|
39
|
+
symmetric: true,
|
|
40
|
+
subtle: { name: 'AES-KW', length: bits },
|
|
41
|
+
usages: none,
|
|
42
|
+
keyOps: { encrypt: 'wrapKey', decrypt: 'unwrapKey' },
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function aesgcmkw(bits) {
|
|
46
|
+
return {
|
|
47
|
+
kty: ['oct'],
|
|
48
|
+
symmetric: true,
|
|
49
|
+
subtle: { name: 'AES-GCM', length: bits },
|
|
50
|
+
usages: none,
|
|
51
|
+
gcmkw: `A${bits}GCM`,
|
|
52
|
+
keyOps: { encrypt: 'encrypt', decrypt: 'decrypt' },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function pbes2(bits, kwBits) {
|
|
56
|
+
return {
|
|
57
|
+
kty: ['oct'],
|
|
58
|
+
symmetric: true,
|
|
59
|
+
subtle: { name: 'PBKDF2' },
|
|
60
|
+
usages: none,
|
|
61
|
+
pbes2Hash: `SHA-${bits}`,
|
|
62
|
+
kwBits,
|
|
63
|
+
keyOps: { encrypt: 'deriveBits', decrypt: 'deriveBits' },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const JWE = table({
|
|
67
|
+
dir: {
|
|
68
|
+
kty: ['oct'],
|
|
69
|
+
symmetric: true,
|
|
70
|
+
subtle: { name: 'AES-GCM' },
|
|
71
|
+
usages: none,
|
|
72
|
+
keyOps: { encrypt: 'encrypt', decrypt: 'decrypt' },
|
|
73
|
+
},
|
|
74
|
+
'RSA-OAEP': rsaes(1),
|
|
75
|
+
'RSA-OAEP-256': rsaes(256),
|
|
76
|
+
'RSA-OAEP-384': rsaes(384),
|
|
77
|
+
'RSA-OAEP-512': rsaes(512),
|
|
78
|
+
'ECDH-ES': ecdh(),
|
|
79
|
+
'ECDH-ES+A128KW': ecdh(128),
|
|
80
|
+
'ECDH-ES+A192KW': ecdh(192),
|
|
81
|
+
'ECDH-ES+A256KW': ecdh(256),
|
|
82
|
+
A128KW: aeskw(128),
|
|
83
|
+
A192KW: aeskw(192),
|
|
84
|
+
A256KW: aeskw(256),
|
|
85
|
+
A128GCMKW: aesgcmkw(128),
|
|
86
|
+
A192GCMKW: aesgcmkw(192),
|
|
87
|
+
A256GCMKW: aesgcmkw(256),
|
|
88
|
+
'PBES2-HS256+A128KW': pbes2(256, 128),
|
|
89
|
+
'PBES2-HS384+A192KW': pbes2(384, 192),
|
|
90
|
+
'PBES2-HS512+A256KW': pbes2(512, 256),
|
|
91
|
+
});
|
|
92
|
+
const content = { public: [], private: [] };
|
|
93
|
+
const contentOps = { encrypt: 'encrypt', decrypt: 'decrypt' };
|
|
94
|
+
function gcm(bits) {
|
|
95
|
+
return {
|
|
96
|
+
kty: ['oct'],
|
|
97
|
+
symmetric: true,
|
|
98
|
+
subtle: { name: 'AES-GCM', length: bits },
|
|
99
|
+
usages: content,
|
|
100
|
+
keyOps: contentOps,
|
|
101
|
+
cekBits: bits,
|
|
102
|
+
ivBits: 96,
|
|
103
|
+
cbc: false,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function cbc(bits) {
|
|
107
|
+
return {
|
|
108
|
+
kty: ['oct'],
|
|
109
|
+
symmetric: true,
|
|
110
|
+
subtle: { name: 'AES-CBC', length: bits },
|
|
111
|
+
usages: content,
|
|
112
|
+
keyOps: contentOps,
|
|
113
|
+
cekBits: bits,
|
|
114
|
+
ivBits: 128,
|
|
115
|
+
cbc: true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const ENC = table({
|
|
119
|
+
A128GCM: gcm(128),
|
|
120
|
+
A192GCM: gcm(192),
|
|
121
|
+
A256GCM: gcm(256),
|
|
122
|
+
'A128CBC-HS256': cbc(256),
|
|
123
|
+
'A192CBC-HS384': cbc(384),
|
|
124
|
+
'A256CBC-HS512': cbc(512),
|
|
125
|
+
});
|
|
126
|
+
const unsupportedAlgHeader = 'Invalid or unsupported "alg" (JWE Algorithm) header value';
|
|
127
|
+
export function jweAlgorithm(alg) {
|
|
128
|
+
const entry = JWE[alg];
|
|
129
|
+
if (!entry) {
|
|
130
|
+
throw new JOSENotSupported(unsupportedAlgHeader);
|
|
131
|
+
}
|
|
132
|
+
return entry;
|
|
133
|
+
}
|
|
134
|
+
export function maybeJWEAlgorithm(alg) {
|
|
135
|
+
return JWE[alg];
|
|
136
|
+
}
|
|
137
|
+
export function jweEncryption(enc) {
|
|
138
|
+
const entry = ENC[enc];
|
|
139
|
+
if (!entry) {
|
|
140
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${enc}`);
|
|
141
|
+
}
|
|
142
|
+
return entry;
|
|
143
|
+
}
|
package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_decrypt.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { decrypt, generateCek } from './content_encryption.js';
|
|
2
|
+
import { decodeBase64url, encodeBase64url, parseJoseHeader } from './helpers.js';
|
|
3
|
+
import { JOSEAlgNotAllowed, JOSENotSupported, JWEInvalid } from '../util/errors.js';
|
|
4
|
+
import { isDisjoint, isObject } from './type_checks.js';
|
|
5
|
+
import { decryptKeyManagement } from './key_management.js';
|
|
6
|
+
import { concat, decoder, encode } from './buffer_utils.js';
|
|
7
|
+
import { validateCrit, validateAlgorithms, JWE_RECOGNIZED } from './options.js';
|
|
8
|
+
import { prepareKey } from './key.js';
|
|
9
|
+
import { jweAlgorithm, jweEncryption } from './jwe_algorithms.js';
|
|
10
|
+
import { decompress } from './deflate.js';
|
|
11
|
+
export function checkShared(jwe) {
|
|
12
|
+
if (jwe.iv !== undefined && typeof jwe.iv !== 'string') {
|
|
13
|
+
throw new JWEInvalid('JWE Initialization Vector incorrect type');
|
|
14
|
+
}
|
|
15
|
+
if (typeof jwe.ciphertext !== 'string') {
|
|
16
|
+
throw new JWEInvalid('JWE Ciphertext missing or incorrect type');
|
|
17
|
+
}
|
|
18
|
+
if (jwe.tag !== undefined && typeof jwe.tag !== 'string') {
|
|
19
|
+
throw new JWEInvalid('JWE Authentication Tag incorrect type');
|
|
20
|
+
}
|
|
21
|
+
if (jwe.protected !== undefined && typeof jwe.protected !== 'string') {
|
|
22
|
+
throw new JWEInvalid('JWE Protected Header incorrect type');
|
|
23
|
+
}
|
|
24
|
+
if (jwe.aad !== undefined && typeof jwe.aad !== 'string') {
|
|
25
|
+
throw new JWEInvalid('JWE AAD incorrect type');
|
|
26
|
+
}
|
|
27
|
+
if (jwe.unprotected !== undefined && !isObject(jwe.unprotected)) {
|
|
28
|
+
throw new JWEInvalid('JWE Shared Unprotected Header incorrect type');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function checkRecipient(jwe) {
|
|
32
|
+
if (jwe.encrypted_key !== undefined && typeof jwe.encrypted_key !== 'string') {
|
|
33
|
+
throw new JWEInvalid('JWE Encrypted Key incorrect type');
|
|
34
|
+
}
|
|
35
|
+
if (jwe.header !== undefined && !isObject(jwe.header)) {
|
|
36
|
+
throw new JWEInvalid('JWE Per-Recipient Unprotected Header incorrect type');
|
|
37
|
+
}
|
|
38
|
+
if (jwe.protected === undefined && jwe.header === undefined && jwe.unprotected === undefined) {
|
|
39
|
+
throw new JWEInvalid('JOSE Header missing');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function shareJWE(jwe) {
|
|
43
|
+
let parsedProt;
|
|
44
|
+
if (jwe.protected) {
|
|
45
|
+
parsedProt = parseJoseHeader(jwe.protected, JWEInvalid, 'JWE Protected Header is invalid');
|
|
46
|
+
}
|
|
47
|
+
const protectedHeader = jwe.protected !== undefined ? encode(jwe.protected) : new Uint8Array();
|
|
48
|
+
return {
|
|
49
|
+
parsedProt,
|
|
50
|
+
ciphertext: decodeBase64url(jwe.ciphertext, 'ciphertext', JWEInvalid),
|
|
51
|
+
iv: jwe.iv !== undefined ? decodeBase64url(jwe.iv, 'iv', JWEInvalid) : undefined,
|
|
52
|
+
tag: jwe.tag !== undefined ? decodeBase64url(jwe.tag, 'tag', JWEInvalid) : undefined,
|
|
53
|
+
additionalData: jwe.aad !== undefined
|
|
54
|
+
? concat(protectedHeader, encode('.'), encodeBase64url(jwe.aad, 'aad', JWEInvalid))
|
|
55
|
+
: protectedHeader,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function decryptResult(jwe, decrypted) {
|
|
59
|
+
const result = { plaintext: decrypted.plaintext };
|
|
60
|
+
if (jwe.protected !== undefined) {
|
|
61
|
+
result.protectedHeader = decrypted.parsedProt;
|
|
62
|
+
}
|
|
63
|
+
if (jwe.aad !== undefined) {
|
|
64
|
+
result.additionalAuthenticatedData = decodeBase64url(jwe.aad, 'aad', JWEInvalid);
|
|
65
|
+
}
|
|
66
|
+
if (jwe.unprotected !== undefined) {
|
|
67
|
+
result.sharedUnprotectedHeader = jwe.unprotected;
|
|
68
|
+
}
|
|
69
|
+
if (jwe.header !== undefined) {
|
|
70
|
+
result.unprotectedHeader = jwe.header;
|
|
71
|
+
}
|
|
72
|
+
if (decrypted.resolvedKey) {
|
|
73
|
+
return { ...result, key: decrypted.key };
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
export function prepareDecrypt(options) {
|
|
78
|
+
return {
|
|
79
|
+
keyManagementAlgorithms: options && validateAlgorithms('keyManagementAlgorithms', options.keyManagementAlgorithms),
|
|
80
|
+
contentEncryptionAlgorithms: options &&
|
|
81
|
+
validateAlgorithms('contentEncryptionAlgorithms', options.contentEncryptionAlgorithms),
|
|
82
|
+
options,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export async function decryptRecipient(jwe, token, shared, key) {
|
|
86
|
+
const { options } = shared;
|
|
87
|
+
const { parsedProt } = token;
|
|
88
|
+
let joseHeader;
|
|
89
|
+
if (jwe.header !== undefined || jwe.unprotected !== undefined) {
|
|
90
|
+
if (!isDisjoint(parsedProt, jwe.header, jwe.unprotected)) {
|
|
91
|
+
throw new JWEInvalid('JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint');
|
|
92
|
+
}
|
|
93
|
+
joseHeader = { ...parsedProt, ...jwe.header, ...jwe.unprotected };
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
joseHeader = parsedProt ?? {};
|
|
97
|
+
}
|
|
98
|
+
validateCrit(JWEInvalid, JWE_RECOGNIZED, options?.crit, parsedProt, joseHeader);
|
|
99
|
+
if (joseHeader.zip !== undefined && joseHeader.zip !== 'DEF') {
|
|
100
|
+
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
101
|
+
}
|
|
102
|
+
if (joseHeader.zip !== undefined && !parsedProt?.zip) {
|
|
103
|
+
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
104
|
+
}
|
|
105
|
+
const { alg, enc } = joseHeader;
|
|
106
|
+
if (typeof alg !== 'string' || !alg) {
|
|
107
|
+
throw new JWEInvalid('missing JWE Algorithm (alg) in JWE Header');
|
|
108
|
+
}
|
|
109
|
+
if (typeof enc !== 'string' || !enc) {
|
|
110
|
+
throw new JWEInvalid('missing JWE Encryption Algorithm (enc) in JWE Header');
|
|
111
|
+
}
|
|
112
|
+
const { keyManagementAlgorithms, contentEncryptionAlgorithms } = shared;
|
|
113
|
+
if ((keyManagementAlgorithms && !keyManagementAlgorithms.has(alg)) ||
|
|
114
|
+
(!keyManagementAlgorithms && alg.startsWith('PBES2'))) {
|
|
115
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
116
|
+
}
|
|
117
|
+
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
|
|
118
|
+
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
119
|
+
}
|
|
120
|
+
const encEntry = jweEncryption(enc);
|
|
121
|
+
let encryptedKey;
|
|
122
|
+
if (jwe.encrypted_key !== undefined) {
|
|
123
|
+
encryptedKey = decodeBase64url(jwe.encrypted_key, 'encrypted_key', JWEInvalid);
|
|
124
|
+
}
|
|
125
|
+
let resolvedKey = false;
|
|
126
|
+
if (typeof key === 'function') {
|
|
127
|
+
key = await key(parsedProt, jwe);
|
|
128
|
+
resolvedKey = true;
|
|
129
|
+
}
|
|
130
|
+
const algEntry = jweAlgorithm(alg);
|
|
131
|
+
const k = await prepareKey(alg === 'dir' ? encEntry : algEntry, key, 'decrypt');
|
|
132
|
+
let cek;
|
|
133
|
+
try {
|
|
134
|
+
cek = await decryptKeyManagement(alg, encEntry, k, encryptedKey, joseHeader, options);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
cek = generateCek(encEntry);
|
|
141
|
+
}
|
|
142
|
+
let plaintext = await decrypt(encEntry, cek, token.ciphertext, token.iv, token.tag, token.additionalData);
|
|
143
|
+
if (joseHeader.zip === 'DEF') {
|
|
144
|
+
const maxDecompressedLength = options?.maxDecompressedLength ?? 250_000;
|
|
145
|
+
if (maxDecompressedLength === 0) {
|
|
146
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
147
|
+
}
|
|
148
|
+
if (maxDecompressedLength !== Infinity &&
|
|
149
|
+
(!Number.isSafeInteger(maxDecompressedLength) || maxDecompressedLength < 1)) {
|
|
150
|
+
throw new TypeError('maxDecompressedLength must be 0, a positive safe integer, or Infinity');
|
|
151
|
+
}
|
|
152
|
+
plaintext = await decompress(plaintext, maxDecompressedLength).catch((cause) => {
|
|
153
|
+
if (cause instanceof JWEInvalid)
|
|
154
|
+
throw cause;
|
|
155
|
+
throw new JWEInvalid('Failed to decompress plaintext', { cause });
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return { plaintext, parsedProt, key: k, resolvedKey };
|
|
159
|
+
}
|
|
160
|
+
export async function decryptJWE(jwe, shared, key) {
|
|
161
|
+
return decryptRecipient(jwe, shareJWE(jwe), shared, key);
|
|
162
|
+
}
|
|
163
|
+
export async function decryptCompact(jwe, shared, key) {
|
|
164
|
+
if (jwe instanceof Uint8Array) {
|
|
165
|
+
jwe = decoder.decode(jwe);
|
|
166
|
+
}
|
|
167
|
+
if (typeof jwe !== 'string') {
|
|
168
|
+
throw new JWEInvalid('Compact JWE must be a string or Uint8Array');
|
|
169
|
+
}
|
|
170
|
+
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag, length, } = jwe.split('.');
|
|
171
|
+
if (length !== 5) {
|
|
172
|
+
throw new JWEInvalid('Invalid Compact JWE');
|
|
173
|
+
}
|
|
174
|
+
return decryptJWE({
|
|
175
|
+
ciphertext,
|
|
176
|
+
iv: iv || undefined,
|
|
177
|
+
protected: protectedHeader,
|
|
178
|
+
tag: tag || undefined,
|
|
179
|
+
encrypted_key: encryptedKey || undefined,
|
|
180
|
+
}, shared, key);
|
|
181
|
+
}
|