jose 3.20.1 → 3.20.4
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/browser/jwe/flattened/decrypt.js +7 -11
- package/dist/browser/jwe/flattened/encrypt.js +2 -5
- package/dist/browser/jws/flattened/sign.js +1 -2
- package/dist/browser/jws/flattened/verify.js +2 -4
- package/dist/browser/lib/cek.js +3 -2
- package/dist/browser/lib/decrypt_key_management.js +4 -1
- package/dist/browser/lib/encrypt_key_management.js +1 -3
- package/dist/browser/lib/iv.js +3 -2
- package/dist/browser/runtime/aesgcmkw.js +1 -3
- package/dist/browser/runtime/random.js +1 -2
- package/dist/browser/util/errors.js +66 -34
- package/dist/node/cjs/jwe/compact/decrypt.js +1 -1
- package/dist/node/cjs/jwe/flattened/decrypt.js +18 -22
- package/dist/node/cjs/jwe/flattened/encrypt.js +13 -16
- package/dist/node/cjs/jwe/general/decrypt.js +2 -2
- package/dist/node/cjs/jwk/embedded.js +2 -2
- package/dist/node/cjs/jwk/from_key_like.js +1 -1
- package/dist/node/cjs/jwk/parse.js +1 -1
- package/dist/node/cjs/jwk/thumbprint.js +2 -2
- package/dist/node/cjs/jwks/remote.js +3 -3
- package/dist/node/cjs/jws/compact/verify.js +1 -1
- package/dist/node/cjs/jws/flattened/sign.js +8 -9
- package/dist/node/cjs/jws/flattened/verify.js +11 -13
- package/dist/node/cjs/jws/general/verify.js +2 -2
- package/dist/node/cjs/jwt/decrypt.js +2 -2
- package/dist/node/cjs/jwt/produce.js +4 -4
- package/dist/node/cjs/jwt/unsecured.js +1 -1
- package/dist/node/cjs/jwt/verify.js +2 -2
- package/dist/node/cjs/key/export.js +3 -3
- package/dist/node/cjs/key/import.js +10 -10
- package/dist/node/cjs/lib/cek.js +4 -3
- package/dist/node/cjs/lib/check_key_type.js +4 -4
- package/dist/node/cjs/lib/decrypt_key_management.js +16 -13
- package/dist/node/cjs/lib/encrypt_key_management.js +14 -16
- package/dist/node/cjs/lib/iv.js +4 -3
- package/dist/node/cjs/lib/jwt_claims_set.js +4 -4
- package/dist/node/cjs/runtime/aesgcmkw.js +4 -6
- package/dist/node/cjs/runtime/aeskw.js +11 -11
- package/dist/node/cjs/runtime/asn1.js +6 -6
- package/dist/node/cjs/runtime/cbc_tag.js +2 -2
- package/dist/node/cjs/runtime/check_cek_length.js +1 -1
- package/dist/node/cjs/runtime/ciphers.js +1 -1
- package/dist/node/cjs/runtime/decrypt.js +15 -15
- package/dist/node/cjs/runtime/digest.js +1 -1
- package/dist/node/cjs/runtime/ecdhes.js +18 -18
- package/dist/node/cjs/runtime/encrypt.js +14 -14
- package/dist/node/cjs/runtime/fetch_jwks.js +2 -2
- package/dist/node/cjs/runtime/generate.js +4 -4
- package/dist/node/cjs/runtime/get_named_curve.js +5 -5
- package/dist/node/cjs/runtime/get_sign_verify_key.js +5 -5
- package/dist/node/cjs/runtime/invalid_key_input.js +2 -2
- package/dist/node/cjs/runtime/is_key_like.js +1 -1
- package/dist/node/cjs/runtime/jwk_to_key.js +11 -11
- package/dist/node/cjs/runtime/key_to_jwk.js +27 -27
- package/dist/node/cjs/runtime/node_key.js +4 -4
- package/dist/node/cjs/runtime/pbes2kw.js +13 -13
- package/dist/node/cjs/runtime/random.js +3 -2
- package/dist/node/cjs/runtime/rsaes.js +7 -7
- package/dist/node/cjs/runtime/secret_key.js +1 -1
- package/dist/node/cjs/runtime/sign.js +4 -4
- package/dist/node/cjs/runtime/verify.js +5 -5
- package/dist/node/cjs/runtime/zlib.js +2 -2
- package/dist/node/cjs/util/decode_protected_header.js +2 -2
- package/dist/node/cjs/util/errors.js +69 -37
- package/dist/node/cjs/util/generate_key_pair.js +1 -1
- package/dist/node/cjs/util/generate_secret.js +1 -1
- package/dist/node/esm/jwe/flattened/decrypt.js +7 -11
- package/dist/node/esm/jwe/flattened/encrypt.js +2 -5
- package/dist/node/esm/jws/flattened/sign.js +1 -2
- package/dist/node/esm/jws/flattened/verify.js +2 -4
- package/dist/node/esm/lib/cek.js +3 -2
- package/dist/node/esm/lib/decrypt_key_management.js +4 -1
- package/dist/node/esm/lib/encrypt_key_management.js +1 -3
- package/dist/node/esm/lib/iv.js +3 -2
- package/dist/node/esm/runtime/aesgcmkw.js +1 -3
- package/dist/node/esm/runtime/random.js +1 -2
- package/dist/node/esm/util/errors.js +66 -34
- package/dist/types/types.d.ts +1 -0
- package/dist/types/util/errors.d.ts +21 -18
- package/package.json +2 -1
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { decode as base64url } from '../../runtime/base64url.js';
|
|
2
2
|
import decrypt from '../../runtime/decrypt.js';
|
|
3
3
|
import { inflate } from '../../runtime/zlib.js';
|
|
4
|
-
import random from '../../runtime/random.js';
|
|
5
4
|
import { JOSEAlgNotAllowed, JOSENotSupported, JWEInvalid } from '../../util/errors.js';
|
|
6
5
|
import isDisjoint from '../../lib/is_disjoint.js';
|
|
7
6
|
import isObject from '../../lib/is_object.js';
|
|
8
7
|
import decryptKeyManagement from '../../lib/decrypt_key_management.js';
|
|
9
8
|
import { encoder, decoder, concat } from '../../lib/buffer_utils.js';
|
|
10
|
-
import
|
|
9
|
+
import generateCek from '../../lib/cek.js';
|
|
11
10
|
import validateCrit from '../../lib/validate_crit.js';
|
|
12
11
|
import validateAlgorithms from '../../lib/validate_algorithms.js';
|
|
13
|
-
const generateCek = cekFactory(random);
|
|
14
|
-
const checkExtensions = validateCrit.bind(undefined, JWEInvalid, new Map());
|
|
15
|
-
const checkAlgOption = validateAlgorithms.bind(undefined, 'keyManagementAlgorithms');
|
|
16
|
-
const checkEncOption = validateAlgorithms.bind(undefined, 'contentEncryptionAlgorithms');
|
|
17
12
|
async function flattenedDecrypt(jwe, key, options) {
|
|
18
13
|
var _a;
|
|
19
14
|
if (!isObject(jwe)) {
|
|
@@ -64,7 +59,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
64
59
|
...jwe.header,
|
|
65
60
|
...jwe.unprotected,
|
|
66
61
|
};
|
|
67
|
-
|
|
62
|
+
validateCrit(JWEInvalid, new Map(), options === null || options === void 0 ? void 0 : options.crit, parsedProt, joseHeader);
|
|
68
63
|
if (joseHeader.zip !== undefined) {
|
|
69
64
|
if (!parsedProt || !parsedProt.zip) {
|
|
70
65
|
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
|
|
@@ -80,8 +75,9 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
80
75
|
if (typeof enc !== 'string' || !enc) {
|
|
81
76
|
throw new JWEInvalid('missing JWE Encryption Algorithm (enc) in JWE Header');
|
|
82
77
|
}
|
|
83
|
-
const keyManagementAlgorithms = options &&
|
|
84
|
-
const contentEncryptionAlgorithms = options &&
|
|
78
|
+
const keyManagementAlgorithms = options && validateAlgorithms('keyManagementAlgorithms', options.keyManagementAlgorithms);
|
|
79
|
+
const contentEncryptionAlgorithms = options &&
|
|
80
|
+
validateAlgorithms('contentEncryptionAlgorithms', options.contentEncryptionAlgorithms);
|
|
85
81
|
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg)) {
|
|
86
82
|
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter not allowed');
|
|
87
83
|
}
|
|
@@ -99,10 +95,10 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
99
95
|
}
|
|
100
96
|
let cek;
|
|
101
97
|
try {
|
|
102
|
-
cek = await decryptKeyManagement(alg, key, encryptedKey, joseHeader);
|
|
98
|
+
cek = await decryptKeyManagement(alg, key, encryptedKey, joseHeader, options);
|
|
103
99
|
}
|
|
104
100
|
catch (err) {
|
|
105
|
-
if (err instanceof TypeError) {
|
|
101
|
+
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
106
102
|
throw err;
|
|
107
103
|
}
|
|
108
104
|
cek = generateCek(enc);
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { encode as base64url } from '../../runtime/base64url.js';
|
|
2
|
-
import random from '../../runtime/random.js';
|
|
3
2
|
import encrypt from '../../runtime/encrypt.js';
|
|
4
3
|
import { deflate } from '../../runtime/zlib.js';
|
|
5
|
-
import
|
|
4
|
+
import generateIv from '../../lib/iv.js';
|
|
6
5
|
import encryptKeyManagement from '../../lib/encrypt_key_management.js';
|
|
7
6
|
import { JOSENotSupported, JWEInvalid } from '../../util/errors.js';
|
|
8
7
|
import isDisjoint from '../../lib/is_disjoint.js';
|
|
9
8
|
import { encoder, decoder, concat } from '../../lib/buffer_utils.js';
|
|
10
9
|
import validateCrit from '../../lib/validate_crit.js';
|
|
11
|
-
const generateIv = ivFactory(random);
|
|
12
|
-
const checkExtensions = validateCrit.bind(undefined, JWEInvalid, new Map());
|
|
13
10
|
class FlattenedEncrypt {
|
|
14
11
|
constructor(plaintext) {
|
|
15
12
|
if (!(plaintext instanceof Uint8Array)) {
|
|
@@ -75,7 +72,7 @@ class FlattenedEncrypt {
|
|
|
75
72
|
...this._unprotectedHeader,
|
|
76
73
|
...this._sharedUnprotectedHeader,
|
|
77
74
|
};
|
|
78
|
-
|
|
75
|
+
validateCrit(JWEInvalid, new Map(), options === null || options === void 0 ? void 0 : options.crit, this._protectedHeader, joseHeader);
|
|
79
76
|
if (joseHeader.zip !== undefined) {
|
|
80
77
|
if (!this._protectedHeader || !this._protectedHeader.zip) {
|
|
81
78
|
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
|
|
@@ -5,7 +5,6 @@ import { JWSInvalid } from '../../util/errors.js';
|
|
|
5
5
|
import { encoder, decoder, concat } from '../../lib/buffer_utils.js';
|
|
6
6
|
import checkKeyType from '../../lib/check_key_type.js';
|
|
7
7
|
import validateCrit from '../../lib/validate_crit.js';
|
|
8
|
-
const checkExtensions = validateCrit.bind(undefined, JWSInvalid, new Map([['b64', true]]));
|
|
9
8
|
class FlattenedSign {
|
|
10
9
|
constructor(payload) {
|
|
11
10
|
if (!(payload instanceof Uint8Array)) {
|
|
@@ -38,7 +37,7 @@ class FlattenedSign {
|
|
|
38
37
|
...this._protectedHeader,
|
|
39
38
|
...this._unprotectedHeader,
|
|
40
39
|
};
|
|
41
|
-
const extensions =
|
|
40
|
+
const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options === null || options === void 0 ? void 0 : options.crit, this._protectedHeader, joseHeader);
|
|
42
41
|
let b64 = true;
|
|
43
42
|
if (extensions.has('b64')) {
|
|
44
43
|
b64 = this._protectedHeader.b64;
|
|
@@ -7,8 +7,6 @@ import isObject from '../../lib/is_object.js';
|
|
|
7
7
|
import checkKeyType from '../../lib/check_key_type.js';
|
|
8
8
|
import validateCrit from '../../lib/validate_crit.js';
|
|
9
9
|
import validateAlgorithms from '../../lib/validate_algorithms.js';
|
|
10
|
-
const checkExtensions = validateCrit.bind(undefined, JWSInvalid, new Map([['b64', true]]));
|
|
11
|
-
const checkAlgOption = validateAlgorithms.bind(undefined, 'algorithms');
|
|
12
10
|
async function flattenedVerify(jws, key, options) {
|
|
13
11
|
var _a;
|
|
14
12
|
if (!isObject(jws)) {
|
|
@@ -46,7 +44,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
46
44
|
...parsedProt,
|
|
47
45
|
...jws.header,
|
|
48
46
|
};
|
|
49
|
-
const extensions =
|
|
47
|
+
const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options === null || options === void 0 ? void 0 : options.crit, parsedProt, joseHeader);
|
|
50
48
|
let b64 = true;
|
|
51
49
|
if (extensions.has('b64')) {
|
|
52
50
|
b64 = parsedProt.b64;
|
|
@@ -58,7 +56,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
58
56
|
if (typeof alg !== 'string' || !alg) {
|
|
59
57
|
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
60
58
|
}
|
|
61
|
-
const algorithms = options &&
|
|
59
|
+
const algorithms = options && validateAlgorithms('algorithms', options.algorithms);
|
|
62
60
|
if (algorithms && !algorithms.has(alg)) {
|
|
63
61
|
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter not allowed');
|
|
64
62
|
}
|
package/dist/browser/lib/cek.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JOSENotSupported } from '../util/errors.js';
|
|
2
|
+
import random from '../runtime/random.js';
|
|
2
3
|
const bitLengths = new Map([
|
|
3
4
|
['A128CBC-HS256', 256],
|
|
4
5
|
['A128GCM', 128],
|
|
@@ -7,12 +8,12 @@ const bitLengths = new Map([
|
|
|
7
8
|
['A256CBC-HS512', 512],
|
|
8
9
|
['A256GCM', 256],
|
|
9
10
|
]);
|
|
10
|
-
const
|
|
11
|
+
const generateCek = (alg) => {
|
|
11
12
|
const bitLength = bitLengths.get(alg);
|
|
12
13
|
if (!bitLength) {
|
|
13
14
|
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
14
15
|
}
|
|
15
16
|
return random(new Uint8Array(bitLength >> 3));
|
|
16
17
|
};
|
|
17
|
-
export default
|
|
18
|
+
export default generateCek;
|
|
18
19
|
export { bitLengths };
|
|
@@ -9,7 +9,7 @@ import { bitLengths as cekLengths } from '../lib/cek.js';
|
|
|
9
9
|
import { importJWK } from '../key/import.js';
|
|
10
10
|
import checkKeyType from './check_key_type.js';
|
|
11
11
|
import isObject from './is_object.js';
|
|
12
|
-
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
|
|
12
|
+
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
13
13
|
checkKeyType(alg, key, 'decrypt');
|
|
14
14
|
switch (alg) {
|
|
15
15
|
case 'dir': {
|
|
@@ -63,6 +63,9 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
|
|
|
63
63
|
throw new JWEInvalid('JWE Encrypted Key missing');
|
|
64
64
|
if (typeof joseHeader.p2c !== 'number')
|
|
65
65
|
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
66
|
+
const p2cLimit = (options === null || options === void 0 ? void 0 : options.maxPBES2Count) || 10000;
|
|
67
|
+
if (joseHeader.p2c > p2cLimit)
|
|
68
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
66
69
|
if (typeof joseHeader.p2s !== 'string')
|
|
67
70
|
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
68
71
|
return pbes2Kw(alg, key, encryptedKey, joseHeader.p2c, base64url(joseHeader.p2s));
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import random from '../runtime/random.js';
|
|
2
1
|
import { wrap as aesKw } from '../runtime/aeskw.js';
|
|
3
2
|
import * as ECDH from '../runtime/ecdhes.js';
|
|
4
3
|
import { encrypt as pbes2Kw } from '../runtime/pbes2kw.js';
|
|
5
4
|
import { encrypt as rsaEs } from '../runtime/rsaes.js';
|
|
6
5
|
import { wrap as aesGcmKw } from '../runtime/aesgcmkw.js';
|
|
7
6
|
import { encode as base64url } from '../runtime/base64url.js';
|
|
8
|
-
import
|
|
7
|
+
import generateCek, { bitLengths as cekLengths } from '../lib/cek.js';
|
|
9
8
|
import { JOSENotSupported } from '../util/errors.js';
|
|
10
9
|
import { exportJWK } from '../key/export.js';
|
|
11
10
|
import checkKeyType from './check_key_type.js';
|
|
12
|
-
const generateCek = cekFactory(random);
|
|
13
11
|
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
14
12
|
let encryptedKey;
|
|
15
13
|
let parameters;
|
package/dist/browser/lib/iv.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JOSENotSupported } from '../util/errors.js';
|
|
2
|
+
import random from '../runtime/random.js';
|
|
2
3
|
const bitLengths = new Map([
|
|
3
4
|
['A128CBC-HS256', 128],
|
|
4
5
|
['A128GCM', 96],
|
|
@@ -10,12 +11,12 @@ const bitLengths = new Map([
|
|
|
10
11
|
['A256GCM', 96],
|
|
11
12
|
['A256GCMKW', 96],
|
|
12
13
|
]);
|
|
13
|
-
const
|
|
14
|
+
const generateIv = (alg) => {
|
|
14
15
|
const bitLength = bitLengths.get(alg);
|
|
15
16
|
if (!bitLength) {
|
|
16
17
|
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
17
18
|
}
|
|
18
19
|
return random(new Uint8Array(bitLength >> 3));
|
|
19
20
|
};
|
|
20
|
-
export default
|
|
21
|
+
export default generateIv;
|
|
21
22
|
export { bitLengths };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import encrypt from './encrypt.js';
|
|
2
2
|
import decrypt from './decrypt.js';
|
|
3
|
-
import
|
|
4
|
-
import random from './random.js';
|
|
3
|
+
import generateIv from '../lib/iv.js';
|
|
5
4
|
import { encode as base64url } from './base64url.js';
|
|
6
|
-
const generateIv = ivFactory(random);
|
|
7
5
|
export const wrap = async (alg, key, cek, iv) => {
|
|
8
6
|
const jweAlgorithm = alg.substr(0, 7);
|
|
9
7
|
iv || (iv = generateIv(jweAlgorithm));
|
|
@@ -2,114 +2,146 @@ export class JOSEError extends Error {
|
|
|
2
2
|
constructor(message) {
|
|
3
3
|
var _a;
|
|
4
4
|
super(message);
|
|
5
|
-
this.code =
|
|
5
|
+
this.code = 'ERR_JOSE_GENERIC';
|
|
6
6
|
this.name = this.constructor.name;
|
|
7
7
|
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, this.constructor);
|
|
8
8
|
}
|
|
9
|
+
static get code() {
|
|
10
|
+
return 'ERR_JOSE_GENERIC';
|
|
11
|
+
}
|
|
9
12
|
}
|
|
10
|
-
JOSEError.code = 'ERR_JOSE_GENERIC';
|
|
11
13
|
export class JWTClaimValidationFailed extends JOSEError {
|
|
12
14
|
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
13
15
|
super(message);
|
|
14
|
-
this.code =
|
|
16
|
+
this.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
17
|
+
this.claim = claim;
|
|
18
|
+
this.reason = reason;
|
|
19
|
+
}
|
|
20
|
+
static get code() {
|
|
21
|
+
return 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class JWTExpired extends JOSEError {
|
|
25
|
+
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = 'ERR_JWT_EXPIRED';
|
|
15
28
|
this.claim = claim;
|
|
16
29
|
this.reason = reason;
|
|
17
30
|
}
|
|
31
|
+
static get code() {
|
|
32
|
+
return 'ERR_JWT_EXPIRED';
|
|
33
|
+
}
|
|
18
34
|
}
|
|
19
|
-
JWTClaimValidationFailed.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
20
35
|
export class JOSEAlgNotAllowed extends JOSEError {
|
|
21
36
|
constructor() {
|
|
22
37
|
super(...arguments);
|
|
23
|
-
this.code =
|
|
38
|
+
this.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
39
|
+
}
|
|
40
|
+
static get code() {
|
|
41
|
+
return 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
24
42
|
}
|
|
25
43
|
}
|
|
26
|
-
JOSEAlgNotAllowed.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
27
44
|
export class JOSENotSupported extends JOSEError {
|
|
28
45
|
constructor() {
|
|
29
46
|
super(...arguments);
|
|
30
|
-
this.code =
|
|
47
|
+
this.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
48
|
+
}
|
|
49
|
+
static get code() {
|
|
50
|
+
return 'ERR_JOSE_NOT_SUPPORTED';
|
|
31
51
|
}
|
|
32
52
|
}
|
|
33
|
-
JOSENotSupported.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
34
53
|
export class JWEDecryptionFailed extends JOSEError {
|
|
35
54
|
constructor() {
|
|
36
55
|
super(...arguments);
|
|
37
|
-
this.code =
|
|
56
|
+
this.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
38
57
|
this.message = 'decryption operation failed';
|
|
39
58
|
}
|
|
59
|
+
static get code() {
|
|
60
|
+
return 'ERR_JWE_DECRYPTION_FAILED';
|
|
61
|
+
}
|
|
40
62
|
}
|
|
41
|
-
JWEDecryptionFailed.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
42
63
|
export class JWEInvalid extends JOSEError {
|
|
43
64
|
constructor() {
|
|
44
65
|
super(...arguments);
|
|
45
|
-
this.code =
|
|
66
|
+
this.code = 'ERR_JWE_INVALID';
|
|
67
|
+
}
|
|
68
|
+
static get code() {
|
|
69
|
+
return 'ERR_JWE_INVALID';
|
|
46
70
|
}
|
|
47
71
|
}
|
|
48
|
-
JWEInvalid.code = 'ERR_JWE_INVALID';
|
|
49
72
|
export class JWSInvalid extends JOSEError {
|
|
50
73
|
constructor() {
|
|
51
74
|
super(...arguments);
|
|
52
|
-
this.code =
|
|
75
|
+
this.code = 'ERR_JWS_INVALID';
|
|
76
|
+
}
|
|
77
|
+
static get code() {
|
|
78
|
+
return 'ERR_JWS_INVALID';
|
|
53
79
|
}
|
|
54
80
|
}
|
|
55
|
-
JWSInvalid.code = 'ERR_JWS_INVALID';
|
|
56
81
|
export class JWTInvalid extends JOSEError {
|
|
57
82
|
constructor() {
|
|
58
83
|
super(...arguments);
|
|
59
|
-
this.code =
|
|
84
|
+
this.code = 'ERR_JWT_INVALID';
|
|
85
|
+
}
|
|
86
|
+
static get code() {
|
|
87
|
+
return 'ERR_JWT_INVALID';
|
|
60
88
|
}
|
|
61
89
|
}
|
|
62
|
-
JWTInvalid.code = 'ERR_JWT_INVALID';
|
|
63
90
|
export class JWKInvalid extends JOSEError {
|
|
64
91
|
constructor() {
|
|
65
92
|
super(...arguments);
|
|
66
|
-
this.code =
|
|
93
|
+
this.code = 'ERR_JWK_INVALID';
|
|
94
|
+
}
|
|
95
|
+
static get code() {
|
|
96
|
+
return 'ERR_JWK_INVALID';
|
|
67
97
|
}
|
|
68
98
|
}
|
|
69
|
-
JWKInvalid.code = 'ERR_JWK_INVALID';
|
|
70
99
|
export class JWKSInvalid extends JOSEError {
|
|
71
100
|
constructor() {
|
|
72
101
|
super(...arguments);
|
|
73
|
-
this.code =
|
|
102
|
+
this.code = 'ERR_JWKS_INVALID';
|
|
103
|
+
}
|
|
104
|
+
static get code() {
|
|
105
|
+
return 'ERR_JWKS_INVALID';
|
|
74
106
|
}
|
|
75
107
|
}
|
|
76
|
-
JWKSInvalid.code = 'ERR_JWKS_INVALID';
|
|
77
108
|
export class JWKSNoMatchingKey extends JOSEError {
|
|
78
109
|
constructor() {
|
|
79
110
|
super(...arguments);
|
|
80
|
-
this.code =
|
|
111
|
+
this.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
81
112
|
this.message = 'no applicable key found in the JSON Web Key Set';
|
|
82
113
|
}
|
|
114
|
+
static get code() {
|
|
115
|
+
return 'ERR_JWKS_NO_MATCHING_KEY';
|
|
116
|
+
}
|
|
83
117
|
}
|
|
84
|
-
JWKSNoMatchingKey.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
85
118
|
export class JWKSMultipleMatchingKeys extends JOSEError {
|
|
86
119
|
constructor() {
|
|
87
120
|
super(...arguments);
|
|
88
|
-
this.code =
|
|
121
|
+
this.code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
89
122
|
this.message = 'multiple matching keys found in the JSON Web Key Set';
|
|
90
123
|
}
|
|
124
|
+
static get code() {
|
|
125
|
+
return 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
126
|
+
}
|
|
91
127
|
}
|
|
92
|
-
JWKSMultipleMatchingKeys.code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
93
128
|
export class JWKSTimeout extends JOSEError {
|
|
94
129
|
constructor() {
|
|
95
130
|
super(...arguments);
|
|
96
|
-
this.code =
|
|
131
|
+
this.code = 'ERR_JWKS_TIMEOUT';
|
|
97
132
|
this.message = 'request timed out';
|
|
98
133
|
}
|
|
134
|
+
static get code() {
|
|
135
|
+
return 'ERR_JWKS_TIMEOUT';
|
|
136
|
+
}
|
|
99
137
|
}
|
|
100
|
-
JWKSTimeout.code = 'ERR_JWKS_TIMEOUT';
|
|
101
138
|
export class JWSSignatureVerificationFailed extends JOSEError {
|
|
102
139
|
constructor() {
|
|
103
140
|
super(...arguments);
|
|
104
|
-
this.code =
|
|
141
|
+
this.code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
105
142
|
this.message = 'signature verification failed';
|
|
106
143
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
export class JWTExpired extends JWTClaimValidationFailed {
|
|
110
|
-
constructor() {
|
|
111
|
-
super(...arguments);
|
|
112
|
-
this.code = JWTExpired.code;
|
|
144
|
+
static get code() {
|
|
145
|
+
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
113
146
|
}
|
|
114
147
|
}
|
|
115
|
-
JWTExpired.code = 'ERR_JWT_EXPIRED';
|
|
@@ -15,7 +15,7 @@ async function compactDecrypt(jwe, key, options) {
|
|
|
15
15
|
if (length !== 5) {
|
|
16
16
|
throw new errors_js_1.JWEInvalid('Invalid Compact JWE');
|
|
17
17
|
}
|
|
18
|
-
const decrypted = await
|
|
18
|
+
const decrypted = await decrypt_js_1.default({
|
|
19
19
|
ciphertext: (ciphertext || undefined),
|
|
20
20
|
iv: (iv || undefined),
|
|
21
21
|
protected: protectedHeader || undefined,
|
|
@@ -4,7 +4,6 @@ exports.flattenedDecrypt = void 0;
|
|
|
4
4
|
const base64url_js_1 = require("../../runtime/base64url.js");
|
|
5
5
|
const decrypt_js_1 = require("../../runtime/decrypt.js");
|
|
6
6
|
const zlib_js_1 = require("../../runtime/zlib.js");
|
|
7
|
-
const random_js_1 = require("../../runtime/random.js");
|
|
8
7
|
const errors_js_1 = require("../../util/errors.js");
|
|
9
8
|
const is_disjoint_js_1 = require("../../lib/is_disjoint.js");
|
|
10
9
|
const is_object_js_1 = require("../../lib/is_object.js");
|
|
@@ -13,13 +12,9 @@ const buffer_utils_js_1 = require("../../lib/buffer_utils.js");
|
|
|
13
12
|
const cek_js_1 = require("../../lib/cek.js");
|
|
14
13
|
const validate_crit_js_1 = require("../../lib/validate_crit.js");
|
|
15
14
|
const validate_algorithms_js_1 = require("../../lib/validate_algorithms.js");
|
|
16
|
-
const generateCek = (0, cek_js_1.default)(random_js_1.default);
|
|
17
|
-
const checkExtensions = validate_crit_js_1.default.bind(undefined, errors_js_1.JWEInvalid, new Map());
|
|
18
|
-
const checkAlgOption = validate_algorithms_js_1.default.bind(undefined, 'keyManagementAlgorithms');
|
|
19
|
-
const checkEncOption = validate_algorithms_js_1.default.bind(undefined, 'contentEncryptionAlgorithms');
|
|
20
15
|
async function flattenedDecrypt(jwe, key, options) {
|
|
21
16
|
var _a;
|
|
22
|
-
if (!
|
|
17
|
+
if (!is_object_js_1.default(jwe)) {
|
|
23
18
|
throw new errors_js_1.JWEInvalid('Flattened JWE must be an object');
|
|
24
19
|
}
|
|
25
20
|
if (jwe.protected === undefined && jwe.header === undefined && jwe.unprotected === undefined) {
|
|
@@ -43,15 +38,15 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
43
38
|
if (jwe.aad !== undefined && typeof jwe.aad !== 'string') {
|
|
44
39
|
throw new errors_js_1.JWEInvalid('JWE AAD incorrect type');
|
|
45
40
|
}
|
|
46
|
-
if (jwe.header !== undefined && !
|
|
41
|
+
if (jwe.header !== undefined && !is_object_js_1.default(jwe.header)) {
|
|
47
42
|
throw new errors_js_1.JWEInvalid('JWE Shared Unprotected Header incorrect type');
|
|
48
43
|
}
|
|
49
|
-
if (jwe.unprotected !== undefined && !
|
|
44
|
+
if (jwe.unprotected !== undefined && !is_object_js_1.default(jwe.unprotected)) {
|
|
50
45
|
throw new errors_js_1.JWEInvalid('JWE Per-Recipient Unprotected Header incorrect type');
|
|
51
46
|
}
|
|
52
47
|
let parsedProt;
|
|
53
48
|
if (jwe.protected) {
|
|
54
|
-
const protectedHeader =
|
|
49
|
+
const protectedHeader = base64url_js_1.decode(jwe.protected);
|
|
55
50
|
try {
|
|
56
51
|
parsedProt = JSON.parse(buffer_utils_js_1.decoder.decode(protectedHeader));
|
|
57
52
|
}
|
|
@@ -59,7 +54,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
59
54
|
throw new errors_js_1.JWEInvalid('JWE Protected Header is invalid');
|
|
60
55
|
}
|
|
61
56
|
}
|
|
62
|
-
if (!
|
|
57
|
+
if (!is_disjoint_js_1.default(parsedProt, jwe.header, jwe.unprotected)) {
|
|
63
58
|
throw new errors_js_1.JWEInvalid('JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint');
|
|
64
59
|
}
|
|
65
60
|
const joseHeader = {
|
|
@@ -67,7 +62,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
67
62
|
...jwe.header,
|
|
68
63
|
...jwe.unprotected,
|
|
69
64
|
};
|
|
70
|
-
|
|
65
|
+
validate_crit_js_1.default(errors_js_1.JWEInvalid, new Map(), options === null || options === void 0 ? void 0 : options.crit, parsedProt, joseHeader);
|
|
71
66
|
if (joseHeader.zip !== undefined) {
|
|
72
67
|
if (!parsedProt || !parsedProt.zip) {
|
|
73
68
|
throw new errors_js_1.JWEInvalid('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
|
|
@@ -83,8 +78,9 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
83
78
|
if (typeof enc !== 'string' || !enc) {
|
|
84
79
|
throw new errors_js_1.JWEInvalid('missing JWE Encryption Algorithm (enc) in JWE Header');
|
|
85
80
|
}
|
|
86
|
-
const keyManagementAlgorithms = options &&
|
|
87
|
-
const contentEncryptionAlgorithms = options &&
|
|
81
|
+
const keyManagementAlgorithms = options && validate_algorithms_js_1.default('keyManagementAlgorithms', options.keyManagementAlgorithms);
|
|
82
|
+
const contentEncryptionAlgorithms = options &&
|
|
83
|
+
validate_algorithms_js_1.default('contentEncryptionAlgorithms', options.contentEncryptionAlgorithms);
|
|
88
84
|
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg)) {
|
|
89
85
|
throw new errors_js_1.JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter not allowed');
|
|
90
86
|
}
|
|
@@ -93,7 +89,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
93
89
|
}
|
|
94
90
|
let encryptedKey;
|
|
95
91
|
if (jwe.encrypted_key !== undefined) {
|
|
96
|
-
encryptedKey =
|
|
92
|
+
encryptedKey = base64url_js_1.decode(jwe.encrypted_key);
|
|
97
93
|
}
|
|
98
94
|
let resolvedKey = false;
|
|
99
95
|
if (typeof key === 'function') {
|
|
@@ -102,25 +98,25 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
102
98
|
}
|
|
103
99
|
let cek;
|
|
104
100
|
try {
|
|
105
|
-
cek = await
|
|
101
|
+
cek = await decrypt_key_management_js_1.default(alg, key, encryptedKey, joseHeader, options);
|
|
106
102
|
}
|
|
107
103
|
catch (err) {
|
|
108
|
-
if (err instanceof TypeError) {
|
|
104
|
+
if (err instanceof TypeError || err instanceof errors_js_1.JWEInvalid || err instanceof errors_js_1.JOSENotSupported) {
|
|
109
105
|
throw err;
|
|
110
106
|
}
|
|
111
|
-
cek =
|
|
107
|
+
cek = cek_js_1.default(enc);
|
|
112
108
|
}
|
|
113
|
-
const iv =
|
|
114
|
-
const tag =
|
|
109
|
+
const iv = base64url_js_1.decode(jwe.iv);
|
|
110
|
+
const tag = base64url_js_1.decode(jwe.tag);
|
|
115
111
|
const protectedHeader = buffer_utils_js_1.encoder.encode((_a = jwe.protected) !== null && _a !== void 0 ? _a : '');
|
|
116
112
|
let additionalData;
|
|
117
113
|
if (jwe.aad !== undefined) {
|
|
118
|
-
additionalData =
|
|
114
|
+
additionalData = buffer_utils_js_1.concat(protectedHeader, buffer_utils_js_1.encoder.encode('.'), buffer_utils_js_1.encoder.encode(jwe.aad));
|
|
119
115
|
}
|
|
120
116
|
else {
|
|
121
117
|
additionalData = protectedHeader;
|
|
122
118
|
}
|
|
123
|
-
let plaintext = await
|
|
119
|
+
let plaintext = await decrypt_js_1.default(enc, cek, base64url_js_1.decode(jwe.ciphertext), iv, tag, additionalData);
|
|
124
120
|
if (joseHeader.zip === 'DEF') {
|
|
125
121
|
plaintext = await ((options === null || options === void 0 ? void 0 : options.inflateRaw) || zlib_js_1.inflate)(plaintext);
|
|
126
122
|
}
|
|
@@ -129,7 +125,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
129
125
|
result.protectedHeader = parsedProt;
|
|
130
126
|
}
|
|
131
127
|
if (jwe.aad !== undefined) {
|
|
132
|
-
result.additionalAuthenticatedData =
|
|
128
|
+
result.additionalAuthenticatedData = base64url_js_1.decode(jwe.aad);
|
|
133
129
|
}
|
|
134
130
|
if (jwe.unprotected !== undefined) {
|
|
135
131
|
result.sharedUnprotectedHeader = jwe.unprotected;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FlattenedEncrypt = void 0;
|
|
4
4
|
const base64url_js_1 = require("../../runtime/base64url.js");
|
|
5
|
-
const random_js_1 = require("../../runtime/random.js");
|
|
6
5
|
const encrypt_js_1 = require("../../runtime/encrypt.js");
|
|
7
6
|
const zlib_js_1 = require("../../runtime/zlib.js");
|
|
8
7
|
const iv_js_1 = require("../../lib/iv.js");
|
|
@@ -11,8 +10,6 @@ const errors_js_1 = require("../../util/errors.js");
|
|
|
11
10
|
const is_disjoint_js_1 = require("../../lib/is_disjoint.js");
|
|
12
11
|
const buffer_utils_js_1 = require("../../lib/buffer_utils.js");
|
|
13
12
|
const validate_crit_js_1 = require("../../lib/validate_crit.js");
|
|
14
|
-
const generateIv = (0, iv_js_1.default)(random_js_1.default);
|
|
15
|
-
const checkExtensions = validate_crit_js_1.default.bind(undefined, errors_js_1.JWEInvalid, new Map());
|
|
16
13
|
class FlattenedEncrypt {
|
|
17
14
|
constructor(plaintext) {
|
|
18
15
|
if (!(plaintext instanceof Uint8Array)) {
|
|
@@ -70,7 +67,7 @@ class FlattenedEncrypt {
|
|
|
70
67
|
if (!this._protectedHeader && !this._unprotectedHeader && !this._sharedUnprotectedHeader) {
|
|
71
68
|
throw new errors_js_1.JWEInvalid('either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()');
|
|
72
69
|
}
|
|
73
|
-
if (!
|
|
70
|
+
if (!is_disjoint_js_1.default(this._protectedHeader, this._unprotectedHeader, this._sharedUnprotectedHeader)) {
|
|
74
71
|
throw new errors_js_1.JWEInvalid('JWE Shared Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint');
|
|
75
72
|
}
|
|
76
73
|
const joseHeader = {
|
|
@@ -78,7 +75,7 @@ class FlattenedEncrypt {
|
|
|
78
75
|
...this._unprotectedHeader,
|
|
79
76
|
...this._sharedUnprotectedHeader,
|
|
80
77
|
};
|
|
81
|
-
|
|
78
|
+
validate_crit_js_1.default(errors_js_1.JWEInvalid, new Map(), options === null || options === void 0 ? void 0 : options.crit, this._protectedHeader, joseHeader);
|
|
82
79
|
if (joseHeader.zip !== undefined) {
|
|
83
80
|
if (!this._protectedHeader || !this._protectedHeader.zip) {
|
|
84
81
|
throw new errors_js_1.JWEInvalid('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
|
|
@@ -108,7 +105,7 @@ class FlattenedEncrypt {
|
|
|
108
105
|
let cek;
|
|
109
106
|
{
|
|
110
107
|
let parameters;
|
|
111
|
-
({ cek, encryptedKey, parameters } = await
|
|
108
|
+
({ cek, encryptedKey, parameters } = await encrypt_key_management_js_1.default(alg, enc, key, this._cek, this._keyManagementParameters));
|
|
112
109
|
if (parameters) {
|
|
113
110
|
if (!this._protectedHeader) {
|
|
114
111
|
this.setProtectedHeader(parameters);
|
|
@@ -118,19 +115,19 @@ class FlattenedEncrypt {
|
|
|
118
115
|
}
|
|
119
116
|
}
|
|
120
117
|
}
|
|
121
|
-
this._iv || (this._iv =
|
|
118
|
+
this._iv || (this._iv = iv_js_1.default(enc));
|
|
122
119
|
let additionalData;
|
|
123
120
|
let protectedHeader;
|
|
124
121
|
let aadMember;
|
|
125
122
|
if (this._protectedHeader) {
|
|
126
|
-
protectedHeader = buffer_utils_js_1.encoder.encode(
|
|
123
|
+
protectedHeader = buffer_utils_js_1.encoder.encode(base64url_js_1.encode(JSON.stringify(this._protectedHeader)));
|
|
127
124
|
}
|
|
128
125
|
else {
|
|
129
126
|
protectedHeader = buffer_utils_js_1.encoder.encode('');
|
|
130
127
|
}
|
|
131
128
|
if (this._aad) {
|
|
132
|
-
aadMember =
|
|
133
|
-
additionalData =
|
|
129
|
+
aadMember = base64url_js_1.encode(this._aad);
|
|
130
|
+
additionalData = buffer_utils_js_1.concat(protectedHeader, buffer_utils_js_1.encoder.encode('.'), buffer_utils_js_1.encoder.encode(aadMember));
|
|
134
131
|
}
|
|
135
132
|
else {
|
|
136
133
|
additionalData = protectedHeader;
|
|
@@ -139,19 +136,19 @@ class FlattenedEncrypt {
|
|
|
139
136
|
let tag;
|
|
140
137
|
if (joseHeader.zip === 'DEF') {
|
|
141
138
|
const deflated = await ((options === null || options === void 0 ? void 0 : options.deflateRaw) || zlib_js_1.deflate)(this._plaintext);
|
|
142
|
-
({ ciphertext, tag } = await
|
|
139
|
+
({ ciphertext, tag } = await encrypt_js_1.default(enc, deflated, cek, this._iv, additionalData));
|
|
143
140
|
}
|
|
144
141
|
else {
|
|
145
142
|
;
|
|
146
|
-
({ ciphertext, tag } = await
|
|
143
|
+
({ ciphertext, tag } = await encrypt_js_1.default(enc, this._plaintext, cek, this._iv, additionalData));
|
|
147
144
|
}
|
|
148
145
|
const jwe = {
|
|
149
|
-
ciphertext:
|
|
150
|
-
iv:
|
|
151
|
-
tag:
|
|
146
|
+
ciphertext: base64url_js_1.encode(ciphertext),
|
|
147
|
+
iv: base64url_js_1.encode(this._iv),
|
|
148
|
+
tag: base64url_js_1.encode(tag),
|
|
152
149
|
};
|
|
153
150
|
if (encryptedKey) {
|
|
154
|
-
jwe.encrypted_key =
|
|
151
|
+
jwe.encrypted_key = base64url_js_1.encode(encryptedKey);
|
|
155
152
|
}
|
|
156
153
|
if (aadMember) {
|
|
157
154
|
jwe.aad = aadMember;
|
|
@@ -5,7 +5,7 @@ const decrypt_js_1 = require("../flattened/decrypt.js");
|
|
|
5
5
|
const errors_js_1 = require("../../util/errors.js");
|
|
6
6
|
const is_object_js_1 = require("../../lib/is_object.js");
|
|
7
7
|
async function generalDecrypt(jwe, key, options) {
|
|
8
|
-
if (!
|
|
8
|
+
if (!is_object_js_1.default(jwe)) {
|
|
9
9
|
throw new errors_js_1.JWEInvalid('General JWE must be an object');
|
|
10
10
|
}
|
|
11
11
|
if (!Array.isArray(jwe.recipients) || !jwe.recipients.every(is_object_js_1.default)) {
|
|
@@ -13,7 +13,7 @@ async function generalDecrypt(jwe, key, options) {
|
|
|
13
13
|
}
|
|
14
14
|
for (const recipient of jwe.recipients) {
|
|
15
15
|
try {
|
|
16
|
-
return await
|
|
16
|
+
return await decrypt_js_1.default({
|
|
17
17
|
aad: jwe.aad,
|
|
18
18
|
ciphertext: jwe.ciphertext,
|
|
19
19
|
encrypted_key: recipient.encrypted_key,
|