oidc-spa 7.1.7 → 7.1.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"loginSilent.js","sourceRoot":"","sources":["../src/core/loginSilent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,kCAqKC;AA5LD,8CAA6C;AAC7C,kDAAmE;AACnE,yCAA4E;AAC5E,gEAA+D;AAC/D,wCAA0C;AAE1C,+CAAsE;AACtE,4DAAkE;AAgBlE,SAAsB,WAAW,CAAC,MAejC;;;;;YAEO,uBAAuB,GAOvB,MAAM,wBAPiB,EACvB,6BAA6B,GAM7B,MAAM,8BANuB,EAC7B,QAAQ,GAKR,MAAM,SALE,EACR,0BAA0B,GAI1B,MAAM,2BAJoB,EAC1B,mBAAmB,GAGnB,MAAM,oBAHa,EACnB,mBAAmB,GAEnB,MAAM,oBAFa,EACnB,SAAS,GACT,MAAM,UADG,CACF;YAEL,OAAO,GAAG,IAAI,mBAAQ,EAAuB,CAAC;YAE9C,cAAc,GAAW,CAAC;gBAC5B,IAAI,SAAS,EAAE,CAAC;oBACZ,OAAO,KAAM,CAAC;gBAClB,CAAC;gBAED,IAAM,cAAc,GAAG,IAAA,qCAAiB,GAAE,CAAC;gBAC3C,IAAM,KAAK,GAAG,IAAA,gBAAQ,GAAE,CAAC;gBAEzB,6DAA6D;gBAC7D,IAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,IAAK,CAAC,CAAC,CAAC,IAAK,CAAC;gBAE5C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;oBAC/B,OAAO,aAAa,CAAC;gBACzB,CAAC;gBAEO,IAAA,QAAQ,GAAU,cAAc,SAAxB,EAAE,GAAG,GAAK,cAAc,IAAnB,CAAoB;gBAEzC,oDAAoD;gBACpD,8CAA8C;gBAC9C,IAAM,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C;wBAEtB,OAAO,CAAC,OAAO,CAAC;4BACZ,OAAO,EAAE,qCAAqC;4BAC9C,gBAAgB,kBAAA;yBACnB,CAAC,CAAC;oBACP,CAAC,EACD,UAAC,KAAY;wBACT,IAAI,KAAK,CAAC,OAAO,KAAK,iBAAiB,EAAE,CAAC;4BACtC,+DAA+D;4BAC/D,mCAAmC;4BACnC,mEAAmE;4BACnE,0CAA0C;4BAC1C,yEAAyE;4BAEzE,YAAY,CAAC,OAAO,CAAC,CAAC;4BAEtB,OAAO,CAAC,OAAO,CAAC;gCACZ,OAAO,EAAE,SAAS;gCAClB,KAAK,EAAE,sCAAsC;6BAChD,CAAC,CAAC;4BAEH,OAAO;wBACX,CAAC;wBAED,yEAAyE;wBACzE,qEAAqE;oBACzE,CAAC,CACJ,CAAC;oBAEN,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,UAAA,MAAM;wBAClB,4BAA4B,EAAE,CAAC;wBAE/B,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;4BAC/B,IAAA,2BAAe,EAAC,EAAE,oBAAoB,EAAE,6BAA6B,EAAE,CAAC,CAAC;wBAC7E,CAAC;oBACL,CAAC,CAAC,CAAC;oBAEH,sBAAO,OAAO,CAAC,EAAE,EAAC;;;;CACrB"}
package/entrypoint.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export declare function oidcEarlyInit(params: {
2
2
  freezeFetch: boolean;
3
3
  freezeXMLHttpRequest: boolean;
4
+ freezeWebSocket?: boolean;
4
5
  }): {
5
6
  shouldLoadApp: boolean;
6
7
  };
package/entrypoint.js CHANGED
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.oidcEarlyInit = oidcEarlyInit;
4
4
  var handleOidcCallback_1 = require("./core/handleOidcCallback");
5
+ var iframeMessageProtection_1 = require("./core/iframeMessageProtection");
5
6
  function oidcEarlyInit(params) {
6
- var _a = params !== null && params !== void 0 ? params : {}, freezeFetch = _a.freezeFetch, freezeXMLHttpRequest = _a.freezeXMLHttpRequest;
7
+ var _a = params !== null && params !== void 0 ? params : {}, freezeFetch = _a.freezeFetch, freezeXMLHttpRequest = _a.freezeXMLHttpRequest, _b = _a.freezeWebSocket, freezeWebSocket = _b === void 0 ? false : _b;
7
8
  var isHandled = (0, handleOidcCallback_1.handleOidcCallback)().isHandled;
8
9
  var shouldLoadApp = !isHandled;
9
10
  if (shouldLoadApp) {
11
+ (0, handleOidcCallback_1.moveRedirectAuthResponseFromSessionStorageToMemory)();
10
12
  if (freezeXMLHttpRequest) {
11
13
  var XMLHttpRequest_trusted = globalThis.XMLHttpRequest;
12
14
  Object.freeze(XMLHttpRequest_trusted.prototype);
@@ -29,6 +31,18 @@ function oidcEarlyInit(params) {
29
31
  value: fetch_trusted
30
32
  });
31
33
  }
34
+ if (freezeWebSocket) {
35
+ var WebSocket_trusted = globalThis.WebSocket;
36
+ Object.freeze(WebSocket_trusted.prototype);
37
+ Object.freeze(WebSocket_trusted);
38
+ Object.defineProperty(globalThis, "WebSocket", {
39
+ configurable: false,
40
+ writable: false,
41
+ enumerable: true,
42
+ value: WebSocket_trusted
43
+ });
44
+ }
45
+ (0, iframeMessageProtection_1.preventSessionStorageSetItemOfPublicKeyByThirdParty)();
32
46
  }
33
47
  return { shouldLoadApp: shouldLoadApp };
34
48
  }
package/entrypoint.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"entrypoint.js","sourceRoot":"","sources":["src/entrypoint.ts"],"names":[],"mappings":";;AAEA,sCAsCC;AAxCD,gEAA+D;AAE/D,SAAgB,aAAa,CAAC,MAA+D;IACnF,IAAA,KAAwC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,EAAlD,WAAW,iBAAA,EAAE,oBAAoB,0BAAiB,CAAC;IAEnD,IAAA,SAAS,GAAK,IAAA,uCAAkB,GAAE,UAAzB,CAA0B;IAE3C,IAAM,aAAa,GAAG,CAAC,SAAS,CAAC;IAEjC,IAAI,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A,6EAAmD,GAAE,CAAC;IAC1D,CAAC;IAED,OAAO,EAAE,aAAa,eAAA,EAAE,CAAC;AAC7B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oidc-spa",
3
- "version": "7.1.7",
3
+ "version": "7.1.9",
4
4
  "description": "Openidconnect client for Single Page Applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,6 +41,7 @@
41
41
  "./src/core/createOidc.ts",
42
42
  "./src/core/evtIsUserActive.ts",
43
43
  "./src/core/handleOidcCallback.ts",
44
+ "./src/core/iframeMessageProtection.ts",
44
45
  "./src/core/index.ts",
45
46
  "./src/core/initialLocationHref.ts",
46
47
  "./src/core/isNewBrowserSession.ts",
@@ -64,6 +65,7 @@
64
65
  "./src/tools/Evt.ts",
65
66
  "./src/tools/StatefulEvt.ts",
66
67
  "./src/tools/ValueOrAsyncGetter.ts",
68
+ "./src/tools/asymmetricEncryption.ts",
67
69
  "./src/tools/base64.ts",
68
70
  "./src/tools/createObjectThatThrowsIfAccessed.ts",
69
71
  "./src/tools/decodeJwt.ts",
@@ -122,6 +124,9 @@
122
124
  "./core/handleOidcCallback.d.ts",
123
125
  "./core/handleOidcCallback.js",
124
126
  "./core/handleOidcCallback.js.map",
127
+ "./core/iframeMessageProtection.d.ts",
128
+ "./core/iframeMessageProtection.js",
129
+ "./core/iframeMessageProtection.js.map",
125
130
  "./core/index.d.ts",
126
131
  "./core/index.js",
127
132
  "./core/index.js.map",
@@ -191,6 +196,9 @@
191
196
  "./tools/ValueOrAsyncGetter.d.ts",
192
197
  "./tools/ValueOrAsyncGetter.js",
193
198
  "./tools/ValueOrAsyncGetter.js.map",
199
+ "./tools/asymmetricEncryption.d.ts",
200
+ "./tools/asymmetricEncryption.js",
201
+ "./tools/asymmetricEncryption.js.map",
194
202
  "./tools/base64.d.ts",
195
203
  "./tools/base64.js",
196
204
  "./tools/base64.js.map",
@@ -5,15 +5,6 @@ export type AuthResponse = {
5
5
  [key: string]: string | undefined;
6
6
  };
7
7
 
8
- export function getIsAuthResponse(data: any): data is AuthResponse {
9
- return (
10
- data instanceof Object &&
11
- "state" in data &&
12
- typeof data.state === "string" &&
13
- Object.values(data).every(value => value === undefined || typeof value === "string")
14
- );
15
- }
16
-
17
8
  export function authResponseToUrl(authResponse: AuthResponse): string {
18
9
  let authResponseUrl = "https://dummy.com";
19
10
 
@@ -8,6 +8,7 @@ import { assert, id } from "../vendor/frontend/tsafe";
8
8
  import type { AuthResponse } from "./AuthResponse";
9
9
  import { initialLocationHref } from "./initialLocationHref";
10
10
  import { captureFetch } from "./trustedFetch";
11
+ import { encryptAuthResponse } from "./iframeMessageProtection";
11
12
 
12
13
  captureFetch();
13
14
 
@@ -111,7 +112,8 @@ function handleOidcCallback_nonMemoized(): { isHandled: boolean } {
111
112
  // NOTE: This is a "better than nothing" approach.
112
113
  // Under some circumstances it's possible to get stuck on this url
113
114
  // if there is no "next" page in the history for example, navigating
114
- // forward is a NoOp. So in that case it's better to navigate to the home.
115
+ // forward is a NoOp. So in that case it's better to reload the same route
116
+ // with just the authResponse removed from the url to avoid re-entering here.
115
117
  setTimeout(() => {
116
118
  const { protocol, host, pathname, hash } = window.location;
117
119
  window.location.href = `${protocol}//${host}${pathname}${hash}`;
@@ -131,9 +133,9 @@ function handleOidcCallback_nonMemoized(): { isHandled: boolean } {
131
133
 
132
134
  switch (stateData.context) {
133
135
  case "iframe":
134
- setTimeout(() => {
135
- parent.postMessage(authResponse, location.origin);
136
- }, 0);
136
+ encryptAuthResponse({
137
+ authResponse
138
+ }).then(({ encryptedMessage }) => parent.postMessage(encryptedMessage, location.origin));
137
139
  break;
138
140
  case "redirect":
139
141
  markStateDataAsProcessedByCallback({ stateQueryParamValue });
@@ -159,11 +161,27 @@ function handleOidcCallback_nonMemoized(): { isHandled: boolean } {
159
161
  return { isHandled };
160
162
  }
161
163
 
162
- const { readRedirectAuthResponses, writeRedirectAuthResponses } = (() => {
164
+ const {
165
+ readRedirectAuthResponses,
166
+ writeRedirectAuthResponses,
167
+ moveRedirectAuthResponseFromSessionStorageToMemory
168
+ } = (() => {
163
169
  const AUTH_RESPONSES_KEY = "oidc-spa:authResponses";
164
170
 
171
+ let authResponses_movedToMemoryFromSessionStorage: AuthResponse[] | undefined = undefined;
172
+
173
+ // NOTE: Here we note that we can re-write on session storage some auth response
174
+ // after earlyInit in retrieveRedirectAuthResponseAndStateData
175
+ // In situation where there are more than one client in the same app and we can't use iframe,
176
+ // we can have one client that has to redirect before the response has been dealt with.
177
+ // In most case it won't happen if the init sequence is deterministic but the client
178
+ // can be instantiated at any time really.
179
+ // So the move to memory of the response is fully effective only when theres one client.
165
180
  function writeRedirectAuthResponses(params: { authResponses: AuthResponse[] }): void {
166
181
  const { authResponses } = params;
182
+
183
+ authResponses_movedToMemoryFromSessionStorage = undefined;
184
+
167
185
  if (authResponses.length === 0) {
168
186
  sessionStorage.removeItem(AUTH_RESPONSES_KEY);
169
187
  return;
@@ -172,6 +190,10 @@ const { readRedirectAuthResponses, writeRedirectAuthResponses } = (() => {
172
190
  }
173
191
 
174
192
  function readRedirectAuthResponses(): AuthResponse[] {
193
+ if (authResponses_movedToMemoryFromSessionStorage !== undefined) {
194
+ return authResponses_movedToMemoryFromSessionStorage;
195
+ }
196
+
175
197
  const raw = sessionStorage.getItem(AUTH_RESPONSES_KEY);
176
198
 
177
199
  if (raw === null) {
@@ -181,9 +203,23 @@ const { readRedirectAuthResponses, writeRedirectAuthResponses } = (() => {
181
203
  return JSON.parse(raw);
182
204
  }
183
205
 
184
- return { writeRedirectAuthResponses, readRedirectAuthResponses };
206
+ function moveRedirectAuthResponseFromSessionStorageToMemory() {
207
+ const authResponses = readRedirectAuthResponses();
208
+
209
+ writeRedirectAuthResponses({ authResponses: [] });
210
+
211
+ authResponses_movedToMemoryFromSessionStorage = authResponses;
212
+ }
213
+
214
+ return {
215
+ writeRedirectAuthResponses,
216
+ readRedirectAuthResponses,
217
+ moveRedirectAuthResponseFromSessionStorageToMemory
218
+ };
185
219
  })();
186
220
 
221
+ export { moveRedirectAuthResponseFromSessionStorageToMemory };
222
+
187
223
  export function retrieveRedirectAuthResponseAndStateData(params: {
188
224
  configId: string;
189
225
  }): { authResponse: AuthResponse; stateData: StateData.Redirect } | undefined {
@@ -215,9 +251,7 @@ export function retrieveRedirectAuthResponseAndStateData(params: {
215
251
  authResponseAndStateData = { authResponse, stateData };
216
252
  }
217
253
 
218
- if (authResponseAndStateData !== undefined) {
219
- writeRedirectAuthResponses({ authResponses });
220
- }
254
+ writeRedirectAuthResponses({ authResponses });
221
255
 
222
256
  return authResponseAndStateData;
223
257
  }
@@ -0,0 +1,99 @@
1
+ import { assert } from "tsafe/assert";
2
+ import { asymmetricEncrypt, asymmetricDecrypt, generateKeys } from "../tools/asymmetricEncryption";
3
+ import { type AuthResponse } from "./AuthResponse";
4
+
5
+ const setItem_real = Storage.prototype.setItem;
6
+
7
+ const SESSION_STORAGE_PREFIX = "oidc-spa_iframe_authResponse_publicKey_";
8
+
9
+ export function preventSessionStorageSetItemOfPublicKeyByThirdParty() {
10
+ const setItem_protected = function setItem(this: any, key: string, value: string): void {
11
+ if (this !== sessionStorage) {
12
+ return setItem_real.call(this, key, value);
13
+ }
14
+
15
+ if (key.startsWith(SESSION_STORAGE_PREFIX)) {
16
+ throw new Error(
17
+ "Attack prevented by oidc-spa. You have malicious code running in your system"
18
+ );
19
+ }
20
+
21
+ return setItem_real.call(sessionStorage, key, value);
22
+ };
23
+
24
+ {
25
+ const pd = Object.getOwnPropertyDescriptor(Storage.prototype, "setItem");
26
+
27
+ assert(pd !== undefined);
28
+
29
+ Object.defineProperty(Storage.prototype, "setItem", {
30
+ enumerable: pd.enumerable,
31
+ writable: pd.writable,
32
+ value: setItem_protected
33
+ });
34
+ }
35
+ }
36
+
37
+ const ENCRYPTED_AUTH_RESPONSES_PREFIX = "oidc-spa_encrypted_authResponse_";
38
+
39
+ function getSessionStorageKey(params: { stateQueryParamValue: string }) {
40
+ const { stateQueryParamValue } = params;
41
+
42
+ return `${SESSION_STORAGE_PREFIX}${stateQueryParamValue}`;
43
+ }
44
+
45
+ export async function initIframeMessageProtection(params: { stateQueryParamValue: string }) {
46
+ const { stateQueryParamValue } = params;
47
+
48
+ const { publicKey, privateKey } = await generateKeys();
49
+
50
+ const sessionStorageKey = getSessionStorageKey({ stateQueryParamValue });
51
+
52
+ setItem_real.call(sessionStorage, sessionStorageKey, publicKey);
53
+
54
+ function getIsEncryptedAuthResponse(params: { message: unknown }): boolean {
55
+ const { message } = params;
56
+
57
+ return typeof message === "string" && message.startsWith(ENCRYPTED_AUTH_RESPONSES_PREFIX);
58
+ }
59
+
60
+ async function decodeEncryptedAuth(params: {
61
+ encryptedAuthResponse: string;
62
+ }): Promise<{ authResponse: AuthResponse }> {
63
+ const { encryptedAuthResponse } = params;
64
+
65
+ const { message: authResponse_str } = await asymmetricDecrypt({
66
+ encryptedMessage: encryptedAuthResponse.slice(ENCRYPTED_AUTH_RESPONSES_PREFIX.length),
67
+ privateKey
68
+ });
69
+
70
+ const authResponse: AuthResponse = JSON.parse(authResponse_str);
71
+
72
+ return { authResponse };
73
+ }
74
+
75
+ function clearSessionStoragePublicKey() {
76
+ sessionStorage.removeItem(sessionStorageKey);
77
+ }
78
+
79
+ return { getIsEncryptedAuthResponse, decodeEncryptedAuth, clearSessionStoragePublicKey };
80
+ }
81
+
82
+ export async function encryptAuthResponse(params: { authResponse: AuthResponse }) {
83
+ const { authResponse } = params;
84
+
85
+ const publicKey = sessionStorage.getItem(
86
+ getSessionStorageKey({ stateQueryParamValue: authResponse.state })
87
+ );
88
+
89
+ assert(publicKey !== null, "2293302");
90
+
91
+ const { encryptedMessage: encryptedMessage_withoutPrefix } = await asymmetricEncrypt({
92
+ publicKey,
93
+ message: JSON.stringify(authResponse)
94
+ });
95
+
96
+ const encryptedMessage = `${ENCRYPTED_AUTH_RESPONSES_PREFIX}${encryptedMessage_withoutPrefix}`;
97
+
98
+ return { encryptedMessage };
99
+ }
@@ -5,8 +5,9 @@ import { getStateData, clearStateStore, type StateData } from "./StateData";
5
5
  import { getDownlinkAndRtt } from "../tools/getDownlinkAndRtt";
6
6
  import { getIsDev } from "../tools/isDev";
7
7
  import type { User as OidcClientTsUser } from "../vendor/frontend/oidc-client-ts-and-jwt-decode";
8
- import { type AuthResponse, getIsAuthResponse } from "./AuthResponse";
8
+ import { type AuthResponse } from "./AuthResponse";
9
9
  import { addOrUpdateSearchParam } from "../tools/urlSearchParams";
10
+ import { initIframeMessageProtection } from "./iframeMessageProtection";
10
11
 
11
12
  type ResultOfLoginSilent =
12
13
  | {
@@ -74,6 +75,11 @@ export async function loginSilent(params: {
74
75
  return Math.max(BASE_DELAY_MS, dynamicDelay);
75
76
  })();
76
77
 
78
+ const { decodeEncryptedAuth, getIsEncryptedAuthResponse, clearSessionStoragePublicKey } =
79
+ await initIframeMessageProtection({
80
+ stateQueryParamValue: stateQueryParamValue_instance
81
+ });
82
+
77
83
  const timeout = setTimeout(async () => {
78
84
  dResult.resolve({
79
85
  outcome: "failure",
@@ -81,12 +87,20 @@ export async function loginSilent(params: {
81
87
  });
82
88
  }, timeoutDelayMs);
83
89
 
84
- const listener = (event: MessageEvent) => {
85
- if (!getIsAuthResponse(event.data)) {
90
+ const listener = async (event: MessageEvent) => {
91
+ if (event.origin !== window.location.origin) {
92
+ return;
93
+ }
94
+
95
+ if (
96
+ !getIsEncryptedAuthResponse({
97
+ message: event.data
98
+ })
99
+ ) {
86
100
  return;
87
101
  }
88
102
 
89
- const authResponse = event.data;
103
+ const { authResponse } = await decodeEncryptedAuth({ encryptedAuthResponse: event.data });
90
104
 
91
105
  const stateData = getStateData({ stateQueryParamValue: authResponse.state });
92
106
 
@@ -181,6 +195,8 @@ export async function loginSilent(params: {
181
195
  );
182
196
 
183
197
  dResult.pr.then(result => {
198
+ clearSessionStoragePublicKey();
199
+
184
200
  if (result.outcome === "failure") {
185
201
  clearStateStore({ stateQueryParamValue: stateQueryParamValue_instance });
186
202
  }
package/src/entrypoint.ts CHANGED
@@ -1,13 +1,25 @@
1
- import { handleOidcCallback } from "./core/handleOidcCallback";
1
+ import {
2
+ handleOidcCallback,
3
+ moveRedirectAuthResponseFromSessionStorageToMemory
4
+ } from "./core/handleOidcCallback";
5
+ import { preventSessionStorageSetItemOfPublicKeyByThirdParty } from "./core/iframeMessageProtection";
2
6
 
3
- export function oidcEarlyInit(params: { freezeFetch: boolean; freezeXMLHttpRequest: boolean }) {
4
- const { freezeFetch, freezeXMLHttpRequest } = params ?? {};
7
+ export function oidcEarlyInit(params: {
8
+ freezeFetch: boolean;
9
+ freezeXMLHttpRequest: boolean;
10
+ // NOTE: Made optional just to avoid breaking change.
11
+ // Will be made mandatory next major.
12
+ freezeWebSocket?: boolean;
13
+ }) {
14
+ const { freezeFetch, freezeXMLHttpRequest, freezeWebSocket = false } = params ?? {};
5
15
 
6
16
  const { isHandled } = handleOidcCallback();
7
17
 
8
18
  const shouldLoadApp = !isHandled;
9
19
 
10
20
  if (shouldLoadApp) {
21
+ moveRedirectAuthResponseFromSessionStorageToMemory();
22
+
11
23
  if (freezeXMLHttpRequest) {
12
24
  const XMLHttpRequest_trusted = globalThis.XMLHttpRequest;
13
25
 
@@ -35,6 +47,22 @@ export function oidcEarlyInit(params: { freezeFetch: boolean; freezeXMLHttpReque
35
47
  value: fetch_trusted
36
48
  });
37
49
  }
50
+
51
+ if (freezeWebSocket) {
52
+ const WebSocket_trusted = globalThis.WebSocket;
53
+
54
+ Object.freeze(WebSocket_trusted.prototype);
55
+ Object.freeze(WebSocket_trusted);
56
+
57
+ Object.defineProperty(globalThis, "WebSocket", {
58
+ configurable: false,
59
+ writable: false,
60
+ enumerable: true,
61
+ value: WebSocket_trusted
62
+ });
63
+ }
64
+
65
+ preventSessionStorageSetItemOfPublicKeyByThirdParty();
38
66
  }
39
67
 
40
68
  return { shouldLoadApp };
@@ -0,0 +1,184 @@
1
+ type AsymmetricKeys = {
2
+ publicKey: string; // base64-encoded JSON export of CryptoKey
3
+ privateKey: string; // base64-encoded JSON export of CryptoKey
4
+ };
5
+
6
+ const INFO_LABEL = "oidc-spa/tools/asymmetricEncryption";
7
+
8
+ export async function generateKeys(): Promise<AsymmetricKeys> {
9
+ const keyPair = await crypto.subtle.generateKey(
10
+ {
11
+ name: "ECDH",
12
+ namedCurve: "P-256"
13
+ },
14
+ true,
15
+ ["deriveKey", "deriveBits"]
16
+ );
17
+
18
+ const publicKeyRaw = await crypto.subtle.exportKey("jwk", keyPair.publicKey);
19
+ const privateKeyRaw = await crypto.subtle.exportKey("jwk", keyPair.privateKey);
20
+
21
+ return {
22
+ publicKey: btoa(JSON.stringify(publicKeyRaw)),
23
+ privateKey: btoa(JSON.stringify(privateKeyRaw))
24
+ };
25
+ }
26
+
27
+ export async function asymmetricEncrypt(params: {
28
+ publicKey: string;
29
+ message: string;
30
+ }): Promise<{ encryptedMessage: string }> {
31
+ const { publicKey, message } = params;
32
+
33
+ const importedPublicKey = await crypto.subtle.importKey(
34
+ "jwk",
35
+ JSON.parse(atob(publicKey)),
36
+ {
37
+ name: "ECDH",
38
+ namedCurve: "P-256"
39
+ },
40
+ false,
41
+ []
42
+ );
43
+
44
+ const ephemeralKeyPair = await crypto.subtle.generateKey(
45
+ {
46
+ name: "ECDH",
47
+ namedCurve: "P-256"
48
+ },
49
+ true,
50
+ ["deriveKey", "deriveBits"]
51
+ );
52
+
53
+ const sharedSecret = await crypto.subtle.deriveBits(
54
+ {
55
+ name: "ECDH",
56
+ public: importedPublicKey
57
+ },
58
+ ephemeralKeyPair.privateKey,
59
+ 256
60
+ );
61
+
62
+ const salt = crypto.getRandomValues(new Uint8Array(16));
63
+ const infoBytes = new TextEncoder().encode(INFO_LABEL);
64
+
65
+ const hkdfKey = await crypto.subtle.importKey("raw", sharedSecret, "HKDF", false, ["deriveKey"]);
66
+
67
+ const derivedKey = await crypto.subtle.deriveKey(
68
+ {
69
+ name: "HKDF",
70
+ hash: "SHA-256",
71
+ salt,
72
+ info: infoBytes
73
+ },
74
+ hkdfKey,
75
+ { name: "AES-GCM", length: 256 },
76
+ false,
77
+ ["encrypt"]
78
+ );
79
+
80
+ const iv = crypto.getRandomValues(new Uint8Array(12));
81
+ const encodedMessage = new TextEncoder().encode(message);
82
+
83
+ const ciphertext = await crypto.subtle.encrypt(
84
+ {
85
+ name: "AES-GCM",
86
+ iv
87
+ },
88
+ derivedKey,
89
+ encodedMessage
90
+ );
91
+
92
+ const ephemeralPubKeyRaw = await crypto.subtle.exportKey("jwk", ephemeralKeyPair.publicKey);
93
+
94
+ const payload = {
95
+ ephemeralPubKey: ephemeralPubKeyRaw,
96
+ iv: Array.from(iv),
97
+ salt: Array.from(salt),
98
+ ciphertext: Array.from(new Uint8Array(ciphertext))
99
+ };
100
+
101
+ return {
102
+ encryptedMessage: btoa(JSON.stringify(payload))
103
+ };
104
+ }
105
+
106
+ export async function asymmetricDecrypt(params: {
107
+ privateKey: string;
108
+ encryptedMessage: string;
109
+ }): Promise<{ message: string }> {
110
+ const { privateKey, encryptedMessage } = params;
111
+
112
+ const {
113
+ ephemeralPubKey,
114
+ iv,
115
+ salt,
116
+ ciphertext
117
+ }: {
118
+ ephemeralPubKey: JsonWebKey;
119
+ iv: number[];
120
+ salt: number[];
121
+ ciphertext: number[];
122
+ } = JSON.parse(atob(encryptedMessage));
123
+
124
+ const importedPrivateKey = await crypto.subtle.importKey(
125
+ "jwk",
126
+ JSON.parse(atob(privateKey)),
127
+ {
128
+ name: "ECDH",
129
+ namedCurve: "P-256"
130
+ },
131
+ false,
132
+ ["deriveKey", "deriveBits"]
133
+ );
134
+
135
+ const importedEphemeralPubKey = await crypto.subtle.importKey(
136
+ "jwk",
137
+ ephemeralPubKey,
138
+ {
139
+ name: "ECDH",
140
+ namedCurve: "P-256"
141
+ },
142
+ false,
143
+ []
144
+ );
145
+
146
+ const sharedSecret = await crypto.subtle.deriveBits(
147
+ {
148
+ name: "ECDH",
149
+ public: importedEphemeralPubKey
150
+ },
151
+ importedPrivateKey,
152
+ 256
153
+ );
154
+
155
+ const infoBytes = new TextEncoder().encode(INFO_LABEL);
156
+
157
+ const hkdfKey = await crypto.subtle.importKey("raw", sharedSecret, "HKDF", false, ["deriveKey"]);
158
+
159
+ const derivedKey = await crypto.subtle.deriveKey(
160
+ {
161
+ name: "HKDF",
162
+ hash: "SHA-256",
163
+ salt: new Uint8Array(salt),
164
+ info: infoBytes
165
+ },
166
+ hkdfKey,
167
+ { name: "AES-GCM", length: 256 },
168
+ false,
169
+ ["decrypt"]
170
+ );
171
+
172
+ const decryptedBuffer = await crypto.subtle.decrypt(
173
+ {
174
+ name: "AES-GCM",
175
+ iv: new Uint8Array(iv)
176
+ },
177
+ derivedKey,
178
+ new Uint8Array(ciphertext)
179
+ );
180
+
181
+ return {
182
+ message: new TextDecoder().decode(decryptedBuffer)
183
+ };
184
+ }
@@ -0,0 +1,18 @@
1
+ type AsymmetricKeys = {
2
+ publicKey: string;
3
+ privateKey: string;
4
+ };
5
+ export declare function generateKeys(): Promise<AsymmetricKeys>;
6
+ export declare function asymmetricEncrypt(params: {
7
+ publicKey: string;
8
+ message: string;
9
+ }): Promise<{
10
+ encryptedMessage: string;
11
+ }>;
12
+ export declare function asymmetricDecrypt(params: {
13
+ privateKey: string;
14
+ encryptedMessage: string;
15
+ }): Promise<{
16
+ message: string;
17
+ }>;
18
+ export {};