Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates related to #1509 #5330

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5520fe0
use chrome.runtime broadcast sends with custom generated tabId
Jul 26, 2023
2a252a6
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Jul 28, 2023
4c1ab6a
postMessage as backup (wip)
Jul 28, 2023
f76d041
simplify, removed background relay (wip)
Jul 29, 2023
df8cf42
fix broadcast propagation
Jul 30, 2023
3cfce61
fix parent propagation
Jul 31, 2023
640c60b
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Jul 31, 2023
3c57a7a
fetch() instead of BrowserMsg.ajax (wip)
Aug 7, 2023
eb7fed8
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 7, 2023
7405ae3
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 8, 2023
ada3139
better custom reponseText handling for 400 Bad request and test robus…
Aug 8, 2023
1f73b14
proper network error handling
Aug 10, 2023
cc22d8b
Update mock for token substitution
Aug 10, 2023
b4d4fbc
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 16, 2023
5a55e51
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 16, 2023
bab1c82
download progress and timeout implementation with fetch()
Aug 17, 2023
7a75e96
convert 'Failed to fetch' error to AjaxErr
Aug 17, 2023
9a613c5
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 18, 2023
6769139
HTTP/2 support in mock
Aug 18, 2023
cc3e0b0
Status texts from dictionary for HTTP/2
Aug 18, 2023
058849c
fix HTTP/2 Authority check in mock
Aug 19, 2023
bacb346
safer message handling
Aug 19, 2023
cf079e3
trying to fix decryption
Aug 19, 2023
8902ef6
trying to fix decryption (verbosity)
Aug 19, 2023
c0165f5
trying to fix decryption (moved some code out of async)
Aug 20, 2023
3c506d6
send messages in a safer order
Aug 20, 2023
9924b21
don't send passphrase_entry to self
Aug 20, 2023
da31ca1
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Nov 15, 2023
096e437
fix background ajax
sosnovsky Nov 15, 2023
192be2e
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Nov 29, 2023
fd01bf8
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Dec 14, 2023
685f178
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Dec 18, 2023
27f5e2e
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Dec 19, 2023
ea9dbcb
wip
sosnovsky Dec 19, 2023
154006b
wip
sosnovsky Dec 19, 2023
1aa3fc1
wip
sosnovsky Dec 20, 2023
0049ead
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Jan 31, 2024
21ffb95
fix tests
sosnovsky Feb 1, 2024
ebbb987
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions extension/chrome/elements/passphrase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ View.run(
};

private closeDialog = (entered = false, initiatorFrameId?: string) => {
BrowserMsg.send.closeDialog(this);
BrowserMsg.send.passphraseEntry({ entered, initiatorFrameId });
BrowserMsg.send.passphraseEntry({ entered, initiatorFrameId }, () => BrowserMsg.send.closeDialog(this));
};

private submitHandler = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export namespace FesRes {
};
export type ServiceInfo = { vendor: string; service: string; orgId: string; version: string; apiVersion: string };
export type ClientConfiguration = { clientConfiguration: ClientConfigurationJson };
export type DomainConfiguration = { authentication: AuthenticationConfiguration; clientConfiguration: ClientConfigurationJson };
}

/**
Expand Down
15 changes: 8 additions & 7 deletions extension/js/common/api/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ export class Api {
Api.throwIfApiPathTraversalAttempted(req.url);
const headersInit: [string, string][] = req.headers ? Object.entries(req.headers) : [];
// capitalize? .map(([key, value]) => { return [Str.capitalize(key), value]; })
const newTimeoutPromise = (): Promise<never> => {
return new Promise((_resolve, reject) => {
/* error-handled */ setTimeout(() => {
reject(AjaxErr.fromXhr({ readyState, status: -1, statusText: 'timeout' }, reqContext)); // Reject the promise with a timeout error
}, req.timeout ?? 20000);
});
};
let body: BodyInit | undefined;
let duplex: 'half' | undefined;
let uploadPromise: () => void | Promise<void> = Value.noop;
Expand Down Expand Up @@ -173,10 +166,18 @@ export class Api {
};
let readyState = 1; // OPENED
const reqContext = { url: req.url, method: req.method, data: body, stack: req.stack };
const newTimeoutPromise = (): Promise<never> => {
return new Promise((_resolve, reject) => {
/* error-handled */ setTimeout(() => {
reject(AjaxErr.fromXhr({ readyState, status: -1, statusText: 'timeout' }, reqContext)); // Reject the promise with a timeout error
}, req.timeout ?? 20000);
});
};
try {
const fetchPromise = fetch(url, requestInit);
await uploadPromise();
const response = await Promise.race([fetchPromise, newTimeoutPromise()]);

if (!response.ok) {
let responseText: string | undefined;
readyState = 2; // HEADERS_RECEIVED
Expand Down
233 changes: 93 additions & 140 deletions extension/js/common/browser/browser-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { AuthRes } from '../api/authentication/google/google-oauth.js';
import { AjaxErr } from '../api/shared/api-error.js';
import { Buf } from '../core/buf.js';
import { Dict, Str, UrlParams } from '../core/common.js';
import { Dict, Str, UrlParams, Value } from '../core/common.js';
import { NotificationGroupType } from '../notifications.js';
import { Catch } from '../platform/catch.js';
import { PassphraseDialogType } from '../xss-safe-factory.js';
Expand Down Expand Up @@ -224,111 +224,44 @@
BrowserMsg.sendAwait(undefined, 'expirationCacheDeleteExpired', bm, true) as Promise<Bm.Res.ExpirationCacheDeleteExpired>,
},
},
passphraseEntry: (bm: Bm.PassphraseEntry) => {
BrowserMsg.sendCatch('broadcast', 'passphrase_entry', bm);
},
addEndSessionBtn: (dest: Bm.Dest) => {
BrowserMsg.sendCatch(dest, 'add_end_session_btn', {});
},
openPage: (dest: Bm.Dest, bm: Bm.OpenPage) => {
BrowserMsg.sendCatch(dest, 'open_page', bm);
},
setCss: (dest: Bm.Dest, bm: Bm.SetCss) => {
BrowserMsg.sendCatch(dest, 'set_css', bm);
},
addClass: (dest: Bm.Dest, bm: Bm.AddOrRemoveClass) => {
BrowserMsg.sendCatch(dest, 'add_class', bm);
},
removeClass: (dest: Bm.Dest, bm: Bm.AddOrRemoveClass) => {
BrowserMsg.sendCatch(dest, 'remove_class', bm);
},
closeDialog: (frame: ChildFrame) => {
BrowserMsg.sendToParentWindow(frame, 'close_dialog', {});
},
authWindowResult: (dest: Bm.Dest, bm: Bm.AuthWindowResult) => {
BrowserMsg.sendCatch(dest, 'auth_window_result', bm);
},
closePage: (dest: Bm.Dest) => {
BrowserMsg.sendCatch(dest, 'close_page', {});
},
setActiveWindow: (dest: Bm.Dest, bm: Bm.ComposeWindow) => {
BrowserMsg.sendCatch(dest, 'set_active_window', bm);
},
focusPreviousActiveWindow: (dest: Bm.Dest, bm: Bm.ComposeWindow) => {
BrowserMsg.sendCatch(dest, 'focus_previous_active_window', bm);
},
closeComposeWindow: (dest: Bm.Dest, bm: Bm.ComposeWindow) => {
BrowserMsg.sendCatch(dest, 'close_compose_window', bm);
},
focusBody: (dest: Bm.Dest) => {
BrowserMsg.sendCatch(dest, 'focus_body', {});
},
focusFrame: (dest: Bm.Dest, bm: Bm.ComposeWindow) => {
BrowserMsg.sendCatch(dest, 'focus_frame', bm);
},
closeReplyMessage: (dest: Bm.Dest, bm: Bm.ComposeWindow) => {
BrowserMsg.sendCatch(dest, 'close_reply_message', bm);
},
scrollToReplyBox: (dest: Bm.Dest, bm: Bm.ScrollToReplyBox) => {
BrowserMsg.sendCatch(dest, 'scroll_to_reply_box', bm);
},
scrollToCursorInReplyBox: (dest: Bm.Dest, bm: Bm.ScrollToCursorInReplyBox) => {
BrowserMsg.sendCatch(dest, 'scroll_to_cursor_in_reply_box', bm);
},
reinsertReplyBox: (dest: Bm.Dest, bm: Bm.ReinsertReplyBox) => {
BrowserMsg.sendCatch(dest, 'reinsert_reply_box', bm);
},
passphraseDialog: (dest: Bm.Dest, bm: Bm.PassphraseDialog) => {
BrowserMsg.sendCatch(dest, 'passphrase_dialog', bm);
},
notificationShow: (dest: Bm.Dest, bm: Bm.NotificationShow) => {
BrowserMsg.sendCatch(dest, 'notification_show', bm);
},
notificationShowAuthPopupNeeded: (dest: Bm.Dest, bm: Bm.NotificationShowAuthPopupNeeded) => {
BrowserMsg.sendCatch(dest, 'notification_show_auth_popup_needed', bm);
},
showConfirmation: (frame: ChildFrame, bm: Bm.ShowConfirmation) => {
BrowserMsg.sendToParentWindow(frame, 'confirmation_show', bm, 'confirmation_result');
},
renderPublicKeys: (dest: Bm.Dest, bm: Bm.RenderPublicKeys) => {
BrowserMsg.sendCatch(dest, 'render_public_keys', bm);
},
replyPubkeyMismatch: (dest: Bm.Dest) => {
BrowserMsg.sendCatch(dest, 'reply_pubkey_mismatch', {});
},
addPubkeyDialog: (dest: Bm.Dest, bm: Bm.AddPubkeyDialog) => {
BrowserMsg.sendCatch(dest, 'add_pubkey_dialog', bm);
},
reload: (dest: Bm.Dest, bm: Bm.Reload) => {
BrowserMsg.sendCatch(dest, 'reload', bm);
},
redirect: (dest: Bm.Dest, bm: Bm.Redirect) => {
BrowserMsg.sendCatch(dest, 'redirect', bm);
},
addToContacts: (dest: Bm.Dest) => {
BrowserMsg.sendCatch(dest, 'addToContacts', {});
},
reRenderRecipient: (dest: Bm.Dest, bm: Bm.ReRenderRecipient) => {
BrowserMsg.sendCatch(dest, 'reRenderRecipient', bm);
},
showAttachmentPreview: (frame: ChildFrame, bm: Bm.ShowAttachmentPreview) => {
BrowserMsg.sendToParentWindow(frame, 'show_attachment_preview', bm);
},
ajaxProgress: (dest: Bm.Dest, bm: Bm.AjaxProgress) => {
BrowserMsg.sendCatch(dest, 'ajax_progress', bm);
},
pgpBlockRender: (dest: Bm.Dest, bm: RenderMessage) => {
BrowserMsg.sendCatch(dest, 'pgp_block_render', bm);
},
passphraseEntry: (bm: Bm.PassphraseEntry, sendCallback = Value.noop) => BrowserMsg.sendCatch('broadcast', 'passphrase_entry', bm, sendCallback, false),
addEndSessionBtn: (dest: Bm.Dest) => BrowserMsg.sendCatch(dest, 'add_end_session_btn', {}),
openPage: (dest: Bm.Dest, bm: Bm.OpenPage) => BrowserMsg.sendCatch(dest, 'open_page', bm),
setCss: (dest: Bm.Dest, bm: Bm.SetCss) => BrowserMsg.sendCatch(dest, 'set_css', bm),
addClass: (dest: Bm.Dest, bm: Bm.AddOrRemoveClass) => BrowserMsg.sendCatch(dest, 'add_class', bm),
removeClass: (dest: Bm.Dest, bm: Bm.AddOrRemoveClass) => BrowserMsg.sendCatch(dest, 'remove_class', bm),
closeDialog: (frame: ChildFrame) => BrowserMsg.sendToParentWindow(frame, 'close_dialog', {}),
authWindowResult: (dest: Bm.Dest, bm: Bm.AuthWindowResult) => BrowserMsg.sendCatch(dest, 'auth_window_result', bm),
closePage: (dest: Bm.Dest) => BrowserMsg.sendCatch(dest, 'close_page', {}),
setActiveWindow: (dest: Bm.Dest, bm: Bm.ComposeWindow) => BrowserMsg.sendCatch(dest, 'set_active_window', bm),
focusPreviousActiveWindow: (dest: Bm.Dest, bm: Bm.ComposeWindow) => BrowserMsg.sendCatch(dest, 'focus_previous_active_window', bm),
closeComposeWindow: (dest: Bm.Dest, bm: Bm.ComposeWindow) => BrowserMsg.sendCatch(dest, 'close_compose_window', bm),
focusBody: (dest: Bm.Dest) => BrowserMsg.sendCatch(dest, 'focus_body', {}),
focusFrame: (dest: Bm.Dest, bm: Bm.ComposeWindow) => BrowserMsg.sendCatch(dest, 'focus_frame', bm),
closeReplyMessage: (dest: Bm.Dest, bm: Bm.ComposeWindow) => BrowserMsg.sendCatch(dest, 'close_reply_message', bm),
scrollToReplyBox: (dest: Bm.Dest, bm: Bm.ScrollToReplyBox) => BrowserMsg.sendCatch(dest, 'scroll_to_reply_box', bm),
scrollToCursorInReplyBox: (dest: Bm.Dest, bm: Bm.ScrollToCursorInReplyBox) => BrowserMsg.sendCatch(dest, 'scroll_to_cursor_in_reply_box', bm),
reinsertReplyBox: (dest: Bm.Dest, bm: Bm.ReinsertReplyBox) => BrowserMsg.sendCatch(dest, 'reinsert_reply_box', bm),
passphraseDialog: (dest: Bm.Dest, bm: Bm.PassphraseDialog) => BrowserMsg.sendCatch(dest, 'passphrase_dialog', bm),
notificationShow: (dest: Bm.Dest, bm: Bm.NotificationShow) => BrowserMsg.sendCatch(dest, 'notification_show', bm),
notificationShowAuthPopupNeeded: (dest: Bm.Dest, bm: Bm.NotificationShowAuthPopupNeeded) =>
BrowserMsg.sendCatch(dest, 'notification_show_auth_popup_needed', bm),
showConfirmation: (frame: ChildFrame, bm: Bm.ShowConfirmation) => BrowserMsg.sendToParentWindow(frame, 'confirmation_show', bm, 'confirmation_result'),
renderPublicKeys: (dest: Bm.Dest, bm: Bm.RenderPublicKeys) => BrowserMsg.sendCatch(dest, 'render_public_keys', bm),
replyPubkeyMismatch: (dest: Bm.Dest) => BrowserMsg.sendCatch(dest, 'reply_pubkey_mismatch', {}),
addPubkeyDialog: (dest: Bm.Dest, bm: Bm.AddPubkeyDialog) => BrowserMsg.sendCatch(dest, 'add_pubkey_dialog', bm),
reload: (dest: Bm.Dest, bm: Bm.Reload) => BrowserMsg.sendCatch(dest, 'reload', bm),
redirect: (dest: Bm.Dest, bm: Bm.Redirect) => BrowserMsg.sendCatch(dest, 'redirect', bm),
addToContacts: (dest: Bm.Dest) => BrowserMsg.sendCatch(dest, 'addToContacts', {}),
reRenderRecipient: (dest: Bm.Dest, bm: Bm.ReRenderRecipient) => BrowserMsg.sendCatch(dest, 'reRenderRecipient', bm),
showAttachmentPreview: (frame: ChildFrame, bm: Bm.ShowAttachmentPreview) => BrowserMsg.sendToParentWindow(frame, 'show_attachment_preview', bm),
ajaxProgress: (dest: Bm.Dest, bm: Bm.AjaxProgress) => BrowserMsg.sendCatch(dest, 'ajax_progress', bm),
pgpBlockRender: (dest: Bm.Dest, bm: RenderMessage) => BrowserMsg.sendCatch(dest, 'pgp_block_render', bm),
pgpBlockReady: (frame: ChildFrame, bm: Bm.PgpBlockReady) => BrowserMsg.sendToParentWindow(frame, 'pgp_block_ready', bm),
pgpBlockRetry: (frame: ChildFrame, bm: Bm.PgpBlockRetry) => BrowserMsg.sendToParentWindow(frame, 'pgp_block_retry', bm),
setHandlerReadyForPGPBlock: (dest: Bm.Dest) => {
BrowserMsg.sendCatch(dest, 'set_handler_ready_for_pgp_block', {});
},
pgpBlockReady: (frame: ChildFrame, bm: Bm.PgpBlockReady) => {
BrowserMsg.sendToParentWindow(frame, 'pgp_block_ready', bm);
},
pgpBlockRetry: (frame: ChildFrame, bm: Bm.PgpBlockRetry) => {
BrowserMsg.sendToParentWindow(frame, 'pgp_block_retry', bm);
},
};
private static readonly processed = new Set<string>(); // or ExpirationCache?
/* eslint-disable @typescript-eslint/naming-convention */
Expand Down Expand Up @@ -462,24 +395,27 @@

protected static listenForWindowMessages(dest: Bm.Dest) {
const extensionOrigin = Env.getExtensionOrigin();
addEventListener('message', async e => {

addEventListener('message', e => {
if (e.origin !== 'https://mail.google.com' && e.origin !== extensionOrigin) return;
const encryptedMsg = e.data as SymEncryptedMessage;
if (BrowserMsg.processed.has(encryptedMsg.uid)) return;
let handled = false;
if ([dest, 'broadcast'].includes(encryptedMsg.to)) {
const msg = await SymmetricMessageEncryption.decrypt(encryptedMsg);
handled = BrowserMsg.handleMsg(msg, (rawResponse: Bm.RawResponse) => {
if (msg.responseName && typeof msg.data.bm.messageSender !== 'undefined') {
// send response as a new request
BrowserMsg.sendRaw(msg.data.bm.messageSender, msg.responseName, rawResponse.result as Dict<unknown>).catch(Catch.reportErr);
}
});
}
if (!handled && encryptedMsg.propagateToParent) {
BrowserMsg.processed.add(encryptedMsg.uid);
BrowserMsg.sendUpParentLine(encryptedMsg);
}
if (!encryptedMsg || typeof encryptedMsg.uid !== 'string' || BrowserMsg.processed.has(encryptedMsg.uid)) return;
Catch.try(async () => {
let handled = false;
if ([dest, 'broadcast'].includes(encryptedMsg.to)) {
const msg = await SymmetricMessageEncryption.decrypt(encryptedMsg);
handled = BrowserMsg.handleMsg(msg, (rawResponse: Bm.RawResponse) => {
if (msg.responseName && typeof msg.data.bm.messageSender !== 'undefined') {
// send response as a new request
BrowserMsg.sendRaw(msg.data.bm.messageSender, msg.responseName, rawResponse.result as Dict<unknown>).catch(Catch.reportErr);
}
});
}
if (!handled && encryptedMsg.propagateToParent) {
BrowserMsg.processed.add(encryptedMsg.uid);
BrowserMsg.sendUpParentLine(encryptedMsg);
}
})();
});
}

Expand Down Expand Up @@ -539,11 +475,18 @@
return false;
}

private static sendCatch(dest: Bm.Dest | undefined, name: string, bm: Dict<unknown>) {
BrowserMsg.sendAwait(dest, name, bm).catch(Catch.reportErr);
}
private static sendCatch = (dest: Bm.Dest | undefined, name: string, bm: Dict<unknown>, sendCallback = Value.noop, postToSelf = true) => {
BrowserMsg.sendAwait(dest, name, bm, false, sendCallback, postToSelf).catch(Catch.reportErr);
};

private static async sendAwait(destString: string | undefined, name: string, bm?: Dict<unknown>, awaitRes = false): Promise<Bm.Response> {
private static sendAwait = async (
destString: string | undefined,
name: string,
bm?: Dict<unknown>,
awaitRes = false,
sendCallback = Value.noop,
postToSelf = true
): Promise<Bm.Response> => {
bm = bm || {};
// console.debug(`sendAwait ${name} to ${destString || 'bg'}`, bm);
const isBackgroundPage = Env.isBackgroundPage();
Expand All @@ -552,30 +495,25 @@
const handler: Bm.AsyncRespondingHandler = BrowserMsg.HANDLERS_REGISTERED_BACKGROUND[name];
return await handler(bm);
}
return await BrowserMsg.sendRaw(destString, name, bm, awaitRes);
}
return await BrowserMsg.sendRaw(destString, name, bm, awaitRes, sendCallback, postToSelf);
};

private static sendRaw(destString: string | undefined, name: string, bm: Dict<unknown>, awaitRes = false): Promise<Bm.Response> {
private static sendRaw = async (
destString: string | undefined,
name: string,
bm: Dict<unknown>,
awaitRes = false,
sendCallback = Value.noop,
postToSelf = true
): Promise<Bm.Response> => {
const msg: Bm.Raw = {
name,
data: { bm },
to: destString || null, // eslint-disable-line no-null/no-null
uid: SymmetricMessageEncryption.generateIV(),
stack: Catch.stackTrace(),
};
// eslint-disable-next-line no-null/no-null
if (!Env.isBackgroundPage() && msg.to !== null) {
const validMsg: Bm.RawWithWindowExtensions = { ...msg, to: msg.to };
// send via window messaging in parallel
Catch.try(async () => {
// todo: can objUrls be deleted by another recipient?
const encryptedMsg = await SymmetricMessageEncryption.encrypt(validMsg);
BrowserMsg.sendToChildren(encryptedMsg);
postMessage(encryptedMsg, '*');
BrowserMsg.sendUpParentLine(encryptedMsg);
})();
}
return new Promise((resolve, reject) => {
const runtimeMessagePromise = new Promise((resolve, reject) => {
const processRawMsgResponse = (r: Bm.RawResponse) => {
if (!awaitRes) {
resolve(undefined);
Expand Down Expand Up @@ -635,7 +573,22 @@
}
}
});
}
// eslint-disable-next-line no-null/no-null
if (!Env.isBackgroundPage() && msg.to !== null) {
// send via window messaging in parallel
const validMsg: Bm.RawWithWindowExtensions = { ...msg, to: msg.to };
// todo: can objUrls be deleted by another recipient?
const encryptedMsg = await SymmetricMessageEncryption.encrypt(validMsg);
BrowserMsg.sendToChildren(encryptedMsg);
if (postToSelf) {
window.postMessage(encryptedMsg, '*');

Check warning

Code scanning / CodeQL

Cross-window communication with unrestricted target origin Medium

Sensitive data
is sent to another window without origin restriction.
}
BrowserMsg.sendUpParentLine(encryptedMsg);
}
sendCallback();
// only runtimeMessagePromise can potentially yield a result
return runtimeMessagePromise;
};

private static sendUpParentLine(encryptedMsg: SymEncryptedMessage) {
const encryptedWithPropagationFlag: SymEncryptedMessage = { ...encryptedMsg, propagateToParent: true };
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/core/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class Str {

public static is7bit = (content: string | Uint8Array): boolean => {
for (let i = 0; i < content.length; i++) {
const code = typeof content === 'string' ? content.charCodeAt(i) : content[i] ?? 0;
const code = typeof content === 'string' ? content.charCodeAt(i) : (content[i] ?? 0);
if (!(code >= 0 && code <= 127)) {
return false;
}
Expand Down
6 changes: 0 additions & 6 deletions extension/js/common/domain-configuration.ts

This file was deleted.

14 changes: 8 additions & 6 deletions extension/js/common/platform/store/encryption-key-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import { secureRandomBytes } from '../util.js';
export class EncryptionKeyStore {
private static key = 'cryptup_cryptokey' as const;

public static async get(length?: number): Promise<ArrayBuffer> {
public static get = async (length?: number): Promise<Buf> => {
const storageObj = await storageGet('local', [EncryptionKeyStore.key]);
const value = storageObj[EncryptionKeyStore.key];
if (!length || typeof value !== 'undefined') {
return Buf.fromBase64Str(value as string);
if (typeof value === 'string') {
return Buf.fromBase64Str(value);
} else if (!length) {
throw new Error('Failed to read the crypto key from local storage!');
}
const newKey = secureRandomBytes(length);
await storageSet('local', { [EncryptionKeyStore.key]: new Buf(newKey).toBase64Str() });
const newKey = new Buf(secureRandomBytes(length));
await storageSet('local', { [EncryptionKeyStore.key]: newKey.toBase64Str() });
return newKey;
}
};
}
Loading
Loading