jose 5.6.0 → 5.6.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/jwks/remote.js +1 -1
- package/dist/browser/lib/decrypt_key_management.js +2 -4
- package/dist/browser/lib/encrypt_key_management.js +2 -4
- package/dist/browser/runtime/get_sign_verify_key.js +3 -3
- package/dist/browser/runtime/normalize_key.js +28 -6
- package/dist/node/cjs/jwks/remote.js +1 -1
- package/dist/node/cjs/lib/decrypt_key_management.js +2 -4
- package/dist/node/cjs/lib/encrypt_key_management.js +2 -4
- package/dist/node/cjs/runtime/normalize_key.js +1 -0
- package/dist/node/esm/jwks/remote.js +1 -1
- package/dist/node/esm/lib/decrypt_key_management.js +2 -4
- package/dist/node/esm/lib/encrypt_key_management.js +2 -4
- package/dist/node/esm/runtime/normalize_key.js +1 -1
- 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.6.
|
|
13
|
+
const VERSION = 'v5.6.2';
|
|
14
14
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
15
15
|
}
|
|
16
16
|
export const experimental_jwksCache = Symbol();
|
|
@@ -3,7 +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
|
|
6
|
+
import normalize from '../runtime/normalize_key.js';
|
|
7
7
|
import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
|
|
8
8
|
import { bitLength as cekLength } from '../lib/cek.js';
|
|
9
9
|
import { importJWK } from '../key/import.js';
|
|
@@ -11,10 +11,8 @@ import checkKeyType from './check_key_type.js';
|
|
|
11
11
|
import isObject from './is_object.js';
|
|
12
12
|
import { unwrap as aesGcmKw } from './aesgcmkw.js';
|
|
13
13
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
14
|
-
if (normalize.normalizePrivateKey) {
|
|
15
|
-
key = await normalize.normalizePrivateKey(key, alg);
|
|
16
|
-
}
|
|
17
14
|
checkKeyType(alg, key, 'decrypt');
|
|
15
|
+
key = (await normalize.normalizePrivateKey?.(key, alg)) || key;
|
|
18
16
|
switch (alg) {
|
|
19
17
|
case 'dir': {
|
|
20
18
|
if (encryptedKey !== undefined)
|
|
@@ -3,7 +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
|
|
6
|
+
import normalize from '../runtime/normalize_key.js';
|
|
7
7
|
import generateCek, { bitLength as cekLength } from '../lib/cek.js';
|
|
8
8
|
import { JOSENotSupported } from '../util/errors.js';
|
|
9
9
|
import { exportJWK } from '../key/export.js';
|
|
@@ -13,10 +13,8 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
13
13
|
let encryptedKey;
|
|
14
14
|
let parameters;
|
|
15
15
|
let cek;
|
|
16
|
-
if (normalize.normalizePublicKey) {
|
|
17
|
-
key = await normalize.normalizePublicKey(key, alg);
|
|
18
|
-
}
|
|
19
16
|
checkKeyType(alg, key, 'encrypt');
|
|
17
|
+
key = (await normalize.normalizePublicKey?.(key, alg)) || key;
|
|
20
18
|
switch (alg) {
|
|
21
19
|
case 'dir': {
|
|
22
20
|
cek = key;
|
|
@@ -2,12 +2,12 @@ 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
|
-
import
|
|
5
|
+
import normalize from './normalize_key.js';
|
|
6
6
|
export default async function getCryptoKey(alg, key, usage) {
|
|
7
|
-
if (
|
|
7
|
+
if (usage === 'sign') {
|
|
8
8
|
key = await normalize.normalizePrivateKey(key, alg);
|
|
9
9
|
}
|
|
10
|
-
if (
|
|
10
|
+
if (usage === 'verify') {
|
|
11
11
|
key = await normalize.normalizePublicKey(key, alg);
|
|
12
12
|
}
|
|
13
13
|
if (isCryptoKey(key)) {
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import { decode } from './base64url.js';
|
|
2
2
|
import importJWK from './jwk_to_key.js';
|
|
3
3
|
const normalizeSecretKey = (k) => decode(k);
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let privCache;
|
|
5
|
+
let pubCache;
|
|
6
|
+
const isKeyObject = (key) => {
|
|
7
|
+
return key?.[Symbol.toStringTag] === 'KeyObject';
|
|
8
|
+
};
|
|
9
|
+
const importAndCache = async (cache, key, jwk, alg) => {
|
|
10
|
+
let cached = cache.get(key);
|
|
11
|
+
if (cached?.[alg]) {
|
|
12
|
+
return cached[alg];
|
|
13
|
+
}
|
|
14
|
+
const cryptoKey = await importJWK({ ...jwk, alg });
|
|
15
|
+
if (!cached) {
|
|
16
|
+
cache.set(key, { [alg]: cryptoKey });
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
cached[alg] = cryptoKey;
|
|
20
|
+
}
|
|
21
|
+
return cryptoKey;
|
|
22
|
+
};
|
|
23
|
+
const normalizePublicKey = (key, alg) => {
|
|
24
|
+
if (isKeyObject(key)) {
|
|
6
25
|
let jwk = key.export({ format: 'jwk' });
|
|
7
26
|
delete jwk.d;
|
|
8
27
|
delete jwk.dp;
|
|
@@ -13,17 +32,20 @@ export const normalizePublicKey = async (key, alg) => {
|
|
|
13
32
|
if (jwk.k) {
|
|
14
33
|
return normalizeSecretKey(jwk.k);
|
|
15
34
|
}
|
|
16
|
-
|
|
35
|
+
pubCache || (pubCache = new WeakMap());
|
|
36
|
+
return importAndCache(pubCache, key, jwk, alg);
|
|
17
37
|
}
|
|
18
38
|
return key;
|
|
19
39
|
};
|
|
20
|
-
|
|
21
|
-
if (key
|
|
40
|
+
const normalizePrivateKey = (key, alg) => {
|
|
41
|
+
if (isKeyObject(key)) {
|
|
22
42
|
let jwk = key.export({ format: 'jwk' });
|
|
23
43
|
if (jwk.k) {
|
|
24
44
|
return normalizeSecretKey(jwk.k);
|
|
25
45
|
}
|
|
26
|
-
|
|
46
|
+
privCache || (privCache = new WeakMap());
|
|
47
|
+
return importAndCache(privCache, key, jwk, alg);
|
|
27
48
|
}
|
|
28
49
|
return key;
|
|
29
50
|
};
|
|
51
|
+
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.6.
|
|
16
|
+
const VERSION = 'v5.6.2';
|
|
17
17
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
18
18
|
}
|
|
19
19
|
exports.experimental_jwksCache = Symbol();
|
|
@@ -5,7 +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
|
|
8
|
+
const normalize_key_js_1 = require("../runtime/normalize_key.js");
|
|
9
9
|
const errors_js_1 = require("../util/errors.js");
|
|
10
10
|
const cek_js_1 = require("../lib/cek.js");
|
|
11
11
|
const import_js_1 = require("../key/import.js");
|
|
@@ -13,10 +13,8 @@ const check_key_type_js_1 = require("./check_key_type.js");
|
|
|
13
13
|
const is_object_js_1 = require("./is_object.js");
|
|
14
14
|
const aesgcmkw_js_1 = require("./aesgcmkw.js");
|
|
15
15
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
16
|
-
if (normalize.normalizePrivateKey) {
|
|
17
|
-
key = await normalize.normalizePrivateKey(key, alg);
|
|
18
|
-
}
|
|
19
16
|
(0, check_key_type_js_1.default)(alg, key, 'decrypt');
|
|
17
|
+
key = (await normalize_key_js_1.default.normalizePrivateKey?.(key, alg)) || key;
|
|
20
18
|
switch (alg) {
|
|
21
19
|
case 'dir': {
|
|
22
20
|
if (encryptedKey !== undefined)
|
|
@@ -5,7 +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
|
|
8
|
+
const normalize_key_js_1 = require("../runtime/normalize_key.js");
|
|
9
9
|
const cek_js_1 = require("../lib/cek.js");
|
|
10
10
|
const errors_js_1 = require("../util/errors.js");
|
|
11
11
|
const export_js_1 = require("../key/export.js");
|
|
@@ -15,10 +15,8 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
15
15
|
let encryptedKey;
|
|
16
16
|
let parameters;
|
|
17
17
|
let cek;
|
|
18
|
-
if (normalize.normalizePublicKey) {
|
|
19
|
-
key = await normalize.normalizePublicKey(key, alg);
|
|
20
|
-
}
|
|
21
18
|
(0, check_key_type_js_1.default)(alg, key, 'encrypt');
|
|
19
|
+
key = (await normalize_key_js_1.default.normalizePublicKey?.(key, alg)) || key;
|
|
22
20
|
switch (alg) {
|
|
23
21
|
case 'dir': {
|
|
24
22
|
cek = key;
|
|
@@ -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.6.
|
|
13
|
+
const VERSION = 'v5.6.2';
|
|
14
14
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
15
15
|
}
|
|
16
16
|
export const experimental_jwksCache = Symbol();
|
|
@@ -3,7 +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
|
|
6
|
+
import normalize from '../runtime/normalize_key.js';
|
|
7
7
|
import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
|
|
8
8
|
import { bitLength as cekLength } from '../lib/cek.js';
|
|
9
9
|
import { importJWK } from '../key/import.js';
|
|
@@ -11,10 +11,8 @@ import checkKeyType from './check_key_type.js';
|
|
|
11
11
|
import isObject from './is_object.js';
|
|
12
12
|
import { unwrap as aesGcmKw } from './aesgcmkw.js';
|
|
13
13
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
14
|
-
if (normalize.normalizePrivateKey) {
|
|
15
|
-
key = await normalize.normalizePrivateKey(key, alg);
|
|
16
|
-
}
|
|
17
14
|
checkKeyType(alg, key, 'decrypt');
|
|
15
|
+
key = (await normalize.normalizePrivateKey?.(key, alg)) || key;
|
|
18
16
|
switch (alg) {
|
|
19
17
|
case 'dir': {
|
|
20
18
|
if (encryptedKey !== undefined)
|
|
@@ -3,7 +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
|
|
6
|
+
import normalize from '../runtime/normalize_key.js';
|
|
7
7
|
import generateCek, { bitLength as cekLength } from '../lib/cek.js';
|
|
8
8
|
import { JOSENotSupported } from '../util/errors.js';
|
|
9
9
|
import { exportJWK } from '../key/export.js';
|
|
@@ -13,10 +13,8 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
13
13
|
let encryptedKey;
|
|
14
14
|
let parameters;
|
|
15
15
|
let cek;
|
|
16
|
-
if (normalize.normalizePublicKey) {
|
|
17
|
-
key = await normalize.normalizePublicKey(key, alg);
|
|
18
|
-
}
|
|
19
16
|
checkKeyType(alg, key, 'encrypt');
|
|
17
|
+
key = (await normalize.normalizePublicKey?.(key, alg)) || key;
|
|
20
18
|
switch (alg) {
|
|
21
19
|
case 'dir': {
|
|
22
20
|
cek = key;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export default {};
|