@suveren/gateway 0.4.1 → 0.6.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/bin/suveren-gateway.js +86 -5
- package/content/integrations/calendar.json +116 -22
- package/content/integrations/deploy-github.json +164 -0
- package/content/integrations/gmail.json +13 -4
- package/content/integrations/index.json +2 -1
- package/dist/control-plane/index.mjs +84 -7
- package/dist/mcp-server/http.mjs +147 -21
- package/dist/ui/assets/index-DecSrutK.js +105 -0
- package/dist/ui/index.html +1 -1
- package/node_modules/@hap/core/dist/index.d.mts +21 -0
- package/node_modules/@hap/core/dist/index.d.ts +21 -0
- package/node_modules/@hap/core/dist/index.js +17 -0
- package/node_modules/@hap/core/dist/index.mjs +17 -0
- package/node_modules/@hap/core/package.json +1 -1
- package/node_modules/@hap/core/src/gatekeeper.ts +28 -0
- package/node_modules/@hap/core/src/types.ts +21 -0
- package/node_modules/fast-uri/index.js +37 -1
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/fast-uri/test/security.test.js +136 -0
- package/node_modules/hono/dist/cjs/helper/proxy/index.js +4 -0
- package/node_modules/hono/dist/cjs/jsx/base.js +1 -9
- package/node_modules/hono/dist/cjs/jsx/hooks/index.js +14 -11
- package/node_modules/hono/dist/cjs/middleware/cors/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -6
- package/node_modules/hono/dist/cjs/utils/cookie.js +2 -1
- package/node_modules/hono/dist/helper/proxy/index.js +4 -0
- package/node_modules/hono/dist/jsx/base.js +1 -9
- package/node_modules/hono/dist/jsx/hooks/index.js +14 -11
- package/node_modules/hono/dist/middleware/cors/index.js +1 -1
- package/node_modules/hono/dist/middleware/language/language.js +10 -6
- package/node_modules/hono/dist/utils/cookie.js +2 -1
- package/node_modules/hono/package.json +2 -3
- package/node_modules/ip-address/README.md +142 -128
- package/node_modules/ip-address/dist/common.d.ts +6 -0
- package/node_modules/ip-address/dist/common.js +17 -1
- package/node_modules/ip-address/dist/common.js.map +1 -1
- package/node_modules/ip-address/dist/ipv4.js +3 -12
- package/node_modules/ip-address/dist/ipv4.js.map +1 -1
- package/node_modules/ip-address/dist/ipv6.d.ts +9 -2
- package/node_modules/ip-address/dist/ipv6.js +35 -16
- package/node_modules/ip-address/dist/ipv6.js.map +1 -1
- package/node_modules/ip-address/package.json +5 -3
- package/node_modules/jose/README.md +13 -13
- package/node_modules/jose/dist/types/index.d.ts +6 -5
- package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +7 -19
- package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +7 -19
- package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
- package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +20 -21
- package/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
- package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
- package/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
- package/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
- package/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
- package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
- package/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
- package/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
- package/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwt/encrypt.d.ts +10 -34
- package/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
- package/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
- package/node_modules/jose/dist/types/key/export.d.ts +0 -14
- package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
- package/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
- package/node_modules/jose/dist/types/key/import.d.ts +18 -28
- package/node_modules/jose/dist/types/types.d.ts +239 -222
- package/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
- package/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
- package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
- package/node_modules/jose/dist/types/util/errors.d.ts +128 -121
- package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +4 -22
- package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
- package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
- package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +15 -3
- package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +65 -81
- package/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
- package/node_modules/jose/dist/webapi/jwks/local.js +31 -72
- package/node_modules/jose/dist/webapi/jwks/remote.js +19 -28
- package/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
- package/node_modules/jose/dist/webapi/jws/compact/verify.js +4 -16
- package/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -65
- package/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
- package/node_modules/jose/dist/webapi/jws/general/sign.js +19 -15
- package/node_modules/jose/dist/webapi/jws/general/verify.js +29 -9
- package/node_modules/jose/dist/webapi/jwt/decrypt.js +5 -5
- package/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
- package/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
- package/node_modules/jose/dist/webapi/jwt/verify.js +6 -6
- package/node_modules/jose/dist/webapi/key/export.js +37 -4
- package/node_modules/jose/dist/webapi/key/generate_key_pair.js +33 -82
- package/node_modules/jose/dist/webapi/key/import.js +8 -8
- package/node_modules/jose/dist/webapi/lib/asn1.js +53 -122
- package/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
- package/node_modules/jose/dist/webapi/lib/content_encryption.js +34 -109
- package/node_modules/jose/dist/webapi/lib/crypto_key.js +18 -126
- package/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
- package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +0 -1
- package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +116 -0
- package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +186 -0
- package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +110 -0
- package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +8 -98
- package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +76 -0
- package/node_modules/jose/dist/webapi/lib/jws_sign.js +74 -0
- package/node_modules/jose/dist/webapi/lib/jws_verify.js +107 -0
- package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +68 -109
- package/node_modules/jose/dist/webapi/lib/key.js +132 -0
- package/node_modules/jose/dist/webapi/lib/key_algorithm.js +10 -0
- package/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
- package/node_modules/jose/dist/webapi/lib/key_management.js +162 -92
- package/node_modules/jose/dist/webapi/lib/options.js +48 -0
- package/node_modules/jose/dist/webapi/lib/signing.js +14 -56
- package/node_modules/jose/dist/webapi/lib/type_checks.js +13 -18
- package/node_modules/jose/dist/webapi/util/base64url.js +13 -4
- package/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
- package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
- package/node_modules/jose/dist/webapi/util/errors.js +1 -1
- package/node_modules/jose/package.json +2 -4
- package/package.json +2 -2
- package/profiles/deploy/0.6.profile.json +168 -0
- package/profiles/deploy/0.7.profile.json +168 -0
- package/profiles/email/0.4.profile.json +9 -2
- package/profiles/index.json +3 -1
- package/dist/ui/assets/index-Cog54HOo.js +0 -105
- package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
- package/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
- package/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
- package/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
- package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
- package/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
- package/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
- package/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
- package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
- package/node_modules/jose/dist/webapi/lib/validate_crit.js +0 -33
|
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
|
|
|
9
9
|
let USER_AGENT;
|
|
10
10
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
11
11
|
const NAME = 'jose';
|
|
12
|
-
const VERSION = 'v6.2.
|
|
12
|
+
const VERSION = 'v6.2.7';
|
|
13
13
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
14
|
}
|
|
15
15
|
export const customFetch = Symbol();
|
|
@@ -51,7 +51,7 @@ function isFreshJwksCache(input, cacheMaxAge) {
|
|
|
51
51
|
}
|
|
52
52
|
return true;
|
|
53
53
|
}
|
|
54
|
-
class
|
|
54
|
+
class RemoteJWKSetImpl {
|
|
55
55
|
#url;
|
|
56
56
|
#timeoutDuration;
|
|
57
57
|
#cooldownDuration;
|
|
@@ -67,12 +67,12 @@ class RemoteJWKSet {
|
|
|
67
67
|
throw new TypeError('url must be an instance of URL');
|
|
68
68
|
}
|
|
69
69
|
this.#url = new URL(url.href);
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const opts = options ?? {};
|
|
71
|
+
this.#timeoutDuration = typeof opts.timeoutDuration === 'number' ? opts.timeoutDuration : 5000;
|
|
72
72
|
this.#cooldownDuration =
|
|
73
|
-
typeof
|
|
74
|
-
this.#cacheMaxAge = typeof
|
|
75
|
-
this.#headers = new Headers(
|
|
73
|
+
typeof opts.cooldownDuration === 'number' ? opts.cooldownDuration : 30000;
|
|
74
|
+
this.#cacheMaxAge = typeof opts.cacheMaxAge === 'number' ? opts.cacheMaxAge : 600000;
|
|
75
|
+
this.#headers = new Headers(opts.headers);
|
|
76
76
|
if (USER_AGENT && !this.#headers.has('User-Agent')) {
|
|
77
77
|
this.#headers.set('User-Agent', USER_AGENT);
|
|
78
78
|
}
|
|
@@ -80,10 +80,11 @@ class RemoteJWKSet {
|
|
|
80
80
|
this.#headers.set('accept', 'application/json');
|
|
81
81
|
this.#headers.append('accept', 'application/jwk-set+json');
|
|
82
82
|
}
|
|
83
|
-
this.#customFetch =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
this.#customFetch = opts[customFetch];
|
|
84
|
+
const cache = opts[jwksCache];
|
|
85
|
+
if (cache !== undefined) {
|
|
86
|
+
this.#cache = cache;
|
|
87
|
+
if (isFreshJwksCache(cache, this.#cacheMaxAge)) {
|
|
87
88
|
this.#jwksTimestamp = this.#cache.uat;
|
|
88
89
|
this.#local = createLocalJWKSet(this.#cache.jwks);
|
|
89
90
|
}
|
|
@@ -92,15 +93,14 @@ class RemoteJWKSet {
|
|
|
92
93
|
pendingFetch() {
|
|
93
94
|
return !!this.#pendingFetch;
|
|
94
95
|
}
|
|
96
|
+
#validFor(duration) {
|
|
97
|
+
return typeof this.#jwksTimestamp === 'number' && Date.now() < this.#jwksTimestamp + duration;
|
|
98
|
+
}
|
|
95
99
|
coolingDown() {
|
|
96
|
-
return
|
|
97
|
-
? Date.now() < this.#jwksTimestamp + this.#cooldownDuration
|
|
98
|
-
: false;
|
|
100
|
+
return this.#validFor(this.#cooldownDuration);
|
|
99
101
|
}
|
|
100
102
|
fresh() {
|
|
101
|
-
return
|
|
102
|
-
? Date.now() < this.#jwksTimestamp + this.#cacheMaxAge
|
|
103
|
-
: false;
|
|
103
|
+
return this.#validFor(this.#cacheMaxAge);
|
|
104
104
|
}
|
|
105
105
|
jwks() {
|
|
106
106
|
return this.#local?.jwks();
|
|
@@ -134,45 +134,36 @@ class RemoteJWKSet {
|
|
|
134
134
|
this.#cache.jwks = json;
|
|
135
135
|
}
|
|
136
136
|
this.#jwksTimestamp = Date.now();
|
|
137
|
-
this.#pendingFetch = undefined;
|
|
138
137
|
})
|
|
139
|
-
.
|
|
138
|
+
.finally(() => {
|
|
140
139
|
this.#pendingFetch = undefined;
|
|
141
|
-
throw err;
|
|
142
140
|
});
|
|
143
141
|
await this.#pendingFetch;
|
|
144
142
|
}
|
|
145
143
|
}
|
|
146
144
|
export function createRemoteJWKSet(url, options) {
|
|
147
|
-
const set = new
|
|
145
|
+
const set = new RemoteJWKSetImpl(url, options);
|
|
148
146
|
const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
149
147
|
Object.defineProperties(remoteJWKSet, {
|
|
150
148
|
coolingDown: {
|
|
151
149
|
get: () => set.coolingDown(),
|
|
152
150
|
enumerable: true,
|
|
153
|
-
configurable: false,
|
|
154
151
|
},
|
|
155
152
|
fresh: {
|
|
156
153
|
get: () => set.fresh(),
|
|
157
154
|
enumerable: true,
|
|
158
|
-
configurable: false,
|
|
159
155
|
},
|
|
160
156
|
reload: {
|
|
161
157
|
value: () => set.reload(),
|
|
162
158
|
enumerable: true,
|
|
163
|
-
configurable: false,
|
|
164
|
-
writable: false,
|
|
165
159
|
},
|
|
166
160
|
reloading: {
|
|
167
161
|
get: () => set.pendingFetch(),
|
|
168
162
|
enumerable: true,
|
|
169
|
-
configurable: false,
|
|
170
163
|
},
|
|
171
164
|
jwks: {
|
|
172
165
|
value: () => set.jwks(),
|
|
173
166
|
enumerable: true,
|
|
174
|
-
configurable: false,
|
|
175
|
-
writable: false,
|
|
176
167
|
},
|
|
177
168
|
});
|
|
178
169
|
return remoteJWKSet;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { FlattenedSign } from '../flattened/sign.js';
|
|
2
|
+
import { unencodedPayload } from '../../lib/jws_sign.js';
|
|
2
3
|
export class CompactSign {
|
|
3
4
|
#flattened;
|
|
5
|
+
#protectedHeader;
|
|
4
6
|
constructor(payload) {
|
|
5
7
|
this.#flattened = new FlattenedSign(payload);
|
|
6
8
|
}
|
|
7
9
|
setProtectedHeader(protectedHeader) {
|
|
8
10
|
this.#flattened.setProtectedHeader(protectedHeader);
|
|
11
|
+
this.#protectedHeader = protectedHeader;
|
|
9
12
|
return this;
|
|
10
13
|
}
|
|
11
14
|
async sign(key, options) {
|
|
12
|
-
|
|
13
|
-
if (jws.payload === undefined) {
|
|
15
|
+
if (unencodedPayload(this.#protectedHeader)) {
|
|
14
16
|
throw new TypeError('use the flattened module for creating JWS with b64: false');
|
|
15
17
|
}
|
|
18
|
+
const jws = await this.#flattened.sign(key, options);
|
|
16
19
|
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
17
20
|
}
|
|
18
21
|
}
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JWSInvalid } from '../../util/errors.js';
|
|
3
|
-
import { decoder } from '../../lib/buffer_utils.js';
|
|
1
|
+
import { prepareVerify, verifyCompact } from '../../lib/jws_verify.js';
|
|
4
2
|
export async function compactVerify(jws, key, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
if (typeof jws !== 'string') {
|
|
9
|
-
throw new JWSInvalid('Compact JWS must be a string or Uint8Array');
|
|
10
|
-
}
|
|
11
|
-
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split('.');
|
|
12
|
-
if (length !== 3) {
|
|
13
|
-
throw new JWSInvalid('Invalid Compact JWS');
|
|
14
|
-
}
|
|
15
|
-
const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
|
|
16
|
-
const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
|
|
3
|
+
const verified = await verifyCompact(jws, prepareVerify(options), key);
|
|
4
|
+
const result = { payload: verified[0], protectedHeader: verified[1] };
|
|
17
5
|
if (typeof key === 'function') {
|
|
18
|
-
return { ...result, key: verified
|
|
6
|
+
return { ...result, key: verified[3] };
|
|
19
7
|
}
|
|
20
8
|
return result;
|
|
21
9
|
}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { sign } from '../../lib/signing.js';
|
|
3
|
-
import { isDisjoint } from '../../lib/type_checks.js';
|
|
4
|
-
import { JWSInvalid } from '../../util/errors.js';
|
|
5
|
-
import { concat, encode } from '../../lib/buffer_utils.js';
|
|
6
|
-
import { checkKeyType } from '../../lib/check_key_type.js';
|
|
7
|
-
import { validateCrit } from '../../lib/validate_crit.js';
|
|
8
|
-
import { normalizeKey } from '../../lib/normalize_key.js';
|
|
1
|
+
import { createSignature } from '../../lib/jws_sign.js';
|
|
9
2
|
import { assertNotSet } from '../../lib/helpers.js';
|
|
10
3
|
export class FlattenedSign {
|
|
11
4
|
#payload;
|
|
@@ -28,62 +21,11 @@ export class FlattenedSign {
|
|
|
28
21
|
return this;
|
|
29
22
|
}
|
|
30
23
|
async sign(key, options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
const joseHeader = {
|
|
38
|
-
...this.#protectedHeader,
|
|
39
|
-
...this.#unprotectedHeader,
|
|
40
|
-
};
|
|
41
|
-
const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
42
|
-
let b64 = true;
|
|
43
|
-
if (extensions.has('b64')) {
|
|
44
|
-
b64 = this.#protectedHeader.b64;
|
|
45
|
-
if (typeof b64 !== 'boolean') {
|
|
46
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const { alg } = joseHeader;
|
|
50
|
-
if (typeof alg !== 'string' || !alg) {
|
|
51
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
52
|
-
}
|
|
53
|
-
checkKeyType(alg, key, 'sign');
|
|
54
|
-
let payloadS;
|
|
55
|
-
let payloadB;
|
|
56
|
-
if (b64) {
|
|
57
|
-
payloadS = b64u(this.#payload);
|
|
58
|
-
payloadB = encode(payloadS);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
payloadB = this.#payload;
|
|
62
|
-
payloadS = '';
|
|
63
|
-
}
|
|
64
|
-
let protectedHeaderString;
|
|
65
|
-
let protectedHeaderBytes;
|
|
66
|
-
if (this.#protectedHeader) {
|
|
67
|
-
protectedHeaderString = b64u(JSON.stringify(this.#protectedHeader));
|
|
68
|
-
protectedHeaderBytes = encode(protectedHeaderString);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
protectedHeaderString = '';
|
|
72
|
-
protectedHeaderBytes = new Uint8Array();
|
|
73
|
-
}
|
|
74
|
-
const data = concat(protectedHeaderBytes, encode('.'), payloadB);
|
|
75
|
-
const k = await normalizeKey(key, alg);
|
|
76
|
-
const signature = await sign(alg, k, data);
|
|
77
|
-
const jws = {
|
|
78
|
-
signature: b64u(signature),
|
|
79
|
-
payload: payloadS,
|
|
80
|
-
};
|
|
81
|
-
if (this.#unprotectedHeader) {
|
|
82
|
-
jws.header = this.#unprotectedHeader;
|
|
83
|
-
}
|
|
84
|
-
if (this.#protectedHeader) {
|
|
85
|
-
jws.protected = protectedHeaderString;
|
|
86
|
-
}
|
|
87
|
-
return jws;
|
|
24
|
+
return createSignature({
|
|
25
|
+
payload: this.#payload,
|
|
26
|
+
protectedHeader: this.#protectedHeader,
|
|
27
|
+
unprotectedHeader: this.#unprotectedHeader,
|
|
28
|
+
crit: options?.crit,
|
|
29
|
+
}, key);
|
|
88
30
|
}
|
|
89
31
|
}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { verify } from '../../lib/signing.js';
|
|
3
|
-
import { JOSEAlgNotAllowed, JWSInvalid, JWSSignatureVerificationFailed } from '../../util/errors.js';
|
|
4
|
-
import { concat, encoder, decoder, encode } from '../../lib/buffer_utils.js';
|
|
5
|
-
import { decodeBase64url } from '../../lib/helpers.js';
|
|
6
|
-
import { isDisjoint } from '../../lib/type_checks.js';
|
|
1
|
+
import { JWSInvalid } from '../../util/errors.js';
|
|
7
2
|
import { isObject } from '../../lib/type_checks.js';
|
|
8
|
-
import {
|
|
9
|
-
import { validateCrit } from '../../lib/validate_crit.js';
|
|
10
|
-
import { validateAlgorithms } from '../../lib/validate_algorithms.js';
|
|
11
|
-
import { normalizeKey } from '../../lib/normalize_key.js';
|
|
3
|
+
import { prepareVerify, verifySignature, verifyResult } from '../../lib/jws_verify.js';
|
|
12
4
|
export async function flattenedVerify(jws, key, options) {
|
|
13
5
|
if (!isObject(jws)) {
|
|
14
6
|
throw new JWSInvalid('Flattened JWS must be an object');
|
|
@@ -28,83 +20,5 @@ export async function flattenedVerify(jws, key, options) {
|
|
|
28
20
|
if (jws.header !== undefined && !isObject(jws.header)) {
|
|
29
21
|
throw new JWSInvalid('JWS Unprotected Header incorrect type');
|
|
30
22
|
}
|
|
31
|
-
|
|
32
|
-
if (jws.protected) {
|
|
33
|
-
try {
|
|
34
|
-
const protectedHeader = b64u(jws.protected);
|
|
35
|
-
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
throw new JWSInvalid('JWS Protected Header is invalid');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!isDisjoint(parsedProt, jws.header)) {
|
|
42
|
-
throw new JWSInvalid('JWS Protected and JWS Unprotected Header Parameter names must be disjoint');
|
|
43
|
-
}
|
|
44
|
-
const joseHeader = {
|
|
45
|
-
...parsedProt,
|
|
46
|
-
...jws.header,
|
|
47
|
-
};
|
|
48
|
-
const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options?.crit, parsedProt, joseHeader);
|
|
49
|
-
let b64 = true;
|
|
50
|
-
if (extensions.has('b64')) {
|
|
51
|
-
b64 = parsedProt.b64;
|
|
52
|
-
if (typeof b64 !== 'boolean') {
|
|
53
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const { alg } = joseHeader;
|
|
57
|
-
if (typeof alg !== 'string' || !alg) {
|
|
58
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
59
|
-
}
|
|
60
|
-
const algorithms = options && validateAlgorithms('algorithms', options.algorithms);
|
|
61
|
-
if (algorithms && !algorithms.has(alg)) {
|
|
62
|
-
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
63
|
-
}
|
|
64
|
-
if (b64) {
|
|
65
|
-
if (typeof jws.payload !== 'string') {
|
|
66
|
-
throw new JWSInvalid('JWS Payload must be a string');
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else if (typeof jws.payload !== 'string' && !(jws.payload instanceof Uint8Array)) {
|
|
70
|
-
throw new JWSInvalid('JWS Payload must be a string or an Uint8Array instance');
|
|
71
|
-
}
|
|
72
|
-
let resolvedKey = false;
|
|
73
|
-
if (typeof key === 'function') {
|
|
74
|
-
key = await key(parsedProt, jws);
|
|
75
|
-
resolvedKey = true;
|
|
76
|
-
}
|
|
77
|
-
checkKeyType(alg, key, 'verify');
|
|
78
|
-
const data = concat(jws.protected !== undefined ? encode(jws.protected) : new Uint8Array(), encode('.'), typeof jws.payload === 'string'
|
|
79
|
-
? b64
|
|
80
|
-
? encode(jws.payload)
|
|
81
|
-
: encoder.encode(jws.payload)
|
|
82
|
-
: jws.payload);
|
|
83
|
-
const signature = decodeBase64url(jws.signature, 'signature', JWSInvalid);
|
|
84
|
-
const k = await normalizeKey(key, alg);
|
|
85
|
-
const verified = await verify(alg, k, signature, data);
|
|
86
|
-
if (!verified) {
|
|
87
|
-
throw new JWSSignatureVerificationFailed();
|
|
88
|
-
}
|
|
89
|
-
let payload;
|
|
90
|
-
if (b64) {
|
|
91
|
-
payload = decodeBase64url(jws.payload, 'payload', JWSInvalid);
|
|
92
|
-
}
|
|
93
|
-
else if (typeof jws.payload === 'string') {
|
|
94
|
-
payload = encoder.encode(jws.payload);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
payload = jws.payload;
|
|
98
|
-
}
|
|
99
|
-
const result = { payload };
|
|
100
|
-
if (jws.protected !== undefined) {
|
|
101
|
-
result.protectedHeader = parsedProt;
|
|
102
|
-
}
|
|
103
|
-
if (jws.header !== undefined) {
|
|
104
|
-
result.unprotectedHeader = jws.header;
|
|
105
|
-
}
|
|
106
|
-
if (resolvedKey) {
|
|
107
|
-
return { ...result, key: k };
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
23
|
+
return verifyResult(jws, await verifySignature(jws, prepareVerify(options), key));
|
|
110
24
|
}
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSignature } from '../../lib/jws_sign.js';
|
|
2
2
|
import { JWSInvalid } from '../../util/errors.js';
|
|
3
3
|
import { assertNotSet } from '../../lib/helpers.js';
|
|
4
4
|
class IndividualSignature {
|
|
5
5
|
#parent;
|
|
6
|
-
|
|
7
|
-
unprotectedHeader;
|
|
8
|
-
options;
|
|
9
|
-
key;
|
|
6
|
+
state;
|
|
10
7
|
constructor(sig, key, options) {
|
|
11
8
|
this.#parent = sig;
|
|
12
|
-
this.
|
|
13
|
-
this.options = options;
|
|
9
|
+
this.state = [undefined, undefined, key, options?.crit];
|
|
14
10
|
}
|
|
15
11
|
setProtectedHeader(protectedHeader) {
|
|
16
|
-
assertNotSet(this.
|
|
17
|
-
this.
|
|
12
|
+
assertNotSet(this.state[0], 'setProtectedHeader');
|
|
13
|
+
this.state[0] = protectedHeader;
|
|
18
14
|
return this;
|
|
19
15
|
}
|
|
20
16
|
setUnprotectedHeader(unprotectedHeader) {
|
|
21
|
-
assertNotSet(this.
|
|
22
|
-
this.
|
|
17
|
+
assertNotSet(this.state[1], 'setUnprotectedHeader');
|
|
18
|
+
this.state[1] = unprotectedHeader;
|
|
23
19
|
return this;
|
|
24
20
|
}
|
|
25
21
|
addSignature(...args) {
|
|
@@ -47,16 +43,24 @@ export class GeneralSign {
|
|
|
47
43
|
if (!this.#signatures.length) {
|
|
48
44
|
throw new JWSInvalid('at least one signature must be added');
|
|
49
45
|
}
|
|
46
|
+
if (!(this.#payload instanceof Uint8Array)) {
|
|
47
|
+
throw new TypeError('payload must be an instance of Uint8Array');
|
|
48
|
+
}
|
|
50
49
|
const jws = {
|
|
51
50
|
signatures: [],
|
|
52
51
|
payload: '',
|
|
53
52
|
};
|
|
53
|
+
const encoded = [];
|
|
54
54
|
for (let i = 0; i < this.#signatures.length; i++) {
|
|
55
55
|
const signature = this.#signatures[i];
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
const [protectedHeader, unprotectedHeader, key, crit] = signature.state;
|
|
57
|
+
const { payload, ...rest } = await createSignature({
|
|
58
|
+
payload: this.#payload,
|
|
59
|
+
protectedHeader,
|
|
60
|
+
unprotectedHeader,
|
|
61
|
+
crit,
|
|
62
|
+
encoded,
|
|
63
|
+
}, key);
|
|
60
64
|
if (i === 0) {
|
|
61
65
|
jws.payload = payload;
|
|
62
66
|
}
|
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { prepareVerify, verifySignature, verifyResult } from '../../lib/jws_verify.js';
|
|
2
2
|
import { JWSInvalid, JWSSignatureVerificationFailed } from '../../util/errors.js';
|
|
3
3
|
import { isObject } from '../../lib/type_checks.js';
|
|
4
4
|
export async function generalVerify(jws, key, options) {
|
|
5
5
|
if (!isObject(jws)) {
|
|
6
6
|
throw new JWSInvalid('General JWS must be an object');
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
const { signatures, payload } = jws;
|
|
9
|
+
if (!Array.isArray(signatures) || !signatures.every(isObject)) {
|
|
9
10
|
throw new JWSInvalid('JWS Signatures missing or incorrect type');
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
let shared;
|
|
13
|
+
try {
|
|
14
|
+
if (payload === undefined)
|
|
15
|
+
throw new Error();
|
|
16
|
+
shared = prepareVerify(options);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new JWSSignatureVerificationFailed();
|
|
20
|
+
}
|
|
21
|
+
for (const signature of signatures) {
|
|
12
22
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
23
|
+
const { protected: encodedProtected, header, signature: encodedSignature } = signature;
|
|
24
|
+
if (encodedProtected === undefined && header === undefined)
|
|
25
|
+
throw new Error();
|
|
26
|
+
if (encodedProtected !== undefined && typeof encodedProtected !== 'string') {
|
|
27
|
+
throw new Error();
|
|
28
|
+
}
|
|
29
|
+
if (typeof encodedSignature !== 'string')
|
|
30
|
+
throw new Error();
|
|
31
|
+
if (header !== undefined && !isObject(header))
|
|
32
|
+
throw new Error();
|
|
33
|
+
return verifyResult(signature, await verifySignature({
|
|
34
|
+
header,
|
|
35
|
+
payload,
|
|
36
|
+
protected: encodedProtected,
|
|
37
|
+
signature: encodedSignature,
|
|
38
|
+
}, shared, key));
|
|
19
39
|
}
|
|
20
40
|
catch {
|
|
21
41
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { prepareDecrypt, decryptCompact } from '../lib/jwe_decrypt.js';
|
|
2
2
|
import { validateClaimsSet } from '../lib/jwt_claims_set.js';
|
|
3
3
|
import { JWTClaimValidationFailed } from '../util/errors.js';
|
|
4
4
|
export async function jwtDecrypt(jwt, key, options) {
|
|
5
|
-
const decrypted = await
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const decrypted = await decryptCompact(jwt, prepareDecrypt(options), key);
|
|
6
|
+
const protectedHeader = decrypted[1];
|
|
7
|
+
const payload = validateClaimsSet(protectedHeader, decrypted[0], options);
|
|
8
8
|
if (protectedHeader.iss !== undefined && protectedHeader.iss !== payload.iss) {
|
|
9
9
|
throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, 'iss', 'mismatch');
|
|
10
10
|
}
|
|
@@ -17,7 +17,7 @@ export async function jwtDecrypt(jwt, key, options) {
|
|
|
17
17
|
}
|
|
18
18
|
const result = { payload, protectedHeader };
|
|
19
19
|
if (typeof key === 'function') {
|
|
20
|
-
return { ...result, key: decrypted
|
|
20
|
+
return { ...result, key: decrypted[2] };
|
|
21
21
|
}
|
|
22
22
|
return result;
|
|
23
23
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CompactSign } from '../jws/compact/sign.js';
|
|
2
|
+
import { unencodedPayload } from '../lib/jws_sign.js';
|
|
2
3
|
import { JWTInvalid } from '../util/errors.js';
|
|
3
4
|
import { JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
|
|
4
5
|
export class SignJWT {
|
|
@@ -42,9 +43,7 @@ export class SignJWT {
|
|
|
42
43
|
async sign(key, options) {
|
|
43
44
|
const sig = new CompactSign(this.#jwt.data());
|
|
44
45
|
sig.setProtectedHeader(this.#protectedHeader);
|
|
45
|
-
if (
|
|
46
|
-
this.#protectedHeader.crit.includes('b64') &&
|
|
47
|
-
this.#protectedHeader.b64 === false) {
|
|
46
|
+
if (unencodedPayload(this.#protectedHeader)) {
|
|
48
47
|
throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
|
|
49
48
|
}
|
|
50
49
|
return sig.sign(key, options);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as b64u from '../util/base64url.js';
|
|
2
|
-
import {
|
|
2
|
+
import { strictDecoder } from '../lib/buffer_utils.js';
|
|
3
|
+
import { decodeBase64url } from '../lib/helpers.js';
|
|
3
4
|
import { JWTInvalid } from '../util/errors.js';
|
|
4
5
|
import { validateClaimsSet, JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
|
|
5
6
|
export class UnsecuredJWT {
|
|
@@ -50,14 +51,14 @@ export class UnsecuredJWT {
|
|
|
50
51
|
}
|
|
51
52
|
let header;
|
|
52
53
|
try {
|
|
53
|
-
header = JSON.parse(
|
|
54
|
+
header = JSON.parse(strictDecoder.decode(b64u.decode(encodedHeader)));
|
|
54
55
|
if (header.alg !== 'none')
|
|
55
56
|
throw new Error();
|
|
56
57
|
}
|
|
57
58
|
catch {
|
|
58
59
|
throw new JWTInvalid('Invalid Unsecured JWT');
|
|
59
60
|
}
|
|
60
|
-
const payload = validateClaimsSet(header,
|
|
61
|
+
const payload = validateClaimsSet(header, decodeBase64url(encodedPayload, 'payload', JWTInvalid), options);
|
|
61
62
|
return { payload, header };
|
|
62
63
|
}
|
|
63
64
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { prepareVerify, verifyCompact } from '../lib/jws_verify.js';
|
|
2
2
|
import { validateClaimsSet } from '../lib/jwt_claims_set.js';
|
|
3
3
|
import { JWTInvalid } from '../util/errors.js';
|
|
4
4
|
export async function jwtVerify(jwt, key, options) {
|
|
5
|
-
const verified = await
|
|
6
|
-
if (verified
|
|
5
|
+
const verified = await verifyCompact(jwt, prepareVerify(options), key);
|
|
6
|
+
if (!verified[2]) {
|
|
7
7
|
throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
|
|
8
8
|
}
|
|
9
|
-
const payload = validateClaimsSet(verified
|
|
10
|
-
const result = { payload, protectedHeader: verified
|
|
9
|
+
const payload = validateClaimsSet(verified[1], verified[0], options);
|
|
10
|
+
const result = { payload, protectedHeader: verified[1] };
|
|
11
11
|
if (typeof key === 'function') {
|
|
12
|
-
return { ...result, key: verified
|
|
12
|
+
return { ...result, key: verified[3] };
|
|
13
13
|
}
|
|
14
14
|
return result;
|
|
15
15
|
}
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
import { toSPKI as exportPublic, toPKCS8 as exportPrivate } from '../lib/asn1.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { invalidKeyInput } from '../lib/invalid_key_input.js';
|
|
3
|
+
import { encode as b64u } from '../util/base64url.js';
|
|
4
|
+
import { isCryptoKey, isKeyObject } from '../lib/is_key_like.js';
|
|
5
|
+
function omitUndefinedProperties(jwk) {
|
|
6
|
+
return Object.fromEntries(Object.entries(jwk).filter(([, value]) => value !== undefined));
|
|
7
|
+
}
|
|
8
|
+
async function keyToJWK(key) {
|
|
9
|
+
if (isKeyObject(key)) {
|
|
10
|
+
if (key.type === 'secret') {
|
|
11
|
+
key = key.export();
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return key.export({ format: 'jwk' });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (key instanceof Uint8Array) {
|
|
18
|
+
return {
|
|
19
|
+
kty: 'oct',
|
|
20
|
+
k: b64u(key),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (!isCryptoKey(key)) {
|
|
24
|
+
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'KeyObject', 'Uint8Array'));
|
|
25
|
+
}
|
|
26
|
+
if (!key.extractable) {
|
|
27
|
+
throw new TypeError('non-extractable CryptoKey cannot be exported as a JWK');
|
|
28
|
+
}
|
|
29
|
+
const { ext, key_ops, alg, use, ...jwk } = omitUndefinedProperties(await crypto.subtle.exportKey('jwk', key));
|
|
30
|
+
if (jwk.kty === 'AKP') {
|
|
31
|
+
;
|
|
32
|
+
jwk.alg = alg;
|
|
33
|
+
}
|
|
34
|
+
return jwk;
|
|
35
|
+
}
|
|
36
|
+
export function exportSPKI(key) {
|
|
4
37
|
return exportPublic(key);
|
|
5
38
|
}
|
|
6
|
-
export
|
|
39
|
+
export function exportPKCS8(key) {
|
|
7
40
|
return exportPrivate(key);
|
|
8
41
|
}
|
|
9
|
-
export
|
|
42
|
+
export function exportJWK(key) {
|
|
10
43
|
return keyToJWK(key);
|
|
11
44
|
}
|