mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 19:23:52 +00:00
[PM-21378] Switch encrypt service to use SDK functions (#14538)
* Add new encrypt service functions * Undo changes * Cleanup * Fix build * Fix comments * Switch encrypt service to use SDK functions * Move remaining functions to PureCrypto * Tests * Increase test coverage * Enforce sdk.ready and drop unused codepaths * Delete unused code * Add forgotten sdk init logic * Fix build error * Fix browser extension failing to unlock after process reload due to outdated usage of decryptString * Fix send encryption * Fix client key half decryption being stuck * Attempt to fix sharereplay * Fix build * Fix type / add filter / add distinctuntilchange * Fix capitalization
This commit is contained in:
@@ -118,14 +118,14 @@ export class LocalBackedSessionStorageService
|
||||
return null;
|
||||
}
|
||||
|
||||
const valueJson = await this.encryptService.decryptString(new EncString(local), encKey);
|
||||
if (valueJson == null) {
|
||||
try {
|
||||
const valueJson = await this.encryptService.decryptString(new EncString(local), encKey);
|
||||
return JSON.parse(valueJson);
|
||||
} catch {
|
||||
// error with decryption, value is lost, delete state and start over
|
||||
await this.localStorage.remove(this.sessionStorageKey(key));
|
||||
return null;
|
||||
}
|
||||
|
||||
return JSON.parse(valueJson);
|
||||
}
|
||||
|
||||
private async updateLocalSessionValue(key: string, value: unknown): Promise<void> {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { AccountServiceImplementation } from "@bitwarden/common/auth/services/ac
|
||||
import { ClientType } from "@bitwarden/common/enums";
|
||||
import { EncryptServiceImplementation } from "@bitwarden/common/key-management/crypto/services/encrypt.service.implementation";
|
||||
import { RegionConfig } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
|
||||
import { Message, MessageSender } from "@bitwarden/common/platform/messaging";
|
||||
// eslint-disable-next-line no-restricted-imports -- For dependency creation
|
||||
import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal";
|
||||
@@ -58,6 +59,7 @@ import { EphemeralValueStorageService } from "./platform/services/ephemeral-valu
|
||||
import { I18nMainService } from "./platform/services/i18n.main.service";
|
||||
import { SSOLocalhostCallbackService } from "./platform/services/sso-localhost-callback.service";
|
||||
import { ElectronMainMessagingService } from "./services/electron-main-messaging.service";
|
||||
import { MainSdkLoadService } from "./services/main-sdk-load-service";
|
||||
import { isMacAppStore } from "./utils";
|
||||
|
||||
export class Main {
|
||||
@@ -88,6 +90,7 @@ export class Main {
|
||||
desktopAutofillSettingsService: DesktopAutofillSettingsService;
|
||||
versionMain: VersionMain;
|
||||
sshAgentService: MainSshAgentService;
|
||||
sdkLoadService: SdkLoadService;
|
||||
mainDesktopAutotypeService: MainDesktopAutotypeService;
|
||||
|
||||
constructor() {
|
||||
@@ -144,6 +147,8 @@ export class Main {
|
||||
|
||||
this.i18nService = new I18nMainService("en", "./locales/", globalStateProvider);
|
||||
|
||||
this.sdkLoadService = new MainSdkLoadService();
|
||||
|
||||
this.mainCryptoFunctionService = new NodeCryptoFunctionService();
|
||||
|
||||
const stateEventRegistrarService = new StateEventRegistrarService(
|
||||
@@ -386,6 +391,8 @@ export class Main {
|
||||
this.windowMain.win.on("minimize", () => {
|
||||
this.messagingService.send("windowHidden");
|
||||
});
|
||||
|
||||
await this.sdkLoadService.loadAndInit();
|
||||
},
|
||||
(e: any) => {
|
||||
this.logService.error("Error while running migrations:", e);
|
||||
|
||||
9
apps/desktop/src/services/main-sdk-load-service.ts
Normal file
9
apps/desktop/src/services/main-sdk-load-service.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
|
||||
import * as sdk from "@bitwarden/sdk-internal";
|
||||
|
||||
export class MainSdkLoadService extends SdkLoadService {
|
||||
async load(): Promise<void> {
|
||||
const module = await import("@bitwarden/sdk-internal/bitwarden_wasm_internal_bg.wasm");
|
||||
(sdk as any).init(module);
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,9 @@ const main = {
|
||||
},
|
||||
],
|
||||
},
|
||||
experiments: {
|
||||
asyncWebAssembly: true,
|
||||
},
|
||||
plugins: [
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
|
||||
Reference in New Issue
Block a user