jose 5.9.6 → 6.0.0
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/README.md +21 -19
- package/dist/types/index.d.ts +5 -5
- package/dist/types/jwe/compact/decrypt.d.ts +4 -4
- package/dist/types/jwe/compact/encrypt.d.ts +4 -4
- package/dist/types/jwe/flattened/decrypt.d.ts +4 -4
- package/dist/types/jwe/flattened/encrypt.d.ts +6 -6
- package/dist/types/jwe/general/decrypt.d.ts +4 -4
- package/dist/types/jwe/general/encrypt.d.ts +7 -7
- package/dist/types/jwk/embedded.d.ts +2 -2
- package/dist/types/jwk/thumbprint.d.ts +5 -5
- package/dist/types/jwks/local.d.ts +2 -2
- package/dist/types/jwks/remote.d.ts +104 -25
- package/dist/types/jws/compact/sign.d.ts +4 -4
- package/dist/types/jws/compact/verify.d.ts +4 -4
- package/dist/types/jws/flattened/sign.d.ts +4 -4
- package/dist/types/jws/flattened/verify.d.ts +4 -4
- package/dist/types/jws/general/sign.d.ts +6 -6
- package/dist/types/jws/general/verify.d.ts +4 -4
- package/dist/types/jwt/decrypt.d.ts +5 -5
- package/dist/types/jwt/encrypt.d.ts +4 -4
- package/dist/types/jwt/produce.d.ts +3 -3
- package/dist/types/jwt/sign.d.ts +3 -3
- package/dist/types/jwt/unsecured.d.ts +5 -5
- package/dist/types/jwt/verify.d.ts +5 -5
- package/dist/types/key/export.d.ts +10 -12
- package/dist/types/key/generate_key_pair.d.ts +10 -11
- package/dist/types/key/generate_secret.d.ts +6 -9
- package/dist/types/key/import.d.ts +20 -27
- package/dist/types/types.d.ts +38 -59
- package/dist/types/util/decode_jwt.d.ts +2 -2
- package/dist/types/util/decode_protected_header.d.ts +2 -2
- package/dist/types/util/errors.d.ts +6 -6
- package/dist/{browser → webapi}/index.js +2 -2
- package/dist/{node/esm → webapi}/jwe/flattened/decrypt.js +8 -4
- package/dist/{node/esm → webapi}/jwe/flattened/encrypt.js +7 -3
- package/dist/{node/esm → webapi}/jwe/general/encrypt.js +8 -3
- package/dist/{node/esm → webapi}/jwk/thumbprint.js +18 -8
- package/dist/{node/esm → webapi}/jwks/local.js +4 -6
- package/dist/{node/esm → webapi}/jwks/remote.js +34 -6
- package/dist/{node/esm → webapi}/jws/flattened/sign.js +7 -5
- package/dist/{browser → webapi}/jws/flattened/verify.js +8 -14
- package/dist/{browser → webapi}/jwt/unsecured.js +1 -1
- package/dist/{node/esm → webapi}/key/export.js +2 -3
- package/dist/{browser/runtime/generate.js → webapi/key/generate_key_pair.js} +5 -54
- package/dist/webapi/key/generate_secret.js +40 -0
- package/dist/{browser → webapi}/key/import.js +9 -7
- package/dist/{node/esm → webapi}/lib/aesgcmkw.js +3 -3
- package/dist/{browser/runtime → webapi/lib}/aeskw.js +9 -16
- package/dist/{browser/runtime → webapi/lib}/asn1.js +25 -17
- package/dist/{browser/runtime → webapi/lib}/base64url.js +17 -9
- package/dist/{browser → webapi}/lib/buffer_utils.js +4 -19
- package/dist/{browser → webapi}/lib/cek.js +1 -2
- package/dist/{browser/runtime → webapi/lib}/check_cek_length.js +1 -2
- package/dist/{browser → webapi}/lib/check_iv_length.js +1 -2
- package/dist/webapi/lib/check_key_type.js +126 -0
- package/dist/{node/esm → webapi}/lib/crypto_key.js +11 -23
- package/dist/{browser/runtime → webapi/lib}/decrypt.js +26 -10
- package/dist/{node/esm → webapi}/lib/decrypt_key_management.js +22 -24
- package/dist/{browser/runtime → webapi/lib}/digest.js +1 -3
- package/dist/webapi/lib/ecdhes.js +46 -0
- package/dist/{browser/runtime → webapi/lib}/encrypt.js +8 -10
- package/dist/{node/esm → webapi}/lib/encrypt_key_management.js +26 -23
- package/dist/webapi/lib/get_sign_verify_key.js +12 -0
- package/dist/{node/esm → webapi}/lib/is_disjoint.js +1 -2
- package/dist/{browser → webapi}/lib/is_jwk.js +1 -1
- package/dist/webapi/lib/is_key_like.js +14 -0
- package/dist/{browser → webapi}/lib/is_object.js +2 -2
- package/dist/{node/esm → webapi}/lib/iv.js +1 -2
- package/dist/{browser/runtime → webapi/lib}/jwk_to_key.js +4 -10
- package/dist/webapi/lib/key_to_jwk.js +27 -0
- package/dist/webapi/lib/normalize_key.js +164 -0
- package/dist/webapi/lib/pbes2kw.js +37 -0
- package/dist/webapi/lib/rsaes.js +24 -0
- package/dist/{browser/runtime → webapi/lib}/sign.js +1 -3
- package/dist/{browser/runtime → webapi/lib}/subtle_dsa.js +5 -4
- package/dist/{browser → webapi}/lib/validate_algorithms.js +1 -2
- package/dist/{node/esm → webapi}/lib/validate_crit.js +3 -4
- package/dist/{browser/runtime → webapi/lib}/verify.js +1 -3
- package/dist/{node/esm → webapi}/util/base64url.js +1 -1
- package/package.json +36 -219
- package/dist/browser/jwe/compact/encrypt.js +0 -26
- package/dist/browser/jwe/flattened/decrypt.js +0 -161
- package/dist/browser/jwe/flattened/encrypt.js +0 -153
- package/dist/browser/jwe/general/encrypt.js +0 -174
- package/dist/browser/jwk/thumbprint.js +0 -53
- package/dist/browser/jwks/local.js +0 -121
- package/dist/browser/jwks/remote.js +0 -139
- package/dist/browser/jws/compact/sign.js +0 -17
- package/dist/browser/jws/flattened/sign.js +0 -81
- package/dist/browser/jws/general/sign.js +0 -67
- package/dist/browser/jwt/encrypt.js +0 -68
- package/dist/browser/jwt/produce.js +0 -75
- package/dist/browser/jwt/sign.js +0 -20
- package/dist/browser/key/export.js +0 -12
- package/dist/browser/key/generate_key_pair.js +0 -4
- package/dist/browser/key/generate_secret.js +0 -4
- package/dist/browser/lib/aesgcmkw.js +0 -16
- package/dist/browser/lib/check_key_type.js +0 -77
- package/dist/browser/lib/check_p2s.js +0 -6
- package/dist/browser/lib/crypto_key.js +0 -152
- package/dist/browser/lib/decrypt_key_management.js +0 -129
- package/dist/browser/lib/encrypt_key_management.js +0 -89
- package/dist/browser/lib/format_pem.js +0 -4
- package/dist/browser/lib/is_disjoint.js +0 -22
- package/dist/browser/lib/iv.js +0 -20
- package/dist/browser/lib/validate_crit.js +0 -34
- package/dist/browser/package.json +0 -1
- package/dist/browser/runtime/bogus.js +0 -6
- package/dist/browser/runtime/ecdhes.js +0 -47
- package/dist/browser/runtime/fetch_jwks.js +0 -34
- package/dist/browser/runtime/get_sign_verify_key.js +0 -24
- package/dist/browser/runtime/is_key_like.js +0 -8
- package/dist/browser/runtime/key_to_jwk.js +0 -21
- package/dist/browser/runtime/normalize_key.js +0 -68
- package/dist/browser/runtime/pbes2kw.js +0 -51
- package/dist/browser/runtime/random.js +0 -2
- package/dist/browser/runtime/rsaes.js +0 -37
- package/dist/browser/runtime/runtime.js +0 -1
- package/dist/browser/runtime/subtle_rsaes.js +0 -12
- package/dist/browser/runtime/timing_safe_equal.js +0 -19
- package/dist/browser/runtime/webcrypto.js +0 -2
- package/dist/browser/util/base64url.js +0 -3
- package/dist/browser/util/errors.js +0 -114
- package/dist/browser/util/runtime.js +0 -2
- package/dist/node/cjs/index.js +0 -69
- package/dist/node/cjs/jwe/compact/decrypt.js +0 -30
- package/dist/node/cjs/jwe/compact/encrypt.js +0 -31
- package/dist/node/cjs/jwe/flattened/decrypt.js +0 -164
- package/dist/node/cjs/jwe/flattened/encrypt.js +0 -165
- package/dist/node/cjs/jwe/general/decrypt.js +0 -34
- package/dist/node/cjs/jwe/general/encrypt.js +0 -186
- package/dist/node/cjs/jwk/embedded.js +0 -20
- package/dist/node/cjs/jwk/thumbprint.js +0 -57
- package/dist/node/cjs/jwks/local.js +0 -125
- package/dist/node/cjs/jwks/remote.js +0 -152
- package/dist/node/cjs/jws/compact/sign.js +0 -22
- package/dist/node/cjs/jws/compact/verify.js +0 -24
- package/dist/node/cjs/jws/flattened/sign.js +0 -88
- package/dist/node/cjs/jws/flattened/verify.js +0 -125
- package/dist/node/cjs/jws/general/sign.js +0 -77
- package/dist/node/cjs/jws/general/verify.js +0 -27
- package/dist/node/cjs/jwt/decrypt.js +0 -26
- package/dist/node/cjs/jwt/encrypt.js +0 -79
- package/dist/node/cjs/jwt/produce.js +0 -80
- package/dist/node/cjs/jwt/sign.js +0 -25
- package/dist/node/cjs/jwt/unsecured.js +0 -36
- package/dist/node/cjs/jwt/verify.js +0 -18
- package/dist/node/cjs/key/export.js +0 -17
- package/dist/node/cjs/key/generate_key_pair.js +0 -7
- package/dist/node/cjs/key/generate_secret.js +0 -7
- package/dist/node/cjs/key/import.js +0 -51
- package/dist/node/cjs/lib/aesgcmkw.js +0 -20
- package/dist/node/cjs/lib/buffer_utils.js +0 -60
- package/dist/node/cjs/lib/cek.js +0 -23
- package/dist/node/cjs/lib/check_iv_length.js +0 -10
- package/dist/node/cjs/lib/check_key_type.js +0 -80
- package/dist/node/cjs/lib/check_p2s.js +0 -9
- package/dist/node/cjs/lib/crypto_key.js +0 -156
- package/dist/node/cjs/lib/decrypt_key_management.js +0 -131
- package/dist/node/cjs/lib/encrypt_key_management.js +0 -91
- package/dist/node/cjs/lib/epoch.js +0 -3
- package/dist/node/cjs/lib/invalid_key_input.js +0 -34
- package/dist/node/cjs/lib/is_disjoint.js +0 -24
- package/dist/node/cjs/lib/is_jwk.js +0 -19
- package/dist/node/cjs/lib/is_object.js +0 -19
- package/dist/node/cjs/lib/iv.js +0 -23
- package/dist/node/cjs/lib/jwt_claims_set.js +0 -106
- package/dist/node/cjs/lib/private_symbols.js +0 -4
- package/dist/node/cjs/lib/secs.js +0 -57
- package/dist/node/cjs/lib/validate_algorithms.js +0 -13
- package/dist/node/cjs/lib/validate_crit.js +0 -36
- package/dist/node/cjs/runtime/aeskw.js +0 -55
- package/dist/node/cjs/runtime/asn1.js +0 -54
- package/dist/node/cjs/runtime/base64url.js +0 -20
- package/dist/node/cjs/runtime/cbc_tag.js +0 -11
- package/dist/node/cjs/runtime/check_cek_length.js +0 -37
- package/dist/node/cjs/runtime/check_key_length.js +0 -18
- package/dist/node/cjs/runtime/ciphers.js +0 -8
- package/dist/node/cjs/runtime/decrypt.js +0 -103
- package/dist/node/cjs/runtime/digest.js +0 -5
- package/dist/node/cjs/runtime/dsa_digest.js +0 -25
- package/dist/node/cjs/runtime/ecdhes.js +0 -70
- package/dist/node/cjs/runtime/encrypt.js +0 -80
- package/dist/node/cjs/runtime/fetch_jwks.js +0 -45
- package/dist/node/cjs/runtime/generate.js +0 -101
- package/dist/node/cjs/runtime/get_named_curve.js +0 -61
- package/dist/node/cjs/runtime/get_sign_verify_key.js +0 -31
- package/dist/node/cjs/runtime/hmac_digest.js +0 -16
- package/dist/node/cjs/runtime/is_key_like.js +0 -11
- package/dist/node/cjs/runtime/is_key_object.js +0 -4
- package/dist/node/cjs/runtime/jwk_to_key.js +0 -10
- package/dist/node/cjs/runtime/key_to_jwk.js +0 -36
- package/dist/node/cjs/runtime/node_key.js +0 -106
- package/dist/node/cjs/runtime/normalize_key.js +0 -3
- package/dist/node/cjs/runtime/pbes2kw.js +0 -48
- package/dist/node/cjs/runtime/random.js +0 -5
- package/dist/node/cjs/runtime/rsaes.js +0 -71
- package/dist/node/cjs/runtime/runtime.js +0 -3
- package/dist/node/cjs/runtime/sign.js +0 -19
- package/dist/node/cjs/runtime/timing_safe_equal.js +0 -5
- package/dist/node/cjs/runtime/verify.js +0 -31
- package/dist/node/cjs/runtime/webcrypto.js +0 -9
- package/dist/node/cjs/util/base64url.js +0 -6
- package/dist/node/cjs/util/decode_jwt.js +0 -35
- package/dist/node/cjs/util/decode_protected_header.js +0 -37
- package/dist/node/cjs/util/errors.js +0 -117
- package/dist/node/cjs/util/runtime.js +0 -4
- package/dist/node/esm/index.js +0 -30
- package/dist/node/esm/jwe/compact/decrypt.js +0 -27
- package/dist/node/esm/jwe/general/decrypt.js +0 -31
- package/dist/node/esm/jwk/embedded.js +0 -17
- package/dist/node/esm/jws/compact/verify.js +0 -21
- package/dist/node/esm/jws/flattened/verify.js +0 -122
- package/dist/node/esm/jws/general/verify.js +0 -24
- package/dist/node/esm/jwt/decrypt.js +0 -23
- package/dist/node/esm/jwt/unsecured.js +0 -32
- package/dist/node/esm/jwt/verify.js +0 -15
- package/dist/node/esm/key/generate_key_pair.js +0 -4
- package/dist/node/esm/key/generate_secret.js +0 -4
- package/dist/node/esm/key/import.js +0 -45
- package/dist/node/esm/lib/buffer_utils.js +0 -51
- package/dist/node/esm/lib/cek.js +0 -20
- package/dist/node/esm/lib/check_iv_length.js +0 -8
- package/dist/node/esm/lib/check_key_type.js +0 -77
- package/dist/node/esm/lib/check_p2s.js +0 -6
- package/dist/node/esm/lib/epoch.js +0 -1
- package/dist/node/esm/lib/invalid_key_input.js +0 -31
- package/dist/node/esm/lib/is_jwk.js +0 -13
- package/dist/node/esm/lib/is_object.js +0 -16
- package/dist/node/esm/lib/jwt_claims_set.js +0 -104
- package/dist/node/esm/lib/private_symbols.js +0 -1
- package/dist/node/esm/lib/secs.js +0 -55
- package/dist/node/esm/lib/validate_algorithms.js +0 -11
- package/dist/node/esm/package.json +0 -1
- package/dist/node/esm/runtime/aeskw.js +0 -50
- package/dist/node/esm/runtime/asn1.js +0 -46
- package/dist/node/esm/runtime/base64url.js +0 -14
- package/dist/node/esm/runtime/cbc_tag.js +0 -8
- package/dist/node/esm/runtime/check_cek_length.js +0 -35
- package/dist/node/esm/runtime/check_key_length.js +0 -16
- package/dist/node/esm/runtime/ciphers.js +0 -6
- package/dist/node/esm/runtime/decrypt.js +0 -101
- package/dist/node/esm/runtime/digest.js +0 -3
- package/dist/node/esm/runtime/dsa_digest.js +0 -22
- package/dist/node/esm/runtime/ecdhes.js +0 -64
- package/dist/node/esm/runtime/encrypt.js +0 -78
- package/dist/node/esm/runtime/fetch_jwks.js +0 -43
- package/dist/node/esm/runtime/generate.js +0 -97
- package/dist/node/esm/runtime/get_named_curve.js +0 -58
- package/dist/node/esm/runtime/get_sign_verify_key.js +0 -28
- package/dist/node/esm/runtime/hmac_digest.js +0 -13
- package/dist/node/esm/runtime/is_key_like.js +0 -8
- package/dist/node/esm/runtime/is_key_object.js +0 -2
- package/dist/node/esm/runtime/jwk_to_key.js +0 -8
- package/dist/node/esm/runtime/key_to_jwk.js +0 -34
- package/dist/node/esm/runtime/node_key.js +0 -103
- package/dist/node/esm/runtime/normalize_key.js +0 -1
- package/dist/node/esm/runtime/pbes2kw.js +0 -43
- package/dist/node/esm/runtime/random.js +0 -1
- package/dist/node/esm/runtime/rsaes.js +0 -66
- package/dist/node/esm/runtime/runtime.js +0 -1
- package/dist/node/esm/runtime/sign.js +0 -17
- package/dist/node/esm/runtime/timing_safe_equal.js +0 -3
- package/dist/node/esm/runtime/verify.js +0 -29
- package/dist/node/esm/runtime/webcrypto.js +0 -5
- package/dist/node/esm/util/decode_jwt.js +0 -32
- package/dist/node/esm/util/decode_protected_header.js +0 -34
- package/dist/node/esm/util/runtime.js +0 -2
- package/dist/types/util/runtime.d.ts +0 -3
- /package/dist/{browser → webapi}/jwe/compact/decrypt.js +0 -0
- /package/dist/{node/esm → webapi}/jwe/compact/encrypt.js +0 -0
- /package/dist/{browser → webapi}/jwe/general/decrypt.js +0 -0
- /package/dist/{browser → webapi}/jwk/embedded.js +0 -0
- /package/dist/{node/esm → webapi}/jws/compact/sign.js +0 -0
- /package/dist/{browser → webapi}/jws/compact/verify.js +0 -0
- /package/dist/{node/esm → webapi}/jws/general/sign.js +0 -0
- /package/dist/{browser → webapi}/jws/general/verify.js +0 -0
- /package/dist/{browser → webapi}/jwt/decrypt.js +0 -0
- /package/dist/{node/esm → webapi}/jwt/encrypt.js +0 -0
- /package/dist/{node/esm → webapi}/jwt/produce.js +0 -0
- /package/dist/{node/esm → webapi}/jwt/sign.js +0 -0
- /package/dist/{browser → webapi}/jwt/verify.js +0 -0
- /package/dist/{browser/runtime → webapi/lib}/check_key_length.js +0 -0
- /package/dist/{browser → webapi}/lib/epoch.js +0 -0
- /package/dist/{browser → webapi}/lib/invalid_key_input.js +0 -0
- /package/dist/{browser → webapi}/lib/jwt_claims_set.js +0 -0
- /package/dist/{browser → webapi}/lib/private_symbols.js +0 -0
- /package/dist/{browser → webapi}/lib/secs.js +0 -0
- /package/dist/{browser → webapi}/util/decode_jwt.js +0 -0
- /package/dist/{browser → webapi}/util/decode_protected_header.js +0 -0
- /package/dist/{node/esm → webapi}/util/errors.js +0 -0
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import digest from '../runtime/digest.js';
|
|
2
|
-
export const encoder = new TextEncoder();
|
|
3
|
-
export const decoder = new TextDecoder();
|
|
4
|
-
const MAX_INT32 = 2 ** 32;
|
|
5
|
-
export function concat(...buffers) {
|
|
6
|
-
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
7
|
-
const buf = new Uint8Array(size);
|
|
8
|
-
let i = 0;
|
|
9
|
-
for (const buffer of buffers) {
|
|
10
|
-
buf.set(buffer, i);
|
|
11
|
-
i += buffer.length;
|
|
12
|
-
}
|
|
13
|
-
return buf;
|
|
14
|
-
}
|
|
15
|
-
export function p2s(alg, p2sInput) {
|
|
16
|
-
return concat(encoder.encode(alg), new Uint8Array([0]), p2sInput);
|
|
17
|
-
}
|
|
18
|
-
function writeUInt32BE(buf, value, offset) {
|
|
19
|
-
if (value < 0 || value >= MAX_INT32) {
|
|
20
|
-
throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
|
|
21
|
-
}
|
|
22
|
-
buf.set([value >>> 24, value >>> 16, value >>> 8, value & 0xff], offset);
|
|
23
|
-
}
|
|
24
|
-
export function uint64be(value) {
|
|
25
|
-
const high = Math.floor(value / MAX_INT32);
|
|
26
|
-
const low = value % MAX_INT32;
|
|
27
|
-
const buf = new Uint8Array(8);
|
|
28
|
-
writeUInt32BE(buf, high, 0);
|
|
29
|
-
writeUInt32BE(buf, low, 4);
|
|
30
|
-
return buf;
|
|
31
|
-
}
|
|
32
|
-
export function uint32be(value) {
|
|
33
|
-
const buf = new Uint8Array(4);
|
|
34
|
-
writeUInt32BE(buf, value);
|
|
35
|
-
return buf;
|
|
36
|
-
}
|
|
37
|
-
export function lengthAndInput(input) {
|
|
38
|
-
return concat(uint32be(input.length), input);
|
|
39
|
-
}
|
|
40
|
-
export async function concatKdf(secret, bits, value) {
|
|
41
|
-
const iterations = Math.ceil((bits >> 3) / 32);
|
|
42
|
-
const res = new Uint8Array(iterations * 32);
|
|
43
|
-
for (let iter = 0; iter < iterations; iter++) {
|
|
44
|
-
const buf = new Uint8Array(4 + secret.length + value.length);
|
|
45
|
-
buf.set(uint32be(iter + 1));
|
|
46
|
-
buf.set(secret, 4);
|
|
47
|
-
buf.set(value, 4 + secret.length);
|
|
48
|
-
res.set(await digest('sha256', buf), iter * 32);
|
|
49
|
-
}
|
|
50
|
-
return res.slice(0, bits >> 3);
|
|
51
|
-
}
|
package/dist/node/esm/lib/cek.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { JOSENotSupported } from '../util/errors.js';
|
|
2
|
-
import random from '../runtime/random.js';
|
|
3
|
-
export function bitLength(alg) {
|
|
4
|
-
switch (alg) {
|
|
5
|
-
case 'A128GCM':
|
|
6
|
-
return 128;
|
|
7
|
-
case 'A192GCM':
|
|
8
|
-
return 192;
|
|
9
|
-
case 'A256GCM':
|
|
10
|
-
case 'A128CBC-HS256':
|
|
11
|
-
return 256;
|
|
12
|
-
case 'A192CBC-HS384':
|
|
13
|
-
return 384;
|
|
14
|
-
case 'A256CBC-HS512':
|
|
15
|
-
return 512;
|
|
16
|
-
default:
|
|
17
|
-
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export default (alg) => random(new Uint8Array(bitLength(alg) >> 3));
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { JWEInvalid } from '../util/errors.js';
|
|
2
|
-
import { bitLength } from './iv.js';
|
|
3
|
-
const checkIvLength = (enc, iv) => {
|
|
4
|
-
if (iv.length << 3 !== bitLength(enc)) {
|
|
5
|
-
throw new JWEInvalid('Invalid Initialization Vector length');
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
export default checkIvLength;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { withAlg as invalidKeyInput } from './invalid_key_input.js';
|
|
2
|
-
import isKeyLike, { types } from '../runtime/is_key_like.js';
|
|
3
|
-
import * as jwk from './is_jwk.js';
|
|
4
|
-
const tag = (key) => key?.[Symbol.toStringTag];
|
|
5
|
-
const jwkMatchesOp = (alg, key, usage) => {
|
|
6
|
-
if (key.use !== undefined && key.use !== 'sig') {
|
|
7
|
-
throw new TypeError('Invalid key for this operation, when present its use must be sig');
|
|
8
|
-
}
|
|
9
|
-
if (key.key_ops !== undefined && key.key_ops.includes?.(usage) !== true) {
|
|
10
|
-
throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${usage}`);
|
|
11
|
-
}
|
|
12
|
-
if (key.alg !== undefined && key.alg !== alg) {
|
|
13
|
-
throw new TypeError(`Invalid key for this operation, when present its alg must be ${alg}`);
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
};
|
|
17
|
-
const symmetricTypeCheck = (alg, key, usage, allowJwk) => {
|
|
18
|
-
if (key instanceof Uint8Array)
|
|
19
|
-
return;
|
|
20
|
-
if (allowJwk && jwk.isJWK(key)) {
|
|
21
|
-
if (jwk.isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
22
|
-
return;
|
|
23
|
-
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
24
|
-
}
|
|
25
|
-
if (!isKeyLike(key)) {
|
|
26
|
-
throw new TypeError(invalidKeyInput(alg, key, ...types, 'Uint8Array', allowJwk ? 'JSON Web Key' : null));
|
|
27
|
-
}
|
|
28
|
-
if (key.type !== 'secret') {
|
|
29
|
-
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const asymmetricTypeCheck = (alg, key, usage, allowJwk) => {
|
|
33
|
-
if (allowJwk && jwk.isJWK(key)) {
|
|
34
|
-
switch (usage) {
|
|
35
|
-
case 'sign':
|
|
36
|
-
if (jwk.isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
37
|
-
return;
|
|
38
|
-
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
|
39
|
-
case 'verify':
|
|
40
|
-
if (jwk.isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
41
|
-
return;
|
|
42
|
-
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!isKeyLike(key)) {
|
|
46
|
-
throw new TypeError(invalidKeyInput(alg, key, ...types, allowJwk ? 'JSON Web Key' : null));
|
|
47
|
-
}
|
|
48
|
-
if (key.type === 'secret') {
|
|
49
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
50
|
-
}
|
|
51
|
-
if (usage === 'sign' && key.type === 'public') {
|
|
52
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
53
|
-
}
|
|
54
|
-
if (usage === 'decrypt' && key.type === 'public') {
|
|
55
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
56
|
-
}
|
|
57
|
-
if (key.algorithm && usage === 'verify' && key.type === 'private') {
|
|
58
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
59
|
-
}
|
|
60
|
-
if (key.algorithm && usage === 'encrypt' && key.type === 'private') {
|
|
61
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
function checkKeyType(allowJwk, alg, key, usage) {
|
|
65
|
-
const symmetric = alg.startsWith('HS') ||
|
|
66
|
-
alg === 'dir' ||
|
|
67
|
-
alg.startsWith('PBES2') ||
|
|
68
|
-
/^A\d{3}(?:GCM)?KW$/.test(alg);
|
|
69
|
-
if (symmetric) {
|
|
70
|
-
symmetricTypeCheck(alg, key, usage, allowJwk);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
asymmetricTypeCheck(alg, key, usage, allowJwk);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export default checkKeyType.bind(undefined, false);
|
|
77
|
-
export const checkKeyTypeWithJwk = checkKeyType.bind(undefined, true);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default (date) => Math.floor(date.getTime() / 1000);
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
function message(msg, actual, ...types) {
|
|
2
|
-
types = types.filter(Boolean);
|
|
3
|
-
if (types.length > 2) {
|
|
4
|
-
const last = types.pop();
|
|
5
|
-
msg += `one of type ${types.join(', ')}, or ${last}.`;
|
|
6
|
-
}
|
|
7
|
-
else if (types.length === 2) {
|
|
8
|
-
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
msg += `of type ${types[0]}.`;
|
|
12
|
-
}
|
|
13
|
-
if (actual == null) {
|
|
14
|
-
msg += ` Received ${actual}`;
|
|
15
|
-
}
|
|
16
|
-
else if (typeof actual === 'function' && actual.name) {
|
|
17
|
-
msg += ` Received function ${actual.name}`;
|
|
18
|
-
}
|
|
19
|
-
else if (typeof actual === 'object' && actual != null) {
|
|
20
|
-
if (actual.constructor?.name) {
|
|
21
|
-
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return msg;
|
|
25
|
-
}
|
|
26
|
-
export default (actual, ...types) => {
|
|
27
|
-
return message('Key must be ', actual, ...types);
|
|
28
|
-
};
|
|
29
|
-
export function withAlg(alg, actual, ...types) {
|
|
30
|
-
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
31
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import isObject from './is_object.js';
|
|
2
|
-
export function isJWK(key) {
|
|
3
|
-
return isObject(key) && typeof key.kty === 'string';
|
|
4
|
-
}
|
|
5
|
-
export function isPrivateJWK(key) {
|
|
6
|
-
return key.kty !== 'oct' && typeof key.d === 'string';
|
|
7
|
-
}
|
|
8
|
-
export function isPublicJWK(key) {
|
|
9
|
-
return key.kty !== 'oct' && typeof key.d === 'undefined';
|
|
10
|
-
}
|
|
11
|
-
export function isSecretJWK(key) {
|
|
12
|
-
return isJWK(key) && key.kty === 'oct' && typeof key.k === 'string';
|
|
13
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
function isObjectLike(value) {
|
|
2
|
-
return typeof value === 'object' && value !== null;
|
|
3
|
-
}
|
|
4
|
-
export default function isObject(input) {
|
|
5
|
-
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== '[object Object]') {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
if (Object.getPrototypeOf(input) === null) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
let proto = input;
|
|
12
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
13
|
-
proto = Object.getPrototypeOf(proto);
|
|
14
|
-
}
|
|
15
|
-
return Object.getPrototypeOf(input) === proto;
|
|
16
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { JWTClaimValidationFailed, JWTExpired, JWTInvalid } from '../util/errors.js';
|
|
2
|
-
import { decoder } from './buffer_utils.js';
|
|
3
|
-
import epoch from './epoch.js';
|
|
4
|
-
import secs from './secs.js';
|
|
5
|
-
import isObject from './is_object.js';
|
|
6
|
-
const normalizeTyp = (value) => value.toLowerCase().replace(/^application\//, '');
|
|
7
|
-
const checkAudiencePresence = (audPayload, audOption) => {
|
|
8
|
-
if (typeof audPayload === 'string') {
|
|
9
|
-
return audOption.includes(audPayload);
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(audPayload)) {
|
|
12
|
-
return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
15
|
-
};
|
|
16
|
-
export default (protectedHeader, encodedPayload, options = {}) => {
|
|
17
|
-
let payload;
|
|
18
|
-
try {
|
|
19
|
-
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
}
|
|
23
|
-
if (!isObject(payload)) {
|
|
24
|
-
throw new JWTInvalid('JWT Claims Set must be a top-level JSON object');
|
|
25
|
-
}
|
|
26
|
-
const { typ } = options;
|
|
27
|
-
if (typ &&
|
|
28
|
-
(typeof protectedHeader.typ !== 'string' ||
|
|
29
|
-
normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
|
|
30
|
-
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, 'typ', 'check_failed');
|
|
31
|
-
}
|
|
32
|
-
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
33
|
-
const presenceCheck = [...requiredClaims];
|
|
34
|
-
if (maxTokenAge !== undefined)
|
|
35
|
-
presenceCheck.push('iat');
|
|
36
|
-
if (audience !== undefined)
|
|
37
|
-
presenceCheck.push('aud');
|
|
38
|
-
if (subject !== undefined)
|
|
39
|
-
presenceCheck.push('sub');
|
|
40
|
-
if (issuer !== undefined)
|
|
41
|
-
presenceCheck.push('iss');
|
|
42
|
-
for (const claim of new Set(presenceCheck.reverse())) {
|
|
43
|
-
if (!(claim in payload)) {
|
|
44
|
-
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, 'missing');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (issuer &&
|
|
48
|
-
!(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
|
49
|
-
throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, 'iss', 'check_failed');
|
|
50
|
-
}
|
|
51
|
-
if (subject && payload.sub !== subject) {
|
|
52
|
-
throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, 'sub', 'check_failed');
|
|
53
|
-
}
|
|
54
|
-
if (audience &&
|
|
55
|
-
!checkAudiencePresence(payload.aud, typeof audience === 'string' ? [audience] : audience)) {
|
|
56
|
-
throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, 'aud', 'check_failed');
|
|
57
|
-
}
|
|
58
|
-
let tolerance;
|
|
59
|
-
switch (typeof options.clockTolerance) {
|
|
60
|
-
case 'string':
|
|
61
|
-
tolerance = secs(options.clockTolerance);
|
|
62
|
-
break;
|
|
63
|
-
case 'number':
|
|
64
|
-
tolerance = options.clockTolerance;
|
|
65
|
-
break;
|
|
66
|
-
case 'undefined':
|
|
67
|
-
tolerance = 0;
|
|
68
|
-
break;
|
|
69
|
-
default:
|
|
70
|
-
throw new TypeError('Invalid clockTolerance option type');
|
|
71
|
-
}
|
|
72
|
-
const { currentDate } = options;
|
|
73
|
-
const now = epoch(currentDate || new Date());
|
|
74
|
-
if ((payload.iat !== undefined || maxTokenAge) && typeof payload.iat !== 'number') {
|
|
75
|
-
throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, 'iat', 'invalid');
|
|
76
|
-
}
|
|
77
|
-
if (payload.nbf !== undefined) {
|
|
78
|
-
if (typeof payload.nbf !== 'number') {
|
|
79
|
-
throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, 'nbf', 'invalid');
|
|
80
|
-
}
|
|
81
|
-
if (payload.nbf > now + tolerance) {
|
|
82
|
-
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, 'nbf', 'check_failed');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (payload.exp !== undefined) {
|
|
86
|
-
if (typeof payload.exp !== 'number') {
|
|
87
|
-
throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, 'exp', 'invalid');
|
|
88
|
-
}
|
|
89
|
-
if (payload.exp <= now - tolerance) {
|
|
90
|
-
throw new JWTExpired('"exp" claim timestamp check failed', payload, 'exp', 'check_failed');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (maxTokenAge) {
|
|
94
|
-
const age = now - payload.iat;
|
|
95
|
-
const max = typeof maxTokenAge === 'number' ? maxTokenAge : secs(maxTokenAge);
|
|
96
|
-
if (age - tolerance > max) {
|
|
97
|
-
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, 'iat', 'check_failed');
|
|
98
|
-
}
|
|
99
|
-
if (age < 0 - tolerance) {
|
|
100
|
-
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, 'iat', 'check_failed');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return payload;
|
|
104
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const unprotected = Symbol();
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const minute = 60;
|
|
2
|
-
const hour = minute * 60;
|
|
3
|
-
const day = hour * 24;
|
|
4
|
-
const week = day * 7;
|
|
5
|
-
const year = day * 365.25;
|
|
6
|
-
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
7
|
-
export default (str) => {
|
|
8
|
-
const matched = REGEX.exec(str);
|
|
9
|
-
if (!matched || (matched[4] && matched[1])) {
|
|
10
|
-
throw new TypeError('Invalid time period format');
|
|
11
|
-
}
|
|
12
|
-
const value = parseFloat(matched[2]);
|
|
13
|
-
const unit = matched[3].toLowerCase();
|
|
14
|
-
let numericDate;
|
|
15
|
-
switch (unit) {
|
|
16
|
-
case 'sec':
|
|
17
|
-
case 'secs':
|
|
18
|
-
case 'second':
|
|
19
|
-
case 'seconds':
|
|
20
|
-
case 's':
|
|
21
|
-
numericDate = Math.round(value);
|
|
22
|
-
break;
|
|
23
|
-
case 'minute':
|
|
24
|
-
case 'minutes':
|
|
25
|
-
case 'min':
|
|
26
|
-
case 'mins':
|
|
27
|
-
case 'm':
|
|
28
|
-
numericDate = Math.round(value * minute);
|
|
29
|
-
break;
|
|
30
|
-
case 'hour':
|
|
31
|
-
case 'hours':
|
|
32
|
-
case 'hr':
|
|
33
|
-
case 'hrs':
|
|
34
|
-
case 'h':
|
|
35
|
-
numericDate = Math.round(value * hour);
|
|
36
|
-
break;
|
|
37
|
-
case 'day':
|
|
38
|
-
case 'days':
|
|
39
|
-
case 'd':
|
|
40
|
-
numericDate = Math.round(value * day);
|
|
41
|
-
break;
|
|
42
|
-
case 'week':
|
|
43
|
-
case 'weeks':
|
|
44
|
-
case 'w':
|
|
45
|
-
numericDate = Math.round(value * week);
|
|
46
|
-
break;
|
|
47
|
-
default:
|
|
48
|
-
numericDate = Math.round(value * year);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
if (matched[1] === '-' || matched[4] === 'ago') {
|
|
52
|
-
return -numericDate;
|
|
53
|
-
}
|
|
54
|
-
return numericDate;
|
|
55
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const validateAlgorithms = (option, algorithms) => {
|
|
2
|
-
if (algorithms !== undefined &&
|
|
3
|
-
(!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== 'string'))) {
|
|
4
|
-
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
5
|
-
}
|
|
6
|
-
if (!algorithms) {
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
return new Set(algorithms);
|
|
10
|
-
};
|
|
11
|
-
export default validateAlgorithms;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module","sideEffects":false}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
|
-
import { KeyObject, createDecipheriv, createCipheriv, createSecretKey } from 'node:crypto';
|
|
3
|
-
import { JOSENotSupported } from '../util/errors.js';
|
|
4
|
-
import { concat } from '../lib/buffer_utils.js';
|
|
5
|
-
import { isCryptoKey } from './webcrypto.js';
|
|
6
|
-
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
7
|
-
import isKeyObject from './is_key_object.js';
|
|
8
|
-
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
9
|
-
import supported from './ciphers.js';
|
|
10
|
-
import { types } from './is_key_like.js';
|
|
11
|
-
function checkKeySize(key, alg) {
|
|
12
|
-
if (key.symmetricKeySize << 3 !== parseInt(alg.slice(1, 4), 10)) {
|
|
13
|
-
throw new TypeError(`Invalid key size for alg: ${alg}`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function ensureKeyObject(key, alg, usage) {
|
|
17
|
-
if (isKeyObject(key)) {
|
|
18
|
-
return key;
|
|
19
|
-
}
|
|
20
|
-
if (key instanceof Uint8Array) {
|
|
21
|
-
return createSecretKey(key);
|
|
22
|
-
}
|
|
23
|
-
if (isCryptoKey(key)) {
|
|
24
|
-
checkEncCryptoKey(key, alg, usage);
|
|
25
|
-
return KeyObject.from(key);
|
|
26
|
-
}
|
|
27
|
-
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
|
28
|
-
}
|
|
29
|
-
export const wrap = (alg, key, cek) => {
|
|
30
|
-
const size = parseInt(alg.slice(1, 4), 10);
|
|
31
|
-
const algorithm = `aes${size}-wrap`;
|
|
32
|
-
if (!supported(algorithm)) {
|
|
33
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
34
|
-
}
|
|
35
|
-
const keyObject = ensureKeyObject(key, alg, 'wrapKey');
|
|
36
|
-
checkKeySize(keyObject, alg);
|
|
37
|
-
const cipher = createCipheriv(algorithm, keyObject, Buffer.alloc(8, 0xa6));
|
|
38
|
-
return concat(cipher.update(cek), cipher.final());
|
|
39
|
-
};
|
|
40
|
-
export const unwrap = (alg, key, encryptedKey) => {
|
|
41
|
-
const size = parseInt(alg.slice(1, 4), 10);
|
|
42
|
-
const algorithm = `aes${size}-wrap`;
|
|
43
|
-
if (!supported(algorithm)) {
|
|
44
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
45
|
-
}
|
|
46
|
-
const keyObject = ensureKeyObject(key, alg, 'unwrapKey');
|
|
47
|
-
checkKeySize(keyObject, alg);
|
|
48
|
-
const cipher = createDecipheriv(algorithm, keyObject, Buffer.alloc(8, 0xa6));
|
|
49
|
-
return concat(cipher.update(encryptedKey), cipher.final());
|
|
50
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { createPrivateKey, createPublicKey, KeyObject } from 'node:crypto';
|
|
2
|
-
import { Buffer } from 'node:buffer';
|
|
3
|
-
import { isCryptoKey } from './webcrypto.js';
|
|
4
|
-
import isKeyObject from './is_key_object.js';
|
|
5
|
-
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
6
|
-
import { types } from './is_key_like.js';
|
|
7
|
-
const genericExport = (keyType, keyFormat, key) => {
|
|
8
|
-
let keyObject;
|
|
9
|
-
if (isCryptoKey(key)) {
|
|
10
|
-
if (!key.extractable) {
|
|
11
|
-
throw new TypeError('CryptoKey is not extractable');
|
|
12
|
-
}
|
|
13
|
-
keyObject = KeyObject.from(key);
|
|
14
|
-
}
|
|
15
|
-
else if (isKeyObject(key)) {
|
|
16
|
-
keyObject = key;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
throw new TypeError(invalidKeyInput(key, ...types));
|
|
20
|
-
}
|
|
21
|
-
if (keyObject.type !== keyType) {
|
|
22
|
-
throw new TypeError(`key is not a ${keyType} key`);
|
|
23
|
-
}
|
|
24
|
-
return keyObject.export({ format: 'pem', type: keyFormat });
|
|
25
|
-
};
|
|
26
|
-
export const toSPKI = (key) => {
|
|
27
|
-
return genericExport('public', 'spki', key);
|
|
28
|
-
};
|
|
29
|
-
export const toPKCS8 = (key) => {
|
|
30
|
-
return genericExport('private', 'pkcs8', key);
|
|
31
|
-
};
|
|
32
|
-
export const fromPKCS8 = (pem) => createPrivateKey({
|
|
33
|
-
key: Buffer.from(pem.replace(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, ''), 'base64'),
|
|
34
|
-
type: 'pkcs8',
|
|
35
|
-
format: 'der',
|
|
36
|
-
});
|
|
37
|
-
export const fromSPKI = (pem) => createPublicKey({
|
|
38
|
-
key: Buffer.from(pem.replace(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, ''), 'base64'),
|
|
39
|
-
type: 'spki',
|
|
40
|
-
format: 'der',
|
|
41
|
-
});
|
|
42
|
-
export const fromX509 = (pem) => createPublicKey({
|
|
43
|
-
key: pem,
|
|
44
|
-
type: 'spki',
|
|
45
|
-
format: 'pem',
|
|
46
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
|
-
import { decoder } from '../lib/buffer_utils.js';
|
|
3
|
-
function normalize(input) {
|
|
4
|
-
let encoded = input;
|
|
5
|
-
if (encoded instanceof Uint8Array) {
|
|
6
|
-
encoded = decoder.decode(encoded);
|
|
7
|
-
}
|
|
8
|
-
return encoded;
|
|
9
|
-
}
|
|
10
|
-
const encode = (input) => Buffer.from(input).toString('base64url');
|
|
11
|
-
export const decodeBase64 = (input) => new Uint8Array(Buffer.from(input, 'base64'));
|
|
12
|
-
export const encodeBase64 = (input) => Buffer.from(input).toString('base64');
|
|
13
|
-
export { encode };
|
|
14
|
-
export const decode = (input) => new Uint8Array(Buffer.from(normalize(input), 'base64url'));
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createHmac } from 'node:crypto';
|
|
2
|
-
import { concat, uint64be } from '../lib/buffer_utils.js';
|
|
3
|
-
export default function cbcTag(aad, iv, ciphertext, macSize, macKey, keySize) {
|
|
4
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
5
|
-
const hmac = createHmac(`sha${macSize}`, macKey);
|
|
6
|
-
hmac.update(macData);
|
|
7
|
-
return hmac.digest().slice(0, keySize >> 3);
|
|
8
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { JWEInvalid, JOSENotSupported } from '../util/errors.js';
|
|
2
|
-
import isKeyObject from './is_key_object.js';
|
|
3
|
-
const checkCekLength = (enc, cek) => {
|
|
4
|
-
let expected;
|
|
5
|
-
switch (enc) {
|
|
6
|
-
case 'A128CBC-HS256':
|
|
7
|
-
case 'A192CBC-HS384':
|
|
8
|
-
case 'A256CBC-HS512':
|
|
9
|
-
expected = parseInt(enc.slice(-3), 10);
|
|
10
|
-
break;
|
|
11
|
-
case 'A128GCM':
|
|
12
|
-
case 'A192GCM':
|
|
13
|
-
case 'A256GCM':
|
|
14
|
-
expected = parseInt(enc.slice(1, 4), 10);
|
|
15
|
-
break;
|
|
16
|
-
default:
|
|
17
|
-
throw new JOSENotSupported(`Content Encryption Algorithm ${enc} is not supported either by JOSE or your javascript runtime`);
|
|
18
|
-
}
|
|
19
|
-
if (cek instanceof Uint8Array) {
|
|
20
|
-
const actual = cek.byteLength << 3;
|
|
21
|
-
if (actual !== expected) {
|
|
22
|
-
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
23
|
-
}
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (isKeyObject(cek) && cek.type === 'secret') {
|
|
27
|
-
const actual = cek.symmetricKeySize << 3;
|
|
28
|
-
if (actual !== expected) {
|
|
29
|
-
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
30
|
-
}
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
throw new TypeError('Invalid Content Encryption Key type');
|
|
34
|
-
};
|
|
35
|
-
export default checkCekLength;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { KeyObject } from 'node:crypto';
|
|
2
|
-
export default (key, alg) => {
|
|
3
|
-
let modulusLength;
|
|
4
|
-
try {
|
|
5
|
-
if (key instanceof KeyObject) {
|
|
6
|
-
modulusLength = key.asymmetricKeyDetails?.modulusLength;
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
modulusLength = Buffer.from(key.n, 'base64url').byteLength << 3;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
catch { }
|
|
13
|
-
if (typeof modulusLength !== 'number' || modulusLength < 2048) {
|
|
14
|
-
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
15
|
-
}
|
|
16
|
-
};
|