jose 5.5.0 → 5.6.1
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/jwks/remote.js +1 -1
- package/dist/browser/lib/check_key_type.js +7 -6
- package/dist/browser/lib/decrypt_key_management.js +2 -0
- package/dist/browser/lib/encrypt_key_management.js +2 -0
- package/dist/browser/runtime/get_sign_verify_key.js +8 -1
- package/dist/browser/runtime/is_key_like.js +4 -1
- package/dist/browser/runtime/normalize_key.js +30 -0
- package/dist/node/cjs/jwks/remote.js +1 -1
- package/dist/node/cjs/lib/check_key_type.js +7 -6
- package/dist/node/cjs/lib/decrypt_key_management.js +2 -0
- package/dist/node/cjs/lib/encrypt_key_management.js +2 -0
- package/dist/node/cjs/runtime/normalize_key.js +3 -0
- package/dist/node/esm/jwks/remote.js +1 -1
- package/dist/node/esm/lib/check_key_type.js +7 -6
- package/dist/node/esm/lib/decrypt_key_management.js +2 -0
- package/dist/node/esm/lib/encrypt_key_management.js +2 -0
- package/dist/node/esm/runtime/normalize_key.js +1 -0
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ function isCloudflareWorkers() {
|
|
|
10
10
|
let USER_AGENT;
|
|
11
11
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
12
12
|
const NAME = 'jose';
|
|
13
|
-
const VERSION = 'v5.
|
|
13
|
+
const VERSION = 'v5.6.1';
|
|
14
14
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
15
15
|
}
|
|
16
16
|
export const experimental_jwksCache = Symbol();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { withAlg as invalidKeyInput } from './invalid_key_input.js';
|
|
2
2
|
import isKeyLike, { types } from '../runtime/is_key_like.js';
|
|
3
|
+
const tag = (key) => key?.[Symbol.toStringTag];
|
|
3
4
|
const symmetricTypeCheck = (alg, key) => {
|
|
4
5
|
if (key instanceof Uint8Array)
|
|
5
6
|
return;
|
|
@@ -7,7 +8,7 @@ const symmetricTypeCheck = (alg, key) => {
|
|
|
7
8
|
throw new TypeError(invalidKeyInput(alg, key, ...types, 'Uint8Array'));
|
|
8
9
|
}
|
|
9
10
|
if (key.type !== 'secret') {
|
|
10
|
-
throw new TypeError(`${
|
|
11
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
11
12
|
}
|
|
12
13
|
};
|
|
13
14
|
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
@@ -15,19 +16,19 @@ const asymmetricTypeCheck = (alg, key, usage) => {
|
|
|
15
16
|
throw new TypeError(invalidKeyInput(alg, key, ...types));
|
|
16
17
|
}
|
|
17
18
|
if (key.type === 'secret') {
|
|
18
|
-
throw new TypeError(`${
|
|
19
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
19
20
|
}
|
|
20
21
|
if (usage === 'sign' && key.type === 'public') {
|
|
21
|
-
throw new TypeError(`${
|
|
22
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
22
23
|
}
|
|
23
24
|
if (usage === 'decrypt' && key.type === 'public') {
|
|
24
|
-
throw new TypeError(`${
|
|
25
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
25
26
|
}
|
|
26
27
|
if (key.algorithm && usage === 'verify' && key.type === 'private') {
|
|
27
|
-
throw new TypeError(`${
|
|
28
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
28
29
|
}
|
|
29
30
|
if (key.algorithm && usage === 'encrypt' && key.type === 'private') {
|
|
30
|
-
throw new TypeError(`${
|
|
31
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
34
|
const checkKeyType = (alg, key, usage) => {
|
|
@@ -3,6 +3,7 @@ import * as ECDH from '../runtime/ecdhes.js';
|
|
|
3
3
|
import { decrypt as pbes2Kw } from '../runtime/pbes2kw.js';
|
|
4
4
|
import { decrypt as rsaEs } from '../runtime/rsaes.js';
|
|
5
5
|
import { decode as base64url } from '../runtime/base64url.js';
|
|
6
|
+
import normalize from '../runtime/normalize_key.js';
|
|
6
7
|
import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
|
|
7
8
|
import { bitLength as cekLength } from '../lib/cek.js';
|
|
8
9
|
import { importJWK } from '../key/import.js';
|
|
@@ -10,6 +11,7 @@ import checkKeyType from './check_key_type.js';
|
|
|
10
11
|
import isObject from './is_object.js';
|
|
11
12
|
import { unwrap as aesGcmKw } from './aesgcmkw.js';
|
|
12
13
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
14
|
+
key = (await normalize.normalizePrivateKey?.(key, alg)) || key;
|
|
13
15
|
checkKeyType(alg, key, 'decrypt');
|
|
14
16
|
switch (alg) {
|
|
15
17
|
case 'dir': {
|
|
@@ -3,6 +3,7 @@ import * as ECDH from '../runtime/ecdhes.js';
|
|
|
3
3
|
import { encrypt as pbes2Kw } from '../runtime/pbes2kw.js';
|
|
4
4
|
import { encrypt as rsaEs } from '../runtime/rsaes.js';
|
|
5
5
|
import { encode as base64url } from '../runtime/base64url.js';
|
|
6
|
+
import normalize from '../runtime/normalize_key.js';
|
|
6
7
|
import generateCek, { bitLength as cekLength } from '../lib/cek.js';
|
|
7
8
|
import { JOSENotSupported } from '../util/errors.js';
|
|
8
9
|
import { exportJWK } from '../key/export.js';
|
|
@@ -12,6 +13,7 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
12
13
|
let encryptedKey;
|
|
13
14
|
let parameters;
|
|
14
15
|
let cek;
|
|
16
|
+
key = (await normalize.normalizePublicKey?.(key, alg)) || key;
|
|
15
17
|
checkKeyType(alg, key, 'encrypt');
|
|
16
18
|
switch (alg) {
|
|
17
19
|
case 'dir': {
|
|
@@ -2,7 +2,14 @@ import crypto, { isCryptoKey } from './webcrypto.js';
|
|
|
2
2
|
import { checkSigCryptoKey } from '../lib/crypto_key.js';
|
|
3
3
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
4
4
|
import { types } from './is_key_like.js';
|
|
5
|
-
|
|
5
|
+
import normalize from './normalize_key.js';
|
|
6
|
+
export default async function getCryptoKey(alg, key, usage) {
|
|
7
|
+
if (usage === 'sign') {
|
|
8
|
+
key = await normalize.normalizePrivateKey(key, alg);
|
|
9
|
+
}
|
|
10
|
+
if (usage === 'verify') {
|
|
11
|
+
key = await normalize.normalizePublicKey(key, alg);
|
|
12
|
+
}
|
|
6
13
|
if (isCryptoKey(key)) {
|
|
7
14
|
checkSigCryptoKey(key, alg, usage);
|
|
8
15
|
return key;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { decode } from './base64url.js';
|
|
2
|
+
import importJWK from './jwk_to_key.js';
|
|
3
|
+
const normalizeSecretKey = (k) => decode(k);
|
|
4
|
+
const normalizePublicKey = async (key, alg) => {
|
|
5
|
+
if (key?.[Symbol.toStringTag] === 'KeyObject') {
|
|
6
|
+
let jwk = key.export({ format: 'jwk' });
|
|
7
|
+
delete jwk.d;
|
|
8
|
+
delete jwk.dp;
|
|
9
|
+
delete jwk.dq;
|
|
10
|
+
delete jwk.p;
|
|
11
|
+
delete jwk.q;
|
|
12
|
+
delete jwk.qi;
|
|
13
|
+
if (jwk.k) {
|
|
14
|
+
return normalizeSecretKey(jwk.k);
|
|
15
|
+
}
|
|
16
|
+
return importJWK({ ...jwk, alg });
|
|
17
|
+
}
|
|
18
|
+
return key;
|
|
19
|
+
};
|
|
20
|
+
const normalizePrivateKey = async (key, alg) => {
|
|
21
|
+
if (key?.[Symbol.toStringTag] === 'KeyObject') {
|
|
22
|
+
let jwk = key.export({ format: 'jwk' });
|
|
23
|
+
if (jwk.k) {
|
|
24
|
+
return normalizeSecretKey(jwk.k);
|
|
25
|
+
}
|
|
26
|
+
return importJWK({ ...jwk, alg });
|
|
27
|
+
}
|
|
28
|
+
return key;
|
|
29
|
+
};
|
|
30
|
+
export default { normalizePublicKey, normalizePrivateKey };
|
|
@@ -13,7 +13,7 @@ function isCloudflareWorkers() {
|
|
|
13
13
|
let USER_AGENT;
|
|
14
14
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
15
15
|
const NAME = 'jose';
|
|
16
|
-
const VERSION = 'v5.
|
|
16
|
+
const VERSION = 'v5.6.1';
|
|
17
17
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
18
18
|
}
|
|
19
19
|
exports.experimental_jwksCache = Symbol();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const invalid_key_input_js_1 = require("./invalid_key_input.js");
|
|
4
4
|
const is_key_like_js_1 = require("../runtime/is_key_like.js");
|
|
5
|
+
const tag = (key) => key?.[Symbol.toStringTag];
|
|
5
6
|
const symmetricTypeCheck = (alg, key) => {
|
|
6
7
|
if (key instanceof Uint8Array)
|
|
7
8
|
return;
|
|
@@ -9,7 +10,7 @@ const symmetricTypeCheck = (alg, key) => {
|
|
|
9
10
|
throw new TypeError((0, invalid_key_input_js_1.withAlg)(alg, key, ...is_key_like_js_1.types, 'Uint8Array'));
|
|
10
11
|
}
|
|
11
12
|
if (key.type !== 'secret') {
|
|
12
|
-
throw new TypeError(`${
|
|
13
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
13
14
|
}
|
|
14
15
|
};
|
|
15
16
|
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
@@ -17,19 +18,19 @@ const asymmetricTypeCheck = (alg, key, usage) => {
|
|
|
17
18
|
throw new TypeError((0, invalid_key_input_js_1.withAlg)(alg, key, ...is_key_like_js_1.types));
|
|
18
19
|
}
|
|
19
20
|
if (key.type === 'secret') {
|
|
20
|
-
throw new TypeError(`${
|
|
21
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
21
22
|
}
|
|
22
23
|
if (usage === 'sign' && key.type === 'public') {
|
|
23
|
-
throw new TypeError(`${
|
|
24
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
24
25
|
}
|
|
25
26
|
if (usage === 'decrypt' && key.type === 'public') {
|
|
26
|
-
throw new TypeError(`${
|
|
27
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
27
28
|
}
|
|
28
29
|
if (key.algorithm && usage === 'verify' && key.type === 'private') {
|
|
29
|
-
throw new TypeError(`${
|
|
30
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
30
31
|
}
|
|
31
32
|
if (key.algorithm && usage === 'encrypt' && key.type === 'private') {
|
|
32
|
-
throw new TypeError(`${
|
|
33
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
const checkKeyType = (alg, key, usage) => {
|
|
@@ -5,6 +5,7 @@ const ECDH = require("../runtime/ecdhes.js");
|
|
|
5
5
|
const pbes2kw_js_1 = require("../runtime/pbes2kw.js");
|
|
6
6
|
const rsaes_js_1 = require("../runtime/rsaes.js");
|
|
7
7
|
const base64url_js_1 = require("../runtime/base64url.js");
|
|
8
|
+
const normalize_key_js_1 = require("../runtime/normalize_key.js");
|
|
8
9
|
const errors_js_1 = require("../util/errors.js");
|
|
9
10
|
const cek_js_1 = require("../lib/cek.js");
|
|
10
11
|
const import_js_1 = require("../key/import.js");
|
|
@@ -12,6 +13,7 @@ const check_key_type_js_1 = require("./check_key_type.js");
|
|
|
12
13
|
const is_object_js_1 = require("./is_object.js");
|
|
13
14
|
const aesgcmkw_js_1 = require("./aesgcmkw.js");
|
|
14
15
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
16
|
+
key = (await normalize_key_js_1.default.normalizePrivateKey?.(key, alg)) || key;
|
|
15
17
|
(0, check_key_type_js_1.default)(alg, key, 'decrypt');
|
|
16
18
|
switch (alg) {
|
|
17
19
|
case 'dir': {
|
|
@@ -5,6 +5,7 @@ const ECDH = require("../runtime/ecdhes.js");
|
|
|
5
5
|
const pbes2kw_js_1 = require("../runtime/pbes2kw.js");
|
|
6
6
|
const rsaes_js_1 = require("../runtime/rsaes.js");
|
|
7
7
|
const base64url_js_1 = require("../runtime/base64url.js");
|
|
8
|
+
const normalize_key_js_1 = require("../runtime/normalize_key.js");
|
|
8
9
|
const cek_js_1 = require("../lib/cek.js");
|
|
9
10
|
const errors_js_1 = require("../util/errors.js");
|
|
10
11
|
const export_js_1 = require("../key/export.js");
|
|
@@ -14,6 +15,7 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
14
15
|
let encryptedKey;
|
|
15
16
|
let parameters;
|
|
16
17
|
let cek;
|
|
18
|
+
key = (await normalize_key_js_1.default.normalizePublicKey?.(key, alg)) || key;
|
|
17
19
|
(0, check_key_type_js_1.default)(alg, key, 'encrypt');
|
|
18
20
|
switch (alg) {
|
|
19
21
|
case 'dir': {
|
|
@@ -10,7 +10,7 @@ function isCloudflareWorkers() {
|
|
|
10
10
|
let USER_AGENT;
|
|
11
11
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
12
12
|
const NAME = 'jose';
|
|
13
|
-
const VERSION = 'v5.
|
|
13
|
+
const VERSION = 'v5.6.1';
|
|
14
14
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
15
15
|
}
|
|
16
16
|
export const experimental_jwksCache = Symbol();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { withAlg as invalidKeyInput } from './invalid_key_input.js';
|
|
2
2
|
import isKeyLike, { types } from '../runtime/is_key_like.js';
|
|
3
|
+
const tag = (key) => key?.[Symbol.toStringTag];
|
|
3
4
|
const symmetricTypeCheck = (alg, key) => {
|
|
4
5
|
if (key instanceof Uint8Array)
|
|
5
6
|
return;
|
|
@@ -7,7 +8,7 @@ const symmetricTypeCheck = (alg, key) => {
|
|
|
7
8
|
throw new TypeError(invalidKeyInput(alg, key, ...types, 'Uint8Array'));
|
|
8
9
|
}
|
|
9
10
|
if (key.type !== 'secret') {
|
|
10
|
-
throw new TypeError(`${
|
|
11
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
11
12
|
}
|
|
12
13
|
};
|
|
13
14
|
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
@@ -15,19 +16,19 @@ const asymmetricTypeCheck = (alg, key, usage) => {
|
|
|
15
16
|
throw new TypeError(invalidKeyInput(alg, key, ...types));
|
|
16
17
|
}
|
|
17
18
|
if (key.type === 'secret') {
|
|
18
|
-
throw new TypeError(`${
|
|
19
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
19
20
|
}
|
|
20
21
|
if (usage === 'sign' && key.type === 'public') {
|
|
21
|
-
throw new TypeError(`${
|
|
22
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
22
23
|
}
|
|
23
24
|
if (usage === 'decrypt' && key.type === 'public') {
|
|
24
|
-
throw new TypeError(`${
|
|
25
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
25
26
|
}
|
|
26
27
|
if (key.algorithm && usage === 'verify' && key.type === 'private') {
|
|
27
|
-
throw new TypeError(`${
|
|
28
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
28
29
|
}
|
|
29
30
|
if (key.algorithm && usage === 'encrypt' && key.type === 'private') {
|
|
30
|
-
throw new TypeError(`${
|
|
31
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
34
|
const checkKeyType = (alg, key, usage) => {
|
|
@@ -3,6 +3,7 @@ import * as ECDH from '../runtime/ecdhes.js';
|
|
|
3
3
|
import { decrypt as pbes2Kw } from '../runtime/pbes2kw.js';
|
|
4
4
|
import { decrypt as rsaEs } from '../runtime/rsaes.js';
|
|
5
5
|
import { decode as base64url } from '../runtime/base64url.js';
|
|
6
|
+
import normalize from '../runtime/normalize_key.js';
|
|
6
7
|
import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
|
|
7
8
|
import { bitLength as cekLength } from '../lib/cek.js';
|
|
8
9
|
import { importJWK } from '../key/import.js';
|
|
@@ -10,6 +11,7 @@ import checkKeyType from './check_key_type.js';
|
|
|
10
11
|
import isObject from './is_object.js';
|
|
11
12
|
import { unwrap as aesGcmKw } from './aesgcmkw.js';
|
|
12
13
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
14
|
+
key = (await normalize.normalizePrivateKey?.(key, alg)) || key;
|
|
13
15
|
checkKeyType(alg, key, 'decrypt');
|
|
14
16
|
switch (alg) {
|
|
15
17
|
case 'dir': {
|
|
@@ -3,6 +3,7 @@ import * as ECDH from '../runtime/ecdhes.js';
|
|
|
3
3
|
import { encrypt as pbes2Kw } from '../runtime/pbes2kw.js';
|
|
4
4
|
import { encrypt as rsaEs } from '../runtime/rsaes.js';
|
|
5
5
|
import { encode as base64url } from '../runtime/base64url.js';
|
|
6
|
+
import normalize from '../runtime/normalize_key.js';
|
|
6
7
|
import generateCek, { bitLength as cekLength } from '../lib/cek.js';
|
|
7
8
|
import { JOSENotSupported } from '../util/errors.js';
|
|
8
9
|
import { exportJWK } from '../key/export.js';
|
|
@@ -12,6 +13,7 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
12
13
|
let encryptedKey;
|
|
13
14
|
let parameters;
|
|
14
15
|
let cek;
|
|
16
|
+
key = (await normalize.normalizePublicKey?.(key, alg)) || key;
|
|
15
17
|
checkKeyType(alg, key, 'encrypt');
|
|
16
18
|
switch (alg) {
|
|
17
19
|
case 'dir': {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|