inray 0.0.13 → 0.0.14
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/LICENSE.md +1 -1
- package/README.md +1 -1
- package/dist/jose/src/index.d.ts +3 -2
- package/dist/jose/src/index.d.ts.map +1 -1
- package/dist/jose/src/index.js +3 -2
- package/dist/jose/src/index.js.map +1 -1
- package/dist/jose/src/jwe/compact/decrypt.d.ts +14 -10
- package/dist/jose/src/jwe/compact/decrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/compact/decrypt.js +7 -4
- package/dist/jose/src/jwe/compact/decrypt.js.map +1 -1
- package/dist/jose/src/jwe/compact/encrypt.d.ts +18 -17
- package/dist/jose/src/jwe/compact/encrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/compact/encrypt.js +27 -29
- package/dist/jose/src/jwe/compact/encrypt.js.map +1 -1
- package/dist/jose/src/jwe/flattened/decrypt.d.ts +14 -12
- package/dist/jose/src/jwe/flattened/decrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/flattened/decrypt.js +6 -10
- package/dist/jose/src/jwe/flattened/decrypt.js.map +1 -1
- package/dist/jose/src/jwe/flattened/encrypt.d.ts +22 -23
- package/dist/jose/src/jwe/flattened/encrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/flattened/encrypt.js +66 -43
- package/dist/jose/src/jwe/flattened/encrypt.js.map +1 -1
- package/dist/jose/src/jwe/general/decrypt.d.ts +19 -13
- package/dist/jose/src/jwe/general/decrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/general/decrypt.js +27 -34
- package/dist/jose/src/jwe/general/decrypt.js.map +1 -1
- package/dist/jose/src/jwe/general/encrypt.d.ts +25 -28
- package/dist/jose/src/jwe/general/encrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/general/encrypt.js +94 -67
- package/dist/jose/src/jwe/general/encrypt.js.map +1 -1
- package/dist/jose/src/jwk/embedded.d.ts +6 -4
- package/dist/jose/src/jwk/embedded.d.ts.map +1 -1
- package/dist/jose/src/jwk/embedded.js +9 -22
- package/dist/jose/src/jwk/embedded.js.map +1 -1
- package/dist/jose/src/jwk/thumbprint.d.ts +9 -7
- package/dist/jose/src/jwk/thumbprint.d.ts.map +1 -1
- package/dist/jose/src/jwk/thumbprint.js +26 -32
- package/dist/jose/src/jwk/thumbprint.js.map +1 -1
- package/dist/jose/src/jwks/local.d.ts +18 -10
- package/dist/jose/src/jwks/local.d.ts.map +1 -1
- package/dist/jose/src/jwks/local.js +92 -90
- package/dist/jose/src/jwks/local.js.map +1 -1
- package/dist/jose/src/jwks/remote.d.ts +43 -39
- package/dist/jose/src/jwks/remote.d.ts.map +1 -1
- package/dist/jose/src/jwks/remote.js +145 -121
- package/dist/jose/src/jwks/remote.js.map +1 -1
- package/dist/jose/src/jws/compact/sign.d.ts +7 -10
- package/dist/jose/src/jws/compact/sign.d.ts.map +1 -1
- package/dist/jose/src/jws/compact/sign.js +16 -16
- package/dist/jose/src/jws/compact/sign.js.map +1 -1
- package/dist/jose/src/jws/compact/verify.d.ts +14 -12
- package/dist/jose/src/jws/compact/verify.d.ts.map +1 -1
- package/dist/jose/src/jws/compact/verify.js +6 -2
- package/dist/jose/src/jws/compact/verify.js.map +1 -1
- package/dist/jose/src/jws/flattened/sign.d.ts +8 -11
- package/dist/jose/src/jws/flattened/sign.d.ts.map +1 -1
- package/dist/jose/src/jws/flattened/sign.js +26 -21
- package/dist/jose/src/jws/flattened/sign.js.map +1 -1
- package/dist/jose/src/jws/flattened/verify.d.ts +14 -13
- package/dist/jose/src/jws/flattened/verify.d.ts.map +1 -1
- package/dist/jose/src/jws/flattened/verify.js +19 -6
- package/dist/jose/src/jws/flattened/verify.js.map +1 -1
- package/dist/jose/src/jws/general/sign.d.ts +18 -19
- package/dist/jose/src/jws/general/sign.d.ts.map +1 -1
- package/dist/jose/src/jws/general/sign.js +24 -21
- package/dist/jose/src/jws/general/sign.js.map +1 -1
- package/dist/jose/src/jws/general/verify.d.ts +20 -17
- package/dist/jose/src/jws/general/verify.d.ts.map +1 -1
- package/dist/jose/src/jws/general/verify.js +28 -48
- package/dist/jose/src/jws/general/verify.js.map +1 -1
- package/dist/jose/src/jwt/decrypt.d.ts +15 -21
- package/dist/jose/src/jwt/decrypt.d.ts.map +1 -1
- package/dist/jose/src/jwt/decrypt.js +18 -15
- package/dist/jose/src/jwt/decrypt.js.map +1 -1
- package/dist/jose/src/jwt/encrypt.d.ts +33 -23
- package/dist/jose/src/jwt/encrypt.d.ts.map +1 -1
- package/dist/jose/src/jwt/encrypt.js +90 -44
- package/dist/jose/src/jwt/encrypt.js.map +1 -1
- package/dist/jose/src/jwt/sign.d.ts +19 -9
- package/dist/jose/src/jwt/sign.d.ts.map +1 -1
- package/dist/jose/src/jwt/sign.js +51 -15
- package/dist/jose/src/jwt/sign.js.map +1 -1
- package/dist/jose/src/jwt/unsecured.d.ts +19 -15
- package/dist/jose/src/jwt/unsecured.d.ts.map +1 -1
- package/dist/jose/src/jwt/unsecured.js +57 -27
- package/dist/jose/src/jwt/unsecured.js.map +1 -1
- package/dist/jose/src/jwt/verify.d.ts +14 -21
- package/dist/jose/src/jwt/verify.d.ts.map +1 -1
- package/dist/jose/src/jwt/verify.js +9 -7
- package/dist/jose/src/jwt/verify.js.map +1 -1
- package/dist/jose/src/key/export.d.ts +7 -7
- package/dist/jose/src/key/export.d.ts.map +1 -1
- package/dist/jose/src/key/export.js +42 -46
- package/dist/jose/src/key/export.js.map +1 -1
- package/dist/jose/src/key/generate_key_pair.d.ts +18 -14
- package/dist/jose/src/key/generate_key_pair.d.ts.map +1 -1
- package/dist/jose/src/key/generate_key_pair.js +18 -17
- package/dist/jose/src/key/generate_key_pair.js.map +1 -1
- package/dist/jose/src/key/generate_secret.d.ts +16 -11
- package/dist/jose/src/key/generate_secret.d.ts.map +1 -1
- package/dist/jose/src/key/generate_secret.js +11 -16
- package/dist/jose/src/key/generate_secret.js.map +1 -1
- package/dist/jose/src/key/import.d.ts +27 -21
- package/dist/jose/src/key/import.d.ts.map +1 -1
- package/dist/jose/src/key/import.js +27 -30
- package/dist/jose/src/key/import.js.map +1 -1
- package/dist/jose/src/lib/asn1.d.ts +1 -1
- package/dist/jose/src/lib/asn1.d.ts.map +1 -1
- package/dist/jose/src/lib/asn1.js +11 -20
- package/dist/jose/src/lib/asn1.js.map +1 -1
- package/dist/jose/src/lib/base64.d.ts +11 -0
- package/dist/jose/src/lib/base64.d.ts.map +1 -0
- package/dist/jose/src/lib/base64.js +36 -0
- package/dist/jose/src/lib/base64.js.map +1 -0
- package/dist/jose/src/lib/buffer_utils.d.ts +1 -4
- package/dist/jose/src/lib/buffer_utils.d.ts.map +1 -1
- package/dist/jose/src/lib/buffer_utils.js +6 -51
- package/dist/jose/src/lib/buffer_utils.js.map +1 -1
- package/dist/jose/src/lib/content_encryption.d.ts +1 -2
- package/dist/jose/src/lib/content_encryption.d.ts.map +1 -1
- package/dist/jose/src/lib/content_encryption.js +76 -63
- package/dist/jose/src/lib/content_encryption.js.map +1 -1
- package/dist/jose/src/lib/crypto_key.d.ts +23 -0
- package/dist/jose/src/lib/crypto_key.d.ts.map +1 -0
- package/dist/jose/src/lib/crypto_key.js +41 -0
- package/dist/jose/src/lib/crypto_key.js.map +1 -0
- package/dist/jose/src/lib/deflate.d.ts +1 -3
- package/dist/jose/src/lib/deflate.d.ts.map +1 -1
- package/dist/jose/src/lib/deflate.js +22 -24
- package/dist/jose/src/lib/deflate.js.map +1 -1
- package/dist/jose/src/lib/helpers.d.ts +20 -0
- package/dist/jose/src/lib/helpers.d.ts.map +1 -0
- package/dist/jose/src/lib/helpers.js +56 -0
- package/dist/jose/src/lib/helpers.js.map +1 -0
- package/dist/jose/src/lib/invalid_key_input.d.ts +11 -0
- package/dist/jose/src/lib/invalid_key_input.d.ts.map +1 -0
- package/dist/jose/src/lib/invalid_key_input.js +35 -0
- package/dist/jose/src/lib/invalid_key_input.js.map +1 -0
- package/dist/jose/src/lib/is_key_like.d.ts +14 -0
- package/dist/jose/src/lib/is_key_like.d.ts.map +1 -0
- package/dist/jose/src/lib/is_key_like.js +29 -0
- package/dist/jose/src/lib/is_key_like.js.map +1 -0
- package/dist/jose/src/lib/jwe_algorithms.d.ts +3 -24
- package/dist/jose/src/lib/jwe_algorithms.d.ts.map +1 -1
- package/dist/jose/src/lib/jwe_algorithms.js +6 -22
- package/dist/jose/src/lib/jwe_algorithms.js.map +1 -1
- package/dist/jose/src/lib/jwe_decrypt.d.ts +23 -19
- package/dist/jose/src/lib/jwe_decrypt.d.ts.map +1 -1
- package/dist/jose/src/lib/jwe_decrypt.js +106 -179
- package/dist/jose/src/lib/jwe_decrypt.js.map +1 -1
- package/dist/jose/src/lib/jwe_encrypt.d.ts +19 -20
- package/dist/jose/src/lib/jwe_encrypt.d.ts.map +1 -1
- package/dist/jose/src/lib/jwe_encrypt.js +50 -96
- package/dist/jose/src/lib/jwe_encrypt.js.map +1 -1
- package/dist/jose/src/lib/jwk_to_key.d.ts +12 -0
- package/dist/jose/src/lib/jwk_to_key.d.ts.map +1 -0
- package/dist/jose/src/lib/jwk_to_key.js +26 -0
- package/dist/jose/src/lib/jwk_to_key.js.map +1 -0
- package/dist/jose/src/lib/jws_algorithms.d.ts +1 -1
- package/dist/jose/src/lib/jws_algorithms.d.ts.map +1 -1
- package/dist/jose/src/lib/jws_algorithms.js +3 -9
- package/dist/jose/src/lib/jws_algorithms.js.map +1 -1
- package/dist/jose/src/lib/jws_sign.d.ts +11 -13
- package/dist/jose/src/lib/jws_sign.d.ts.map +1 -1
- package/dist/jose/src/lib/jws_sign.js +50 -49
- package/dist/jose/src/lib/jws_sign.js.map +1 -1
- package/dist/jose/src/lib/jws_verify.d.ts +10 -9
- package/dist/jose/src/lib/jws_verify.d.ts.map +1 -1
- package/dist/jose/src/lib/jws_verify.js +66 -105
- package/dist/jose/src/lib/jws_verify.js.map +1 -1
- package/dist/jose/src/lib/jwt_claims_set.d.ts +15 -12
- package/dist/jose/src/lib/jwt_claims_set.d.ts.map +1 -1
- package/dist/jose/src/lib/jwt_claims_set.js +83 -133
- package/dist/jose/src/lib/jwt_claims_set.js.map +1 -1
- package/dist/jose/src/lib/key.d.ts +16 -23
- package/dist/jose/src/lib/key.d.ts.map +1 -1
- package/dist/jose/src/lib/key.js +91 -191
- package/dist/jose/src/lib/key.js.map +1 -1
- package/dist/jose/src/lib/key_algorithm.d.ts +1 -1
- package/dist/jose/src/lib/key_algorithm.js +1 -1
- package/dist/jose/src/lib/key_descriptor.d.ts +6 -7
- package/dist/jose/src/lib/key_descriptor.d.ts.map +1 -1
- package/dist/jose/src/lib/key_descriptor.js +1 -1
- package/dist/jose/src/lib/key_descriptor.js.map +1 -1
- package/dist/jose/src/lib/key_management.d.ts +4 -5
- package/dist/jose/src/lib/key_management.d.ts.map +1 -1
- package/dist/jose/src/lib/key_management.js +131 -153
- package/dist/jose/src/lib/key_management.js.map +1 -1
- package/dist/jose/src/lib/options.d.ts +30 -0
- package/dist/jose/src/lib/options.d.ts.map +1 -0
- package/dist/jose/src/lib/options.js +64 -0
- package/dist/jose/src/lib/options.js.map +1 -0
- package/dist/jose/src/lib/signing.d.ts +13 -0
- package/dist/jose/src/lib/signing.d.ts.map +1 -0
- package/dist/jose/src/lib/signing.js +35 -0
- package/dist/jose/src/lib/signing.js.map +1 -0
- package/dist/jose/src/lib/type_checks.d.ts +24 -0
- package/dist/jose/src/lib/type_checks.d.ts.map +1 -0
- package/dist/jose/src/lib/type_checks.js +44 -0
- package/dist/jose/src/lib/type_checks.js.map +1 -0
- package/dist/jose/src/util/base64url.d.ts +8 -8
- package/dist/jose/src/util/base64url.d.ts.map +1 -1
- package/dist/jose/src/util/base64url.js +45 -17
- package/dist/jose/src/util/base64url.js.map +1 -1
- package/dist/jose/src/util/decode_jwt.d.ts +6 -11
- package/dist/jose/src/util/decode_jwt.d.ts.map +1 -1
- package/dist/jose/src/util/decode_jwt.js +35 -16
- package/dist/jose/src/util/decode_jwt.js.map +1 -1
- package/dist/jose/src/util/decode_protected_header.d.ts +4 -6
- package/dist/jose/src/util/decode_protected_header.d.ts.map +1 -1
- package/dist/jose/src/util/decode_protected_header.js +10 -14
- package/dist/jose/src/util/decode_protected_header.js.map +1 -1
- package/dist/jose/src/util/errors.d.ts +61 -59
- package/dist/jose/src/util/errors.d.ts.map +1 -1
- package/dist/jose/src/util/errors.js +37 -33
- package/dist/jose/src/util/errors.js.map +1 -1
- package/dist/media_types/_db.d.ts +1 -1
- package/package.json +1 -1
- package/dist/jose/src/lib/validate.d.ts +0 -53
- package/dist/jose/src/lib/validate.d.ts.map +0 -1
- package/dist/jose/src/lib/validate.js +0 -166
- package/dist/jose/src/lib/validate.js.map +0 -1
|
@@ -1,71 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Original library: jose (v6.2.
|
|
2
|
+
* Original library: jose (v6.2.9)
|
|
3
3
|
* - Copyright (c) 2018 Filip Skokan
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
6
6
|
* - Evgeniy Bushin
|
|
7
7
|
*/
|
|
8
8
|
/***/
|
|
9
|
-
import {
|
|
9
|
+
import { prepareVerify, verifySignature, verifyResult } from '../../lib/jws_verify.js';
|
|
10
10
|
import { JWSInvalid, JWSSignatureVerificationFailed } from '../../util/errors.js';
|
|
11
|
-
import { isObject } from '../../lib/
|
|
12
|
-
function snapshotSignature(signature, payload) {
|
|
13
|
-
try {
|
|
14
|
-
const jws = snapshotJws(signature, [payload]);
|
|
15
|
-
const protectedHeader = parseProtectedHeader(jws.protected);
|
|
16
|
-
const { b64, crit } = protectedHeader;
|
|
17
|
-
return [
|
|
18
|
-
jws,
|
|
19
|
-
protectedHeader,
|
|
20
|
-
Array.isArray(crit) && crit.includes('b64')
|
|
21
|
-
? typeof b64 === 'boolean'
|
|
22
|
-
? b64
|
|
23
|
-
? 1
|
|
24
|
-
: 2
|
|
25
|
-
: 0
|
|
26
|
-
: 1,
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
11
|
+
import { isObject } from '../../lib/type_checks.js';
|
|
33
12
|
export async function generalVerify(jws, key, options) {
|
|
34
13
|
if (!isObject(jws)) {
|
|
35
14
|
throw new JWSInvalid('General JWS must be an object');
|
|
36
15
|
}
|
|
37
|
-
const { signatures, payload
|
|
38
|
-
if (!Array.isArray(signatures)) {
|
|
16
|
+
const { signatures, payload } = jws;
|
|
17
|
+
if (!Array.isArray(signatures) || !signatures.every(isObject)) {
|
|
39
18
|
throw new JWSInvalid('JWS Signatures missing or incorrect type');
|
|
40
19
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
let shared;
|
|
21
|
+
try {
|
|
22
|
+
if (payload === undefined)
|
|
23
|
+
throw new Error();
|
|
24
|
+
shared = prepareVerify(options);
|
|
44
25
|
}
|
|
45
|
-
|
|
26
|
+
catch {
|
|
46
27
|
// Reporting the real fault here would distinguish a malformed token from a signature that is
|
|
47
28
|
// simply not the caller's. Stay indistinguishable.
|
|
48
29
|
throw new JWSSignatureVerificationFailed();
|
|
49
30
|
}
|
|
50
|
-
const
|
|
51
|
-
const payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload;
|
|
52
|
-
const candidates = signatureEntries
|
|
53
|
-
.map((signature) => snapshotSignature(signature, payload))
|
|
54
|
-
.filter((candidate) => candidate !== undefined);
|
|
55
|
-
// RFC 7797, Section 3: reject differing b64 values across signatures.
|
|
56
|
-
let payloadEncodings = 0;
|
|
57
|
-
for (const [, , payloadEncoding] of candidates) {
|
|
58
|
-
payloadEncodings |= payloadEncoding;
|
|
59
|
-
if (payloadEncodings === 3) {
|
|
60
|
-
throw new JWSInvalid('inconsistent use of JWS Unencoded Payload (RFC7797)');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// RFC 7515, Section 5.2, steps 9-10: at least one signature must validate.
|
|
64
|
-
// Returning the first valid signature is this API’s selection policy.
|
|
65
|
-
for (const candidate of candidates) {
|
|
31
|
+
for (const signature of signatures) {
|
|
66
32
|
try {
|
|
67
|
-
const
|
|
68
|
-
|
|
33
|
+
const { protected: encodedProtected, header, signature: encodedSignature } = signature;
|
|
34
|
+
if (encodedProtected === undefined && header === undefined)
|
|
35
|
+
throw new Error();
|
|
36
|
+
if (encodedProtected !== undefined && typeof encodedProtected !== 'string') {
|
|
37
|
+
throw new Error();
|
|
38
|
+
}
|
|
39
|
+
if (typeof encodedSignature !== 'string')
|
|
40
|
+
throw new Error();
|
|
41
|
+
if (header !== undefined && !isObject(header))
|
|
42
|
+
throw new Error();
|
|
43
|
+
return verifyResult(signature, await verifySignature({
|
|
44
|
+
header,
|
|
45
|
+
payload,
|
|
46
|
+
protected: encodedProtected,
|
|
47
|
+
signature: encodedSignature,
|
|
48
|
+
}, shared, key));
|
|
69
49
|
}
|
|
70
50
|
catch {
|
|
71
51
|
//
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../../../src/jose/src/jws/general/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../../../src/jose/src/jws/general/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AASL,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEtF,OAAO,EAAE,UAAU,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAA;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AA8FnD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAA0B,EAC1B,GAAyC,EACzC,OAA6B;IAE7B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,UAAU,CAAC,+BAA+B,CAAC,CAAA;IACvD,CAAC;IAED,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;IACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,UAAU,CAAC,0CAA0C,CAAC,CAAA;IAClE,CAAC;IAED,IAAI,MAAoB,CAAA;IACxB,IAAI,CAAC;QACH,IAAI,OAAO,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,EAAE,CAAA;QAC5C,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,6FAA6F;QAC7F,mDAAmD;QACnD,MAAM,IAAI,8BAA8B,EAAE,CAAA;IAC5C,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,SAAS,CAAA;YACtF,IAAI,gBAAgB,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS;gBAAE,MAAM,IAAI,KAAK,EAAE,CAAA;YAC7E,IAAI,gBAAgB,KAAK,SAAS,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;gBAC3E,MAAM,IAAI,KAAK,EAAE,CAAA;YACnB,CAAC;YACD,IAAI,OAAO,gBAAgB,KAAK,QAAQ;gBAAE,MAAM,IAAI,KAAK,EAAE,CAAA;YAC3D,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,MAAM,IAAI,KAAK,EAAE,CAAA;YAEhE,OAAO,YAAY,CACjB,SAAS,EACT,MAAM,eAAe,CACnB;gBACE,MAAM;gBACN,OAAO;gBACP,SAAS,EAAE,gBAAgB;gBAC3B,SAAS,EAAE,gBAAgB;aAC5B,EACD,MAAM,EACN,GAAG,CACJ,CACF,CAAA;QACH,CAAC;QAAC,MAAM,CAAC;YACP,EAAE;QACJ,CAAC;IACH,CAAC;IACD,MAAM,IAAI,8BAA8B,EAAE,CAAA;AAC5C,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Original library: jose (v6.2.
|
|
2
|
+
* Original library: jose (v6.2.9)
|
|
3
3
|
* - Copyright (c) 2018 Filip Skokan
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
@@ -12,26 +12,21 @@
|
|
|
12
12
|
* @module
|
|
13
13
|
*/
|
|
14
14
|
import type * as types from '../types.d.ts';
|
|
15
|
-
/** JWE
|
|
15
|
+
/** Combination of JWE Decryption options and JWT Claims Set verification options. */
|
|
16
16
|
export interface JWTDecryptOptions extends types.DecryptOptions, types.JWTClaimVerificationOptions {
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* Interface for JWT Decryption dynamic key resolution. No token components have been verified at
|
|
20
|
+
* the time of this function call.
|
|
21
21
|
*
|
|
22
22
|
* @typeParam KeyType Type definition of the keys the function resolves. Narrowing it is what lets
|
|
23
23
|
* {@link types.ResolvedKey.key ResolvedKey.key} be inferred at the call site.
|
|
24
24
|
*/
|
|
25
25
|
export interface JWTDecryptGetKey<KeyType extends types.CryptoKey | Uint8Array = types.CryptoKey | Uint8Array> extends types.GetKeyFunction<types.CompactJWEHeaderParameters, types.FlattenedJWE, KeyType | types.KeyObject | types.JWK> {
|
|
26
26
|
}
|
|
27
|
-
/** @ignore */
|
|
28
|
-
export declare function jwtDecrypt<PayloadType, KeyType extends types.KeyInput, InferredPayloadType>(jwt: string | Uint8Array, key: KeyType, options?: JWTDecryptOptions): Promise<types.InferredJWTResult<types.JWTDecryptResult<unknown>, InferredPayloadType & ([PayloadType] extends [object] ? unknown : unknown extends PayloadType ? unknown : never)>>;
|
|
29
|
-
/** @ignore */
|
|
30
|
-
export declare function jwtDecrypt<PayloadType, KeyType extends types.CryptoKey | Uint8Array, InferredPayloadType>(jwt: string | Uint8Array, getKey: JWTDecryptGetKey<KeyType>, options?: JWTDecryptOptions): Promise<types.InferredJWTResult<types.JWTDecryptResult<unknown>, InferredPayloadType & ([PayloadType] extends [object] ? unknown : unknown extends PayloadType ? unknown : never)> & types.ResolvedKey<KeyType>>;
|
|
31
|
-
/** @ignore */
|
|
32
|
-
export declare function jwtDecrypt<PayloadType, KeyType extends types.KeyInput | JWTDecryptGetKey, InferredPayloadType>(jwt: string | Uint8Array, key: KeyType, options?: JWTDecryptOptions): Promise<types.InferredJWTResult<types.JWTDecryptResult<unknown>, InferredPayloadType & ([PayloadType] extends [object] ? unknown : unknown extends PayloadType ? unknown : never)> & Partial<types.ResolvedKey>>;
|
|
33
27
|
/**
|
|
34
|
-
*
|
|
28
|
+
* Verifies the JWT format (to be a JWE Compact format), decrypts the ciphertext, validates the JWT
|
|
29
|
+
* Claims Set.
|
|
35
30
|
*
|
|
36
31
|
* This function is exported (as a named export) from the main `'jose'` module entry point as well
|
|
37
32
|
* as from its subpath export `'jose/jwt/decrypt'`.
|
|
@@ -53,30 +48,29 @@ export declare function jwtDecrypt<PayloadType, KeyType extends types.KeyInput |
|
|
|
53
48
|
* ```
|
|
54
49
|
*
|
|
55
50
|
* @param jwt JSON Web Token value (encoded as JWE).
|
|
56
|
-
* @param key Private
|
|
51
|
+
* @param key Private Key or Secret to decrypt and verify the JWT with. See
|
|
57
52
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
58
53
|
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
59
54
|
*/
|
|
60
55
|
export declare function jwtDecrypt<PayloadType = types.JWTPayload>(jwt: string | Uint8Array, key: types.KeyInput, options?: JWTDecryptOptions): Promise<types.JWTDecryptResult<PayloadType>>;
|
|
61
56
|
/**
|
|
62
|
-
* Decrypts a JWT and validates its
|
|
63
|
-
* {@link types.ResolvedKey.key resolved key}.
|
|
57
|
+
* Decrypts a JWT and validates its JWT Claims Set, resolving the key dynamically. The result
|
|
58
|
+
* additionally carries the {@link types.ResolvedKey.key resolved key}.
|
|
64
59
|
*
|
|
65
60
|
* @param jwt JSON Web Token value (encoded as JWE).
|
|
66
|
-
* @param getKey Function resolving
|
|
67
|
-
* JWT with. See
|
|
61
|
+
* @param getKey Function resolving Private Key or Secret to decrypt and verify the JWT with. See
|
|
68
62
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
69
63
|
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
70
64
|
*/
|
|
71
65
|
export declare function jwtDecrypt<PayloadType = types.JWTPayload, KeyType extends types.CryptoKey | Uint8Array = types.CryptoKey | Uint8Array>(jwt: string | Uint8Array, getKey: JWTDecryptGetKey<KeyType>, options?: JWTDecryptOptions): Promise<types.JWTDecryptResult<PayloadType> & types.ResolvedKey<KeyType>>;
|
|
72
66
|
/**
|
|
73
|
-
* Accepts
|
|
74
|
-
* `key` only when a
|
|
67
|
+
* Accepts either form of the `key` argument. Use this overload when forwarding a value that may be
|
|
68
|
+
* either a key or a key resolution function; `key` is present on the result only when a resolution
|
|
69
|
+
* function was used.
|
|
75
70
|
*
|
|
76
71
|
* @param jwt JSON Web Token value (encoded as JWE).
|
|
77
|
-
* @param key Private
|
|
78
|
-
*
|
|
79
|
-
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
72
|
+
* @param key Private Key or Secret, or a function resolving one, to decrypt and verify the JWT
|
|
73
|
+
* with. See {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
80
74
|
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
81
75
|
*/
|
|
82
76
|
export declare function jwtDecrypt<PayloadType = types.JWTPayload>(jwt: string | Uint8Array, key: types.KeyInput | JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<types.JWTDecryptResult<PayloadType> & Partial<types.ResolvedKey>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../../../src/jose/src/jwt/decrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL;;;;GAIG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,eAAe,CAAA;AAM3C,
|
|
1
|
+
{"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../../../src/jose/src/jwt/decrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL;;;;GAIG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,eAAe,CAAA;AAM3C,qFAAqF;AACrF,MAAM,WAAW,iBACf,SAAQ,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,2BAA2B;CAAG;AAEpE;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB,CAC/B,OAAO,SAAS,KAAK,CAAC,SAAS,GAAG,UAAU,GAAG,KAAK,CAAC,SAAS,GAAG,UAAU,CAC3E,SAAQ,KAAK,CAAC,cAAc,CAC5B,KAAK,CAAC,0BAA0B,EAChC,KAAK,CAAC,YAAY,EAClB,OAAO,GAAG,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,CACtC;CAAG;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,UAAU,CAAC,WAAW,GAAG,KAAK,CAAC,UAAU,EACvD,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,GAAG,EAAE,KAAK,CAAC,QAAQ,EACnB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAA;AAC/C;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,WAAW,GAAG,KAAK,CAAC,UAAU,EAC9B,OAAO,SAAS,KAAK,CAAC,SAAS,GAAG,UAAU,GAAG,KAAK,CAAC,SAAS,GAAG,UAAU,EAE3E,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,EACjC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;AAC5E;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,WAAW,GAAG,KAAK,CAAC,UAAU,EACvD,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,GAAG,EAAE,KAAK,CAAC,QAAQ,GAAG,gBAAgB,EACtC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Original library: jose (v6.2.
|
|
2
|
+
* Original library: jose (v6.2.9)
|
|
3
3
|
* - Copyright (c) 2018 Filip Skokan
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
@@ -10,20 +10,23 @@ import { prepareDecrypt, decryptCompact } from '../lib/jwe_decrypt.js';
|
|
|
10
10
|
import { validateClaimsSet } from '../lib/jwt_claims_set.js';
|
|
11
11
|
import { JWTClaimValidationFailed } from '../util/errors.js';
|
|
12
12
|
export async function jwtDecrypt(jwt, key, options) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// The audience-array comparison below requires the same element order.
|
|
19
|
-
for (const claim of ['iss', 'sub', 'aud']) {
|
|
20
|
-
if (protectedHeader[claim] !== undefined &&
|
|
21
|
-
(claim === 'aud'
|
|
22
|
-
? JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)
|
|
23
|
-
: protectedHeader[claim] !== payload[claim])) {
|
|
24
|
-
throw new JWTClaimValidationFailed(`replicated "${claim}" claim header parameter mismatch`, payload, claim, 'mismatch');
|
|
25
|
-
}
|
|
13
|
+
const decrypted = await decryptCompact(jwt, prepareDecrypt(options), key);
|
|
14
|
+
const protectedHeader = decrypted[1];
|
|
15
|
+
const payload = validateClaimsSet(protectedHeader, decrypted[0], options);
|
|
16
|
+
if (protectedHeader.iss !== undefined && protectedHeader.iss !== payload.iss) {
|
|
17
|
+
throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, 'iss', 'mismatch');
|
|
26
18
|
}
|
|
27
|
-
|
|
19
|
+
if (protectedHeader.sub !== undefined && protectedHeader.sub !== payload.sub) {
|
|
20
|
+
throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, 'sub', 'mismatch');
|
|
21
|
+
}
|
|
22
|
+
if (protectedHeader.aud !== undefined &&
|
|
23
|
+
JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
|
|
24
|
+
throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, 'aud', 'mismatch');
|
|
25
|
+
}
|
|
26
|
+
const result = { payload, protectedHeader };
|
|
27
|
+
if (typeof key === 'function') {
|
|
28
|
+
return { ...result, key: decrypted[2] };
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
28
31
|
}
|
|
29
32
|
//# sourceMappingURL=decrypt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../../../../src/jose/src/jwt/decrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AASL,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../../../../src/jose/src/jwt/decrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AASL,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAsF5D,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAwB,EACxB,GAAsC,EACtC,OAA2B;IAE3B,MAAM,SAAS,GAAG,MAAM,cAAc,CACpC,GAAG,EACH,cAAc,CAAC,OAAO,CAAC,EACvB,GAAqC,CACtC,CAAA;IACD,MAAM,eAAe,GAAG,SAAS,CAAC,CAAC,CAA8B,CAAA;IACjE,MAAM,OAAO,GAAG,iBAAiB,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;IAEzE,IAAI,eAAe,CAAC,GAAG,KAAK,SAAS,IAAI,eAAe,CAAC,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC;QAC7E,MAAM,IAAI,wBAAwB,CAChC,kDAAkD,EAClD,OAAO,EACP,KAAK,EACL,UAAU,CACX,CAAA;IACH,CAAC;IAED,IAAI,eAAe,CAAC,GAAG,KAAK,SAAS,IAAI,eAAe,CAAC,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC;QAC7E,MAAM,IAAI,wBAAwB,CAChC,kDAAkD,EAClD,OAAO,EACP,KAAK,EACL,UAAU,CACX,CAAA;IACH,CAAC;IAED,IACE,eAAe,CAAC,GAAG,KAAK,SAAS;QACjC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EACnE,CAAC;QACD,MAAM,IAAI,wBAAwB,CAChC,kDAAkD,EAClD,OAAO,EACP,KAAK,EACL,UAAU,CACX,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,CAAA;IAE3C,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAA;IACzC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Original library: jose (v6.2.
|
|
2
|
+
* Original library: jose (v6.2.9)
|
|
3
3
|
* - Copyright (c) 2018 Filip Skokan
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
@@ -12,10 +12,8 @@
|
|
|
12
12
|
* @module
|
|
13
13
|
*/
|
|
14
14
|
import type * as types from '../types.d.ts';
|
|
15
|
-
/** @param payload Initial JWT Claims Set. Defaults to an empty object. */
|
|
16
|
-
declare const EncryptJWT_base: new (payload?: types.JWTPayload) => types.ProduceJWT;
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
16
|
+
* The EncryptJWT class is used to build and encrypt Compact JWE formatted JSON Web Tokens.
|
|
19
17
|
*
|
|
20
18
|
* This class is exported (as a named export) from the main `'jose'` module entry point as well as
|
|
21
19
|
* from its subpath export `'jose/jwt/encrypt'`.
|
|
@@ -35,58 +33,71 @@ declare const EncryptJWT_base: new (payload?: types.JWTPayload) => types.Produce
|
|
|
35
33
|
* console.log(jwt)
|
|
36
34
|
* ```
|
|
37
35
|
*/
|
|
38
|
-
export declare class EncryptJWT
|
|
36
|
+
export declare class EncryptJWT implements types.ProduceJWT {
|
|
39
37
|
#private;
|
|
40
38
|
/**
|
|
41
|
-
*
|
|
39
|
+
* {@link EncryptJWT} constructor
|
|
40
|
+
*
|
|
41
|
+
* @param payload The JWT Claims Set object. Defaults to an empty object.
|
|
42
|
+
*/
|
|
43
|
+
constructor(payload?: types.JWTPayload);
|
|
44
|
+
setIssuer(issuer: string): this;
|
|
45
|
+
setSubject(subject: string): this;
|
|
46
|
+
setAudience(audience: string | string[]): this;
|
|
47
|
+
setJti(jwtId: string): this;
|
|
48
|
+
setNotBefore(input: number | string | Date): this;
|
|
49
|
+
setExpirationTime(input: number | string | Date): this;
|
|
50
|
+
setIssuedAt(input?: number | string | Date): this;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the JWE Protected Header on the EncryptJWT object.
|
|
42
53
|
*
|
|
43
54
|
* @param protectedHeader JWE Protected Header. Must contain an "alg" (JWE Algorithm) and "enc"
|
|
44
55
|
* (JWE Encryption Algorithm) properties.
|
|
45
56
|
*/
|
|
46
57
|
setProtectedHeader(protectedHeader: types.CompactJWEHeaderParameters): this;
|
|
47
58
|
/**
|
|
48
|
-
* Sets JWE Key Management parameters
|
|
49
|
-
*
|
|
50
|
-
*
|
|
59
|
+
* Sets the JWE Key Management parameters to be used when encrypting. Use this method instead of
|
|
60
|
+
* the header setters to configure algorithm inputs such as ECDH-ES "apu" (Agreement PartyUInfo)
|
|
61
|
+
* and "apv" (Agreement PartyVInfo), or PBES2 "p2c" (PBES2 Count). The parameters are added to the
|
|
62
|
+
* appropriate JOSE Header.
|
|
51
63
|
*
|
|
52
64
|
* @param parameters JWE Key Management parameters.
|
|
53
65
|
*/
|
|
54
66
|
setKeyManagementParameters(parameters: types.JWEKeyManagementHeaderParameters): this;
|
|
55
67
|
/**
|
|
56
|
-
* Sets
|
|
57
|
-
* "enc" (Encryption Algorithm)
|
|
68
|
+
* Sets a content encryption key to use, by default a random suitable one is generated for the JWE
|
|
69
|
+
* "enc" (Encryption Algorithm) Header Parameter.
|
|
58
70
|
*
|
|
59
|
-
* @deprecated
|
|
71
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
72
|
+
* validation purposes.
|
|
60
73
|
*
|
|
61
74
|
* @param cek JWE Content Encryption Key.
|
|
62
75
|
*/
|
|
63
76
|
setContentEncryptionKey(cek: Uint8Array): this;
|
|
64
77
|
/**
|
|
65
|
-
* Sets the Initialization Vector for content encryption
|
|
66
|
-
* generated for the JWE "enc" (Encryption Algorithm)
|
|
78
|
+
* Sets the JWE Initialization Vector to use for content encryption, by default a random suitable
|
|
79
|
+
* one is generated for the JWE "enc" (Encryption Algorithm) Header Parameter.
|
|
67
80
|
*
|
|
68
|
-
* @deprecated
|
|
81
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
82
|
+
* validation purposes.
|
|
69
83
|
*
|
|
70
84
|
* @param iv JWE Initialization Vector.
|
|
71
85
|
*/
|
|
72
86
|
setInitializationVector(iv: Uint8Array): this;
|
|
73
87
|
/**
|
|
74
|
-
* Replicates the "iss" (Issuer) Claim
|
|
75
|
-
* decryption.
|
|
88
|
+
* Replicates the "iss" (Issuer) Claim as a JWE Protected Header Parameter.
|
|
76
89
|
*
|
|
77
90
|
* @see {@link https://www.rfc-editor.org/info/rfc7519/#section-5.3 RFC7519#section-5.3}
|
|
78
91
|
*/
|
|
79
92
|
replicateIssuerAsHeader(): this;
|
|
80
93
|
/**
|
|
81
|
-
* Replicates the "sub" (Subject) Claim
|
|
82
|
-
* decryption.
|
|
94
|
+
* Replicates the "sub" (Subject) Claim as a JWE Protected Header Parameter.
|
|
83
95
|
*
|
|
84
96
|
* @see {@link https://www.rfc-editor.org/info/rfc7519/#section-5.3 RFC7519#section-5.3}
|
|
85
97
|
*/
|
|
86
98
|
replicateSubjectAsHeader(): this;
|
|
87
99
|
/**
|
|
88
|
-
* Replicates the "aud" (Audience) Claim
|
|
89
|
-
* decryption.
|
|
100
|
+
* Replicates the "aud" (Audience) Claim as a JWE Protected Header Parameter.
|
|
90
101
|
*
|
|
91
102
|
* @see {@link https://www.rfc-editor.org/info/rfc7519/#section-5.3 RFC7519#section-5.3}
|
|
92
103
|
*/
|
|
@@ -94,11 +105,10 @@ export declare class EncryptJWT extends EncryptJWT_base {
|
|
|
94
105
|
/**
|
|
95
106
|
* Encrypts and returns the JWT.
|
|
96
107
|
*
|
|
97
|
-
* @param key Public
|
|
108
|
+
* @param key Public Key or Secret to encrypt the JWT with. See
|
|
98
109
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
99
110
|
* @param options JWE Encryption options.
|
|
100
111
|
*/
|
|
101
112
|
encrypt(key: types.KeyInput, options?: types.EncryptOptions): Promise<string>;
|
|
102
113
|
}
|
|
103
|
-
export {};
|
|
104
114
|
//# sourceMappingURL=encrypt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../../src/jose/src/jwt/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL;;;;GAIG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../../src/jose/src/jwt/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL;;;;GAIG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,eAAe,CAAA;AAK3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,UAAW,YAAW,KAAK,CAAC,UAAU;;IAiBjD;;;;OAIG;gBACS,OAAO,GAAE,KAAK,CAAC,UAAe;IAI1C,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAKjC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAK9C,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK3B,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI;IAKjD,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI;IAKtD,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI;IAKjD;;;;;OAKG;IACH,kBAAkB,CAAC,eAAe,EAAE,KAAK,CAAC,0BAA0B,GAAG,IAAI;IAM3E;;;;;;;OAOG;IACH,0BAA0B,CAAC,UAAU,EAAE,KAAK,CAAC,gCAAgC,GAAG,IAAI;IAMpF;;;;;;;;OAQG;IACH,uBAAuB,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAM9C;;;;;;;;OAQG;IACH,uBAAuB,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI;IAM7C;;;;OAIG;IACH,uBAAuB,IAAI,IAAI;IAK/B;;;;OAIG;IACH,wBAAwB,IAAI,IAAI;IAKhC;;;;OAIG;IACH,yBAAyB,IAAI,IAAI;IAKjC;;;;;;OAMG;IACG,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;CA2BpF"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Original library: jose (v6.2.
|
|
2
|
+
* Original library: jose (v6.2.9)
|
|
3
3
|
* - Copyright (c) 2018 Filip Skokan
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
6
6
|
* - Evgeniy Bushin
|
|
7
7
|
*/
|
|
8
8
|
/***/
|
|
9
|
-
import {
|
|
10
|
-
import { JWTClaimsBuilder
|
|
11
|
-
import { assertNotSet } from '../lib/
|
|
12
|
-
/** @param payload Initial JWT Claims Set. Defaults to an empty object. */
|
|
13
|
-
const EncryptJWT_base = JWTClaimsBuilder;
|
|
9
|
+
import { CompactEncrypt } from '../jwe/compact/encrypt.js';
|
|
10
|
+
import { JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
|
|
11
|
+
import { assertNotSet } from '../lib/helpers.js';
|
|
14
12
|
/**
|
|
15
|
-
*
|
|
13
|
+
* The EncryptJWT class is used to build and encrypt Compact JWE formatted JSON Web Tokens.
|
|
16
14
|
*
|
|
17
15
|
* This class is exported (as a named export) from the main `'jose'` module entry point as well as
|
|
18
16
|
* from its subpath export `'jose/jwt/encrypt'`.
|
|
@@ -32,63 +30,105 @@ const EncryptJWT_base = JWTClaimsBuilder;
|
|
|
32
30
|
* console.log(jwt)
|
|
33
31
|
* ```
|
|
34
32
|
*/
|
|
35
|
-
export class EncryptJWT
|
|
36
|
-
#
|
|
33
|
+
export class EncryptJWT {
|
|
34
|
+
#cek;
|
|
35
|
+
#iv;
|
|
36
|
+
#keyManagementParameters;
|
|
37
|
+
#protectedHeader;
|
|
37
38
|
#replicateIssuerAsHeader;
|
|
38
39
|
#replicateSubjectAsHeader;
|
|
39
40
|
#replicateAudienceAsHeader;
|
|
41
|
+
#jwt;
|
|
40
42
|
/**
|
|
41
|
-
*
|
|
43
|
+
* {@link EncryptJWT} constructor
|
|
44
|
+
*
|
|
45
|
+
* @param payload The JWT Claims Set object. Defaults to an empty object.
|
|
46
|
+
*/
|
|
47
|
+
constructor(payload = {}) {
|
|
48
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
49
|
+
}
|
|
50
|
+
setIssuer(issuer) {
|
|
51
|
+
this.#jwt.iss = issuer;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
setSubject(subject) {
|
|
55
|
+
this.#jwt.sub = subject;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
setAudience(audience) {
|
|
59
|
+
this.#jwt.aud = audience;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
setJti(jwtId) {
|
|
63
|
+
this.#jwt.jti = jwtId;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
setNotBefore(input) {
|
|
67
|
+
this.#jwt.nbf = input;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
setExpirationTime(input) {
|
|
71
|
+
this.#jwt.exp = input;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
setIssuedAt(input) {
|
|
75
|
+
this.#jwt.iat = input;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Sets the JWE Protected Header on the EncryptJWT object.
|
|
42
80
|
*
|
|
43
81
|
* @param protectedHeader JWE Protected Header. Must contain an "alg" (JWE Algorithm) and "enc"
|
|
44
82
|
* (JWE Encryption Algorithm) properties.
|
|
45
83
|
*/
|
|
46
84
|
setProtectedHeader(protectedHeader) {
|
|
47
|
-
assertNotSet(this.#
|
|
48
|
-
this.#
|
|
85
|
+
assertNotSet(this.#protectedHeader, 'setProtectedHeader');
|
|
86
|
+
this.#protectedHeader = protectedHeader;
|
|
49
87
|
return this;
|
|
50
88
|
}
|
|
51
89
|
/**
|
|
52
|
-
* Sets JWE Key Management parameters
|
|
53
|
-
*
|
|
54
|
-
*
|
|
90
|
+
* Sets the JWE Key Management parameters to be used when encrypting. Use this method instead of
|
|
91
|
+
* the header setters to configure algorithm inputs such as ECDH-ES "apu" (Agreement PartyUInfo)
|
|
92
|
+
* and "apv" (Agreement PartyVInfo), or PBES2 "p2c" (PBES2 Count). The parameters are added to the
|
|
93
|
+
* appropriate JOSE Header.
|
|
55
94
|
*
|
|
56
95
|
* @param parameters JWE Key Management parameters.
|
|
57
96
|
*/
|
|
58
97
|
setKeyManagementParameters(parameters) {
|
|
59
|
-
assertNotSet(this.#
|
|
60
|
-
this.#
|
|
98
|
+
assertNotSet(this.#keyManagementParameters, 'setKeyManagementParameters');
|
|
99
|
+
this.#keyManagementParameters = parameters;
|
|
61
100
|
return this;
|
|
62
101
|
}
|
|
63
102
|
/**
|
|
64
|
-
* Sets
|
|
65
|
-
* "enc" (Encryption Algorithm)
|
|
103
|
+
* Sets a content encryption key to use, by default a random suitable one is generated for the JWE
|
|
104
|
+
* "enc" (Encryption Algorithm) Header Parameter.
|
|
66
105
|
*
|
|
67
|
-
* @deprecated
|
|
106
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
107
|
+
* validation purposes.
|
|
68
108
|
*
|
|
69
109
|
* @param cek JWE Content Encryption Key.
|
|
70
110
|
*/
|
|
71
111
|
setContentEncryptionKey(cek) {
|
|
72
|
-
assertNotSet(this.#
|
|
73
|
-
this.#
|
|
112
|
+
assertNotSet(this.#cek, 'setContentEncryptionKey');
|
|
113
|
+
this.#cek = cek;
|
|
74
114
|
return this;
|
|
75
115
|
}
|
|
76
116
|
/**
|
|
77
|
-
* Sets the Initialization Vector for content encryption
|
|
78
|
-
* generated for the JWE "enc" (Encryption Algorithm)
|
|
117
|
+
* Sets the JWE Initialization Vector to use for content encryption, by default a random suitable
|
|
118
|
+
* one is generated for the JWE "enc" (Encryption Algorithm) Header Parameter.
|
|
79
119
|
*
|
|
80
|
-
* @deprecated
|
|
120
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
121
|
+
* validation purposes.
|
|
81
122
|
*
|
|
82
123
|
* @param iv JWE Initialization Vector.
|
|
83
124
|
*/
|
|
84
125
|
setInitializationVector(iv) {
|
|
85
|
-
assertNotSet(this.#
|
|
86
|
-
this.#
|
|
126
|
+
assertNotSet(this.#iv, 'setInitializationVector');
|
|
127
|
+
this.#iv = iv;
|
|
87
128
|
return this;
|
|
88
129
|
}
|
|
89
130
|
/**
|
|
90
|
-
* Replicates the "iss" (Issuer) Claim
|
|
91
|
-
* decryption.
|
|
131
|
+
* Replicates the "iss" (Issuer) Claim as a JWE Protected Header Parameter.
|
|
92
132
|
*
|
|
93
133
|
* @see {@link https://www.rfc-editor.org/info/rfc7519/#section-5.3 RFC7519#section-5.3}
|
|
94
134
|
*/
|
|
@@ -97,8 +137,7 @@ export class EncryptJWT extends EncryptJWT_base {
|
|
|
97
137
|
return this;
|
|
98
138
|
}
|
|
99
139
|
/**
|
|
100
|
-
* Replicates the "sub" (Subject) Claim
|
|
101
|
-
* decryption.
|
|
140
|
+
* Replicates the "sub" (Subject) Claim as a JWE Protected Header Parameter.
|
|
102
141
|
*
|
|
103
142
|
* @see {@link https://www.rfc-editor.org/info/rfc7519/#section-5.3 RFC7519#section-5.3}
|
|
104
143
|
*/
|
|
@@ -107,8 +146,7 @@ export class EncryptJWT extends EncryptJWT_base {
|
|
|
107
146
|
return this;
|
|
108
147
|
}
|
|
109
148
|
/**
|
|
110
|
-
* Replicates the "aud" (Audience) Claim
|
|
111
|
-
* decryption.
|
|
149
|
+
* Replicates the "aud" (Audience) Claim as a JWE Protected Header Parameter.
|
|
112
150
|
*
|
|
113
151
|
* @see {@link https://www.rfc-editor.org/info/rfc7519/#section-5.3 RFC7519#section-5.3}
|
|
114
152
|
*/
|
|
@@ -119,26 +157,34 @@ export class EncryptJWT extends EncryptJWT_base {
|
|
|
119
157
|
/**
|
|
120
158
|
* Encrypts and returns the JWT.
|
|
121
159
|
*
|
|
122
|
-
* @param key Public
|
|
160
|
+
* @param key Public Key or Secret to encrypt the JWT with. See
|
|
123
161
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
124
162
|
* @param options JWE Encryption options.
|
|
125
163
|
*/
|
|
126
164
|
async encrypt(key, options) {
|
|
127
|
-
const
|
|
128
|
-
if (this.#
|
|
165
|
+
const enc = new CompactEncrypt(this.#jwt.data());
|
|
166
|
+
if (this.#protectedHeader &&
|
|
129
167
|
(this.#replicateIssuerAsHeader ||
|
|
130
168
|
this.#replicateSubjectAsHeader ||
|
|
131
169
|
this.#replicateAudienceAsHeader)) {
|
|
132
|
-
this.#
|
|
133
|
-
...this.#
|
|
134
|
-
iss: this.#replicateIssuerAsHeader ?
|
|
135
|
-
sub: this.#replicateSubjectAsHeader ?
|
|
136
|
-
aud: this.#replicateAudienceAsHeader ?
|
|
170
|
+
this.#protectedHeader = {
|
|
171
|
+
...this.#protectedHeader,
|
|
172
|
+
iss: this.#replicateIssuerAsHeader ? this.#jwt.iss : undefined,
|
|
173
|
+
sub: this.#replicateSubjectAsHeader ? this.#jwt.sub : undefined,
|
|
174
|
+
aud: this.#replicateAudienceAsHeader ? this.#jwt.aud : undefined,
|
|
137
175
|
};
|
|
138
176
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
177
|
+
enc.setProtectedHeader(this.#protectedHeader);
|
|
178
|
+
if (this.#iv) {
|
|
179
|
+
enc.setInitializationVector(this.#iv);
|
|
180
|
+
}
|
|
181
|
+
if (this.#cek) {
|
|
182
|
+
enc.setContentEncryptionKey(this.#cek);
|
|
183
|
+
}
|
|
184
|
+
if (this.#keyManagementParameters) {
|
|
185
|
+
enc.setKeyManagementParameters(this.#keyManagementParameters);
|
|
186
|
+
}
|
|
187
|
+
return enc.encrypt(key, options);
|
|
142
188
|
}
|
|
143
189
|
}
|
|
144
190
|
//# sourceMappingURL=encrypt.js.map
|