jose 3.19.0 → 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/jwk/embedded.js +2 -2
- package/dist/browser/jwks/remote.js +7 -10
- package/dist/browser/jws/flattened/sign.js +1 -2
- package/dist/browser/jws/flattened/verify.js +2 -4
- package/dist/browser/jwt/encrypt.js +1 -1
- package/dist/browser/{lib/jwt_producer.js → jwt/produce.js} +4 -4
- package/dist/browser/jwt/sign.js +1 -1
- package/dist/browser/jwt/unsecured.js +1 -1
- package/dist/browser/lib/cek.js +3 -2
- package/dist/browser/lib/check_key_type.js +33 -16
- package/dist/browser/lib/decrypt_key_management.js +35 -35
- package/dist/browser/lib/encrypt_key_management.js +3 -5
- package/dist/browser/lib/iv.js +3 -2
- package/dist/browser/runtime/aesgcmkw.js +1 -3
- package/dist/browser/runtime/fetch_jwks.js +16 -3
- package/dist/browser/runtime/is_key_like.js +5 -0
- package/dist/browser/runtime/random.js +1 -2
- package/dist/browser/util/errors.js +73 -34
- package/dist/node/cjs/jwe/flattened/decrypt.js +5 -9
- package/dist/node/cjs/jwe/flattened/encrypt.js +2 -5
- package/dist/node/cjs/jwk/embedded.js +2 -2
- package/dist/node/cjs/jwks/remote.js +7 -10
- package/dist/node/cjs/jws/flattened/sign.js +1 -2
- package/dist/node/cjs/jws/flattened/verify.js +2 -4
- package/dist/node/cjs/jwt/encrypt.js +2 -2
- package/dist/node/cjs/{lib/jwt_producer.js → jwt/produce.js} +5 -4
- package/dist/node/cjs/jwt/sign.js +2 -2
- package/dist/node/cjs/jwt/unsecured.js +2 -2
- package/dist/node/cjs/lib/cek.js +4 -3
- package/dist/node/cjs/lib/check_key_type.js +33 -16
- package/dist/node/cjs/lib/decrypt_key_management.js +35 -35
- package/dist/node/cjs/lib/encrypt_key_management.js +7 -9
- package/dist/node/cjs/lib/iv.js +4 -3
- package/dist/node/cjs/runtime/aesgcmkw.js +1 -3
- package/dist/node/cjs/runtime/fetch_jwks.js +5 -1
- package/dist/node/cjs/runtime/is_key_like.js +11 -0
- package/dist/node/cjs/runtime/random.js +3 -2
- package/dist/node/cjs/util/errors.js +77 -37
- package/dist/node/esm/jwe/flattened/decrypt.js +5 -9
- package/dist/node/esm/jwe/flattened/encrypt.js +2 -5
- package/dist/node/esm/jwk/embedded.js +2 -2
- package/dist/node/esm/jwks/remote.js +7 -10
- package/dist/node/esm/jws/flattened/sign.js +1 -2
- package/dist/node/esm/jws/flattened/verify.js +2 -4
- package/dist/node/esm/jwt/encrypt.js +1 -1
- package/dist/node/esm/{lib/jwt_producer.js → jwt/produce.js} +4 -4
- package/dist/node/esm/jwt/sign.js +1 -1
- package/dist/node/esm/jwt/unsecured.js +1 -1
- package/dist/node/esm/lib/cek.js +3 -2
- package/dist/node/esm/lib/check_key_type.js +33 -16
- package/dist/node/esm/lib/decrypt_key_management.js +35 -35
- package/dist/node/esm/lib/encrypt_key_management.js +3 -5
- package/dist/node/esm/lib/iv.js +3 -2
- package/dist/node/esm/runtime/aesgcmkw.js +1 -3
- package/dist/node/esm/runtime/fetch_jwks.js +6 -2
- package/dist/node/esm/runtime/is_key_like.js +8 -0
- package/dist/node/esm/runtime/random.js +1 -2
- package/dist/node/esm/util/errors.js +73 -34
- package/dist/types/jwe/compact/decrypt.d.ts +1 -1
- package/dist/types/jwe/compact/encrypt.d.ts +1 -1
- package/dist/types/jwe/flattened/decrypt.d.ts +1 -1
- package/dist/types/jwe/flattened/encrypt.d.ts +1 -1
- package/dist/types/jwe/general/decrypt.d.ts +1 -1
- package/dist/types/jwk/embedded.d.ts +2 -3
- package/dist/types/jwk/from_key_like.d.ts +1 -1
- package/dist/types/jwk/parse.d.ts +1 -1
- package/dist/types/jws/compact/sign.d.ts +1 -1
- package/dist/types/jws/compact/verify.d.ts +1 -1
- package/dist/types/jws/flattened/sign.d.ts +1 -1
- package/dist/types/jws/flattened/verify.d.ts +1 -1
- package/dist/types/jws/general/sign.d.ts +1 -1
- package/dist/types/jws/general/verify.d.ts +1 -1
- package/dist/types/jwt/decrypt.d.ts +1 -1
- package/dist/types/jwt/encrypt.d.ts +2 -2
- package/dist/types/{lib/jwt_producer.d.ts → jwt/produce.d.ts} +1 -1
- package/dist/types/jwt/sign.d.ts +2 -2
- package/dist/types/jwt/unsecured.d.ts +1 -1
- package/dist/types/jwt/verify.d.ts +1 -1
- package/dist/types/key/export.d.ts +3 -3
- package/dist/types/key/import.d.ts +4 -4
- package/dist/types/types.d.ts +99 -6
- package/dist/types/util/errors.d.ts +24 -16
- package/dist/types/util/generate_key_pair.d.ts +2 -2
- package/dist/types/util/generate_secret.d.ts +1 -1
- package/package.json +3 -4
|
@@ -1,108 +1,147 @@
|
|
|
1
1
|
export class JOSEError extends Error {
|
|
2
2
|
constructor(message) {
|
|
3
|
+
var _a;
|
|
3
4
|
super(message);
|
|
4
|
-
this.code =
|
|
5
|
+
this.code = 'ERR_JOSE_GENERIC';
|
|
5
6
|
this.name = this.constructor.name;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, this.constructor);
|
|
8
|
+
}
|
|
9
|
+
static get code() {
|
|
10
|
+
return 'ERR_JOSE_GENERIC';
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
|
-
JOSEError.code = 'ERR_JOSE_GENERIC';
|
|
12
13
|
export class JWTClaimValidationFailed extends JOSEError {
|
|
13
14
|
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
14
15
|
super(message);
|
|
15
|
-
this.code =
|
|
16
|
+
this.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
16
17
|
this.claim = claim;
|
|
17
18
|
this.reason = reason;
|
|
18
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';
|
|
28
|
+
this.claim = claim;
|
|
29
|
+
this.reason = reason;
|
|
30
|
+
}
|
|
31
|
+
static get code() {
|
|
32
|
+
return 'ERR_JWT_EXPIRED';
|
|
33
|
+
}
|
|
19
34
|
}
|
|
20
|
-
JWTClaimValidationFailed.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
21
35
|
export class JOSEAlgNotAllowed extends JOSEError {
|
|
22
36
|
constructor() {
|
|
23
37
|
super(...arguments);
|
|
24
|
-
this.code =
|
|
38
|
+
this.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
39
|
+
}
|
|
40
|
+
static get code() {
|
|
41
|
+
return 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
25
42
|
}
|
|
26
43
|
}
|
|
27
|
-
JOSEAlgNotAllowed.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
28
44
|
export class JOSENotSupported extends JOSEError {
|
|
29
45
|
constructor() {
|
|
30
46
|
super(...arguments);
|
|
31
|
-
this.code =
|
|
47
|
+
this.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
48
|
+
}
|
|
49
|
+
static get code() {
|
|
50
|
+
return 'ERR_JOSE_NOT_SUPPORTED';
|
|
32
51
|
}
|
|
33
52
|
}
|
|
34
|
-
JOSENotSupported.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
35
53
|
export class JWEDecryptionFailed extends JOSEError {
|
|
36
54
|
constructor() {
|
|
37
55
|
super(...arguments);
|
|
38
|
-
this.code =
|
|
56
|
+
this.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
39
57
|
this.message = 'decryption operation failed';
|
|
40
58
|
}
|
|
59
|
+
static get code() {
|
|
60
|
+
return 'ERR_JWE_DECRYPTION_FAILED';
|
|
61
|
+
}
|
|
41
62
|
}
|
|
42
|
-
JWEDecryptionFailed.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
43
63
|
export class JWEInvalid extends JOSEError {
|
|
44
64
|
constructor() {
|
|
45
65
|
super(...arguments);
|
|
46
|
-
this.code =
|
|
66
|
+
this.code = 'ERR_JWE_INVALID';
|
|
67
|
+
}
|
|
68
|
+
static get code() {
|
|
69
|
+
return 'ERR_JWE_INVALID';
|
|
47
70
|
}
|
|
48
71
|
}
|
|
49
|
-
JWEInvalid.code = 'ERR_JWE_INVALID';
|
|
50
72
|
export class JWSInvalid extends JOSEError {
|
|
51
73
|
constructor() {
|
|
52
74
|
super(...arguments);
|
|
53
|
-
this.code =
|
|
75
|
+
this.code = 'ERR_JWS_INVALID';
|
|
76
|
+
}
|
|
77
|
+
static get code() {
|
|
78
|
+
return 'ERR_JWS_INVALID';
|
|
54
79
|
}
|
|
55
80
|
}
|
|
56
|
-
JWSInvalid.code = 'ERR_JWS_INVALID';
|
|
57
81
|
export class JWTInvalid extends JOSEError {
|
|
58
82
|
constructor() {
|
|
59
83
|
super(...arguments);
|
|
60
|
-
this.code =
|
|
84
|
+
this.code = 'ERR_JWT_INVALID';
|
|
85
|
+
}
|
|
86
|
+
static get code() {
|
|
87
|
+
return 'ERR_JWT_INVALID';
|
|
61
88
|
}
|
|
62
89
|
}
|
|
63
|
-
JWTInvalid.code = 'ERR_JWT_INVALID';
|
|
64
90
|
export class JWKInvalid extends JOSEError {
|
|
65
91
|
constructor() {
|
|
66
92
|
super(...arguments);
|
|
67
|
-
this.code =
|
|
93
|
+
this.code = 'ERR_JWK_INVALID';
|
|
94
|
+
}
|
|
95
|
+
static get code() {
|
|
96
|
+
return 'ERR_JWK_INVALID';
|
|
68
97
|
}
|
|
69
98
|
}
|
|
70
|
-
JWKInvalid.code = 'ERR_JWK_INVALID';
|
|
71
99
|
export class JWKSInvalid extends JOSEError {
|
|
72
100
|
constructor() {
|
|
73
101
|
super(...arguments);
|
|
74
|
-
this.code =
|
|
102
|
+
this.code = 'ERR_JWKS_INVALID';
|
|
103
|
+
}
|
|
104
|
+
static get code() {
|
|
105
|
+
return 'ERR_JWKS_INVALID';
|
|
75
106
|
}
|
|
76
107
|
}
|
|
77
|
-
JWKSInvalid.code = 'ERR_JWKS_INVALID';
|
|
78
108
|
export class JWKSNoMatchingKey extends JOSEError {
|
|
79
109
|
constructor() {
|
|
80
110
|
super(...arguments);
|
|
81
|
-
this.code =
|
|
111
|
+
this.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
82
112
|
this.message = 'no applicable key found in the JSON Web Key Set';
|
|
83
113
|
}
|
|
114
|
+
static get code() {
|
|
115
|
+
return 'ERR_JWKS_NO_MATCHING_KEY';
|
|
116
|
+
}
|
|
84
117
|
}
|
|
85
|
-
JWKSNoMatchingKey.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
86
118
|
export class JWKSMultipleMatchingKeys extends JOSEError {
|
|
87
119
|
constructor() {
|
|
88
120
|
super(...arguments);
|
|
89
|
-
this.code =
|
|
121
|
+
this.code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
90
122
|
this.message = 'multiple matching keys found in the JSON Web Key Set';
|
|
91
123
|
}
|
|
124
|
+
static get code() {
|
|
125
|
+
return 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
126
|
+
}
|
|
92
127
|
}
|
|
93
|
-
|
|
94
|
-
export class JWSSignatureVerificationFailed extends JOSEError {
|
|
128
|
+
export class JWKSTimeout extends JOSEError {
|
|
95
129
|
constructor() {
|
|
96
130
|
super(...arguments);
|
|
97
|
-
this.code =
|
|
98
|
-
this.message = '
|
|
131
|
+
this.code = 'ERR_JWKS_TIMEOUT';
|
|
132
|
+
this.message = 'request timed out';
|
|
133
|
+
}
|
|
134
|
+
static get code() {
|
|
135
|
+
return 'ERR_JWKS_TIMEOUT';
|
|
99
136
|
}
|
|
100
137
|
}
|
|
101
|
-
JWSSignatureVerificationFailed
|
|
102
|
-
export class JWTExpired extends JWTClaimValidationFailed {
|
|
138
|
+
export class JWSSignatureVerificationFailed extends JOSEError {
|
|
103
139
|
constructor() {
|
|
104
140
|
super(...arguments);
|
|
105
|
-
this.code =
|
|
141
|
+
this.code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
142
|
+
this.message = 'signature verification failed';
|
|
143
|
+
}
|
|
144
|
+
static get code() {
|
|
145
|
+
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
106
146
|
}
|
|
107
147
|
}
|
|
108
|
-
JWTExpired.code = 'ERR_JWT_EXPIRED';
|
|
@@ -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;
|
|
@@ -12,8 +12,8 @@ async function EmbeddedJWK(protectedHeader, token) {
|
|
|
12
12
|
if (!(0, is_object_js_1.default)(joseHeader.jwk)) {
|
|
13
13
|
throw new errors_js_1.JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
|
|
14
14
|
}
|
|
15
|
-
const key =
|
|
16
|
-
if (key.type !== 'public') {
|
|
15
|
+
const key = await (0, import_js_1.importJWK)({ ...joseHeader.jwk, ext: true }, joseHeader.alg, true);
|
|
16
|
+
if (key instanceof Uint8Array || key.type !== 'public') {
|
|
17
17
|
throw new errors_js_1.JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
|
|
18
18
|
}
|
|
19
19
|
return key;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRemoteJWKSet = void 0;
|
|
4
4
|
const fetch_jwks_js_1 = require("../runtime/fetch_jwks.js");
|
|
5
|
-
const
|
|
5
|
+
const import_js_1 = require("../key/import.js");
|
|
6
6
|
const errors_js_1 = require("../util/errors.js");
|
|
7
7
|
const is_object_js_1 = require("../lib/is_object.js");
|
|
8
8
|
function getKtyFromAlg(alg) {
|
|
9
|
-
switch (alg.substr(0, 2)) {
|
|
9
|
+
switch (typeof alg === 'string' && alg.substr(0, 2)) {
|
|
10
10
|
case 'RS':
|
|
11
11
|
case 'PS':
|
|
12
12
|
return 'RSA';
|
|
@@ -35,7 +35,7 @@ class RemoteJWKSet {
|
|
|
35
35
|
typeof (options === null || options === void 0 ? void 0 : options.cooldownDuration) === 'number' ? options === null || options === void 0 ? void 0 : options.cooldownDuration : 30000;
|
|
36
36
|
}
|
|
37
37
|
coolingDown() {
|
|
38
|
-
if (
|
|
38
|
+
if (!this._cooldownStarted) {
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
41
|
return Date.now() < this._cooldownStarted + this._cooldownDuration;
|
|
@@ -59,7 +59,7 @@ class RemoteJWKSet {
|
|
|
59
59
|
candidate = jwk.key_ops.includes('verify');
|
|
60
60
|
}
|
|
61
61
|
if (candidate && protectedHeader.alg === 'EdDSA') {
|
|
62
|
-
candidate =
|
|
62
|
+
candidate = jwk.crv === 'Ed25519' || jwk.crv === 'Ed448';
|
|
63
63
|
}
|
|
64
64
|
if (candidate) {
|
|
65
65
|
switch (protectedHeader.alg) {
|
|
@@ -91,13 +91,10 @@ class RemoteJWKSet {
|
|
|
91
91
|
else if (length !== 1) {
|
|
92
92
|
throw new errors_js_1.JWKSMultipleMatchingKeys();
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
this._cached.set(jwk, {});
|
|
96
|
-
}
|
|
97
|
-
const cached = this._cached.get(jwk);
|
|
94
|
+
const cached = this._cached.get(jwk) || this._cached.set(jwk, {}).get(jwk);
|
|
98
95
|
if (cached[protectedHeader.alg] === undefined) {
|
|
99
|
-
const keyObject =
|
|
100
|
-
if (keyObject.type !== 'public') {
|
|
96
|
+
const keyObject = await (0, import_js_1.importJWK)({ ...jwk, ext: true }, protectedHeader.alg);
|
|
97
|
+
if (keyObject instanceof Uint8Array || keyObject.type !== 'public') {
|
|
101
98
|
throw new errors_js_1.JWKSInvalid('JSON Web Key Set members must be public keys');
|
|
102
99
|
}
|
|
103
100
|
cached[protectedHeader.alg] = keyObject;
|
|
@@ -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
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EncryptJWT = void 0;
|
|
4
4
|
const encrypt_js_1 = require("../jwe/compact/encrypt.js");
|
|
5
5
|
const buffer_utils_js_1 = require("../lib/buffer_utils.js");
|
|
6
|
-
const
|
|
7
|
-
class EncryptJWT extends
|
|
6
|
+
const produce_js_1 = require("./produce.js");
|
|
7
|
+
class EncryptJWT extends produce_js_1.ProduceJWT {
|
|
8
8
|
setProtectedHeader(protectedHeader) {
|
|
9
9
|
if (this._protectedHeader) {
|
|
10
10
|
throw new TypeError('setProtectedHeader can only be called once');
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
exports.ProduceJWT = void 0;
|
|
4
|
+
const epoch_js_1 = require("../lib/epoch.js");
|
|
5
|
+
const is_object_js_1 = require("../lib/is_object.js");
|
|
6
|
+
const secs_js_1 = require("../lib/secs.js");
|
|
6
7
|
class ProduceJWT {
|
|
7
8
|
constructor(payload) {
|
|
8
9
|
if (!(0, is_object_js_1.default)(payload)) {
|
|
@@ -54,4 +55,4 @@ class ProduceJWT {
|
|
|
54
55
|
return this;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
exports.
|
|
58
|
+
exports.ProduceJWT = ProduceJWT;
|
|
@@ -4,8 +4,8 @@ exports.SignJWT = void 0;
|
|
|
4
4
|
const sign_js_1 = require("../jws/compact/sign.js");
|
|
5
5
|
const errors_js_1 = require("../util/errors.js");
|
|
6
6
|
const buffer_utils_js_1 = require("../lib/buffer_utils.js");
|
|
7
|
-
const
|
|
8
|
-
class SignJWT extends
|
|
7
|
+
const produce_js_1 = require("./produce.js");
|
|
8
|
+
class SignJWT extends produce_js_1.ProduceJWT {
|
|
9
9
|
setProtectedHeader(protectedHeader) {
|
|
10
10
|
this._protectedHeader = protectedHeader;
|
|
11
11
|
return this;
|
|
@@ -5,8 +5,8 @@ const base64url = require("../runtime/base64url.js");
|
|
|
5
5
|
const buffer_utils_js_1 = require("../lib/buffer_utils.js");
|
|
6
6
|
const errors_js_1 = require("../util/errors.js");
|
|
7
7
|
const jwt_claims_set_js_1 = require("../lib/jwt_claims_set.js");
|
|
8
|
-
const
|
|
9
|
-
class UnsecuredJWT extends
|
|
8
|
+
const produce_js_1 = require("./produce.js");
|
|
9
|
+
class UnsecuredJWT extends produce_js_1.ProduceJWT {
|
|
10
10
|
encode() {
|
|
11
11
|
const header = base64url.encode(JSON.stringify({ alg: 'none' }));
|
|
12
12
|
const payload = base64url.encode(JSON.stringify(this._payload));
|
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,30 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const invalid_key_input_js_1 = require("../runtime/invalid_key_input.js");
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const is_key_like_js_1 = require("../runtime/is_key_like.js");
|
|
5
|
+
const symmetricTypeCheck = (key) => {
|
|
6
|
+
if (key instanceof Uint8Array)
|
|
7
|
+
return;
|
|
8
|
+
if (!(0, is_key_like_js_1.default)(key)) {
|
|
9
|
+
throw new TypeError((0, invalid_key_input_js_1.default)(key, ...is_key_like_js_1.types, 'Uint8Array'));
|
|
7
10
|
}
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
alg.startsWith('PBES2') ||
|
|
11
|
-
alg.match(/^A\d{3}(?:GCM)?KW$/)) {
|
|
12
|
-
if (key instanceof Uint8Array || key.type === 'secret') {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
throw new TypeError('CryptoKey or KeyObject instances for symmetric algorithms must be of type "secret"');
|
|
11
|
+
if (key.type !== 'secret') {
|
|
12
|
+
throw new TypeError(`${is_key_like_js_1.types.join(' or ')} instances for symmetric algorithms must be of type "secret"`);
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
};
|
|
15
|
+
const asymmetricTypeCheck = (key, usage) => {
|
|
16
|
+
if (!(0, is_key_like_js_1.default)(key)) {
|
|
17
|
+
throw new TypeError((0, invalid_key_input_js_1.default)(key, ...is_key_like_js_1.types));
|
|
19
18
|
}
|
|
20
19
|
if (key.type === 'secret') {
|
|
21
|
-
throw new TypeError('
|
|
20
|
+
throw new TypeError(`${is_key_like_js_1.types.join(' or ')} instances for asymmetric algorithms must not be of type "secret"`);
|
|
22
21
|
}
|
|
23
22
|
if (usage === 'sign' && key.type === 'public') {
|
|
24
|
-
throw new TypeError('
|
|
23
|
+
throw new TypeError(`${is_key_like_js_1.types.join(' or ')} instances for asymmetric algorithm signing must be of type "private"`);
|
|
25
24
|
}
|
|
26
25
|
if (usage === 'decrypt' && key.type === 'public') {
|
|
27
|
-
throw new TypeError('
|
|
26
|
+
throw new TypeError(`${is_key_like_js_1.types.join(' or ')} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
27
|
+
}
|
|
28
|
+
if (key.algorithm && usage === 'verify' && key.type === 'private') {
|
|
29
|
+
throw new TypeError(`${is_key_like_js_1.types.join(' or ')} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
30
|
+
}
|
|
31
|
+
if (key.algorithm && usage === 'encrypt' && key.type === 'private') {
|
|
32
|
+
throw new TypeError(`${is_key_like_js_1.types.join(' or ')} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const checkKeyType = (alg, key, usage) => {
|
|
36
|
+
const symmetric = alg.startsWith('HS') ||
|
|
37
|
+
alg === 'dir' ||
|
|
38
|
+
alg.startsWith('PBES2') ||
|
|
39
|
+
/^A\d{3}(?:GCM)?KW$/.test(alg);
|
|
40
|
+
if (symmetric) {
|
|
41
|
+
symmetricTypeCheck(key);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
asymmetricTypeCheck(key, usage);
|
|
28
45
|
}
|
|
29
46
|
};
|
|
30
47
|
exports.default = checkKeyType;
|
|
@@ -10,81 +10,81 @@ const errors_js_1 = require("../util/errors.js");
|
|
|
10
10
|
const cek_js_1 = require("../lib/cek.js");
|
|
11
11
|
const import_js_1 = require("../key/import.js");
|
|
12
12
|
const check_key_type_js_1 = require("./check_key_type.js");
|
|
13
|
-
|
|
14
|
-
if (!encryptedKey) {
|
|
15
|
-
throw new errors_js_1.JWEInvalid('JWE Encrypted Key missing');
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function assertHeaderParameter(joseHeader, parameter, name) {
|
|
19
|
-
if (joseHeader[parameter] === undefined) {
|
|
20
|
-
throw new errors_js_1.JWEInvalid(`JOSE Header ${name} (${parameter}) missing`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
13
|
+
const is_object_js_1 = require("./is_object.js");
|
|
23
14
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
|
|
24
15
|
(0, check_key_type_js_1.default)(alg, key, 'decrypt');
|
|
25
16
|
switch (alg) {
|
|
26
17
|
case 'dir': {
|
|
27
|
-
if (encryptedKey !== undefined)
|
|
18
|
+
if (encryptedKey !== undefined)
|
|
28
19
|
throw new errors_js_1.JWEInvalid('Encountered unexpected JWE Encrypted Key');
|
|
29
|
-
}
|
|
30
20
|
return key;
|
|
31
21
|
}
|
|
32
22
|
case 'ECDH-ES':
|
|
33
|
-
if (encryptedKey !== undefined)
|
|
23
|
+
if (encryptedKey !== undefined)
|
|
34
24
|
throw new errors_js_1.JWEInvalid('Encountered unexpected JWE Encrypted Key');
|
|
35
|
-
}
|
|
36
25
|
case 'ECDH-ES+A128KW':
|
|
37
26
|
case 'ECDH-ES+A192KW':
|
|
38
27
|
case 'ECDH-ES+A256KW': {
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
if (!(0, is_object_js_1.default)(joseHeader.epk))
|
|
29
|
+
throw new errors_js_1.JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
30
|
+
if (!ECDH.ecdhAllowed(key))
|
|
41
31
|
throw new errors_js_1.JOSENotSupported('ECDH-ES with the provided key is not allowed or not supported by your javascript runtime');
|
|
42
|
-
}
|
|
43
32
|
const epk = await (0, import_js_1.importJWK)(joseHeader.epk, alg);
|
|
44
33
|
let partyUInfo;
|
|
45
34
|
let partyVInfo;
|
|
46
|
-
if (joseHeader.apu !== undefined)
|
|
35
|
+
if (joseHeader.apu !== undefined) {
|
|
36
|
+
if (typeof joseHeader.apu !== 'string')
|
|
37
|
+
throw new errors_js_1.JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
47
38
|
partyUInfo = (0, base64url_js_1.decode)(joseHeader.apu);
|
|
48
|
-
|
|
39
|
+
}
|
|
40
|
+
if (joseHeader.apv !== undefined) {
|
|
41
|
+
if (typeof joseHeader.apv !== 'string')
|
|
42
|
+
throw new errors_js_1.JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
49
43
|
partyVInfo = (0, base64url_js_1.decode)(joseHeader.apv);
|
|
44
|
+
}
|
|
50
45
|
const sharedSecret = await ECDH.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, parseInt(alg.substr(-5, 3), 10) || cek_js_1.bitLengths.get(joseHeader.enc), partyUInfo, partyVInfo);
|
|
51
|
-
if (alg === 'ECDH-ES')
|
|
46
|
+
if (alg === 'ECDH-ES')
|
|
52
47
|
return sharedSecret;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return (0, aeskw_js_1.unwrap)(kwAlg, sharedSecret, encryptedKey);
|
|
48
|
+
if (encryptedKey === undefined)
|
|
49
|
+
throw new errors_js_1.JWEInvalid('JWE Encrypted Key missing');
|
|
50
|
+
return (0, aeskw_js_1.unwrap)(alg.substr(-6), sharedSecret, encryptedKey);
|
|
57
51
|
}
|
|
58
52
|
case 'RSA1_5':
|
|
59
53
|
case 'RSA-OAEP':
|
|
60
54
|
case 'RSA-OAEP-256':
|
|
61
55
|
case 'RSA-OAEP-384':
|
|
62
56
|
case 'RSA-OAEP-512': {
|
|
63
|
-
|
|
57
|
+
if (encryptedKey === undefined)
|
|
58
|
+
throw new errors_js_1.JWEInvalid('JWE Encrypted Key missing');
|
|
64
59
|
return (0, rsaes_js_1.decrypt)(alg, key, encryptedKey);
|
|
65
60
|
}
|
|
66
61
|
case 'PBES2-HS256+A128KW':
|
|
67
62
|
case 'PBES2-HS384+A192KW':
|
|
68
63
|
case 'PBES2-HS512+A256KW': {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
if (encryptedKey === undefined)
|
|
65
|
+
throw new errors_js_1.JWEInvalid('JWE Encrypted Key missing');
|
|
66
|
+
if (typeof joseHeader.p2c !== 'number')
|
|
67
|
+
throw new errors_js_1.JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
68
|
+
if (typeof joseHeader.p2s !== 'string')
|
|
69
|
+
throw new errors_js_1.JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
70
|
+
return (0, pbes2kw_js_1.decrypt)(alg, key, encryptedKey, joseHeader.p2c, (0, base64url_js_1.decode)(joseHeader.p2s));
|
|
75
71
|
}
|
|
76
72
|
case 'A128KW':
|
|
77
73
|
case 'A192KW':
|
|
78
74
|
case 'A256KW': {
|
|
79
|
-
|
|
75
|
+
if (encryptedKey === undefined)
|
|
76
|
+
throw new errors_js_1.JWEInvalid('JWE Encrypted Key missing');
|
|
80
77
|
return (0, aeskw_js_1.unwrap)(alg, key, encryptedKey);
|
|
81
78
|
}
|
|
82
79
|
case 'A128GCMKW':
|
|
83
80
|
case 'A192GCMKW':
|
|
84
81
|
case 'A256GCMKW': {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
if (encryptedKey === undefined)
|
|
83
|
+
throw new errors_js_1.JWEInvalid('JWE Encrypted Key missing');
|
|
84
|
+
if (typeof joseHeader.iv !== 'string')
|
|
85
|
+
throw new errors_js_1.JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
86
|
+
if (typeof joseHeader.tag !== 'string')
|
|
87
|
+
throw new errors_js_1.JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
88
88
|
const iv = (0, base64url_js_1.decode)(joseHeader.iv);
|
|
89
89
|
const tag = (0, base64url_js_1.decode)(joseHeader.tag);
|
|
90
90
|
return (0, aesgcmkw_js_1.unwrap)(alg, key, encryptedKey, iv, tag);
|