jose 4.9.1 → 4.9.2
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/flattened/decrypt.js +2 -2
- package/dist/node/cjs/lib/decrypt_key_management.js +4 -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 +7 -0
- package/package.json +1 -1
|
@@ -95,10 +95,10 @@ export 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 { importJWK } from '../key/import.js';
|
|
|
9
9
|
import checkKeyType from './check_key_type.js';
|
|
10
10
|
import isObject from './is_object.js';
|
|
11
11
|
import { unwrap as aesGcmKw } from './aesgcmkw.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));
|
|
@@ -98,10 +98,10 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
98
98
|
}
|
|
99
99
|
let cek;
|
|
100
100
|
try {
|
|
101
|
-
cek = await (0, decrypt_key_management_js_1.default)(alg, key, encryptedKey, joseHeader);
|
|
101
|
+
cek = await (0, 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
107
|
cek = (0, cek_js_1.default)(enc);
|
|
@@ -11,7 +11,7 @@ const import_js_1 = require("../key/import.js");
|
|
|
11
11
|
const check_key_type_js_1 = require("./check_key_type.js");
|
|
12
12
|
const is_object_js_1 = require("./is_object.js");
|
|
13
13
|
const aesgcmkw_js_1 = require("./aesgcmkw.js");
|
|
14
|
-
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
|
|
14
|
+
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
15
15
|
(0, check_key_type_js_1.default)(alg, key, 'decrypt');
|
|
16
16
|
switch (alg) {
|
|
17
17
|
case 'dir': {
|
|
@@ -65,6 +65,9 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
|
|
|
65
65
|
throw new errors_js_1.JWEInvalid('JWE Encrypted Key missing');
|
|
66
66
|
if (typeof joseHeader.p2c !== 'number')
|
|
67
67
|
throw new errors_js_1.JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
68
|
+
const p2cLimit = (options === null || options === void 0 ? void 0 : options.maxPBES2Count) || 10000;
|
|
69
|
+
if (joseHeader.p2c > p2cLimit)
|
|
70
|
+
throw new errors_js_1.JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
68
71
|
if (typeof joseHeader.p2s !== 'string')
|
|
69
72
|
throw new errors_js_1.JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
70
73
|
return (0, pbes2kw_js_1.decrypt)(alg, key, encryptedKey, joseHeader.p2c, (0, base64url_js_1.decode)(joseHeader.p2s));
|
|
@@ -95,10 +95,10 @@ export 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 { importJWK } from '../key/import.js';
|
|
|
9
9
|
import checkKeyType from './check_key_type.js';
|
|
10
10
|
import isObject from './is_object.js';
|
|
11
11
|
import { unwrap as aesGcmKw } from './aesgcmkw.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));
|
package/dist/types/types.d.ts
CHANGED
|
@@ -401,6 +401,13 @@ export interface DecryptOptions extends CritOption {
|
|
|
401
401
|
* with compressed plaintext.
|
|
402
402
|
*/
|
|
403
403
|
inflateRaw?: InflateFunction
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* (PBES2 Key Management Algorithms only) Maximum allowed "p2c" (PBES2 Count) Header Parameter
|
|
407
|
+
* value. The PBKDF2 iteration count defines the algorithm's computational expense. By default
|
|
408
|
+
* this value is set to 10000.
|
|
409
|
+
*/
|
|
410
|
+
maxPBES2Count?: number
|
|
404
411
|
}
|
|
405
412
|
|
|
406
413
|
/** JWE Deflate option. */
|