jose 4.0.2 → 4.1.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/{runtime → lib}/aesgcmkw.js +8 -8
- package/dist/browser/lib/cek.js +18 -16
- package/dist/browser/lib/check_iv_length.js +2 -2
- package/dist/browser/lib/check_key_type.js +1 -1
- package/dist/browser/lib/crypto_key.js +150 -0
- package/dist/browser/lib/decrypt_key_management.js +3 -3
- package/dist/browser/lib/encrypt_key_management.js +3 -3
- package/dist/browser/{runtime → lib}/invalid_key_input.js +0 -0
- package/dist/browser/lib/iv.js +24 -19
- package/dist/browser/runtime/aeskw.js +6 -4
- package/dist/browser/runtime/asn1.js +4 -4
- package/dist/browser/runtime/bogus.js +1 -1
- package/dist/browser/runtime/check_cek_length.js +4 -34
- package/dist/browser/runtime/decrypt.js +20 -8
- package/dist/browser/runtime/ecdhes.js +4 -1
- package/dist/browser/runtime/encrypt.js +20 -8
- package/dist/browser/runtime/generate.js +4 -4
- package/dist/browser/runtime/get_sign_verify_key.js +4 -2
- package/dist/browser/runtime/jwk_to_key.js +4 -4
- package/dist/browser/runtime/key_to_jwk.js +1 -1
- package/dist/browser/runtime/pbes2kw.js +15 -36
- package/dist/browser/runtime/rsaes.js +4 -1
- package/dist/browser/runtime/subtle_dsa.js +7 -26
- package/dist/node/cjs/{runtime → lib}/aesgcmkw.js +8 -8
- package/dist/node/cjs/lib/cek.js +20 -17
- package/dist/node/cjs/lib/check_iv_length.js +1 -1
- package/dist/node/cjs/lib/check_key_type.js +1 -1
- package/dist/node/cjs/lib/crypto_key.js +155 -0
- package/dist/node/cjs/lib/decrypt_key_management.js +2 -2
- package/dist/node/cjs/lib/encrypt_key_management.js +2 -2
- package/dist/node/cjs/{runtime → lib}/invalid_key_input.js +0 -11
- package/dist/node/cjs/lib/iv.js +26 -20
- package/dist/node/cjs/runtime/aeskw.js +4 -2
- package/dist/node/cjs/runtime/asn1.js +2 -2
- package/dist/node/cjs/runtime/decrypt.js +4 -2
- package/dist/node/cjs/runtime/ecdhes.js +7 -4
- package/dist/node/cjs/runtime/encrypt.js +4 -2
- package/dist/node/cjs/runtime/get_named_curve.js +2 -2
- package/dist/node/cjs/runtime/get_sign_verify_key.js +6 -4
- package/dist/node/cjs/runtime/global.js +11 -0
- package/dist/node/cjs/runtime/key_to_jwk.js +2 -2
- package/dist/node/cjs/runtime/node_key.js +6 -10
- package/dist/node/cjs/runtime/pbes2kw.js +4 -2
- package/dist/node/cjs/runtime/rsaes.js +4 -2
- package/dist/node/cjs/runtime/webcrypto.js +1 -149
- package/dist/node/esm/{runtime → lib}/aesgcmkw.js +8 -8
- package/dist/node/esm/lib/cek.js +18 -16
- package/dist/node/esm/lib/check_iv_length.js +2 -2
- package/dist/node/esm/lib/check_key_type.js +1 -1
- package/dist/node/esm/lib/crypto_key.js +150 -0
- package/dist/node/esm/lib/decrypt_key_management.js +3 -3
- package/dist/node/esm/lib/encrypt_key_management.js +3 -3
- package/dist/node/esm/{runtime → lib}/invalid_key_input.js +0 -11
- package/dist/node/esm/lib/iv.js +24 -19
- package/dist/node/esm/runtime/aeskw.js +6 -4
- package/dist/node/esm/runtime/asn1.js +4 -4
- package/dist/node/esm/runtime/decrypt.js +6 -4
- package/dist/node/esm/runtime/ecdhes.js +9 -6
- package/dist/node/esm/runtime/encrypt.js +6 -4
- package/dist/node/esm/runtime/get_named_curve.js +4 -4
- package/dist/node/esm/runtime/get_sign_verify_key.js +7 -5
- package/dist/node/esm/runtime/global.js +6 -0
- package/dist/node/esm/runtime/key_to_jwk.js +4 -4
- package/dist/node/esm/runtime/node_key.js +6 -10
- package/dist/node/esm/runtime/pbes2kw.js +6 -4
- package/dist/node/esm/runtime/rsaes.js +6 -4
- package/dist/node/esm/runtime/webcrypto.js +0 -147
- package/dist/types/jwks/remote.d.ts +4 -0
- package/package.json +4 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'util';
|
|
2
1
|
export default (actual, ...types) => {
|
|
3
2
|
let msg = 'Key must be ';
|
|
4
3
|
if (types.length > 2) {
|
|
@@ -21,16 +20,6 @@ export default (actual, ...types) => {
|
|
|
21
20
|
if (actual.constructor && actual.constructor.name) {
|
|
22
21
|
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
23
22
|
}
|
|
24
|
-
else {
|
|
25
|
-
const inspected = inspect(actual, { depth: -1 });
|
|
26
|
-
msg += ` Received ${inspected}`;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
let inspected = inspect(actual, { colors: false });
|
|
31
|
-
if (inspected.length > 25)
|
|
32
|
-
inspected = `${inspected.slice(0, 25)}...`;
|
|
33
|
-
msg += ` Received type ${typeof actual} (${inspected})`;
|
|
34
23
|
}
|
|
35
24
|
return msg;
|
|
36
25
|
};
|
package/dist/node/esm/lib/iv.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { JOSENotSupported } from '../util/errors.js';
|
|
2
2
|
import random from '../runtime/random.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
export function bitLength(alg) {
|
|
4
|
+
switch (alg) {
|
|
5
|
+
case 'A128CBC-HS256':
|
|
6
|
+
return 128;
|
|
7
|
+
case 'A128GCM':
|
|
8
|
+
return 96;
|
|
9
|
+
case 'A128GCMKW':
|
|
10
|
+
return 96;
|
|
11
|
+
case 'A192CBC-HS384':
|
|
12
|
+
return 128;
|
|
13
|
+
case 'A192GCM':
|
|
14
|
+
return 96;
|
|
15
|
+
case 'A192GCMKW':
|
|
16
|
+
return 96;
|
|
17
|
+
case 'A256CBC-HS512':
|
|
18
|
+
return 128;
|
|
19
|
+
case 'A256GCM':
|
|
20
|
+
return 96;
|
|
21
|
+
case 'A256GCMKW':
|
|
22
|
+
return 96;
|
|
23
|
+
default:
|
|
24
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
18
25
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export default generateIv;
|
|
22
|
-
export { bitLengths };
|
|
26
|
+
}
|
|
27
|
+
export default (alg) => random(new Uint8Array(bitLength(alg) >> 3));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import { createDecipheriv, createCipheriv } from 'crypto';
|
|
2
|
+
import { KeyObject, createDecipheriv, createCipheriv } from 'crypto';
|
|
3
3
|
import { JOSENotSupported } from '../util/errors.js';
|
|
4
4
|
import { concat } from '../lib/buffer_utils.js';
|
|
5
5
|
import getSecretKey from './secret_key.js';
|
|
6
|
-
import { isCryptoKey
|
|
6
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
7
|
+
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
7
8
|
import isKeyObject from './is_key_object.js';
|
|
8
|
-
import invalidKeyInput from '
|
|
9
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
9
10
|
import supported from './ciphers.js';
|
|
10
11
|
function checkKeySize(key, alg) {
|
|
11
12
|
if (key.symmetricKeySize << 3 !== parseInt(alg.substr(1, 3), 10)) {
|
|
@@ -20,7 +21,8 @@ function ensureKeyObject(key, alg, usage) {
|
|
|
20
21
|
return getSecretKey(key);
|
|
21
22
|
}
|
|
22
23
|
if (isCryptoKey(key)) {
|
|
23
|
-
|
|
24
|
+
checkEncCryptoKey(key, alg, usage);
|
|
25
|
+
return KeyObject.from(key);
|
|
24
26
|
}
|
|
25
27
|
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array'));
|
|
26
28
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { createPrivateKey, createPublicKey } from 'crypto';
|
|
1
|
+
import { createPrivateKey, createPublicKey, KeyObject } from 'crypto';
|
|
2
2
|
import { Buffer } from 'buffer';
|
|
3
|
-
import { isCryptoKey
|
|
3
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
4
4
|
import isKeyObject from './is_key_object.js';
|
|
5
|
-
import invalidKeyInput from '
|
|
5
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
6
6
|
const genericExport = (keyType, keyFormat, key) => {
|
|
7
7
|
let keyObject;
|
|
8
8
|
if (isCryptoKey(key)) {
|
|
9
9
|
if (!key.extractable) {
|
|
10
10
|
throw new TypeError('CryptoKey is not extractable');
|
|
11
11
|
}
|
|
12
|
-
keyObject =
|
|
12
|
+
keyObject = KeyObject.from(key);
|
|
13
13
|
}
|
|
14
14
|
else if (isKeyObject(key)) {
|
|
15
15
|
keyObject = key;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { createDecipheriv } from 'crypto';
|
|
1
|
+
import { createDecipheriv, KeyObject } from '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
5
|
import { JOSENotSupported, JWEDecryptionFailed } from '../util/errors.js';
|
|
6
6
|
import timingSafeEqual from './timing_safe_equal.js';
|
|
7
7
|
import cbcTag from './cbc_tag.js';
|
|
8
|
-
import { isCryptoKey
|
|
8
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
9
|
+
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
9
10
|
import isKeyObject from './is_key_object.js';
|
|
10
|
-
import invalidKeyInput from '
|
|
11
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
11
12
|
import supported from './ciphers.js';
|
|
12
13
|
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
13
14
|
const keySize = parseInt(enc.substr(1, 3), 10);
|
|
@@ -64,7 +65,8 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
64
65
|
const decrypt = async (enc, cek, ciphertext, iv, tag, aad) => {
|
|
65
66
|
let key;
|
|
66
67
|
if (isCryptoKey(cek)) {
|
|
67
|
-
|
|
68
|
+
checkEncCryptoKey(cek, enc, 'decrypt');
|
|
69
|
+
key = KeyObject.from(cek);
|
|
68
70
|
}
|
|
69
71
|
else if (cek instanceof Uint8Array || isKeyObject(cek)) {
|
|
70
72
|
key = cek;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { diffieHellman, generateKeyPair as generateKeyPairCb } from 'crypto';
|
|
1
|
+
import { diffieHellman, generateKeyPair as generateKeyPairCb, KeyObject } from 'crypto';
|
|
2
2
|
import { promisify } from 'util';
|
|
3
3
|
import getNamedCurve from './get_named_curve.js';
|
|
4
4
|
import { encoder, concat, uint32be, lengthAndInput, concatKdf } from '../lib/buffer_utils.js';
|
|
5
5
|
import digest from './digest.js';
|
|
6
6
|
import { JOSENotSupported } from '../util/errors.js';
|
|
7
|
-
import { isCryptoKey
|
|
7
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
8
|
+
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
8
9
|
import isKeyObject from './is_key_object.js';
|
|
9
|
-
import invalidKeyInput from '
|
|
10
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
10
11
|
const generateKeyPair = promisify(generateKeyPairCb);
|
|
11
12
|
export const deriveKey = async (publicKee, privateKee, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) => {
|
|
12
13
|
let publicKey;
|
|
13
14
|
if (isCryptoKey(publicKee)) {
|
|
14
|
-
|
|
15
|
+
checkEncCryptoKey(publicKee, 'ECDH-ES');
|
|
16
|
+
publicKey = KeyObject.from(publicKee);
|
|
15
17
|
}
|
|
16
18
|
else if (isKeyObject(publicKee)) {
|
|
17
19
|
publicKey = publicKee;
|
|
@@ -21,7 +23,8 @@ export const deriveKey = async (publicKee, privateKee, algorithm, keyLength, apu
|
|
|
21
23
|
}
|
|
22
24
|
let privateKey;
|
|
23
25
|
if (isCryptoKey(privateKee)) {
|
|
24
|
-
|
|
26
|
+
checkEncCryptoKey(privateKee, 'ECDH-ES', 'deriveBits', 'deriveKey');
|
|
27
|
+
privateKey = KeyObject.from(privateKee);
|
|
25
28
|
}
|
|
26
29
|
else if (isKeyObject(privateKee)) {
|
|
27
30
|
privateKey = privateKee;
|
|
@@ -36,7 +39,7 @@ export const deriveKey = async (publicKee, privateKee, algorithm, keyLength, apu
|
|
|
36
39
|
export const generateEpk = async (kee) => {
|
|
37
40
|
let key;
|
|
38
41
|
if (isCryptoKey(kee)) {
|
|
39
|
-
key =
|
|
42
|
+
key = KeyObject.from(kee);
|
|
40
43
|
}
|
|
41
44
|
else if (isKeyObject(kee)) {
|
|
42
45
|
key = kee;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { createCipheriv } from 'crypto';
|
|
1
|
+
import { createCipheriv, KeyObject } from '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
5
|
import cbcTag from './cbc_tag.js';
|
|
6
|
-
import { isCryptoKey
|
|
6
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
7
|
+
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
7
8
|
import isKeyObject from './is_key_object.js';
|
|
8
|
-
import invalidKeyInput from '
|
|
9
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
9
10
|
import { JOSENotSupported } from '../util/errors.js';
|
|
10
11
|
import supported from './ciphers.js';
|
|
11
12
|
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
@@ -42,7 +43,8 @@ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
|
42
43
|
const encrypt = async (enc, plaintext, cek, iv, aad) => {
|
|
43
44
|
let key;
|
|
44
45
|
if (isCryptoKey(cek)) {
|
|
45
|
-
|
|
46
|
+
checkEncCryptoKey(cek, enc, 'encrypt');
|
|
47
|
+
key = KeyObject.from(cek);
|
|
46
48
|
}
|
|
47
49
|
else if (cek instanceof Uint8Array || isKeyObject(cek)) {
|
|
48
50
|
key = cek;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import { createPublicKey } from 'crypto';
|
|
2
|
+
import { createPublicKey, KeyObject } from 'crypto';
|
|
3
3
|
import { JOSENotSupported } from '../util/errors.js';
|
|
4
|
-
import { isCryptoKey
|
|
4
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
5
5
|
import isKeyObject from './is_key_object.js';
|
|
6
|
-
import invalidKeyInput from '
|
|
6
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
7
7
|
const p256 = Buffer.from([42, 134, 72, 206, 61, 3, 1, 7]);
|
|
8
8
|
const p384 = Buffer.from([43, 129, 4, 0, 34]);
|
|
9
9
|
const p521 = Buffer.from([43, 129, 4, 0, 35]);
|
|
@@ -27,7 +27,7 @@ const getNamedCurve = (kee, raw) => {
|
|
|
27
27
|
var _a;
|
|
28
28
|
let key;
|
|
29
29
|
if (isCryptoKey(kee)) {
|
|
30
|
-
key =
|
|
30
|
+
key = KeyObject.from(kee);
|
|
31
31
|
}
|
|
32
32
|
else if (isKeyObject(kee)) {
|
|
33
33
|
key = kee;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isCryptoKey
|
|
1
|
+
import { KeyObject } from 'crypto';
|
|
2
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
3
|
+
import { checkSigCryptoKey } from '../lib/crypto_key.js';
|
|
3
4
|
import getSecretKey from './secret_key.js';
|
|
4
|
-
import invalidKeyInput from '
|
|
5
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
5
6
|
export default function getSignVerifyKey(alg, key, usage) {
|
|
6
7
|
if (key instanceof Uint8Array) {
|
|
7
8
|
if (!alg.startsWith('HS')) {
|
|
@@ -9,11 +10,12 @@ export default function getSignVerifyKey(alg, key, usage) {
|
|
|
9
10
|
}
|
|
10
11
|
return getSecretKey(key);
|
|
11
12
|
}
|
|
12
|
-
if (key instanceof
|
|
13
|
+
if (key instanceof KeyObject) {
|
|
13
14
|
return key;
|
|
14
15
|
}
|
|
15
16
|
if (isCryptoKey(key)) {
|
|
16
|
-
|
|
17
|
+
checkSigCryptoKey(key, alg, usage);
|
|
18
|
+
return KeyObject.from(key);
|
|
17
19
|
}
|
|
18
20
|
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array'));
|
|
19
21
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createPublicKey } from 'crypto';
|
|
1
|
+
import { KeyObject, createPublicKey } from 'crypto';
|
|
2
2
|
import { encode as base64url } from './base64url.js';
|
|
3
3
|
import Asn1SequenceDecoder from './asn1_sequence_decoder.js';
|
|
4
4
|
import { JOSENotSupported } from '../util/errors.js';
|
|
5
5
|
import getNamedCurve from './get_named_curve.js';
|
|
6
|
-
import { isCryptoKey
|
|
6
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
7
7
|
import isKeyObject from './is_key_object.js';
|
|
8
|
-
import invalidKeyInput from '
|
|
8
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
9
9
|
const [major, minor] = process.version
|
|
10
10
|
.substr(1)
|
|
11
11
|
.split('.')
|
|
@@ -17,7 +17,7 @@ const keyToJWK = (key) => {
|
|
|
17
17
|
if (!key.extractable) {
|
|
18
18
|
throw new TypeError('CryptoKey is not extractable');
|
|
19
19
|
}
|
|
20
|
-
keyObject =
|
|
20
|
+
keyObject = KeyObject.from(key);
|
|
21
21
|
}
|
|
22
22
|
else if (isKeyObject(key)) {
|
|
23
23
|
keyObject = key;
|
|
@@ -7,6 +7,10 @@ const [major, minor] = process.version
|
|
|
7
7
|
.split('.')
|
|
8
8
|
.map((str) => parseInt(str, 10));
|
|
9
9
|
const rsaPssParams = major >= 17 || (major === 16 && minor >= 9);
|
|
10
|
+
const PSS = {
|
|
11
|
+
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
12
|
+
saltLength: constants.RSA_PSS_SALTLEN_DIGEST,
|
|
13
|
+
};
|
|
10
14
|
const ecCurveAlgMap = new Map([
|
|
11
15
|
['ES256', 'P-256'],
|
|
12
16
|
['ES256K', 'secp256k1'],
|
|
@@ -46,11 +50,7 @@ export default function keyForCrypto(alg, key) {
|
|
|
46
50
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa or rsa-pss');
|
|
47
51
|
}
|
|
48
52
|
checkModulusLength(key, alg);
|
|
49
|
-
return {
|
|
50
|
-
key,
|
|
51
|
-
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
52
|
-
saltLength: constants.RSA_PSS_SALTLEN_DIGEST,
|
|
53
|
-
};
|
|
53
|
+
return { key, ...PSS };
|
|
54
54
|
case !rsaPssParams && 'PS256':
|
|
55
55
|
case !rsaPssParams && 'PS384':
|
|
56
56
|
case !rsaPssParams && 'PS512':
|
|
@@ -58,11 +58,7 @@ export default function keyForCrypto(alg, key) {
|
|
|
58
58
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
59
59
|
}
|
|
60
60
|
checkModulusLength(key, alg);
|
|
61
|
-
return {
|
|
62
|
-
key,
|
|
63
|
-
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
64
|
-
saltLength: constants.RSA_PSS_SALTLEN_DIGEST,
|
|
65
|
-
};
|
|
61
|
+
return { key, ...PSS };
|
|
66
62
|
case 'ES256':
|
|
67
63
|
case 'ES256K':
|
|
68
64
|
case 'ES384':
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { promisify } from 'util';
|
|
2
|
-
import { pbkdf2 as pbkdf2cb } from 'crypto';
|
|
2
|
+
import { KeyObject, pbkdf2 as pbkdf2cb } from 'crypto';
|
|
3
3
|
import random from './random.js';
|
|
4
4
|
import { p2s as concatSalt } from '../lib/buffer_utils.js';
|
|
5
5
|
import { encode as base64url } from './base64url.js';
|
|
6
6
|
import { wrap, unwrap } from './aeskw.js';
|
|
7
7
|
import checkP2s from '../lib/check_p2s.js';
|
|
8
|
-
import { isCryptoKey
|
|
8
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
9
|
+
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
9
10
|
import isKeyObject from './is_key_object.js';
|
|
10
|
-
import invalidKeyInput from '
|
|
11
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
11
12
|
const pbkdf2 = promisify(pbkdf2cb);
|
|
12
13
|
function getPassword(key, alg) {
|
|
13
14
|
if (isKeyObject(key)) {
|
|
@@ -17,7 +18,8 @@ function getPassword(key, alg) {
|
|
|
17
18
|
return key;
|
|
18
19
|
}
|
|
19
20
|
if (isCryptoKey(key)) {
|
|
20
|
-
|
|
21
|
+
checkEncCryptoKey(key, alg, 'deriveBits', 'deriveKey');
|
|
22
|
+
return KeyObject.from(key).export();
|
|
21
23
|
}
|
|
22
24
|
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array'));
|
|
23
25
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { publicEncrypt, constants, privateDecrypt } from 'crypto';
|
|
1
|
+
import { KeyObject, publicEncrypt, constants, privateDecrypt } from 'crypto';
|
|
2
2
|
import checkModulusLength from './check_modulus_length.js';
|
|
3
|
-
import { isCryptoKey
|
|
3
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
4
|
+
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
4
5
|
import isKeyObject from './is_key_object.js';
|
|
5
|
-
import invalidKeyInput from '
|
|
6
|
+
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
6
7
|
const checkKey = (key, alg) => {
|
|
7
8
|
if (key.asymmetricKeyType !== 'rsa') {
|
|
8
9
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
@@ -41,7 +42,8 @@ function ensureKeyObject(key, alg, ...usages) {
|
|
|
41
42
|
return key;
|
|
42
43
|
}
|
|
43
44
|
if (isCryptoKey(key)) {
|
|
44
|
-
|
|
45
|
+
checkEncCryptoKey(key, alg, ...usages);
|
|
46
|
+
return KeyObject.from(key);
|
|
45
47
|
}
|
|
46
48
|
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey'));
|
|
47
49
|
}
|
|
@@ -6,150 +6,3 @@ export const isCryptoKey = util.types.isCryptoKey
|
|
|
6
6
|
? (obj) => util.types.isCryptoKey(obj)
|
|
7
7
|
:
|
|
8
8
|
(obj) => false;
|
|
9
|
-
function getHashLength(hash) {
|
|
10
|
-
return parseInt(hash === null || hash === void 0 ? void 0 : hash.name.substr(4), 10);
|
|
11
|
-
}
|
|
12
|
-
function getNamedCurve(alg) {
|
|
13
|
-
switch (alg) {
|
|
14
|
-
case 'ES256':
|
|
15
|
-
return 'P-256';
|
|
16
|
-
case 'ES384':
|
|
17
|
-
return 'P-384';
|
|
18
|
-
case 'ES512':
|
|
19
|
-
return 'P-521';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export function getKeyObject(key, alg, usage) {
|
|
23
|
-
switch (alg) {
|
|
24
|
-
case undefined:
|
|
25
|
-
break;
|
|
26
|
-
case 'HS256':
|
|
27
|
-
case 'HS384':
|
|
28
|
-
case 'HS512': {
|
|
29
|
-
if (key.algorithm.name !== 'HMAC') {
|
|
30
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be HMAC.`);
|
|
31
|
-
}
|
|
32
|
-
const expected = parseInt(alg.substr(2), 10);
|
|
33
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
34
|
-
if (actual !== expected) {
|
|
35
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
case 'RS256':
|
|
40
|
-
case 'RS384':
|
|
41
|
-
case 'RS512': {
|
|
42
|
-
if (key.algorithm.name !== 'RSASSA-PKCS1-v1_5') {
|
|
43
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSASSA-PKCS1-v1_5.`);
|
|
44
|
-
}
|
|
45
|
-
const expected = parseInt(alg.substr(2), 10);
|
|
46
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
47
|
-
if (actual !== expected) {
|
|
48
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
case 'PS256':
|
|
53
|
-
case 'PS384':
|
|
54
|
-
case 'PS512': {
|
|
55
|
-
if (key.algorithm.name !== 'RSA-PSS') {
|
|
56
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSA-PSS.`);
|
|
57
|
-
}
|
|
58
|
-
const expected = parseInt(alg.substr(2), 10);
|
|
59
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
60
|
-
if (actual !== expected) {
|
|
61
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case 'EdDSA': {
|
|
66
|
-
if (key.algorithm.name !== 'NODE-ED25519' && key.algorithm.name !== 'NODE-ED448') {
|
|
67
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be NODE-ED25519 or NODE-ED448.`);
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
case 'ES256':
|
|
72
|
-
case 'ES384':
|
|
73
|
-
case 'ES512': {
|
|
74
|
-
if (key.algorithm.name !== 'ECDSA') {
|
|
75
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be ECDSA.`);
|
|
76
|
-
}
|
|
77
|
-
const expected = getNamedCurve(alg);
|
|
78
|
-
const actual = key.algorithm.namedCurve;
|
|
79
|
-
if (actual !== expected) {
|
|
80
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.namedCurve must be ${expected}.`);
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case 'A128GCM':
|
|
85
|
-
case 'A192GCM':
|
|
86
|
-
case 'A256GCM': {
|
|
87
|
-
if (key.algorithm.name !== 'AES-GCM') {
|
|
88
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be AES-GCM.`);
|
|
89
|
-
}
|
|
90
|
-
const expected = parseInt(alg.substr(1, 3), 10);
|
|
91
|
-
const actual = key.algorithm.length;
|
|
92
|
-
if (actual !== expected) {
|
|
93
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.length must be ${expected}.`);
|
|
94
|
-
}
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
case 'A128KW':
|
|
98
|
-
case 'A192KW':
|
|
99
|
-
case 'A256KW': {
|
|
100
|
-
if (key.algorithm.name !== 'AES-KW') {
|
|
101
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be AES-KW.`);
|
|
102
|
-
}
|
|
103
|
-
const expected = parseInt(alg.substr(1, 3), 10);
|
|
104
|
-
const actual = key.algorithm.length;
|
|
105
|
-
if (actual !== expected) {
|
|
106
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.length must be ${expected}.`);
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
case 'ECDH-ES':
|
|
111
|
-
if (key.algorithm.name !== 'ECDH') {
|
|
112
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be ECDH.`);
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
case 'PBES2-HS256+A128KW':
|
|
116
|
-
case 'PBES2-HS384+A192KW':
|
|
117
|
-
case 'PBES2-HS512+A256KW':
|
|
118
|
-
if (key.algorithm.name !== 'PBKDF2') {
|
|
119
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be PBKDF2.`);
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
case 'RSA-OAEP':
|
|
123
|
-
case 'RSA-OAEP-256':
|
|
124
|
-
case 'RSA-OAEP-384':
|
|
125
|
-
case 'RSA-OAEP-512': {
|
|
126
|
-
if (key.algorithm.name !== 'RSA-OAEP') {
|
|
127
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSA-OAEP.`);
|
|
128
|
-
}
|
|
129
|
-
const expected = parseInt(alg.substr(9), 10) || 1;
|
|
130
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
131
|
-
if (actual !== expected) {
|
|
132
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
default:
|
|
137
|
-
throw new TypeError('CryptoKey does not support this operation');
|
|
138
|
-
}
|
|
139
|
-
if (usage && !key.usages.find(Set.prototype.has.bind(usage))) {
|
|
140
|
-
const usages = [...usage];
|
|
141
|
-
let msg = 'CryptoKey does not support this operation, its usages must include ';
|
|
142
|
-
if (usages.length > 2) {
|
|
143
|
-
const last = usages.pop();
|
|
144
|
-
msg += `one of ${usages.join(', ')}, or ${last}.`;
|
|
145
|
-
}
|
|
146
|
-
else if (usages.length === 2) {
|
|
147
|
-
msg += `one of ${usages[0]} or ${usages[1]}.`;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
msg += ` ${usages[0]}.`;
|
|
151
|
-
}
|
|
152
|
-
throw new TypeError(msg);
|
|
153
|
-
}
|
|
154
|
-
return crypto.KeyObject.from(key);
|
|
155
|
-
}
|
|
@@ -4,4 +4,8 @@ export interface RemoteJWKSetOptions {
|
|
|
4
4
|
cooldownDuration?: number;
|
|
5
5
|
agent?: any;
|
|
6
6
|
}
|
|
7
|
+
interface URL {
|
|
8
|
+
href: string;
|
|
9
|
+
}
|
|
7
10
|
export declare function createRemoteJWKSet(url: URL, options?: RemoteJWKSetOptions): GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput>;
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jose",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
@@ -68,6 +68,9 @@
|
|
|
68
68
|
"dist/**/package.json",
|
|
69
69
|
"dist/**/*.js",
|
|
70
70
|
"dist/types/**/*.d.ts",
|
|
71
|
+
"!dist/**/*.bundle.js",
|
|
72
|
+
"!dist/**/*.umd.js",
|
|
73
|
+
"!dist/**/*.min.js",
|
|
71
74
|
"!dist/node/webcrypto/**/*",
|
|
72
75
|
"!dist/types/runtime/*",
|
|
73
76
|
"!dist/types/lib/*"
|