jose 5.2.1 → 5.2.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/compact/decrypt.js +3 -3
- package/dist/browser/jwe/flattened/decrypt.js +18 -14
- package/dist/browser/jwks/remote.js +1 -1
- package/dist/browser/runtime/decrypt.js +7 -1
- package/dist/node/cjs/jwe/compact/decrypt.js +3 -3
- package/dist/node/cjs/jwe/flattened/decrypt.js +18 -14
- package/dist/node/cjs/jwks/remote.js +1 -1
- package/dist/node/cjs/runtime/decrypt.js +6 -0
- package/dist/node/esm/jwe/compact/decrypt.js +3 -3
- package/dist/node/esm/jwe/flattened/decrypt.js +18 -14
- package/dist/node/esm/jwks/remote.js +1 -1
- package/dist/node/esm/runtime/decrypt.js +7 -1
- package/dist/types/key/import.d.ts +17 -4
- package/dist/types/types.d.ts +2 -2
- package/package.json +1 -1
|
@@ -14,9 +14,9 @@ export async function compactDecrypt(jwe, key, options) {
|
|
|
14
14
|
}
|
|
15
15
|
const decrypted = await flattenedDecrypt({
|
|
16
16
|
ciphertext,
|
|
17
|
-
iv:
|
|
18
|
-
protected: protectedHeader
|
|
19
|
-
tag:
|
|
17
|
+
iv: iv || undefined,
|
|
18
|
+
protected: protectedHeader,
|
|
19
|
+
tag: tag || undefined,
|
|
20
20
|
encrypted_key: encryptedKey || undefined,
|
|
21
21
|
}, key, options);
|
|
22
22
|
const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
|
|
@@ -15,14 +15,14 @@ export async function flattenedDecrypt(jwe, key, options) {
|
|
|
15
15
|
if (jwe.protected === undefined && jwe.header === undefined && jwe.unprotected === undefined) {
|
|
16
16
|
throw new JWEInvalid('JOSE Header missing');
|
|
17
17
|
}
|
|
18
|
-
if (typeof jwe.iv !== 'string') {
|
|
19
|
-
throw new JWEInvalid('JWE Initialization Vector
|
|
18
|
+
if (jwe.iv !== undefined && typeof jwe.iv !== 'string') {
|
|
19
|
+
throw new JWEInvalid('JWE Initialization Vector incorrect type');
|
|
20
20
|
}
|
|
21
21
|
if (typeof jwe.ciphertext !== 'string') {
|
|
22
22
|
throw new JWEInvalid('JWE Ciphertext missing or incorrect type');
|
|
23
23
|
}
|
|
24
|
-
if (typeof jwe.tag !== 'string') {
|
|
25
|
-
throw new JWEInvalid('JWE Authentication Tag
|
|
24
|
+
if (jwe.tag !== undefined && typeof jwe.tag !== 'string') {
|
|
25
|
+
throw new JWEInvalid('JWE Authentication Tag incorrect type');
|
|
26
26
|
}
|
|
27
27
|
if (jwe.protected !== undefined && typeof jwe.protected !== 'string') {
|
|
28
28
|
throw new JWEInvalid('JWE Protected Header incorrect type');
|
|
@@ -104,17 +104,21 @@ export async function flattenedDecrypt(jwe, key, options) {
|
|
|
104
104
|
}
|
|
105
105
|
let iv;
|
|
106
106
|
let tag;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
tag = base64url(jwe.tag);
|
|
107
|
+
if (jwe.iv !== undefined) {
|
|
108
|
+
try {
|
|
109
|
+
iv = base64url(jwe.iv);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
throw new JWEInvalid('Failed to base64url decode the iv');
|
|
113
|
+
}
|
|
115
114
|
}
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
if (jwe.tag !== undefined) {
|
|
116
|
+
try {
|
|
117
|
+
tag = base64url(jwe.tag);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
throw new JWEInvalid('Failed to base64url decode the tag');
|
|
121
|
+
}
|
|
118
122
|
}
|
|
119
123
|
const protectedHeader = encoder.encode(jwe.protected ?? '');
|
|
120
124
|
let additionalData;
|
|
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
|
|
|
9
9
|
let USER_AGENT;
|
|
10
10
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
11
11
|
const NAME = 'jose';
|
|
12
|
-
const VERSION = 'v5.2.
|
|
12
|
+
const VERSION = 'v5.2.2';
|
|
13
13
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
14
|
}
|
|
15
15
|
class RemoteJWKSet extends LocalJWKSet {
|
|
@@ -2,7 +2,7 @@ import { concat, uint64be } from '../lib/buffer_utils.js';
|
|
|
2
2
|
import checkIvLength from '../lib/check_iv_length.js';
|
|
3
3
|
import checkCekLength from './check_cek_length.js';
|
|
4
4
|
import timingSafeEqual from './timing_safe_equal.js';
|
|
5
|
-
import { JOSENotSupported, JWEDecryptionFailed } from '../util/errors.js';
|
|
5
|
+
import { JOSENotSupported, JWEDecryptionFailed, JWEInvalid } from '../util/errors.js';
|
|
6
6
|
import crypto, { isCryptoKey } from './webcrypto.js';
|
|
7
7
|
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
8
8
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
@@ -64,6 +64,12 @@ const decrypt = async (enc, cek, ciphertext, iv, tag, aad) => {
|
|
|
64
64
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
65
65
|
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array'));
|
|
66
66
|
}
|
|
67
|
+
if (!iv) {
|
|
68
|
+
throw new JWEInvalid('JWE Initialization Vector missing');
|
|
69
|
+
}
|
|
70
|
+
if (!tag) {
|
|
71
|
+
throw new JWEInvalid('JWE Authentication Tag missing');
|
|
72
|
+
}
|
|
67
73
|
checkIvLength(enc, iv);
|
|
68
74
|
switch (enc) {
|
|
69
75
|
case 'A128CBC-HS256':
|
|
@@ -17,9 +17,9 @@ async function compactDecrypt(jwe, key, options) {
|
|
|
17
17
|
}
|
|
18
18
|
const decrypted = await (0, decrypt_js_1.flattenedDecrypt)({
|
|
19
19
|
ciphertext,
|
|
20
|
-
iv:
|
|
21
|
-
protected: protectedHeader
|
|
22
|
-
tag:
|
|
20
|
+
iv: iv || undefined,
|
|
21
|
+
protected: protectedHeader,
|
|
22
|
+
tag: tag || undefined,
|
|
23
23
|
encrypted_key: encryptedKey || undefined,
|
|
24
24
|
}, key, options);
|
|
25
25
|
const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
|
|
@@ -18,14 +18,14 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
18
18
|
if (jwe.protected === undefined && jwe.header === undefined && jwe.unprotected === undefined) {
|
|
19
19
|
throw new errors_js_1.JWEInvalid('JOSE Header missing');
|
|
20
20
|
}
|
|
21
|
-
if (typeof jwe.iv !== 'string') {
|
|
22
|
-
throw new errors_js_1.JWEInvalid('JWE Initialization Vector
|
|
21
|
+
if (jwe.iv !== undefined && typeof jwe.iv !== 'string') {
|
|
22
|
+
throw new errors_js_1.JWEInvalid('JWE Initialization Vector incorrect type');
|
|
23
23
|
}
|
|
24
24
|
if (typeof jwe.ciphertext !== 'string') {
|
|
25
25
|
throw new errors_js_1.JWEInvalid('JWE Ciphertext missing or incorrect type');
|
|
26
26
|
}
|
|
27
|
-
if (typeof jwe.tag !== 'string') {
|
|
28
|
-
throw new errors_js_1.JWEInvalid('JWE Authentication Tag
|
|
27
|
+
if (jwe.tag !== undefined && typeof jwe.tag !== 'string') {
|
|
28
|
+
throw new errors_js_1.JWEInvalid('JWE Authentication Tag incorrect type');
|
|
29
29
|
}
|
|
30
30
|
if (jwe.protected !== undefined && typeof jwe.protected !== 'string') {
|
|
31
31
|
throw new errors_js_1.JWEInvalid('JWE Protected Header incorrect type');
|
|
@@ -107,17 +107,21 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
107
107
|
}
|
|
108
108
|
let iv;
|
|
109
109
|
let tag;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
tag = (0, base64url_js_1.decode)(jwe.tag);
|
|
110
|
+
if (jwe.iv !== undefined) {
|
|
111
|
+
try {
|
|
112
|
+
iv = (0, base64url_js_1.decode)(jwe.iv);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
throw new errors_js_1.JWEInvalid('Failed to base64url decode the iv');
|
|
116
|
+
}
|
|
118
117
|
}
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
if (jwe.tag !== undefined) {
|
|
119
|
+
try {
|
|
120
|
+
tag = (0, base64url_js_1.decode)(jwe.tag);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
throw new errors_js_1.JWEInvalid('Failed to base64url decode the tag');
|
|
124
|
+
}
|
|
121
125
|
}
|
|
122
126
|
const protectedHeader = buffer_utils_js_1.encoder.encode(jwe.protected ?? '');
|
|
123
127
|
let additionalData;
|
|
@@ -12,7 +12,7 @@ function isCloudflareWorkers() {
|
|
|
12
12
|
let USER_AGENT;
|
|
13
13
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
14
14
|
const NAME = 'jose';
|
|
15
|
-
const VERSION = 'v5.2.
|
|
15
|
+
const VERSION = 'v5.2.2';
|
|
16
16
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
17
17
|
}
|
|
18
18
|
class RemoteJWKSet extends local_js_1.LocalJWKSet {
|
|
@@ -79,6 +79,12 @@ const decrypt = (enc, cek, ciphertext, iv, tag, aad) => {
|
|
|
79
79
|
else {
|
|
80
80
|
throw new TypeError((0, invalid_key_input_js_1.default)(cek, ...is_key_like_js_1.types, 'Uint8Array'));
|
|
81
81
|
}
|
|
82
|
+
if (!iv) {
|
|
83
|
+
throw new errors_js_1.JWEInvalid('JWE Initialization Vector missing');
|
|
84
|
+
}
|
|
85
|
+
if (!tag) {
|
|
86
|
+
throw new errors_js_1.JWEInvalid('JWE Authentication Tag missing');
|
|
87
|
+
}
|
|
82
88
|
(0, check_cek_length_js_1.default)(enc, key);
|
|
83
89
|
(0, check_iv_length_js_1.default)(enc, iv);
|
|
84
90
|
switch (enc) {
|
|
@@ -14,9 +14,9 @@ export async function compactDecrypt(jwe, key, options) {
|
|
|
14
14
|
}
|
|
15
15
|
const decrypted = await flattenedDecrypt({
|
|
16
16
|
ciphertext,
|
|
17
|
-
iv:
|
|
18
|
-
protected: protectedHeader
|
|
19
|
-
tag:
|
|
17
|
+
iv: iv || undefined,
|
|
18
|
+
protected: protectedHeader,
|
|
19
|
+
tag: tag || undefined,
|
|
20
20
|
encrypted_key: encryptedKey || undefined,
|
|
21
21
|
}, key, options);
|
|
22
22
|
const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
|
|
@@ -15,14 +15,14 @@ export async function flattenedDecrypt(jwe, key, options) {
|
|
|
15
15
|
if (jwe.protected === undefined && jwe.header === undefined && jwe.unprotected === undefined) {
|
|
16
16
|
throw new JWEInvalid('JOSE Header missing');
|
|
17
17
|
}
|
|
18
|
-
if (typeof jwe.iv !== 'string') {
|
|
19
|
-
throw new JWEInvalid('JWE Initialization Vector
|
|
18
|
+
if (jwe.iv !== undefined && typeof jwe.iv !== 'string') {
|
|
19
|
+
throw new JWEInvalid('JWE Initialization Vector incorrect type');
|
|
20
20
|
}
|
|
21
21
|
if (typeof jwe.ciphertext !== 'string') {
|
|
22
22
|
throw new JWEInvalid('JWE Ciphertext missing or incorrect type');
|
|
23
23
|
}
|
|
24
|
-
if (typeof jwe.tag !== 'string') {
|
|
25
|
-
throw new JWEInvalid('JWE Authentication Tag
|
|
24
|
+
if (jwe.tag !== undefined && typeof jwe.tag !== 'string') {
|
|
25
|
+
throw new JWEInvalid('JWE Authentication Tag incorrect type');
|
|
26
26
|
}
|
|
27
27
|
if (jwe.protected !== undefined && typeof jwe.protected !== 'string') {
|
|
28
28
|
throw new JWEInvalid('JWE Protected Header incorrect type');
|
|
@@ -104,17 +104,21 @@ export async function flattenedDecrypt(jwe, key, options) {
|
|
|
104
104
|
}
|
|
105
105
|
let iv;
|
|
106
106
|
let tag;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
tag = base64url(jwe.tag);
|
|
107
|
+
if (jwe.iv !== undefined) {
|
|
108
|
+
try {
|
|
109
|
+
iv = base64url(jwe.iv);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
throw new JWEInvalid('Failed to base64url decode the iv');
|
|
113
|
+
}
|
|
115
114
|
}
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
if (jwe.tag !== undefined) {
|
|
116
|
+
try {
|
|
117
|
+
tag = base64url(jwe.tag);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
throw new JWEInvalid('Failed to base64url decode the tag');
|
|
121
|
+
}
|
|
118
122
|
}
|
|
119
123
|
const protectedHeader = encoder.encode(jwe.protected ?? '');
|
|
120
124
|
let additionalData;
|
|
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
|
|
|
9
9
|
let USER_AGENT;
|
|
10
10
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
11
11
|
const NAME = 'jose';
|
|
12
|
-
const VERSION = 'v5.2.
|
|
12
|
+
const VERSION = 'v5.2.2';
|
|
13
13
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
14
|
}
|
|
15
15
|
class RemoteJWKSet extends LocalJWKSet {
|
|
@@ -2,7 +2,7 @@ import { createDecipheriv, KeyObject } from 'node:crypto';
|
|
|
2
2
|
import checkIvLength from '../lib/check_iv_length.js';
|
|
3
3
|
import checkCekLength from './check_cek_length.js';
|
|
4
4
|
import { concat } from '../lib/buffer_utils.js';
|
|
5
|
-
import { JOSENotSupported, JWEDecryptionFailed } from '../util/errors.js';
|
|
5
|
+
import { JOSENotSupported, JWEDecryptionFailed, JWEInvalid } from '../util/errors.js';
|
|
6
6
|
import timingSafeEqual from './timing_safe_equal.js';
|
|
7
7
|
import cbcTag from './cbc_tag.js';
|
|
8
8
|
import { isCryptoKey } from './webcrypto.js';
|
|
@@ -77,6 +77,12 @@ const decrypt = (enc, cek, ciphertext, iv, tag, aad) => {
|
|
|
77
77
|
else {
|
|
78
78
|
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array'));
|
|
79
79
|
}
|
|
80
|
+
if (!iv) {
|
|
81
|
+
throw new JWEInvalid('JWE Initialization Vector missing');
|
|
82
|
+
}
|
|
83
|
+
if (!tag) {
|
|
84
|
+
throw new JWEInvalid('JWE Authentication Tag missing');
|
|
85
|
+
}
|
|
80
86
|
checkCekLength(enc, key);
|
|
81
87
|
checkIvLength(enc, iv);
|
|
82
88
|
switch (enc) {
|
|
@@ -11,6 +11,10 @@ export interface PEMImportOptions {
|
|
|
11
11
|
* Imports a PEM-encoded SPKI string as a runtime-specific public key representation (KeyObject or
|
|
12
12
|
* CryptoKey).
|
|
13
13
|
*
|
|
14
|
+
* Note: The OID id-RSASSA-PSS (1.2.840.113549.1.1.10) is not supported in
|
|
15
|
+
* {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
|
|
16
|
+
* (1.2.840.113549.1.1.1) instead for all RSA algorithms.
|
|
17
|
+
*
|
|
14
18
|
* @param spki PEM-encoded SPKI string
|
|
15
19
|
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
|
|
16
20
|
* with the imported key, its presence is only enforced in Web Crypto API runtimes. See
|
|
@@ -21,6 +25,10 @@ export declare function importSPKI<KeyLikeType extends KeyLike = KeyLike>(spki:
|
|
|
21
25
|
* Imports the SPKI from an X.509 string certificate as a runtime-specific public key representation
|
|
22
26
|
* (KeyObject or CryptoKey).
|
|
23
27
|
*
|
|
28
|
+
* Note: The OID id-RSASSA-PSS (1.2.840.113549.1.1.10) is not supported in
|
|
29
|
+
* {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
|
|
30
|
+
* (1.2.840.113549.1.1.1) instead for all RSA algorithms.
|
|
31
|
+
*
|
|
24
32
|
* @param x509 X.509 certificate string
|
|
25
33
|
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
|
|
26
34
|
* with the imported key, its presence is only enforced in Web Crypto API runtimes. See
|
|
@@ -31,6 +39,10 @@ export declare function importX509<KeyLikeType extends KeyLike = KeyLike>(x509:
|
|
|
31
39
|
* Imports a PEM-encoded PKCS#8 string as a runtime-specific private key representation (KeyObject
|
|
32
40
|
* or CryptoKey).
|
|
33
41
|
*
|
|
42
|
+
* Note: The OID id-RSASSA-PSS (1.2.840.113549.1.1.10) is not supported in
|
|
43
|
+
* {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
|
|
44
|
+
* (1.2.840.113549.1.1.1) instead for all RSA algorithms.
|
|
45
|
+
*
|
|
34
46
|
* @param pkcs8 PEM-encoded PKCS#8 string
|
|
35
47
|
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
|
|
36
48
|
* with the imported key, its presence is only enforced in Web Crypto API runtimes. See
|
|
@@ -38,10 +50,11 @@ export declare function importX509<KeyLikeType extends KeyLike = KeyLike>(x509:
|
|
|
38
50
|
*/
|
|
39
51
|
export declare function importPKCS8<KeyLikeType extends KeyLike = KeyLike>(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<KeyLikeType>;
|
|
40
52
|
/**
|
|
41
|
-
* Imports a JWK to a runtime-specific key representation (KeyLike). Either JWK "alg"
|
|
42
|
-
* Parameter
|
|
43
|
-
*
|
|
44
|
-
*
|
|
53
|
+
* Imports a JWK to a runtime-specific key representation (KeyLike). Either the JWK "alg"
|
|
54
|
+
* (Algorithm) Parameter, or the optional "alg" argument, must be present.
|
|
55
|
+
*
|
|
56
|
+
* Note: When the runtime is using {@link https://w3c.github.io/webcrypto/ Web Cryptography API} the
|
|
57
|
+
* jwk parameters "use", "key_ops", and "ext" are also used in the resulting `CryptoKey`.
|
|
45
58
|
*
|
|
46
59
|
* @param jwk JSON Web Key.
|
|
47
60
|
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
|
package/dist/types/types.d.ts
CHANGED
|
@@ -264,7 +264,7 @@ export interface FlattenedJWE {
|
|
|
264
264
|
* The "iv" member MUST be present and contain the value BASE64URL(JWE Initialization Vector) when
|
|
265
265
|
* the JWE Initialization Vector value is non-empty; otherwise, it MUST be absent.
|
|
266
266
|
*/
|
|
267
|
-
iv
|
|
267
|
+
iv?: string
|
|
268
268
|
|
|
269
269
|
/**
|
|
270
270
|
* The "protected" member MUST be present and contain the value BASE64URL(UTF8(JWE Protected
|
|
@@ -277,7 +277,7 @@ export interface FlattenedJWE {
|
|
|
277
277
|
* The "tag" member MUST be present and contain the value BASE64URL(JWE Authentication Tag) when
|
|
278
278
|
* the JWE Authentication Tag value is non-empty; otherwise, it MUST be absent.
|
|
279
279
|
*/
|
|
280
|
-
tag
|
|
280
|
+
tag?: string
|
|
281
281
|
|
|
282
282
|
/**
|
|
283
283
|
* The "unprotected" member MUST be present and contain the value JWE Shared Unprotected Header
|