jose 3.20.2 → 3.20.3
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 +5 -9
- 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/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 +11 -9
- package/dist/node/cjs/jwe/flattened/decrypt.js +5 -9
- package/dist/node/cjs/jwe/flattened/encrypt.js +2 -5
- package/dist/node/cjs/jws/flattened/sign.js +1 -2
- package/dist/node/cjs/jws/flattened/verify.js +2 -4
- package/dist/node/cjs/lib/cek.js +4 -3
- package/dist/node/cjs/lib/encrypt_key_management.js +5 -7
- package/dist/node/cjs/lib/iv.js +4 -3
- package/dist/node/cjs/runtime/aesgcmkw.js +1 -3
- package/dist/node/cjs/util/errors.js +13 -11
- package/dist/node/esm/jwe/flattened/decrypt.js +5 -9
- 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/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/util/errors.js +11 -9
- package/dist/types/util/errors.d.ts +7 -4
- package/package.json +1 -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
|
}
|
|
@@ -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 };
|
|
@@ -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));
|
|
@@ -21,6 +21,17 @@ export class JWTClaimValidationFailed extends JOSEError {
|
|
|
21
21
|
return 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
export class JWTExpired extends JOSEError {
|
|
25
|
+
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = 'ERR_JWT_EXPIRED';
|
|
28
|
+
this.claim = claim;
|
|
29
|
+
this.reason = reason;
|
|
30
|
+
}
|
|
31
|
+
static get code() {
|
|
32
|
+
return 'ERR_JWT_EXPIRED';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
export class JOSEAlgNotAllowed extends JOSEError {
|
|
25
36
|
constructor() {
|
|
26
37
|
super(...arguments);
|
|
@@ -134,12 +145,3 @@ export class JWSSignatureVerificationFailed extends JOSEError {
|
|
|
134
145
|
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
135
146
|
}
|
|
136
147
|
}
|
|
137
|
-
export class JWTExpired extends JWTClaimValidationFailed {
|
|
138
|
-
constructor() {
|
|
139
|
-
super(...arguments);
|
|
140
|
-
this.code = 'ERR_JWT_EXPIRED';
|
|
141
|
-
}
|
|
142
|
-
static get code() {
|
|
143
|
-
return 'ERR_JWT_EXPIRED';
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -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,10 +12,6 @@ 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
17
|
if (!(0, is_object_js_1.default)(jwe)) {
|
|
@@ -67,7 +62,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
67
62
|
...jwe.header,
|
|
68
63
|
...jwe.unprotected,
|
|
69
64
|
};
|
|
70
|
-
|
|
65
|
+
(0, 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 && (0, validate_algorithms_js_1.default)('keyManagementAlgorithms', options.keyManagementAlgorithms);
|
|
82
|
+
const contentEncryptionAlgorithms = options &&
|
|
83
|
+
(0, 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
|
}
|
|
@@ -108,7 +104,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
108
104
|
if (err instanceof TypeError) {
|
|
109
105
|
throw err;
|
|
110
106
|
}
|
|
111
|
-
cek =
|
|
107
|
+
cek = (0, cek_js_1.default)(enc);
|
|
112
108
|
}
|
|
113
109
|
const iv = (0, base64url_js_1.decode)(jwe.iv);
|
|
114
110
|
const tag = (0, base64url_js_1.decode)(jwe.tag);
|
|
@@ -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)) {
|
|
@@ -78,7 +75,7 @@ class FlattenedEncrypt {
|
|
|
78
75
|
...this._unprotectedHeader,
|
|
79
76
|
...this._sharedUnprotectedHeader,
|
|
80
77
|
};
|
|
81
|
-
|
|
78
|
+
(0, 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');
|
|
@@ -118,7 +115,7 @@ class FlattenedEncrypt {
|
|
|
118
115
|
}
|
|
119
116
|
}
|
|
120
117
|
}
|
|
121
|
-
this._iv || (this._iv =
|
|
118
|
+
this._iv || (this._iv = (0, iv_js_1.default)(enc));
|
|
122
119
|
let additionalData;
|
|
123
120
|
let protectedHeader;
|
|
124
121
|
let aadMember;
|
|
@@ -8,7 +8,6 @@ const errors_js_1 = require("../../util/errors.js");
|
|
|
8
8
|
const buffer_utils_js_1 = require("../../lib/buffer_utils.js");
|
|
9
9
|
const check_key_type_js_1 = require("../../lib/check_key_type.js");
|
|
10
10
|
const validate_crit_js_1 = require("../../lib/validate_crit.js");
|
|
11
|
-
const checkExtensions = validate_crit_js_1.default.bind(undefined, errors_js_1.JWSInvalid, new Map([['b64', true]]));
|
|
12
11
|
class FlattenedSign {
|
|
13
12
|
constructor(payload) {
|
|
14
13
|
if (!(payload instanceof Uint8Array)) {
|
|
@@ -41,7 +40,7 @@ class FlattenedSign {
|
|
|
41
40
|
...this._protectedHeader,
|
|
42
41
|
...this._unprotectedHeader,
|
|
43
42
|
};
|
|
44
|
-
const extensions =
|
|
43
|
+
const extensions = (0, validate_crit_js_1.default)(errors_js_1.JWSInvalid, new Map([['b64', true]]), options === null || options === void 0 ? void 0 : options.crit, this._protectedHeader, joseHeader);
|
|
45
44
|
let b64 = true;
|
|
46
45
|
if (extensions.has('b64')) {
|
|
47
46
|
b64 = this._protectedHeader.b64;
|
|
@@ -10,8 +10,6 @@ const is_object_js_1 = require("../../lib/is_object.js");
|
|
|
10
10
|
const check_key_type_js_1 = require("../../lib/check_key_type.js");
|
|
11
11
|
const validate_crit_js_1 = require("../../lib/validate_crit.js");
|
|
12
12
|
const validate_algorithms_js_1 = require("../../lib/validate_algorithms.js");
|
|
13
|
-
const checkExtensions = validate_crit_js_1.default.bind(undefined, errors_js_1.JWSInvalid, new Map([['b64', true]]));
|
|
14
|
-
const checkAlgOption = validate_algorithms_js_1.default.bind(undefined, 'algorithms');
|
|
15
13
|
async function flattenedVerify(jws, key, options) {
|
|
16
14
|
var _a;
|
|
17
15
|
if (!(0, is_object_js_1.default)(jws)) {
|
|
@@ -49,7 +47,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
49
47
|
...parsedProt,
|
|
50
48
|
...jws.header,
|
|
51
49
|
};
|
|
52
|
-
const extensions =
|
|
50
|
+
const extensions = (0, validate_crit_js_1.default)(errors_js_1.JWSInvalid, new Map([['b64', true]]), options === null || options === void 0 ? void 0 : options.crit, parsedProt, joseHeader);
|
|
53
51
|
let b64 = true;
|
|
54
52
|
if (extensions.has('b64')) {
|
|
55
53
|
b64 = parsedProt.b64;
|
|
@@ -61,7 +59,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
61
59
|
if (typeof alg !== 'string' || !alg) {
|
|
62
60
|
throw new errors_js_1.JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
63
61
|
}
|
|
64
|
-
const algorithms = options &&
|
|
62
|
+
const algorithms = options && (0, validate_algorithms_js_1.default)('algorithms', options.algorithms);
|
|
65
63
|
if (algorithms && !algorithms.has(alg)) {
|
|
66
64
|
throw new errors_js_1.JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter not allowed');
|
|
67
65
|
}
|
package/dist/node/cjs/lib/cek.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bitLengths = void 0;
|
|
4
4
|
const errors_js_1 = require("../util/errors.js");
|
|
5
|
+
const random_js_1 = require("../runtime/random.js");
|
|
5
6
|
const bitLengths = new Map([
|
|
6
7
|
['A128CBC-HS256', 256],
|
|
7
8
|
['A128GCM', 128],
|
|
@@ -11,11 +12,11 @@ const bitLengths = new Map([
|
|
|
11
12
|
['A256GCM', 256],
|
|
12
13
|
]);
|
|
13
14
|
exports.bitLengths = bitLengths;
|
|
14
|
-
const
|
|
15
|
+
const generateCek = (alg) => {
|
|
15
16
|
const bitLength = bitLengths.get(alg);
|
|
16
17
|
if (!bitLength) {
|
|
17
18
|
throw new errors_js_1.JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
18
19
|
}
|
|
19
|
-
return
|
|
20
|
+
return (0, random_js_1.default)(new Uint8Array(bitLength >> 3));
|
|
20
21
|
};
|
|
21
|
-
exports.default =
|
|
22
|
+
exports.default = generateCek;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const random_js_1 = require("../runtime/random.js");
|
|
4
3
|
const aeskw_js_1 = require("../runtime/aeskw.js");
|
|
5
4
|
const ECDH = require("../runtime/ecdhes.js");
|
|
6
5
|
const pbes2kw_js_1 = require("../runtime/pbes2kw.js");
|
|
@@ -11,7 +10,6 @@ const cek_js_1 = require("../lib/cek.js");
|
|
|
11
10
|
const errors_js_1 = require("../util/errors.js");
|
|
12
11
|
const export_js_1 = require("../key/export.js");
|
|
13
12
|
const check_key_type_js_1 = require("./check_key_type.js");
|
|
14
|
-
const generateCek = (0, cek_js_1.default)(random_js_1.default);
|
|
15
13
|
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
16
14
|
let encryptedKey;
|
|
17
15
|
let parameters;
|
|
@@ -43,7 +41,7 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
43
41
|
cek = sharedSecret;
|
|
44
42
|
break;
|
|
45
43
|
}
|
|
46
|
-
cek = providedCek ||
|
|
44
|
+
cek = providedCek || (0, cek_js_1.default)(enc);
|
|
47
45
|
const kwAlg = alg.substr(-6);
|
|
48
46
|
encryptedKey = await (0, aeskw_js_1.wrap)(kwAlg, sharedSecret, cek);
|
|
49
47
|
break;
|
|
@@ -53,14 +51,14 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
53
51
|
case 'RSA-OAEP-256':
|
|
54
52
|
case 'RSA-OAEP-384':
|
|
55
53
|
case 'RSA-OAEP-512': {
|
|
56
|
-
cek = providedCek ||
|
|
54
|
+
cek = providedCek || (0, cek_js_1.default)(enc);
|
|
57
55
|
encryptedKey = await (0, rsaes_js_1.encrypt)(alg, key, cek);
|
|
58
56
|
break;
|
|
59
57
|
}
|
|
60
58
|
case 'PBES2-HS256+A128KW':
|
|
61
59
|
case 'PBES2-HS384+A192KW':
|
|
62
60
|
case 'PBES2-HS512+A256KW': {
|
|
63
|
-
cek = providedCek ||
|
|
61
|
+
cek = providedCek || (0, cek_js_1.default)(enc);
|
|
64
62
|
const { p2c, p2s } = providedParameters;
|
|
65
63
|
({ encryptedKey, ...parameters } = await (0, pbes2kw_js_1.encrypt)(alg, key, cek, p2c, p2s));
|
|
66
64
|
break;
|
|
@@ -68,14 +66,14 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
68
66
|
case 'A128KW':
|
|
69
67
|
case 'A192KW':
|
|
70
68
|
case 'A256KW': {
|
|
71
|
-
cek = providedCek ||
|
|
69
|
+
cek = providedCek || (0, cek_js_1.default)(enc);
|
|
72
70
|
encryptedKey = await (0, aeskw_js_1.wrap)(alg, key, cek);
|
|
73
71
|
break;
|
|
74
72
|
}
|
|
75
73
|
case 'A128GCMKW':
|
|
76
74
|
case 'A192GCMKW':
|
|
77
75
|
case 'A256GCMKW': {
|
|
78
|
-
cek = providedCek ||
|
|
76
|
+
cek = providedCek || (0, cek_js_1.default)(enc);
|
|
79
77
|
const { iv } = providedParameters;
|
|
80
78
|
({ encryptedKey, ...parameters } = await (0, aesgcmkw_js_1.wrap)(alg, key, cek, iv));
|
|
81
79
|
break;
|
package/dist/node/cjs/lib/iv.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bitLengths = void 0;
|
|
4
4
|
const errors_js_1 = require("../util/errors.js");
|
|
5
|
+
const random_js_1 = require("../runtime/random.js");
|
|
5
6
|
const bitLengths = new Map([
|
|
6
7
|
['A128CBC-HS256', 128],
|
|
7
8
|
['A128GCM', 96],
|
|
@@ -14,11 +15,11 @@ const bitLengths = new Map([
|
|
|
14
15
|
['A256GCMKW', 96],
|
|
15
16
|
]);
|
|
16
17
|
exports.bitLengths = bitLengths;
|
|
17
|
-
const
|
|
18
|
+
const generateIv = (alg) => {
|
|
18
19
|
const bitLength = bitLengths.get(alg);
|
|
19
20
|
if (!bitLength) {
|
|
20
21
|
throw new errors_js_1.JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
21
22
|
}
|
|
22
|
-
return
|
|
23
|
+
return (0, random_js_1.default)(new Uint8Array(bitLength >> 3));
|
|
23
24
|
};
|
|
24
|
-
exports.default =
|
|
25
|
+
exports.default = generateIv;
|
|
@@ -4,12 +4,10 @@ exports.unwrap = exports.wrap = void 0;
|
|
|
4
4
|
const encrypt_js_1 = require("./encrypt.js");
|
|
5
5
|
const decrypt_js_1 = require("./decrypt.js");
|
|
6
6
|
const iv_js_1 = require("../lib/iv.js");
|
|
7
|
-
const random_js_1 = require("./random.js");
|
|
8
7
|
const base64url_js_1 = require("./base64url.js");
|
|
9
|
-
const generateIv = (0, iv_js_1.default)(random_js_1.default);
|
|
10
8
|
const wrap = async (alg, key, cek, iv) => {
|
|
11
9
|
const jweAlgorithm = alg.substr(0, 7);
|
|
12
|
-
iv || (iv =
|
|
10
|
+
iv || (iv = (0, iv_js_1.default)(jweAlgorithm));
|
|
13
11
|
const { ciphertext: encryptedKey, tag } = await (0, encrypt_js_1.default)(jweAlgorithm, cek, key, iv, new Uint8Array(0));
|
|
14
12
|
return { encryptedKey, iv: (0, base64url_js_1.encode)(iv), tag: (0, base64url_js_1.encode)(tag) };
|
|
15
13
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.JWSSignatureVerificationFailed = exports.JWKSTimeout = exports.JWKSMultipleMatchingKeys = exports.JWKSNoMatchingKey = exports.JWKSInvalid = exports.JWKInvalid = exports.JWTInvalid = exports.JWSInvalid = exports.JWEInvalid = exports.JWEDecryptionFailed = exports.JOSENotSupported = exports.JOSEAlgNotAllowed = exports.JWTExpired = exports.JWTClaimValidationFailed = exports.JOSEError = void 0;
|
|
4
4
|
class JOSEError extends Error {
|
|
5
5
|
constructor(message) {
|
|
6
6
|
var _a;
|
|
@@ -26,6 +26,18 @@ class JWTClaimValidationFailed extends JOSEError {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
exports.JWTClaimValidationFailed = JWTClaimValidationFailed;
|
|
29
|
+
class JWTExpired extends JOSEError {
|
|
30
|
+
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
31
|
+
super(message);
|
|
32
|
+
this.code = 'ERR_JWT_EXPIRED';
|
|
33
|
+
this.claim = claim;
|
|
34
|
+
this.reason = reason;
|
|
35
|
+
}
|
|
36
|
+
static get code() {
|
|
37
|
+
return 'ERR_JWT_EXPIRED';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.JWTExpired = JWTExpired;
|
|
29
41
|
class JOSEAlgNotAllowed extends JOSEError {
|
|
30
42
|
constructor() {
|
|
31
43
|
super(...arguments);
|
|
@@ -151,13 +163,3 @@ class JWSSignatureVerificationFailed extends JOSEError {
|
|
|
151
163
|
}
|
|
152
164
|
}
|
|
153
165
|
exports.JWSSignatureVerificationFailed = JWSSignatureVerificationFailed;
|
|
154
|
-
class JWTExpired extends JWTClaimValidationFailed {
|
|
155
|
-
constructor() {
|
|
156
|
-
super(...arguments);
|
|
157
|
-
this.code = 'ERR_JWT_EXPIRED';
|
|
158
|
-
}
|
|
159
|
-
static get code() {
|
|
160
|
-
return 'ERR_JWT_EXPIRED';
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
exports.JWTExpired = JWTExpired;
|
|
@@ -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
|
}
|
|
@@ -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/node/esm/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 };
|
|
@@ -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/node/esm/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));
|
|
@@ -21,6 +21,17 @@ export class JWTClaimValidationFailed extends JOSEError {
|
|
|
21
21
|
return 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
export class JWTExpired extends JOSEError {
|
|
25
|
+
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = 'ERR_JWT_EXPIRED';
|
|
28
|
+
this.claim = claim;
|
|
29
|
+
this.reason = reason;
|
|
30
|
+
}
|
|
31
|
+
static get code() {
|
|
32
|
+
return 'ERR_JWT_EXPIRED';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
export class JOSEAlgNotAllowed extends JOSEError {
|
|
25
36
|
constructor() {
|
|
26
37
|
super(...arguments);
|
|
@@ -134,12 +145,3 @@ export class JWSSignatureVerificationFailed extends JOSEError {
|
|
|
134
145
|
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
135
146
|
}
|
|
136
147
|
}
|
|
137
|
-
export class JWTExpired extends JWTClaimValidationFailed {
|
|
138
|
-
constructor() {
|
|
139
|
-
super(...arguments);
|
|
140
|
-
this.code = 'ERR_JWT_EXPIRED';
|
|
141
|
-
}
|
|
142
|
-
static get code() {
|
|
143
|
-
return 'ERR_JWT_EXPIRED';
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -10,6 +10,13 @@ export declare class JWTClaimValidationFailed extends JOSEError {
|
|
|
10
10
|
reason: string;
|
|
11
11
|
constructor(message: string, claim?: string, reason?: string);
|
|
12
12
|
}
|
|
13
|
+
export declare class JWTExpired extends JOSEError implements JWTClaimValidationFailed {
|
|
14
|
+
static get code(): 'ERR_JWT_EXPIRED';
|
|
15
|
+
code: string;
|
|
16
|
+
claim: string;
|
|
17
|
+
reason: string;
|
|
18
|
+
constructor(message: string, claim?: string, reason?: string);
|
|
19
|
+
}
|
|
13
20
|
export declare class JOSEAlgNotAllowed extends JOSEError {
|
|
14
21
|
static get code(): 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
15
22
|
code: string;
|
|
@@ -63,7 +70,3 @@ export declare class JWSSignatureVerificationFailed extends JOSEError {
|
|
|
63
70
|
code: string;
|
|
64
71
|
message: string;
|
|
65
72
|
}
|
|
66
|
-
export declare class JWTExpired extends JWTClaimValidationFailed {
|
|
67
|
-
static get code(): 'ERR_JWT_EXPIRED';
|
|
68
|
-
code: string;
|
|
69
|
-
}
|