jose 3.20.3 → 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 +2 -2
- package/dist/browser/lib/decrypt_key_management.js +4 -1
- package/dist/node/cjs/jwe/compact/decrypt.js +1 -1
- package/dist/node/cjs/jwe/flattened/decrypt.js +17 -17
- package/dist/node/cjs/jwe/flattened/encrypt.js +13 -13
- 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 -8
- package/dist/node/cjs/jws/flattened/verify.js +11 -11
- 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 +1 -1
- 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 -14
- package/dist/node/cjs/lib/iv.js +1 -1
- package/dist/node/cjs/lib/jwt_claims_set.js +4 -4
- package/dist/node/cjs/runtime/aesgcmkw.js +4 -4
- 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/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/generate_key_pair.js +1 -1
- package/dist/node/cjs/util/generate_secret.js +1 -1
- package/dist/node/esm/jwe/flattened/decrypt.js +2 -2
- package/dist/node/esm/lib/decrypt_key_management.js +4 -1
- package/dist/types/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -95,10 +95,10 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
95
95
|
}
|
|
96
96
|
let cek;
|
|
97
97
|
try {
|
|
98
|
-
cek = await decryptKeyManagement(alg, key, encryptedKey, joseHeader);
|
|
98
|
+
cek = await decryptKeyManagement(alg, key, encryptedKey, joseHeader, options);
|
|
99
99
|
}
|
|
100
100
|
catch (err) {
|
|
101
|
-
if (err instanceof TypeError) {
|
|
101
|
+
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
102
102
|
throw err;
|
|
103
103
|
}
|
|
104
104
|
cek = generateCek(enc);
|
|
@@ -9,7 +9,7 @@ import { bitLengths as cekLengths } from '../lib/cek.js';
|
|
|
9
9
|
import { importJWK } from '../key/import.js';
|
|
10
10
|
import checkKeyType from './check_key_type.js';
|
|
11
11
|
import isObject from './is_object.js';
|
|
12
|
-
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
|
|
12
|
+
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
13
13
|
checkKeyType(alg, key, 'decrypt');
|
|
14
14
|
switch (alg) {
|
|
15
15
|
case 'dir': {
|
|
@@ -63,6 +63,9 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
|
|
|
63
63
|
throw new JWEInvalid('JWE Encrypted Key missing');
|
|
64
64
|
if (typeof joseHeader.p2c !== 'number')
|
|
65
65
|
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
66
|
+
const p2cLimit = (options === null || options === void 0 ? void 0 : options.maxPBES2Count) || 10000;
|
|
67
|
+
if (joseHeader.p2c > p2cLimit)
|
|
68
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
66
69
|
if (typeof joseHeader.p2s !== 'string')
|
|
67
70
|
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
68
71
|
return pbes2Kw(alg, key, encryptedKey, joseHeader.p2c, base64url(joseHeader.p2s));
|
|
@@ -15,7 +15,7 @@ async function compactDecrypt(jwe, key, options) {
|
|
|
15
15
|
if (length !== 5) {
|
|
16
16
|
throw new errors_js_1.JWEInvalid('Invalid Compact JWE');
|
|
17
17
|
}
|
|
18
|
-
const decrypted = await
|
|
18
|
+
const decrypted = await decrypt_js_1.default({
|
|
19
19
|
ciphertext: (ciphertext || undefined),
|
|
20
20
|
iv: (iv || undefined),
|
|
21
21
|
protected: protectedHeader || undefined,
|
|
@@ -14,7 +14,7 @@ const validate_crit_js_1 = require("../../lib/validate_crit.js");
|
|
|
14
14
|
const validate_algorithms_js_1 = require("../../lib/validate_algorithms.js");
|
|
15
15
|
async function flattenedDecrypt(jwe, key, options) {
|
|
16
16
|
var _a;
|
|
17
|
-
if (!
|
|
17
|
+
if (!is_object_js_1.default(jwe)) {
|
|
18
18
|
throw new errors_js_1.JWEInvalid('Flattened JWE must be an object');
|
|
19
19
|
}
|
|
20
20
|
if (jwe.protected === undefined && jwe.header === undefined && jwe.unprotected === undefined) {
|
|
@@ -38,15 +38,15 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
38
38
|
if (jwe.aad !== undefined && typeof jwe.aad !== 'string') {
|
|
39
39
|
throw new errors_js_1.JWEInvalid('JWE AAD incorrect type');
|
|
40
40
|
}
|
|
41
|
-
if (jwe.header !== undefined && !
|
|
41
|
+
if (jwe.header !== undefined && !is_object_js_1.default(jwe.header)) {
|
|
42
42
|
throw new errors_js_1.JWEInvalid('JWE Shared Unprotected Header incorrect type');
|
|
43
43
|
}
|
|
44
|
-
if (jwe.unprotected !== undefined && !
|
|
44
|
+
if (jwe.unprotected !== undefined && !is_object_js_1.default(jwe.unprotected)) {
|
|
45
45
|
throw new errors_js_1.JWEInvalid('JWE Per-Recipient Unprotected Header incorrect type');
|
|
46
46
|
}
|
|
47
47
|
let parsedProt;
|
|
48
48
|
if (jwe.protected) {
|
|
49
|
-
const protectedHeader =
|
|
49
|
+
const protectedHeader = base64url_js_1.decode(jwe.protected);
|
|
50
50
|
try {
|
|
51
51
|
parsedProt = JSON.parse(buffer_utils_js_1.decoder.decode(protectedHeader));
|
|
52
52
|
}
|
|
@@ -54,7 +54,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
54
54
|
throw new errors_js_1.JWEInvalid('JWE Protected Header is invalid');
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
if (!
|
|
57
|
+
if (!is_disjoint_js_1.default(parsedProt, jwe.header, jwe.unprotected)) {
|
|
58
58
|
throw new errors_js_1.JWEInvalid('JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint');
|
|
59
59
|
}
|
|
60
60
|
const joseHeader = {
|
|
@@ -62,7 +62,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
62
62
|
...jwe.header,
|
|
63
63
|
...jwe.unprotected,
|
|
64
64
|
};
|
|
65
|
-
|
|
65
|
+
validate_crit_js_1.default(errors_js_1.JWEInvalid, new Map(), options === null || options === void 0 ? void 0 : options.crit, parsedProt, joseHeader);
|
|
66
66
|
if (joseHeader.zip !== undefined) {
|
|
67
67
|
if (!parsedProt || !parsedProt.zip) {
|
|
68
68
|
throw new errors_js_1.JWEInvalid('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
|
|
@@ -78,9 +78,9 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
78
78
|
if (typeof enc !== 'string' || !enc) {
|
|
79
79
|
throw new errors_js_1.JWEInvalid('missing JWE Encryption Algorithm (enc) in JWE Header');
|
|
80
80
|
}
|
|
81
|
-
const keyManagementAlgorithms = options &&
|
|
81
|
+
const keyManagementAlgorithms = options && validate_algorithms_js_1.default('keyManagementAlgorithms', options.keyManagementAlgorithms);
|
|
82
82
|
const contentEncryptionAlgorithms = options &&
|
|
83
|
-
|
|
83
|
+
validate_algorithms_js_1.default('contentEncryptionAlgorithms', options.contentEncryptionAlgorithms);
|
|
84
84
|
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg)) {
|
|
85
85
|
throw new errors_js_1.JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter not allowed');
|
|
86
86
|
}
|
|
@@ -89,7 +89,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
89
89
|
}
|
|
90
90
|
let encryptedKey;
|
|
91
91
|
if (jwe.encrypted_key !== undefined) {
|
|
92
|
-
encryptedKey =
|
|
92
|
+
encryptedKey = base64url_js_1.decode(jwe.encrypted_key);
|
|
93
93
|
}
|
|
94
94
|
let resolvedKey = false;
|
|
95
95
|
if (typeof key === 'function') {
|
|
@@ -98,25 +98,25 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
98
98
|
}
|
|
99
99
|
let cek;
|
|
100
100
|
try {
|
|
101
|
-
cek = await
|
|
101
|
+
cek = await decrypt_key_management_js_1.default(alg, key, encryptedKey, joseHeader, options);
|
|
102
102
|
}
|
|
103
103
|
catch (err) {
|
|
104
|
-
if (err instanceof TypeError) {
|
|
104
|
+
if (err instanceof TypeError || err instanceof errors_js_1.JWEInvalid || err instanceof errors_js_1.JOSENotSupported) {
|
|
105
105
|
throw err;
|
|
106
106
|
}
|
|
107
|
-
cek =
|
|
107
|
+
cek = cek_js_1.default(enc);
|
|
108
108
|
}
|
|
109
|
-
const iv =
|
|
110
|
-
const tag =
|
|
109
|
+
const iv = base64url_js_1.decode(jwe.iv);
|
|
110
|
+
const tag = base64url_js_1.decode(jwe.tag);
|
|
111
111
|
const protectedHeader = buffer_utils_js_1.encoder.encode((_a = jwe.protected) !== null && _a !== void 0 ? _a : '');
|
|
112
112
|
let additionalData;
|
|
113
113
|
if (jwe.aad !== undefined) {
|
|
114
|
-
additionalData =
|
|
114
|
+
additionalData = buffer_utils_js_1.concat(protectedHeader, buffer_utils_js_1.encoder.encode('.'), buffer_utils_js_1.encoder.encode(jwe.aad));
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
117
|
additionalData = protectedHeader;
|
|
118
118
|
}
|
|
119
|
-
let plaintext = await
|
|
119
|
+
let plaintext = await decrypt_js_1.default(enc, cek, base64url_js_1.decode(jwe.ciphertext), iv, tag, additionalData);
|
|
120
120
|
if (joseHeader.zip === 'DEF') {
|
|
121
121
|
plaintext = await ((options === null || options === void 0 ? void 0 : options.inflateRaw) || zlib_js_1.inflate)(plaintext);
|
|
122
122
|
}
|
|
@@ -125,7 +125,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
125
125
|
result.protectedHeader = parsedProt;
|
|
126
126
|
}
|
|
127
127
|
if (jwe.aad !== undefined) {
|
|
128
|
-
result.additionalAuthenticatedData =
|
|
128
|
+
result.additionalAuthenticatedData = base64url_js_1.decode(jwe.aad);
|
|
129
129
|
}
|
|
130
130
|
if (jwe.unprotected !== undefined) {
|
|
131
131
|
result.sharedUnprotectedHeader = jwe.unprotected;
|
|
@@ -67,7 +67,7 @@ class FlattenedEncrypt {
|
|
|
67
67
|
if (!this._protectedHeader && !this._unprotectedHeader && !this._sharedUnprotectedHeader) {
|
|
68
68
|
throw new errors_js_1.JWEInvalid('either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()');
|
|
69
69
|
}
|
|
70
|
-
if (!
|
|
70
|
+
if (!is_disjoint_js_1.default(this._protectedHeader, this._unprotectedHeader, this._sharedUnprotectedHeader)) {
|
|
71
71
|
throw new errors_js_1.JWEInvalid('JWE Shared Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint');
|
|
72
72
|
}
|
|
73
73
|
const joseHeader = {
|
|
@@ -75,7 +75,7 @@ class FlattenedEncrypt {
|
|
|
75
75
|
...this._unprotectedHeader,
|
|
76
76
|
...this._sharedUnprotectedHeader,
|
|
77
77
|
};
|
|
78
|
-
|
|
78
|
+
validate_crit_js_1.default(errors_js_1.JWEInvalid, new Map(), options === null || options === void 0 ? void 0 : options.crit, this._protectedHeader, joseHeader);
|
|
79
79
|
if (joseHeader.zip !== undefined) {
|
|
80
80
|
if (!this._protectedHeader || !this._protectedHeader.zip) {
|
|
81
81
|
throw new errors_js_1.JWEInvalid('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
|
|
@@ -105,7 +105,7 @@ class FlattenedEncrypt {
|
|
|
105
105
|
let cek;
|
|
106
106
|
{
|
|
107
107
|
let parameters;
|
|
108
|
-
({ cek, encryptedKey, parameters } = await
|
|
108
|
+
({ cek, encryptedKey, parameters } = await encrypt_key_management_js_1.default(alg, enc, key, this._cek, this._keyManagementParameters));
|
|
109
109
|
if (parameters) {
|
|
110
110
|
if (!this._protectedHeader) {
|
|
111
111
|
this.setProtectedHeader(parameters);
|
|
@@ -115,19 +115,19 @@ class FlattenedEncrypt {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
this._iv || (this._iv =
|
|
118
|
+
this._iv || (this._iv = iv_js_1.default(enc));
|
|
119
119
|
let additionalData;
|
|
120
120
|
let protectedHeader;
|
|
121
121
|
let aadMember;
|
|
122
122
|
if (this._protectedHeader) {
|
|
123
|
-
protectedHeader = buffer_utils_js_1.encoder.encode(
|
|
123
|
+
protectedHeader = buffer_utils_js_1.encoder.encode(base64url_js_1.encode(JSON.stringify(this._protectedHeader)));
|
|
124
124
|
}
|
|
125
125
|
else {
|
|
126
126
|
protectedHeader = buffer_utils_js_1.encoder.encode('');
|
|
127
127
|
}
|
|
128
128
|
if (this._aad) {
|
|
129
|
-
aadMember =
|
|
130
|
-
additionalData =
|
|
129
|
+
aadMember = base64url_js_1.encode(this._aad);
|
|
130
|
+
additionalData = buffer_utils_js_1.concat(protectedHeader, buffer_utils_js_1.encoder.encode('.'), buffer_utils_js_1.encoder.encode(aadMember));
|
|
131
131
|
}
|
|
132
132
|
else {
|
|
133
133
|
additionalData = protectedHeader;
|
|
@@ -136,19 +136,19 @@ class FlattenedEncrypt {
|
|
|
136
136
|
let tag;
|
|
137
137
|
if (joseHeader.zip === 'DEF') {
|
|
138
138
|
const deflated = await ((options === null || options === void 0 ? void 0 : options.deflateRaw) || zlib_js_1.deflate)(this._plaintext);
|
|
139
|
-
({ ciphertext, tag } = await
|
|
139
|
+
({ ciphertext, tag } = await encrypt_js_1.default(enc, deflated, cek, this._iv, additionalData));
|
|
140
140
|
}
|
|
141
141
|
else {
|
|
142
142
|
;
|
|
143
|
-
({ ciphertext, tag } = await
|
|
143
|
+
({ ciphertext, tag } = await encrypt_js_1.default(enc, this._plaintext, cek, this._iv, additionalData));
|
|
144
144
|
}
|
|
145
145
|
const jwe = {
|
|
146
|
-
ciphertext:
|
|
147
|
-
iv:
|
|
148
|
-
tag:
|
|
146
|
+
ciphertext: base64url_js_1.encode(ciphertext),
|
|
147
|
+
iv: base64url_js_1.encode(this._iv),
|
|
148
|
+
tag: base64url_js_1.encode(tag),
|
|
149
149
|
};
|
|
150
150
|
if (encryptedKey) {
|
|
151
|
-
jwe.encrypted_key =
|
|
151
|
+
jwe.encrypted_key = base64url_js_1.encode(encryptedKey);
|
|
152
152
|
}
|
|
153
153
|
if (aadMember) {
|
|
154
154
|
jwe.aad = aadMember;
|
|
@@ -5,7 +5,7 @@ const decrypt_js_1 = require("../flattened/decrypt.js");
|
|
|
5
5
|
const errors_js_1 = require("../../util/errors.js");
|
|
6
6
|
const is_object_js_1 = require("../../lib/is_object.js");
|
|
7
7
|
async function generalDecrypt(jwe, key, options) {
|
|
8
|
-
if (!
|
|
8
|
+
if (!is_object_js_1.default(jwe)) {
|
|
9
9
|
throw new errors_js_1.JWEInvalid('General JWE must be an object');
|
|
10
10
|
}
|
|
11
11
|
if (!Array.isArray(jwe.recipients) || !jwe.recipients.every(is_object_js_1.default)) {
|
|
@@ -13,7 +13,7 @@ async function generalDecrypt(jwe, key, options) {
|
|
|
13
13
|
}
|
|
14
14
|
for (const recipient of jwe.recipients) {
|
|
15
15
|
try {
|
|
16
|
-
return await
|
|
16
|
+
return await decrypt_js_1.default({
|
|
17
17
|
aad: jwe.aad,
|
|
18
18
|
ciphertext: jwe.ciphertext,
|
|
19
19
|
encrypted_key: recipient.encrypted_key,
|
|
@@ -9,10 +9,10 @@ async function EmbeddedJWK(protectedHeader, token) {
|
|
|
9
9
|
...protectedHeader,
|
|
10
10
|
...token.header,
|
|
11
11
|
};
|
|
12
|
-
if (!
|
|
12
|
+
if (!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 = await
|
|
15
|
+
const key = await import_js_1.importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg, true);
|
|
16
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
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fromKeyLike = void 0;
|
|
4
4
|
const export_js_1 = require("../key/export.js");
|
|
5
5
|
async function fromKeyLike(key) {
|
|
6
|
-
return
|
|
6
|
+
return export_js_1.exportJWK(key);
|
|
7
7
|
}
|
|
8
8
|
exports.fromKeyLike = fromKeyLike;
|
|
9
9
|
exports.default = fromKeyLike;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseJwk = void 0;
|
|
4
4
|
const import_js_1 = require("../key/import.js");
|
|
5
5
|
async function parseJwk(jwk, alg, octAsKeyObject) {
|
|
6
|
-
return
|
|
6
|
+
return import_js_1.importJWK(jwk, alg, octAsKeyObject);
|
|
7
7
|
}
|
|
8
8
|
exports.parseJwk = parseJwk;
|
|
9
9
|
exports.default = parseJwk;
|
|
@@ -12,7 +12,7 @@ const check = (value, description) => {
|
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
async function calculateThumbprint(jwk, digestAlgorithm = 'sha256') {
|
|
15
|
-
if (!
|
|
15
|
+
if (!is_object_js_1.default(jwk)) {
|
|
16
16
|
throw new TypeError('JWK must be an object');
|
|
17
17
|
}
|
|
18
18
|
let components;
|
|
@@ -41,7 +41,7 @@ async function calculateThumbprint(jwk, digestAlgorithm = 'sha256') {
|
|
|
41
41
|
throw new errors_js_1.JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
|
|
42
42
|
}
|
|
43
43
|
const data = buffer_utils_js_1.encoder.encode(JSON.stringify(components));
|
|
44
|
-
return
|
|
44
|
+
return base64url_js_1.encode(await digest_js_1.default(digestAlgorithm, data));
|
|
45
45
|
}
|
|
46
46
|
exports.calculateThumbprint = calculateThumbprint;
|
|
47
47
|
exports.default = calculateThumbprint;
|
|
@@ -19,7 +19,7 @@ function getKtyFromAlg(alg) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
function isJWKLike(key) {
|
|
22
|
-
return
|
|
22
|
+
return is_object_js_1.default(key);
|
|
23
23
|
}
|
|
24
24
|
class RemoteJWKSet {
|
|
25
25
|
constructor(url, options) {
|
|
@@ -93,7 +93,7 @@ class RemoteJWKSet {
|
|
|
93
93
|
}
|
|
94
94
|
const cached = this._cached.get(jwk) || this._cached.set(jwk, {}).get(jwk);
|
|
95
95
|
if (cached[protectedHeader.alg] === undefined) {
|
|
96
|
-
const keyObject = await
|
|
96
|
+
const keyObject = await import_js_1.importJWK({ ...jwk, ext: true }, protectedHeader.alg);
|
|
97
97
|
if (keyObject instanceof Uint8Array || keyObject.type !== 'public') {
|
|
98
98
|
throw new errors_js_1.JWKSInvalid('JSON Web Key Set members must be public keys');
|
|
99
99
|
}
|
|
@@ -103,7 +103,7 @@ class RemoteJWKSet {
|
|
|
103
103
|
}
|
|
104
104
|
async reload() {
|
|
105
105
|
if (!this._pendingFetch) {
|
|
106
|
-
this._pendingFetch =
|
|
106
|
+
this._pendingFetch = fetch_jwks_js_1.default(this._url, this._timeoutDuration, this._options)
|
|
107
107
|
.then((json) => {
|
|
108
108
|
if (typeof json !== 'object' ||
|
|
109
109
|
!json ||
|
|
@@ -15,7 +15,7 @@ async function compactVerify(jws, key, options) {
|
|
|
15
15
|
if (length !== 3) {
|
|
16
16
|
throw new errors_js_1.JWSInvalid('Invalid Compact JWS');
|
|
17
17
|
}
|
|
18
|
-
const verified = await
|
|
18
|
+
const verified = await verify_js_1.default({
|
|
19
19
|
payload: (payload || undefined),
|
|
20
20
|
protected: protectedHeader || undefined,
|
|
21
21
|
signature: (signature || undefined),
|
|
@@ -33,14 +33,14 @@ class FlattenedSign {
|
|
|
33
33
|
if (!this._protectedHeader && !this._unprotectedHeader) {
|
|
34
34
|
throw new errors_js_1.JWSInvalid('either setProtectedHeader or setUnprotectedHeader must be called before #sign()');
|
|
35
35
|
}
|
|
36
|
-
if (!
|
|
36
|
+
if (!is_disjoint_js_1.default(this._protectedHeader, this._unprotectedHeader)) {
|
|
37
37
|
throw new errors_js_1.JWSInvalid('JWS Protected and JWS Unprotected Header Parameter names must be disjoint');
|
|
38
38
|
}
|
|
39
39
|
const joseHeader = {
|
|
40
40
|
...this._protectedHeader,
|
|
41
41
|
...this._unprotectedHeader,
|
|
42
42
|
};
|
|
43
|
-
const extensions =
|
|
43
|
+
const extensions = 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);
|
|
44
44
|
let b64 = true;
|
|
45
45
|
if (extensions.has('b64')) {
|
|
46
46
|
b64 = this._protectedHeader.b64;
|
|
@@ -52,22 +52,22 @@ class FlattenedSign {
|
|
|
52
52
|
if (typeof alg !== 'string' || !alg) {
|
|
53
53
|
throw new errors_js_1.JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
check_key_type_js_1.default(alg, key, 'sign');
|
|
56
56
|
let payload = this._payload;
|
|
57
57
|
if (b64) {
|
|
58
|
-
payload = buffer_utils_js_1.encoder.encode(
|
|
58
|
+
payload = buffer_utils_js_1.encoder.encode(base64url_js_1.encode(payload));
|
|
59
59
|
}
|
|
60
60
|
let protectedHeader;
|
|
61
61
|
if (this._protectedHeader) {
|
|
62
|
-
protectedHeader = buffer_utils_js_1.encoder.encode(
|
|
62
|
+
protectedHeader = buffer_utils_js_1.encoder.encode(base64url_js_1.encode(JSON.stringify(this._protectedHeader)));
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
protectedHeader = buffer_utils_js_1.encoder.encode('');
|
|
66
66
|
}
|
|
67
|
-
const data =
|
|
68
|
-
const signature = await
|
|
67
|
+
const data = buffer_utils_js_1.concat(protectedHeader, buffer_utils_js_1.encoder.encode('.'), payload);
|
|
68
|
+
const signature = await sign_js_1.default(alg, key, data);
|
|
69
69
|
const jws = {
|
|
70
|
-
signature:
|
|
70
|
+
signature: base64url_js_1.encode(signature),
|
|
71
71
|
payload: '',
|
|
72
72
|
};
|
|
73
73
|
if (b64) {
|
|
@@ -12,7 +12,7 @@ const validate_crit_js_1 = require("../../lib/validate_crit.js");
|
|
|
12
12
|
const validate_algorithms_js_1 = require("../../lib/validate_algorithms.js");
|
|
13
13
|
async function flattenedVerify(jws, key, options) {
|
|
14
14
|
var _a;
|
|
15
|
-
if (!
|
|
15
|
+
if (!is_object_js_1.default(jws)) {
|
|
16
16
|
throw new errors_js_1.JWSInvalid('Flattened JWS must be an object');
|
|
17
17
|
}
|
|
18
18
|
if (jws.protected === undefined && jws.header === undefined) {
|
|
@@ -27,12 +27,12 @@ async function flattenedVerify(jws, key, options) {
|
|
|
27
27
|
if (typeof jws.signature !== 'string') {
|
|
28
28
|
throw new errors_js_1.JWSInvalid('JWS Signature missing or incorrect type');
|
|
29
29
|
}
|
|
30
|
-
if (jws.header !== undefined && !
|
|
30
|
+
if (jws.header !== undefined && !is_object_js_1.default(jws.header)) {
|
|
31
31
|
throw new errors_js_1.JWSInvalid('JWS Unprotected Header incorrect type');
|
|
32
32
|
}
|
|
33
33
|
let parsedProt = {};
|
|
34
34
|
if (jws.protected) {
|
|
35
|
-
const protectedHeader =
|
|
35
|
+
const protectedHeader = base64url_js_1.decode(jws.protected);
|
|
36
36
|
try {
|
|
37
37
|
parsedProt = JSON.parse(buffer_utils_js_1.decoder.decode(protectedHeader));
|
|
38
38
|
}
|
|
@@ -40,14 +40,14 @@ async function flattenedVerify(jws, key, options) {
|
|
|
40
40
|
throw new errors_js_1.JWSInvalid('JWS Protected Header is invalid');
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
if (!
|
|
43
|
+
if (!is_disjoint_js_1.default(parsedProt, jws.header)) {
|
|
44
44
|
throw new errors_js_1.JWSInvalid('JWS Protected and JWS Unprotected Header Parameter names must be disjoint');
|
|
45
45
|
}
|
|
46
46
|
const joseHeader = {
|
|
47
47
|
...parsedProt,
|
|
48
48
|
...jws.header,
|
|
49
49
|
};
|
|
50
|
-
const extensions =
|
|
50
|
+
const extensions = validate_crit_js_1.default(errors_js_1.JWSInvalid, new Map([['b64', true]]), options === null || options === void 0 ? void 0 : options.crit, parsedProt, joseHeader);
|
|
51
51
|
let b64 = true;
|
|
52
52
|
if (extensions.has('b64')) {
|
|
53
53
|
b64 = parsedProt.b64;
|
|
@@ -59,7 +59,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
59
59
|
if (typeof alg !== 'string' || !alg) {
|
|
60
60
|
throw new errors_js_1.JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
61
61
|
}
|
|
62
|
-
const algorithms = options &&
|
|
62
|
+
const algorithms = options && validate_algorithms_js_1.default('algorithms', options.algorithms);
|
|
63
63
|
if (algorithms && !algorithms.has(alg)) {
|
|
64
64
|
throw new errors_js_1.JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter not allowed');
|
|
65
65
|
}
|
|
@@ -76,16 +76,16 @@ async function flattenedVerify(jws, key, options) {
|
|
|
76
76
|
key = await key(parsedProt, jws);
|
|
77
77
|
resolvedKey = true;
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
const data =
|
|
81
|
-
const signature =
|
|
82
|
-
const verified = await
|
|
79
|
+
check_key_type_js_1.default(alg, key, 'verify');
|
|
80
|
+
const data = buffer_utils_js_1.concat(buffer_utils_js_1.encoder.encode((_a = jws.protected) !== null && _a !== void 0 ? _a : ''), buffer_utils_js_1.encoder.encode('.'), typeof jws.payload === 'string' ? buffer_utils_js_1.encoder.encode(jws.payload) : jws.payload);
|
|
81
|
+
const signature = base64url_js_1.decode(jws.signature);
|
|
82
|
+
const verified = await verify_js_1.default(alg, key, signature, data);
|
|
83
83
|
if (!verified) {
|
|
84
84
|
throw new errors_js_1.JWSSignatureVerificationFailed();
|
|
85
85
|
}
|
|
86
86
|
let payload;
|
|
87
87
|
if (b64) {
|
|
88
|
-
payload =
|
|
88
|
+
payload = base64url_js_1.decode(jws.payload);
|
|
89
89
|
}
|
|
90
90
|
else if (typeof jws.payload === 'string') {
|
|
91
91
|
payload = buffer_utils_js_1.encoder.encode(jws.payload);
|
|
@@ -5,7 +5,7 @@ const verify_js_1 = require("../flattened/verify.js");
|
|
|
5
5
|
const errors_js_1 = require("../../util/errors.js");
|
|
6
6
|
const is_object_js_1 = require("../../lib/is_object.js");
|
|
7
7
|
async function generalVerify(jws, key, options) {
|
|
8
|
-
if (!
|
|
8
|
+
if (!is_object_js_1.default(jws)) {
|
|
9
9
|
throw new errors_js_1.JWSInvalid('General JWS must be an object');
|
|
10
10
|
}
|
|
11
11
|
if (!Array.isArray(jws.signatures) || !jws.signatures.every(is_object_js_1.default)) {
|
|
@@ -13,7 +13,7 @@ async function generalVerify(jws, key, options) {
|
|
|
13
13
|
}
|
|
14
14
|
for (const signature of jws.signatures) {
|
|
15
15
|
try {
|
|
16
|
-
return await
|
|
16
|
+
return await verify_js_1.default({
|
|
17
17
|
header: signature.header,
|
|
18
18
|
payload: jws.payload,
|
|
19
19
|
protected: signature.protected,
|
|
@@ -5,8 +5,8 @@ const decrypt_js_1 = require("../jwe/compact/decrypt.js");
|
|
|
5
5
|
const jwt_claims_set_js_1 = require("../lib/jwt_claims_set.js");
|
|
6
6
|
const errors_js_1 = require("../util/errors.js");
|
|
7
7
|
async function jwtDecrypt(jwt, key, options) {
|
|
8
|
-
const decrypted = await
|
|
9
|
-
const payload =
|
|
8
|
+
const decrypted = await decrypt_js_1.default(jwt, key, options);
|
|
9
|
+
const payload = jwt_claims_set_js_1.default(decrypted.protectedHeader, decrypted.plaintext, options);
|
|
10
10
|
const { protectedHeader } = decrypted;
|
|
11
11
|
if (protectedHeader.iss !== undefined && protectedHeader.iss !== payload.iss) {
|
|
12
12
|
throw new errors_js_1.JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', 'iss', 'mismatch');
|
|
@@ -6,7 +6,7 @@ const is_object_js_1 = require("../lib/is_object.js");
|
|
|
6
6
|
const secs_js_1 = require("../lib/secs.js");
|
|
7
7
|
class ProduceJWT {
|
|
8
8
|
constructor(payload) {
|
|
9
|
-
if (!
|
|
9
|
+
if (!is_object_js_1.default(payload)) {
|
|
10
10
|
throw new TypeError('JWT Claims Set MUST be an object');
|
|
11
11
|
}
|
|
12
12
|
this._payload = payload;
|
|
@@ -32,7 +32,7 @@ class ProduceJWT {
|
|
|
32
32
|
this._payload = { ...this._payload, nbf: input };
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
this._payload = { ...this._payload, nbf:
|
|
35
|
+
this._payload = { ...this._payload, nbf: epoch_js_1.default(new Date()) + secs_js_1.default(input) };
|
|
36
36
|
}
|
|
37
37
|
return this;
|
|
38
38
|
}
|
|
@@ -41,13 +41,13 @@ class ProduceJWT {
|
|
|
41
41
|
this._payload = { ...this._payload, exp: input };
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
this._payload = { ...this._payload, exp:
|
|
44
|
+
this._payload = { ...this._payload, exp: epoch_js_1.default(new Date()) + secs_js_1.default(input) };
|
|
45
45
|
}
|
|
46
46
|
return this;
|
|
47
47
|
}
|
|
48
48
|
setIssuedAt(input) {
|
|
49
49
|
if (typeof input === 'undefined') {
|
|
50
|
-
this._payload = { ...this._payload, iat:
|
|
50
|
+
this._payload = { ...this._payload, iat: epoch_js_1.default(new Date()) };
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
53
|
this._payload = { ...this._payload, iat: input };
|
|
@@ -29,7 +29,7 @@ class UnsecuredJWT extends produce_js_1.ProduceJWT {
|
|
|
29
29
|
catch {
|
|
30
30
|
throw new errors_js_1.JWTInvalid('Invalid Unsecured JWT');
|
|
31
31
|
}
|
|
32
|
-
const payload =
|
|
32
|
+
const payload = jwt_claims_set_js_1.default(header, base64url.decode(encodedPayload), options);
|
|
33
33
|
return { payload, header };
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -6,11 +6,11 @@ const jwt_claims_set_js_1 = require("../lib/jwt_claims_set.js");
|
|
|
6
6
|
const errors_js_1 = require("../util/errors.js");
|
|
7
7
|
async function jwtVerify(jwt, key, options) {
|
|
8
8
|
var _a;
|
|
9
|
-
const verified = await
|
|
9
|
+
const verified = await verify_js_1.default(jwt, key, options);
|
|
10
10
|
if (((_a = verified.protectedHeader.crit) === null || _a === void 0 ? void 0 : _a.includes('b64')) && verified.protectedHeader.b64 === false) {
|
|
11
11
|
throw new errors_js_1.JWTInvalid('JWTs MUST NOT use unencoded payload');
|
|
12
12
|
}
|
|
13
|
-
const payload =
|
|
13
|
+
const payload = jwt_claims_set_js_1.default(verified.protectedHeader, verified.payload, options);
|
|
14
14
|
const result = { payload, protectedHeader: verified.protectedHeader };
|
|
15
15
|
if (typeof key === 'function') {
|
|
16
16
|
return { ...result, key: verified.key };
|
|
@@ -5,14 +5,14 @@ const asn1_js_1 = require("../runtime/asn1.js");
|
|
|
5
5
|
const asn1_js_2 = require("../runtime/asn1.js");
|
|
6
6
|
const key_to_jwk_js_1 = require("../runtime/key_to_jwk.js");
|
|
7
7
|
async function exportSPKI(key) {
|
|
8
|
-
return
|
|
8
|
+
return asn1_js_1.toSPKI(key);
|
|
9
9
|
}
|
|
10
10
|
exports.exportSPKI = exportSPKI;
|
|
11
11
|
async function exportPKCS8(key) {
|
|
12
|
-
return
|
|
12
|
+
return asn1_js_2.toPKCS8(key);
|
|
13
13
|
}
|
|
14
14
|
exports.exportPKCS8 = exportPKCS8;
|
|
15
15
|
async function exportJWK(key) {
|
|
16
|
-
return
|
|
16
|
+
return key_to_jwk_js_1.default(key);
|
|
17
17
|
}
|
|
18
18
|
exports.exportJWK = exportJWK;
|
|
@@ -65,18 +65,18 @@ function parseElement(bytes) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
function spkiFromX509(buf) {
|
|
68
|
-
return
|
|
68
|
+
return base64url_js_1.encodeBase64(getElement(getElement(parseElement(buf).contents)[0].contents)[6].raw);
|
|
69
69
|
}
|
|
70
70
|
function getSPKI(x509) {
|
|
71
71
|
const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, '');
|
|
72
|
-
const raw =
|
|
73
|
-
return
|
|
72
|
+
const raw = base64url_js_1.decodeBase64(pem);
|
|
73
|
+
return format_pem_js_1.default(spkiFromX509(raw), 'PUBLIC KEY');
|
|
74
74
|
}
|
|
75
75
|
async function importSPKI(spki, alg, options) {
|
|
76
76
|
if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {
|
|
77
77
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
78
78
|
}
|
|
79
|
-
return
|
|
79
|
+
return asn1_js_1.fromSPKI(spki, alg, options);
|
|
80
80
|
}
|
|
81
81
|
exports.importSPKI = importSPKI;
|
|
82
82
|
async function importX509(x509, alg, options) {
|
|
@@ -84,18 +84,18 @@ async function importX509(x509, alg, options) {
|
|
|
84
84
|
throw new TypeError('"x509" must be X.509 formatted string');
|
|
85
85
|
}
|
|
86
86
|
const spki = getSPKI(x509);
|
|
87
|
-
return
|
|
87
|
+
return asn1_js_1.fromSPKI(spki, alg, options);
|
|
88
88
|
}
|
|
89
89
|
exports.importX509 = importX509;
|
|
90
90
|
async function importPKCS8(pkcs8, alg, options) {
|
|
91
91
|
if (typeof pkcs8 !== 'string' || pkcs8.indexOf('-----BEGIN PRIVATE KEY-----') !== 0) {
|
|
92
92
|
throw new TypeError('"pkcs8" must be PCKS8 formatted string');
|
|
93
93
|
}
|
|
94
|
-
return
|
|
94
|
+
return asn1_js_2.fromPKCS8(pkcs8, alg, options);
|
|
95
95
|
}
|
|
96
96
|
exports.importPKCS8 = importPKCS8;
|
|
97
97
|
async function importJWK(jwk, alg, octAsKeyObject) {
|
|
98
|
-
if (!
|
|
98
|
+
if (!is_object_js_1.default(jwk)) {
|
|
99
99
|
throw new TypeError('JWK must be an object');
|
|
100
100
|
}
|
|
101
101
|
alg || (alg = jwk.alg);
|
|
@@ -109,16 +109,16 @@ async function importJWK(jwk, alg, octAsKeyObject) {
|
|
|
109
109
|
}
|
|
110
110
|
octAsKeyObject !== null && octAsKeyObject !== void 0 ? octAsKeyObject : (octAsKeyObject = jwk.ext !== true);
|
|
111
111
|
if (octAsKeyObject) {
|
|
112
|
-
return
|
|
112
|
+
return jwk_to_key_js_1.default({ ...jwk, alg, ext: false });
|
|
113
113
|
}
|
|
114
|
-
return
|
|
114
|
+
return base64url_js_1.decode(jwk.k);
|
|
115
115
|
case 'RSA':
|
|
116
116
|
if (jwk.oth !== undefined) {
|
|
117
117
|
throw new errors_js_1.JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
118
118
|
}
|
|
119
119
|
case 'EC':
|
|
120
120
|
case 'OKP':
|
|
121
|
-
return
|
|
121
|
+
return jwk_to_key_js_1.default({ ...jwk, alg });
|
|
122
122
|
default:
|
|
123
123
|
throw new errors_js_1.JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
124
124
|
}
|
package/dist/node/cjs/lib/cek.js
CHANGED
|
@@ -17,6 +17,6 @@ const generateCek = (alg) => {
|
|
|
17
17
|
if (!bitLength) {
|
|
18
18
|
throw new errors_js_1.JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return random_js_1.default(new Uint8Array(bitLength >> 3));
|
|
21
21
|
};
|
|
22
22
|
exports.default = generateCek;
|