jose 6.2.10 → 6.2.12
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/types/index.d.ts +1 -2
- package/dist/types/jwe/compact/decrypt.d.ts +12 -25
- package/dist/types/jwe/compact/encrypt.d.ts +18 -32
- package/dist/types/jwe/flattened/decrypt.d.ts +12 -25
- package/dist/types/jwe/flattened/encrypt.d.ts +24 -50
- package/dist/types/jwe/general/decrypt.d.ts +15 -30
- package/dist/types/jwe/general/encrypt.d.ts +29 -52
- package/dist/types/jwk/embedded.d.ts +5 -8
- package/dist/types/jwk/thumbprint.d.ts +7 -9
- package/dist/types/jwks/local.d.ts +10 -13
- package/dist/types/jwks/remote.d.ts +29 -41
- package/dist/types/jws/compact/sign.d.ts +8 -13
- package/dist/types/jws/compact/verify.d.ts +14 -26
- package/dist/types/jws/flattened/sign.d.ts +10 -19
- package/dist/types/jws/flattened/verify.d.ts +14 -26
- package/dist/types/jws/general/sign.d.ts +19 -33
- package/dist/types/jws/general/verify.d.ts +17 -32
- package/dist/types/jwt/decrypt.d.ts +20 -27
- package/dist/types/jwt/encrypt.d.ts +30 -35
- package/dist/types/jwt/sign.d.ts +8 -13
- package/dist/types/jwt/unsecured.d.ts +10 -19
- package/dist/types/jwt/verify.d.ts +19 -22
- package/dist/types/key/export.d.ts +10 -10
- package/dist/types/key/generate_key_pair.d.ts +15 -22
- package/dist/types/key/generate_secret.d.ts +12 -19
- package/dist/types/key/import.d.ts +25 -31
- package/dist/types/types.d.ts +184 -319
- package/dist/types/util/base64url.d.ts +7 -7
- package/dist/types/util/decode_jwt.d.ts +5 -7
- package/dist/types/util/decode_protected_header.d.ts +6 -5
- package/dist/types/util/errors.d.ts +50 -88
- package/dist/webapi/index.js +70 -32
- package/dist/webapi/jwe/compact/decrypt.js +6 -8
- package/dist/webapi/jwe/compact/encrypt.js +25 -48
- package/dist/webapi/jwe/flattened/decrypt.js +14 -14
- package/dist/webapi/jwe/flattened/encrypt.js +34 -64
- package/dist/webapi/jwe/general/decrypt.js +38 -49
- package/dist/webapi/jwe/general/encrypt.js +100 -172
- package/dist/webapi/jwk/embedded.js +29 -32
- package/dist/webapi/jwk/thumbprint.js +51 -70
- package/dist/webapi/jwks/local.js +53 -64
- package/dist/webapi/jwks/remote.js +88 -136
- package/dist/webapi/jws/compact/sign.js +19 -21
- package/dist/webapi/jws/compact/verify.js +7 -8
- package/dist/webapi/jws/flattened/sign.js +22 -31
- package/dist/webapi/jws/flattened/verify.js +11 -24
- package/dist/webapi/jws/general/sign.js +55 -73
- package/dist/webapi/jws/general/verify.js +43 -69
- package/dist/webapi/jwt/decrypt.js +12 -20
- package/dist/webapi/jwt/encrypt.js +43 -70
- package/dist/webapi/jwt/sign.js +17 -16
- package/dist/webapi/jwt/unsecured.js +31 -40
- package/dist/webapi/jwt/verify.js +12 -14
- package/dist/webapi/key/export.js +32 -41
- package/dist/webapi/key/generate_key_pair.js +32 -49
- package/dist/webapi/key/generate_secret.js +35 -40
- package/dist/webapi/key/import.js +48 -56
- package/dist/webapi/lib/asn1.js +128 -169
- package/dist/webapi/lib/buffer_utils.js +72 -41
- package/dist/webapi/lib/content_encryption.js +75 -119
- package/dist/webapi/lib/deflate.js +35 -47
- package/dist/webapi/lib/jwe_algorithms.js +102 -93
- package/dist/webapi/lib/jwe_decrypt.js +178 -234
- package/dist/webapi/lib/jwe_encrypt.js +71 -138
- package/dist/webapi/lib/jws_algorithms.js +62 -61
- package/dist/webapi/lib/jws_sign.js +43 -82
- package/dist/webapi/lib/jws_verify.js +78 -131
- package/dist/webapi/lib/jwt_claims_set.js +123 -209
- package/dist/webapi/lib/key.js +147 -139
- package/dist/webapi/lib/key_algorithm.js +13 -8
- package/dist/webapi/lib/key_descriptor.js +8 -6
- package/dist/webapi/lib/key_management.js +169 -235
- package/dist/webapi/lib/validate.js +122 -0
- package/dist/webapi/util/base64url.js +14 -37
- package/dist/webapi/util/decode_jwt.js +32 -31
- package/dist/webapi/util/decode_protected_header.js +18 -23
- package/dist/webapi/util/errors.js +94 -84
- package/package.json +17 -81
- package/dist/webapi/lib/base64.js +0 -22
- package/dist/webapi/lib/crypto_key.js +0 -28
- package/dist/webapi/lib/helpers.js +0 -42
- package/dist/webapi/lib/invalid_key_input.js +0 -26
- package/dist/webapi/lib/is_key_like.js +0 -17
- package/dist/webapi/lib/jwk_metadata.js +0 -20
- package/dist/webapi/lib/jwk_to_key.js +0 -17
- package/dist/webapi/lib/key_options.js +0 -6
- package/dist/webapi/lib/options.js +0 -74
- package/dist/webapi/lib/signing.js +0 -26
- package/dist/webapi/lib/type_checks.js +0 -33
|
@@ -1,134 +1,90 @@
|
|
|
1
|
-
import { concat, uint64be } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { isCryptoKey } from './is_key_like.js';
|
|
6
|
-
export const generateCek = (enc) => crypto.getRandomValues(new Uint8Array(enc.cekBits >> 3));
|
|
1
|
+
import { concat, uint64be } from "./buffer_utils.js";
|
|
2
|
+
import { rawKey, invalidKeyInput, isCryptoKey } from "./key.js";
|
|
3
|
+
import { JWEDecryptionFailed, JWEInvalid } from "../util/errors.js";
|
|
4
|
+
const generateCek = (enc) => crypto.getRandomValues(new Uint8Array(enc.cekBits >> 3));
|
|
7
5
|
function checkCekLength(cek, expected) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
6
|
+
const actual = cek.byteLength << 3;
|
|
7
|
+
if (actual !== expected)
|
|
8
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
10
|
+
const generateIv = (enc) => crypto.getRandomValues(new Uint8Array(enc.ivBits >> 3));
|
|
11
|
+
function checkIvLength(enc, iv) {
|
|
12
|
+
if (iv.length << 3 !== enc.ivBits)
|
|
13
|
+
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
18
14
|
}
|
|
19
15
|
async function cbcKeySetup(enc, cek, usage) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
name: 'HMAC',
|
|
28
|
-
}, false, ['sign']);
|
|
29
|
-
return [encKey, macKey, keySize];
|
|
16
|
+
if (!(cek instanceof Uint8Array))
|
|
17
|
+
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
18
|
+
const keySize = enc.cekBits >> 1, encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", !1, [usage]), macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
19
|
+
hash: `SHA-${keySize << 1}`,
|
|
20
|
+
name: "HMAC"
|
|
21
|
+
}, !1, ["sign"]);
|
|
22
|
+
return [encKey, macKey, keySize];
|
|
30
23
|
}
|
|
31
24
|
async function cbcHmacTag(macKey, macData, keySize) {
|
|
32
|
-
|
|
25
|
+
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
33
26
|
}
|
|
34
27
|
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
|
|
41
|
-
const tag = await cbcHmacTag(macKey, macData, keySize);
|
|
42
|
-
return { ciphertext, tag, iv };
|
|
28
|
+
const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "encrypt"), ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
29
|
+
iv,
|
|
30
|
+
name: "AES-CBC"
|
|
31
|
+
}, encKey, plaintext)), macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8)), tag = await cbcHmacTag(macKey, macData, keySize);
|
|
32
|
+
return { ciphertext, tag, iv };
|
|
43
33
|
}
|
|
44
34
|
async function timingSafeEqual(a, b) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const aHmac = await crypto.subtle.sign(algorithm, key, a);
|
|
48
|
-
return crypto.subtle.verify(algorithm, key, aHmac, b);
|
|
35
|
+
const algorithm = { name: "HMAC", hash: "SHA-256" }, key = await crypto.subtle.generateKey(algorithm, !1, ["sign", "verify"]), aHmac = await crypto.subtle.sign(algorithm, key, a);
|
|
36
|
+
return crypto.subtle.verify(algorithm, key, aHmac, b);
|
|
49
37
|
}
|
|
50
38
|
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
}
|
|
61
|
-
throw new JWEDecryptionFailed();
|
|
62
|
-
}
|
|
63
|
-
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
64
|
-
const encKey = cek instanceof Uint8Array
|
|
65
|
-
? await crypto.subtle.importKey('raw', cek, 'AES-GCM', false, [
|
|
66
|
-
'encrypt',
|
|
67
|
-
])
|
|
68
|
-
: (checkCryptoKey(cek, enc.subtle, 'encrypt'), cek);
|
|
69
|
-
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
70
|
-
additionalData: aad,
|
|
71
|
-
iv: iv,
|
|
72
|
-
name: 'AES-GCM',
|
|
73
|
-
tagLength: 128,
|
|
74
|
-
}, encKey, plaintext));
|
|
75
|
-
const tag = encrypted.slice(-16);
|
|
76
|
-
const ciphertext = encrypted.slice(0, -16);
|
|
77
|
-
return { ciphertext, tag, iv };
|
|
39
|
+
const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "decrypt"), macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8)), expectedTag = await cbcHmacTag(macKey, macData, keySize);
|
|
40
|
+
try {
|
|
41
|
+
if (await timingSafeEqual(tag, expectedTag))
|
|
42
|
+
return new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
throw new JWEDecryptionFailed();
|
|
78
46
|
}
|
|
79
|
-
async function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}, encKey, concat(ciphertext, tag)));
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
throw new JWEDecryptionFailed();
|
|
95
|
-
}
|
|
47
|
+
async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
48
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array))
|
|
49
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
50
|
+
if (iv ? checkIvLength(enc, iv) : iv = generateIv(enc), cek instanceof Uint8Array && checkCekLength(cek, enc.cekBits), enc.cbc)
|
|
51
|
+
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
52
|
+
const encKey = await rawKey(cek, enc.subtle, "encrypt"), encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
53
|
+
additionalData: aad,
|
|
54
|
+
iv,
|
|
55
|
+
name: "AES-GCM",
|
|
56
|
+
tagLength: 128
|
|
57
|
+
}, encKey, plaintext));
|
|
58
|
+
return { ciphertext: encrypted.subarray(0, -16), tag: encrypted.subarray(-16), iv };
|
|
96
59
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
throw new JWEInvalid('JWE Initialization Vector missing');
|
|
120
|
-
}
|
|
121
|
-
if (!tag) {
|
|
122
|
-
throw new JWEInvalid('JWE Authentication Tag missing');
|
|
123
|
-
}
|
|
124
|
-
if (!enc.cbc && tag.length !== 16) {
|
|
125
|
-
throw new JWEInvalid('Invalid Authentication Tag length');
|
|
126
|
-
}
|
|
127
|
-
checkIvLength(enc, iv);
|
|
128
|
-
if (cek instanceof Uint8Array) {
|
|
129
|
-
checkCekLength(cek, enc.cekBits);
|
|
130
|
-
}
|
|
131
|
-
return enc.cbc
|
|
132
|
-
? cbcDecrypt(enc, cek, ciphertext, iv, tag, aad)
|
|
133
|
-
: gcmDecrypt(enc, cek, ciphertext, iv, tag, aad);
|
|
60
|
+
async function decrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
61
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array))
|
|
62
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
63
|
+
if (!iv)
|
|
64
|
+
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
65
|
+
if (!tag)
|
|
66
|
+
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
67
|
+
if (!enc.cbc && tag.length !== 16)
|
|
68
|
+
throw new JWEInvalid("Invalid Authentication Tag length");
|
|
69
|
+
if (checkIvLength(enc, iv), cek instanceof Uint8Array && checkCekLength(cek, enc.cekBits), enc.cbc)
|
|
70
|
+
return cbcDecrypt(enc, cek, ciphertext, iv, tag, aad);
|
|
71
|
+
const encKey = await rawKey(cek, enc.subtle, "decrypt");
|
|
72
|
+
try {
|
|
73
|
+
return new Uint8Array(await crypto.subtle.decrypt({
|
|
74
|
+
additionalData: aad,
|
|
75
|
+
iv,
|
|
76
|
+
name: "AES-GCM",
|
|
77
|
+
tagLength: 128
|
|
78
|
+
}, encKey, concat(ciphertext, tag)));
|
|
79
|
+
} catch {
|
|
80
|
+
throw new JWEDecryptionFailed();
|
|
81
|
+
}
|
|
134
82
|
}
|
|
83
|
+
export {
|
|
84
|
+
checkCekLength,
|
|
85
|
+
checkIvLength,
|
|
86
|
+
decrypt,
|
|
87
|
+
encrypt,
|
|
88
|
+
generateCek,
|
|
89
|
+
generateIv
|
|
90
|
+
};
|
|
@@ -1,52 +1,40 @@
|
|
|
1
|
-
import { JOSENotSupported, JWEInvalid } from
|
|
2
|
-
import { concat } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
9
|
-
}
|
|
1
|
+
import { JOSENotSupported, JWEInvalid } from "../util/errors.js";
|
|
2
|
+
import { concat } from "./buffer_utils.js";
|
|
3
|
+
function validateZip(joseHeader, protectedHeader) {
|
|
4
|
+
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF")
|
|
5
|
+
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
6
|
+
if (joseHeader.zip !== void 0 && !protectedHeader?.zip)
|
|
7
|
+
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
10
8
|
}
|
|
11
9
|
function supported(name) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
if (typeof globalThis[name] > "u")
|
|
11
|
+
throw new JOSENotSupported(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${name} API.`);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
async function transform(stream, input, maxLength = 1 / 0) {
|
|
14
|
+
const writer = stream.writable.getWriter();
|
|
15
|
+
writer.write(input).catch(() => {
|
|
16
|
+
}), writer.close().catch(() => {
|
|
17
|
+
});
|
|
18
|
+
const chunks = [];
|
|
19
|
+
let length = 0;
|
|
20
|
+
const reader = stream.readable.getReader();
|
|
21
|
+
for (; ; ) {
|
|
22
|
+
const { value, done } = await reader.read();
|
|
23
|
+
if (done)
|
|
24
|
+
break;
|
|
25
|
+
if (chunks.push(value), length += value.byteLength, maxLength !== 1 / 0 && length > maxLength)
|
|
26
|
+
throw new JWEInvalid("Decompressed plaintext exceeded the configured limit");
|
|
27
|
+
}
|
|
28
|
+
return concat(...chunks);
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const ds = new DecompressionStream('deflate-raw');
|
|
35
|
-
const writer = ds.writable.getWriter();
|
|
36
|
-
writer.write(input).catch(() => { });
|
|
37
|
-
writer.close().catch(() => { });
|
|
38
|
-
const chunks = [];
|
|
39
|
-
let length = 0;
|
|
40
|
-
const reader = ds.readable.getReader();
|
|
41
|
-
for (;;) {
|
|
42
|
-
const { value, done } = await reader.read();
|
|
43
|
-
if (done)
|
|
44
|
-
break;
|
|
45
|
-
chunks.push(value);
|
|
46
|
-
length += value.byteLength;
|
|
47
|
-
if (maxLength !== Infinity && length > maxLength) {
|
|
48
|
-
throw new JWEInvalid('Decompressed plaintext exceeded the configured limit');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return concat(...chunks);
|
|
30
|
+
async function compress(input) {
|
|
31
|
+
return supported("CompressionStream"), transform(new CompressionStream("deflate-raw"), input);
|
|
52
32
|
}
|
|
33
|
+
async function decompress(input, maxLength) {
|
|
34
|
+
return supported("DecompressionStream"), transform(new DecompressionStream("deflate-raw"), input, maxLength);
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
compress,
|
|
38
|
+
decompress,
|
|
39
|
+
validateZip
|
|
40
|
+
};
|
|
@@ -1,107 +1,116 @@
|
|
|
1
|
-
import { JOSENotSupported } from
|
|
2
|
-
import { table } from
|
|
1
|
+
import { JOSENotSupported } from "../util/errors.js";
|
|
2
|
+
import { table } from "./key_descriptor.js";
|
|
3
3
|
const wrap = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
];
|
|
7
|
-
const derive = [[], ['deriveBits']];
|
|
8
|
-
const none = [[], []];
|
|
4
|
+
["encrypt", "wrapKey"],
|
|
5
|
+
["decrypt", "unwrapKey"]
|
|
6
|
+
], derive = [[], ["deriveBits"]], none = [[], []];
|
|
9
7
|
function rsaes(bits) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
return {
|
|
9
|
+
kty: ["RSA"],
|
|
10
|
+
mode: "key-encryption",
|
|
11
|
+
subtle: { name: "RSA-OAEP", hash: `SHA-${bits}` },
|
|
12
|
+
usages: wrap,
|
|
13
|
+
ops: ["wrapKey", "unwrapKey"]
|
|
14
|
+
};
|
|
16
15
|
}
|
|
17
|
-
function ecdh() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
16
|
+
function ecdh(mode) {
|
|
17
|
+
return {
|
|
18
|
+
kty: ["EC", "OKP"],
|
|
19
|
+
mode,
|
|
20
|
+
subtle: { name: "ECDH" },
|
|
21
|
+
resolve: ({ kty, crv, asymmetricKeyType }) => {
|
|
22
|
+
if (crv === "X25519" || asymmetricKeyType === "x25519")
|
|
23
|
+
return { name: "X25519" };
|
|
24
|
+
if (kty === "OKP")
|
|
25
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
26
|
+
return { name: "ECDH", namedCurve: crv };
|
|
27
|
+
},
|
|
28
|
+
usages: derive,
|
|
29
|
+
ops: [void 0, "deriveBits"]
|
|
30
|
+
};
|
|
33
31
|
}
|
|
34
|
-
function aeskw(bits, gcm =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
function aeskw(bits, gcm = !1) {
|
|
33
|
+
return {
|
|
34
|
+
kty: ["oct"],
|
|
35
|
+
mode: "key-wrapping",
|
|
36
|
+
secret: !0,
|
|
37
|
+
subtle: { name: gcm ? "AES-GCM" : "AES-KW", length: bits },
|
|
38
|
+
usages: none,
|
|
39
|
+
ops: gcm ? ["encrypt", "decrypt"] : ["wrapKey", "unwrapKey"]
|
|
40
|
+
};
|
|
42
41
|
}
|
|
43
42
|
function pbes2() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
return {
|
|
44
|
+
kty: ["oct"],
|
|
45
|
+
mode: "key-wrapping",
|
|
46
|
+
secret: !0,
|
|
47
|
+
subtle: { name: "PBKDF2" },
|
|
48
|
+
usages: none,
|
|
49
|
+
ops: ["deriveBits", "deriveBits"]
|
|
50
|
+
};
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
function contentEncryption(bits, cbc =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
52
|
+
const JWE = table({
|
|
53
|
+
dir: {
|
|
54
|
+
kty: ["oct"],
|
|
55
|
+
mode: "direct-encryption",
|
|
56
|
+
secret: !0,
|
|
57
|
+
subtle: { name: "AES-GCM" },
|
|
58
|
+
usages: none,
|
|
59
|
+
ops: ["encrypt", "decrypt"]
|
|
60
|
+
},
|
|
61
|
+
"RSA-OAEP": rsaes(1),
|
|
62
|
+
"RSA-OAEP-256": rsaes(256),
|
|
63
|
+
"RSA-OAEP-384": rsaes(384),
|
|
64
|
+
"RSA-OAEP-512": rsaes(512),
|
|
65
|
+
"ECDH-ES": ecdh("direct-key-agreement"),
|
|
66
|
+
"ECDH-ES+A128KW": ecdh("key-agreement-with-key-wrapping"),
|
|
67
|
+
"ECDH-ES+A192KW": ecdh("key-agreement-with-key-wrapping"),
|
|
68
|
+
"ECDH-ES+A256KW": ecdh("key-agreement-with-key-wrapping"),
|
|
69
|
+
A128KW: aeskw(128),
|
|
70
|
+
A192KW: aeskw(192),
|
|
71
|
+
A256KW: aeskw(256),
|
|
72
|
+
A128GCMKW: aeskw(128, !0),
|
|
73
|
+
A192GCMKW: aeskw(192, !0),
|
|
74
|
+
A256GCMKW: aeskw(256, !0),
|
|
75
|
+
"PBES2-HS256+A128KW": pbes2(),
|
|
76
|
+
"PBES2-HS384+A192KW": pbes2(),
|
|
77
|
+
"PBES2-HS512+A256KW": pbes2()
|
|
78
|
+
}), contentOps = ["encrypt", "decrypt"];
|
|
79
|
+
function contentEncryption(bits, cbc = !1) {
|
|
80
|
+
return {
|
|
81
|
+
kty: ["oct"],
|
|
82
|
+
secret: !0,
|
|
83
|
+
subtle: { name: cbc ? "AES-CBC" : "AES-GCM", length: bits },
|
|
84
|
+
usages: none,
|
|
85
|
+
ops: contentOps,
|
|
86
|
+
cekBits: bits,
|
|
87
|
+
ivBits: cbc ? 128 : 96,
|
|
88
|
+
cbc
|
|
89
|
+
};
|
|
90
90
|
}
|
|
91
91
|
const ENC = table({
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
A128GCM: contentEncryption(128),
|
|
93
|
+
A192GCM: contentEncryption(192),
|
|
94
|
+
A256GCM: contentEncryption(256),
|
|
95
|
+
"A128CBC-HS256": contentEncryption(256, !0),
|
|
96
|
+
"A192CBC-HS384": contentEncryption(384, !0),
|
|
97
|
+
"A256CBC-HS512": contentEncryption(512, !0)
|
|
98
98
|
});
|
|
99
99
|
function unsupported(parameter, name) {
|
|
100
|
-
|
|
100
|
+
throw new JOSENotSupported(`Invalid or unsupported "${parameter}" (JWE ${name}) header value`);
|
|
101
|
+
}
|
|
102
|
+
function jweAlgorithm(alg) {
|
|
103
|
+
return (typeof alg == "string" ? JWE[alg] : void 0) ?? unsupported("alg", "Algorithm");
|
|
101
104
|
}
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
function isJWECEKTransport(algorithm) {
|
|
106
|
+
return algorithm.mode === "key-wrapping" || algorithm.mode === "key-encryption" || algorithm.mode === "key-agreement-with-key-wrapping";
|
|
104
107
|
}
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
function jweEncryption(enc) {
|
|
109
|
+
return (typeof enc == "string" ? ENC[enc] : void 0) ?? unsupported("enc", "Encryption Algorithm");
|
|
107
110
|
}
|
|
111
|
+
export {
|
|
112
|
+
JWE,
|
|
113
|
+
isJWECEKTransport,
|
|
114
|
+
jweAlgorithm,
|
|
115
|
+
jweEncryption
|
|
116
|
+
};
|