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
|
@@ -15,23 +15,23 @@ const [major, minor] = process.version
|
|
|
15
15
|
const jwkExportSupported = major >= 16 || (major === 15 && minor >= 9);
|
|
16
16
|
const keyToJWK = (key) => {
|
|
17
17
|
let keyObject;
|
|
18
|
-
if (
|
|
18
|
+
if (webcrypto_js_1.isCryptoKey(key)) {
|
|
19
19
|
if (!key.extractable) {
|
|
20
20
|
throw new TypeError('CryptoKey is not extractable');
|
|
21
21
|
}
|
|
22
|
-
keyObject =
|
|
22
|
+
keyObject = webcrypto_js_1.getKeyObject(key);
|
|
23
23
|
}
|
|
24
|
-
else if (
|
|
24
|
+
else if (is_key_object_js_1.default(key)) {
|
|
25
25
|
keyObject = key;
|
|
26
26
|
}
|
|
27
27
|
else if (key instanceof Uint8Array) {
|
|
28
28
|
return {
|
|
29
29
|
kty: 'oct',
|
|
30
|
-
k:
|
|
30
|
+
k: base64url_js_1.encode(key),
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
throw new TypeError(
|
|
34
|
+
throw new TypeError(invalid_key_input_js_1.default(key, 'KeyObject', 'CryptoKey', 'Uint8Array'));
|
|
35
35
|
}
|
|
36
36
|
if (jwkExportSupported) {
|
|
37
37
|
return keyObject.export({ format: 'jwk' });
|
|
@@ -40,7 +40,7 @@ const keyToJWK = (key) => {
|
|
|
40
40
|
case 'secret':
|
|
41
41
|
return {
|
|
42
42
|
kty: 'oct',
|
|
43
|
-
k:
|
|
43
|
+
k: base64url_js_1.encode(keyObject.export()),
|
|
44
44
|
};
|
|
45
45
|
case 'private':
|
|
46
46
|
case 'public': {
|
|
@@ -51,24 +51,24 @@ const keyToJWK = (key) => {
|
|
|
51
51
|
if (keyObject.type === 'private') {
|
|
52
52
|
dec.unsignedInteger();
|
|
53
53
|
}
|
|
54
|
-
const n =
|
|
55
|
-
const e =
|
|
54
|
+
const n = base64url_js_1.encode(dec.unsignedInteger());
|
|
55
|
+
const e = base64url_js_1.encode(dec.unsignedInteger());
|
|
56
56
|
let jwk;
|
|
57
57
|
if (keyObject.type === 'private') {
|
|
58
58
|
jwk = {
|
|
59
|
-
d:
|
|
60
|
-
p:
|
|
61
|
-
q:
|
|
62
|
-
dp:
|
|
63
|
-
dq:
|
|
64
|
-
qi:
|
|
59
|
+
d: base64url_js_1.encode(dec.unsignedInteger()),
|
|
60
|
+
p: base64url_js_1.encode(dec.unsignedInteger()),
|
|
61
|
+
q: base64url_js_1.encode(dec.unsignedInteger()),
|
|
62
|
+
dp: base64url_js_1.encode(dec.unsignedInteger()),
|
|
63
|
+
dq: base64url_js_1.encode(dec.unsignedInteger()),
|
|
64
|
+
qi: base64url_js_1.encode(dec.unsignedInteger()),
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
dec.end();
|
|
68
68
|
return { kty: 'RSA', n, e, ...jwk };
|
|
69
69
|
}
|
|
70
70
|
case 'ec': {
|
|
71
|
-
const crv =
|
|
71
|
+
const crv = get_named_curve_js_1.default(keyObject);
|
|
72
72
|
let len;
|
|
73
73
|
let offset;
|
|
74
74
|
let correction;
|
|
@@ -101,8 +101,8 @@ const keyToJWK = (key) => {
|
|
|
101
101
|
return {
|
|
102
102
|
kty: 'EC',
|
|
103
103
|
crv,
|
|
104
|
-
x:
|
|
105
|
-
y:
|
|
104
|
+
x: base64url_js_1.encode(der.subarray(-len, -len / 2)),
|
|
105
|
+
y: base64url_js_1.encode(der.subarray(-len / 2)),
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
const der = keyObject.export({ type: 'pkcs8', format: 'der' });
|
|
@@ -110,42 +110,42 @@ const keyToJWK = (key) => {
|
|
|
110
110
|
offset += correction;
|
|
111
111
|
}
|
|
112
112
|
return {
|
|
113
|
-
...keyToJWK(
|
|
114
|
-
d:
|
|
113
|
+
...keyToJWK(crypto_1.createPublicKey(keyObject)),
|
|
114
|
+
d: base64url_js_1.encode(der.subarray(offset, offset + len / 2)),
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
case 'ed25519':
|
|
118
118
|
case 'x25519': {
|
|
119
|
-
const crv =
|
|
119
|
+
const crv = get_named_curve_js_1.default(keyObject);
|
|
120
120
|
if (keyObject.type === 'public') {
|
|
121
121
|
const der = keyObject.export({ type: 'spki', format: 'der' });
|
|
122
122
|
return {
|
|
123
123
|
kty: 'OKP',
|
|
124
124
|
crv,
|
|
125
|
-
x:
|
|
125
|
+
x: base64url_js_1.encode(der.subarray(-32)),
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
const der = keyObject.export({ type: 'pkcs8', format: 'der' });
|
|
129
129
|
return {
|
|
130
|
-
...keyToJWK(
|
|
131
|
-
d:
|
|
130
|
+
...keyToJWK(crypto_1.createPublicKey(keyObject)),
|
|
131
|
+
d: base64url_js_1.encode(der.subarray(-32)),
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
case 'ed448':
|
|
135
135
|
case 'x448': {
|
|
136
|
-
const crv =
|
|
136
|
+
const crv = get_named_curve_js_1.default(keyObject);
|
|
137
137
|
if (keyObject.type === 'public') {
|
|
138
138
|
const der = keyObject.export({ type: 'spki', format: 'der' });
|
|
139
139
|
return {
|
|
140
140
|
kty: 'OKP',
|
|
141
141
|
crv,
|
|
142
|
-
x:
|
|
142
|
+
x: base64url_js_1.encode(der.subarray(crv === 'Ed448' ? -57 : -56)),
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
const der = keyObject.export({ type: 'pkcs8', format: 'der' });
|
|
146
146
|
return {
|
|
147
|
-
...keyToJWK(
|
|
148
|
-
d:
|
|
147
|
+
...keyToJWK(crypto_1.createPublicKey(keyObject)),
|
|
148
|
+
d: base64url_js_1.encode(der.subarray(crv === 'Ed448' ? -57 : -56)),
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
default:
|
|
@@ -28,7 +28,7 @@ function keyForCrypto(alg, key) {
|
|
|
28
28
|
if (key.asymmetricKeyType !== 'rsa') {
|
|
29
29
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
check_modulus_length_js_1.default(key, alg);
|
|
32
32
|
return key;
|
|
33
33
|
case rsaPssParams && 'PS256':
|
|
34
34
|
case rsaPssParams && 'PS384':
|
|
@@ -47,7 +47,7 @@ function keyForCrypto(alg, key) {
|
|
|
47
47
|
else if (key.asymmetricKeyType !== 'rsa') {
|
|
48
48
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa or rsa-pss');
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
check_modulus_length_js_1.default(key, alg);
|
|
51
51
|
return {
|
|
52
52
|
key,
|
|
53
53
|
padding: crypto_1.constants.RSA_PKCS1_PSS_PADDING,
|
|
@@ -59,7 +59,7 @@ function keyForCrypto(alg, key) {
|
|
|
59
59
|
if (key.asymmetricKeyType !== 'rsa') {
|
|
60
60
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
check_modulus_length_js_1.default(key, alg);
|
|
63
63
|
return {
|
|
64
64
|
key,
|
|
65
65
|
padding: crypto_1.constants.RSA_PKCS1_PSS_PADDING,
|
|
@@ -72,7 +72,7 @@ function keyForCrypto(alg, key) {
|
|
|
72
72
|
if (key.asymmetricKeyType !== 'ec') {
|
|
73
73
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be ec');
|
|
74
74
|
}
|
|
75
|
-
const actual =
|
|
75
|
+
const actual = get_named_curve_js_1.default(key);
|
|
76
76
|
const expected = ecCurveAlgMap.get(alg);
|
|
77
77
|
if (actual !== expected) {
|
|
78
78
|
throw new TypeError(`Invalid key curve for the algorithm, its curve must be ${expected}, got ${actual}`);
|
|
@@ -11,35 +11,35 @@ const check_p2s_js_1 = require("../lib/check_p2s.js");
|
|
|
11
11
|
const webcrypto_js_1 = require("./webcrypto.js");
|
|
12
12
|
const is_key_object_js_1 = require("./is_key_object.js");
|
|
13
13
|
const invalid_key_input_js_1 = require("./invalid_key_input.js");
|
|
14
|
-
const pbkdf2 =
|
|
14
|
+
const pbkdf2 = util_1.promisify(crypto_1.pbkdf2);
|
|
15
15
|
function getPassword(key, alg) {
|
|
16
|
-
if (
|
|
16
|
+
if (is_key_object_js_1.default(key)) {
|
|
17
17
|
return key.export();
|
|
18
18
|
}
|
|
19
19
|
if (key instanceof Uint8Array) {
|
|
20
20
|
return key;
|
|
21
21
|
}
|
|
22
|
-
if (
|
|
23
|
-
return
|
|
22
|
+
if (webcrypto_js_1.isCryptoKey(key)) {
|
|
23
|
+
return webcrypto_js_1.getKeyObject(key, alg, new Set(['deriveBits', 'deriveKey'])).export();
|
|
24
24
|
}
|
|
25
|
-
throw new TypeError(
|
|
25
|
+
throw new TypeError(invalid_key_input_js_1.default(key, 'KeyObject', 'CryptoKey', 'Uint8Array'));
|
|
26
26
|
}
|
|
27
|
-
const encrypt = async (alg, key, cek, p2c = Math.floor(Math.random() * 2049) + 2048, p2s =
|
|
28
|
-
|
|
29
|
-
const salt =
|
|
27
|
+
const encrypt = async (alg, key, cek, p2c = Math.floor(Math.random() * 2049) + 2048, p2s = random_js_1.default(new Uint8Array(16))) => {
|
|
28
|
+
check_p2s_js_1.default(p2s);
|
|
29
|
+
const salt = buffer_utils_js_1.p2s(alg, p2s);
|
|
30
30
|
const keylen = parseInt(alg.substr(13, 3), 10) >> 3;
|
|
31
31
|
const password = getPassword(key, alg);
|
|
32
32
|
const derivedKey = await pbkdf2(password, salt, p2c, keylen, `sha${alg.substr(8, 3)}`);
|
|
33
|
-
const encryptedKey = await
|
|
34
|
-
return { encryptedKey, p2c, p2s:
|
|
33
|
+
const encryptedKey = await aeskw_js_1.wrap(alg.substr(-6), derivedKey, cek);
|
|
34
|
+
return { encryptedKey, p2c, p2s: base64url_js_1.encode(p2s) };
|
|
35
35
|
};
|
|
36
36
|
exports.encrypt = encrypt;
|
|
37
37
|
const decrypt = async (alg, key, encryptedKey, p2c, p2s) => {
|
|
38
|
-
|
|
39
|
-
const salt =
|
|
38
|
+
check_p2s_js_1.default(p2s);
|
|
39
|
+
const salt = buffer_utils_js_1.p2s(alg, p2s);
|
|
40
40
|
const keylen = parseInt(alg.substr(13, 3), 10) >> 3;
|
|
41
41
|
const password = getPassword(key, alg);
|
|
42
42
|
const derivedKey = await pbkdf2(password, salt, p2c, keylen, `sha${alg.substr(8, 3)}`);
|
|
43
|
-
return
|
|
43
|
+
return aeskw_js_1.unwrap(alg.substr(-6), derivedKey, encryptedKey);
|
|
44
44
|
};
|
|
45
45
|
exports.decrypt = decrypt;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var crypto_1 = require("crypto");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return crypto_1.randomFillSync; } });
|
|
@@ -10,7 +10,7 @@ const checkKey = (key, alg) => {
|
|
|
10
10
|
if (key.asymmetricKeyType !== 'rsa') {
|
|
11
11
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
check_modulus_length_js_1.default(key, alg);
|
|
14
14
|
};
|
|
15
15
|
const resolvePadding = (alg) => {
|
|
16
16
|
switch (alg) {
|
|
@@ -40,20 +40,20 @@ const resolveOaepHash = (alg) => {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
function ensureKeyObject(key, alg, ...usages) {
|
|
43
|
-
if (
|
|
43
|
+
if (is_key_object_js_1.default(key)) {
|
|
44
44
|
return key;
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
46
|
+
if (webcrypto_js_1.isCryptoKey(key)) {
|
|
47
|
+
return webcrypto_js_1.getKeyObject(key, alg, new Set(usages));
|
|
48
48
|
}
|
|
49
|
-
throw new TypeError(
|
|
49
|
+
throw new TypeError(invalid_key_input_js_1.default(key, 'KeyObject', 'CryptoKey'));
|
|
50
50
|
}
|
|
51
51
|
const encrypt = async (alg, key, cek) => {
|
|
52
52
|
const padding = resolvePadding(alg);
|
|
53
53
|
const oaepHash = resolveOaepHash(alg);
|
|
54
54
|
const keyObject = ensureKeyObject(key, alg, 'wrapKey', 'encrypt');
|
|
55
55
|
checkKey(keyObject, alg);
|
|
56
|
-
return
|
|
56
|
+
return crypto_1.publicEncrypt({ key: keyObject, oaepHash, padding }, cek);
|
|
57
57
|
};
|
|
58
58
|
exports.encrypt = encrypt;
|
|
59
59
|
const decrypt = async (alg, key, encryptedKey) => {
|
|
@@ -61,6 +61,6 @@ const decrypt = async (alg, key, encryptedKey) => {
|
|
|
61
61
|
const oaepHash = resolveOaepHash(alg);
|
|
62
62
|
const keyObject = ensureKeyObject(key, alg, 'unwrapKey', 'decrypt');
|
|
63
63
|
checkKey(keyObject, alg);
|
|
64
|
-
return
|
|
64
|
+
return crypto_1.privateDecrypt({ key: keyObject, oaepHash, padding }, encryptedKey);
|
|
65
65
|
};
|
|
66
66
|
exports.decrypt = decrypt;
|
|
@@ -8,22 +8,22 @@ const node_key_js_1 = require("./node_key.js");
|
|
|
8
8
|
const get_sign_verify_key_js_1 = require("./get_sign_verify_key.js");
|
|
9
9
|
let oneShotSign;
|
|
10
10
|
if (crypto.sign.length > 3) {
|
|
11
|
-
oneShotSign =
|
|
11
|
+
oneShotSign = util_1.promisify(crypto.sign);
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
14
|
oneShotSign = crypto.sign;
|
|
15
15
|
}
|
|
16
16
|
const sign = async (alg, key, data) => {
|
|
17
|
-
const keyObject =
|
|
17
|
+
const keyObject = get_sign_verify_key_js_1.default(alg, key, 'sign');
|
|
18
18
|
if (alg.startsWith('HS')) {
|
|
19
19
|
const bitlen = parseInt(alg.substr(-3), 10);
|
|
20
20
|
if (!keyObject.symmetricKeySize || keyObject.symmetricKeySize << 3 < bitlen) {
|
|
21
21
|
throw new TypeError(`${alg} requires symmetric keys to be ${bitlen} bits or larger`);
|
|
22
22
|
}
|
|
23
|
-
const hmac = crypto.createHmac(
|
|
23
|
+
const hmac = crypto.createHmac(hmac_digest_js_1.default(alg), keyObject);
|
|
24
24
|
hmac.update(data);
|
|
25
25
|
return hmac.digest();
|
|
26
26
|
}
|
|
27
|
-
return oneShotSign(
|
|
27
|
+
return oneShotSign(dsa_digest_js_1.default(alg), data, node_key_js_1.default(alg, keyObject));
|
|
28
28
|
};
|
|
29
29
|
exports.default = sign;
|
|
@@ -13,15 +13,15 @@ const [major, minor] = process.version
|
|
|
13
13
|
const oneShotCallbackSupported = major >= 16 || (major === 15 && minor >= 13);
|
|
14
14
|
let oneShotVerify;
|
|
15
15
|
if (crypto.verify.length > 4 && oneShotCallbackSupported) {
|
|
16
|
-
oneShotVerify =
|
|
16
|
+
oneShotVerify = util_1.promisify(crypto.verify);
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
19
|
oneShotVerify = crypto.verify;
|
|
20
20
|
}
|
|
21
21
|
const verify = async (alg, key, signature, data) => {
|
|
22
|
-
const keyObject =
|
|
22
|
+
const keyObject = get_sign_verify_key_js_1.default(alg, key, 'verify');
|
|
23
23
|
if (alg.startsWith('HS')) {
|
|
24
|
-
const expected = await
|
|
24
|
+
const expected = await sign_js_1.default(alg, keyObject, data);
|
|
25
25
|
const actual = signature;
|
|
26
26
|
try {
|
|
27
27
|
return crypto.timingSafeEqual(actual, expected);
|
|
@@ -30,8 +30,8 @@ const verify = async (alg, key, signature, data) => {
|
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
const algorithm =
|
|
34
|
-
const keyInput =
|
|
33
|
+
const algorithm = dsa_digest_js_1.default(alg);
|
|
34
|
+
const keyInput = node_key_js_1.default(alg, keyObject);
|
|
35
35
|
try {
|
|
36
36
|
return await oneShotVerify(algorithm, data, keyInput, signature);
|
|
37
37
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deflate = exports.inflate = void 0;
|
|
4
4
|
const util_1 = require("util");
|
|
5
5
|
const zlib_1 = require("zlib");
|
|
6
|
-
const inflateRaw =
|
|
7
|
-
const deflateRaw =
|
|
6
|
+
const inflateRaw = util_1.promisify(zlib_1.inflateRaw);
|
|
7
|
+
const deflateRaw = util_1.promisify(zlib_1.deflateRaw);
|
|
8
8
|
const inflate = (input) => inflateRaw(input);
|
|
9
9
|
exports.inflate = inflate;
|
|
10
10
|
const deflate = (input) => deflateRaw(input);
|
|
@@ -25,8 +25,8 @@ function decodeProtectedHeader(token) {
|
|
|
25
25
|
if (typeof protectedB64u !== 'string' || !protectedB64u) {
|
|
26
26
|
throw new Error();
|
|
27
27
|
}
|
|
28
|
-
const result = JSON.parse(buffer_utils_js_1.decoder.decode(
|
|
29
|
-
if (!
|
|
28
|
+
const result = JSON.parse(buffer_utils_js_1.decoder.decode(base64url_js_1.decode(protectedB64u)));
|
|
29
|
+
if (!is_object_js_1.default(result)) {
|
|
30
30
|
throw new Error();
|
|
31
31
|
}
|
|
32
32
|
return result;
|
|
@@ -1,133 +1,165 @@
|
|
|
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;
|
|
7
7
|
super(message);
|
|
8
|
-
this.code =
|
|
8
|
+
this.code = 'ERR_JOSE_GENERIC';
|
|
9
9
|
this.name = this.constructor.name;
|
|
10
10
|
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, this.constructor);
|
|
11
11
|
}
|
|
12
|
+
static get code() {
|
|
13
|
+
return 'ERR_JOSE_GENERIC';
|
|
14
|
+
}
|
|
12
15
|
}
|
|
13
16
|
exports.JOSEError = JOSEError;
|
|
14
|
-
JOSEError.code = 'ERR_JOSE_GENERIC';
|
|
15
17
|
class JWTClaimValidationFailed extends JOSEError {
|
|
16
18
|
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
17
19
|
super(message);
|
|
18
|
-
this.code =
|
|
20
|
+
this.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
19
21
|
this.claim = claim;
|
|
20
22
|
this.reason = reason;
|
|
21
23
|
}
|
|
24
|
+
static get code() {
|
|
25
|
+
return 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
exports.JWTClaimValidationFailed = JWTClaimValidationFailed;
|
|
24
|
-
|
|
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;
|
|
25
41
|
class JOSEAlgNotAllowed extends JOSEError {
|
|
26
42
|
constructor() {
|
|
27
43
|
super(...arguments);
|
|
28
|
-
this.code =
|
|
44
|
+
this.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
45
|
+
}
|
|
46
|
+
static get code() {
|
|
47
|
+
return 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
29
48
|
}
|
|
30
49
|
}
|
|
31
50
|
exports.JOSEAlgNotAllowed = JOSEAlgNotAllowed;
|
|
32
|
-
JOSEAlgNotAllowed.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
33
51
|
class JOSENotSupported extends JOSEError {
|
|
34
52
|
constructor() {
|
|
35
53
|
super(...arguments);
|
|
36
|
-
this.code =
|
|
54
|
+
this.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
55
|
+
}
|
|
56
|
+
static get code() {
|
|
57
|
+
return 'ERR_JOSE_NOT_SUPPORTED';
|
|
37
58
|
}
|
|
38
59
|
}
|
|
39
60
|
exports.JOSENotSupported = JOSENotSupported;
|
|
40
|
-
JOSENotSupported.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
41
61
|
class JWEDecryptionFailed extends JOSEError {
|
|
42
62
|
constructor() {
|
|
43
63
|
super(...arguments);
|
|
44
|
-
this.code =
|
|
64
|
+
this.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
45
65
|
this.message = 'decryption operation failed';
|
|
46
66
|
}
|
|
67
|
+
static get code() {
|
|
68
|
+
return 'ERR_JWE_DECRYPTION_FAILED';
|
|
69
|
+
}
|
|
47
70
|
}
|
|
48
71
|
exports.JWEDecryptionFailed = JWEDecryptionFailed;
|
|
49
|
-
JWEDecryptionFailed.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
50
72
|
class JWEInvalid extends JOSEError {
|
|
51
73
|
constructor() {
|
|
52
74
|
super(...arguments);
|
|
53
|
-
this.code =
|
|
75
|
+
this.code = 'ERR_JWE_INVALID';
|
|
76
|
+
}
|
|
77
|
+
static get code() {
|
|
78
|
+
return 'ERR_JWE_INVALID';
|
|
54
79
|
}
|
|
55
80
|
}
|
|
56
81
|
exports.JWEInvalid = JWEInvalid;
|
|
57
|
-
JWEInvalid.code = 'ERR_JWE_INVALID';
|
|
58
82
|
class JWSInvalid extends JOSEError {
|
|
59
83
|
constructor() {
|
|
60
84
|
super(...arguments);
|
|
61
|
-
this.code =
|
|
85
|
+
this.code = 'ERR_JWS_INVALID';
|
|
86
|
+
}
|
|
87
|
+
static get code() {
|
|
88
|
+
return 'ERR_JWS_INVALID';
|
|
62
89
|
}
|
|
63
90
|
}
|
|
64
91
|
exports.JWSInvalid = JWSInvalid;
|
|
65
|
-
JWSInvalid.code = 'ERR_JWS_INVALID';
|
|
66
92
|
class JWTInvalid extends JOSEError {
|
|
67
93
|
constructor() {
|
|
68
94
|
super(...arguments);
|
|
69
|
-
this.code =
|
|
95
|
+
this.code = 'ERR_JWT_INVALID';
|
|
96
|
+
}
|
|
97
|
+
static get code() {
|
|
98
|
+
return 'ERR_JWT_INVALID';
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
101
|
exports.JWTInvalid = JWTInvalid;
|
|
73
|
-
JWTInvalid.code = 'ERR_JWT_INVALID';
|
|
74
102
|
class JWKInvalid extends JOSEError {
|
|
75
103
|
constructor() {
|
|
76
104
|
super(...arguments);
|
|
77
|
-
this.code =
|
|
105
|
+
this.code = 'ERR_JWK_INVALID';
|
|
106
|
+
}
|
|
107
|
+
static get code() {
|
|
108
|
+
return 'ERR_JWK_INVALID';
|
|
78
109
|
}
|
|
79
110
|
}
|
|
80
111
|
exports.JWKInvalid = JWKInvalid;
|
|
81
|
-
JWKInvalid.code = 'ERR_JWK_INVALID';
|
|
82
112
|
class JWKSInvalid extends JOSEError {
|
|
83
113
|
constructor() {
|
|
84
114
|
super(...arguments);
|
|
85
|
-
this.code =
|
|
115
|
+
this.code = 'ERR_JWKS_INVALID';
|
|
116
|
+
}
|
|
117
|
+
static get code() {
|
|
118
|
+
return 'ERR_JWKS_INVALID';
|
|
86
119
|
}
|
|
87
120
|
}
|
|
88
121
|
exports.JWKSInvalid = JWKSInvalid;
|
|
89
|
-
JWKSInvalid.code = 'ERR_JWKS_INVALID';
|
|
90
122
|
class JWKSNoMatchingKey extends JOSEError {
|
|
91
123
|
constructor() {
|
|
92
124
|
super(...arguments);
|
|
93
|
-
this.code =
|
|
125
|
+
this.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
94
126
|
this.message = 'no applicable key found in the JSON Web Key Set';
|
|
95
127
|
}
|
|
128
|
+
static get code() {
|
|
129
|
+
return 'ERR_JWKS_NO_MATCHING_KEY';
|
|
130
|
+
}
|
|
96
131
|
}
|
|
97
132
|
exports.JWKSNoMatchingKey = JWKSNoMatchingKey;
|
|
98
|
-
JWKSNoMatchingKey.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
99
133
|
class JWKSMultipleMatchingKeys extends JOSEError {
|
|
100
134
|
constructor() {
|
|
101
135
|
super(...arguments);
|
|
102
|
-
this.code =
|
|
136
|
+
this.code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
103
137
|
this.message = 'multiple matching keys found in the JSON Web Key Set';
|
|
104
138
|
}
|
|
139
|
+
static get code() {
|
|
140
|
+
return 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
141
|
+
}
|
|
105
142
|
}
|
|
106
143
|
exports.JWKSMultipleMatchingKeys = JWKSMultipleMatchingKeys;
|
|
107
|
-
JWKSMultipleMatchingKeys.code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
108
144
|
class JWKSTimeout extends JOSEError {
|
|
109
145
|
constructor() {
|
|
110
146
|
super(...arguments);
|
|
111
|
-
this.code =
|
|
147
|
+
this.code = 'ERR_JWKS_TIMEOUT';
|
|
112
148
|
this.message = 'request timed out';
|
|
113
149
|
}
|
|
150
|
+
static get code() {
|
|
151
|
+
return 'ERR_JWKS_TIMEOUT';
|
|
152
|
+
}
|
|
114
153
|
}
|
|
115
154
|
exports.JWKSTimeout = JWKSTimeout;
|
|
116
|
-
JWKSTimeout.code = 'ERR_JWKS_TIMEOUT';
|
|
117
155
|
class JWSSignatureVerificationFailed extends JOSEError {
|
|
118
156
|
constructor() {
|
|
119
157
|
super(...arguments);
|
|
120
|
-
this.code =
|
|
158
|
+
this.code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
121
159
|
this.message = 'signature verification failed';
|
|
122
160
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
JWSSignatureVerificationFailed.code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
126
|
-
class JWTExpired extends JWTClaimValidationFailed {
|
|
127
|
-
constructor() {
|
|
128
|
-
super(...arguments);
|
|
129
|
-
this.code = JWTExpired.code;
|
|
161
|
+
static get code() {
|
|
162
|
+
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
130
163
|
}
|
|
131
164
|
}
|
|
132
|
-
exports.
|
|
133
|
-
JWTExpired.code = 'ERR_JWT_EXPIRED';
|
|
165
|
+
exports.JWSSignatureVerificationFailed = JWSSignatureVerificationFailed;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateKeyPair = void 0;
|
|
4
4
|
const generate_js_1 = require("../runtime/generate.js");
|
|
5
5
|
async function generateKeyPair(alg, options) {
|
|
6
|
-
return
|
|
6
|
+
return generate_js_1.generateKeyPair(alg, options);
|
|
7
7
|
}
|
|
8
8
|
exports.generateKeyPair = generateKeyPair;
|
|
9
9
|
exports.default = generateKeyPair;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateSecret = void 0;
|
|
4
4
|
const generate_js_1 = require("../runtime/generate.js");
|
|
5
5
|
async function generateSecret(alg, options) {
|
|
6
|
-
return
|
|
6
|
+
return generate_js_1.generateSecret(alg, options);
|
|
7
7
|
}
|
|
8
8
|
exports.generateSecret = generateSecret;
|
|
9
9
|
exports.default = generateSecret;
|
|
@@ -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);
|