diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index c558aefb0cc..95167b6ca8e 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -92,7 +92,6 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service"; import { LogService as LogServiceAbstraction } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { SdkPureClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service"; import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; @@ -259,10 +258,7 @@ import { LocalBackedSessionStorageService } from "../platform/services/local-bac import { BackgroundPlatformUtilsService } from "../platform/services/platform-utils/background-platform-utils.service"; import { BrowserPlatformUtilsService } from "../platform/services/platform-utils/browser-platform-utils.service"; import { PopupViewCacheBackgroundService } from "../platform/services/popup-view-cache-background.service"; -import { - BrowserSdkClientFactory, - BrowserSdkPureClientFactory, -} from "../platform/services/sdk/browser-sdk-client-factory"; +import { BrowserSdkClientFactory } from "../platform/services/sdk/browser-sdk-client-factory"; import { BrowserSdkLoadService } from "../platform/services/sdk/browser-sdk-load.service"; import { BackgroundTaskSchedulerService } from "../platform/services/task-scheduler/background-task-scheduler.service"; import { BackgroundMemoryStorageService } from "../platform/storage/background-memory-storage.service"; @@ -384,7 +380,6 @@ export default class MainBackground { autoSubmitLoginBackground: AutoSubmitLoginBackground; sdkService: SdkService; sdkLoadService: SdkLoadService; - pureSdkClientFactory: SdkPureClientFactory; cipherAuthorizationService: CipherAuthorizationService; inlineMenuFieldQualificationService: InlineMenuFieldQualificationService; @@ -502,19 +497,13 @@ export default class MainBackground { return derivedKey; }); - this.pureSdkClientFactory = new BrowserSdkPureClientFactory(); this.largeObjectMemoryStorageForStateProviders = new LocalBackedSessionStorageService( sessionKey, this.storageService, // For local backed session storage, we expect that the encrypted data on disk will persist longer than the encryption key in memory // and failures to decrypt because of that are completely expected. For this reason, we pass in `false` to the `EncryptServiceImplementation` // so that MAC failures are not logged. - new EncryptServiceImplementation( - this.pureSdkClientFactory, - this.cryptoFunctionService, - this.logService, - false, - ), + new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, false), this.platformUtilsService, this.logService, ); @@ -550,18 +539,8 @@ export default class MainBackground { ); this.encryptService = BrowserApi.isManifestVersion(2) - ? new EncryptServiceImplementation( - this.pureSdkClientFactory, - this.cryptoFunctionService, - this.logService, - true, - ) - : new EncryptServiceImplementation( - this.pureSdkClientFactory, - this.cryptoFunctionService, - this.logService, - true, - ); + ? new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true) + : new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true); this.singleUserStateProvider = new DefaultSingleUserStateProvider( storageServiceProvider, diff --git a/apps/browser/src/platform/services/sdk/browser-sdk-client-factory.ts b/apps/browser/src/platform/services/sdk/browser-sdk-client-factory.ts index 47b23505b0f..60078f095a8 100644 --- a/apps/browser/src/platform/services/sdk/browser-sdk-client-factory.ts +++ b/apps/browser/src/platform/services/sdk/browser-sdk-client-factory.ts @@ -1,16 +1,5 @@ -import { - SdkClientFactory, - SdkPureClientFactory, -} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; -import type { BitwardenClient, BitwardenPure } from "@bitwarden/sdk-internal"; - -export class BrowserSdkPureClientFactory implements SdkPureClientFactory { - async createPureSdkClient(): Promise { - const instance = (globalThis as any).init_pure(); - - return instance; - } -} +import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; +import type { BitwardenClient } from "@bitwarden/sdk-internal"; /** * SDK client factory with a js fallback for when WASM is not supported. diff --git a/apps/browser/src/platform/services/sdk/fallback.ts b/apps/browser/src/platform/services/sdk/fallback.ts index 364b505485d..82d292fc9ee 100644 --- a/apps/browser/src/platform/services/sdk/fallback.ts +++ b/apps/browser/src/platform/services/sdk/fallback.ts @@ -1,11 +1,6 @@ import * as sdk from "@bitwarden/sdk-internal"; import * as wasm from "@bitwarden/sdk-internal/bitwarden_wasm_internal_bg.wasm.js"; -(globalThis as any).init_pure = () => { - (sdk as any).init(wasm); - - return new sdk.BitwardenPure(); -}; (globalThis as any).init_sdk = (...args: ConstructorParameters) => { (sdk as any).init(wasm); diff --git a/apps/browser/src/platform/services/sdk/wasm.ts b/apps/browser/src/platform/services/sdk/wasm.ts index 02f40f1b9fe..1977a171e23 100644 --- a/apps/browser/src/platform/services/sdk/wasm.ts +++ b/apps/browser/src/platform/services/sdk/wasm.ts @@ -1,11 +1,6 @@ import * as sdk from "@bitwarden/sdk-internal"; import * as wasm from "@bitwarden/sdk-internal/bitwarden_wasm_internal_bg.wasm"; -(globalThis as any).init_pure = () => { - (sdk as any).init(wasm); - - return new sdk.BitwardenPure(); -}; (globalThis as any).init_sdk = (...args: ConstructorParameters) => { (sdk as any).init(wasm); diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index 858580d0807..cef2ee5168b 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -70,10 +70,7 @@ import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/ke import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { - SdkClientFactory, - SdkPureClientFactory, -} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; +import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { @@ -87,10 +84,7 @@ import { flagEnabled } from "@bitwarden/common/platform/misc/flags"; import { TaskSchedulerService } from "@bitwarden/common/platform/scheduling"; import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service"; import { ContainerService } from "@bitwarden/common/platform/services/container.service"; -import { - NoopSdkClientFactory, - NoopSdkPureClientFactory, -} from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory"; +import { NoopSdkClientFactory } from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory"; import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; import { @@ -151,10 +145,7 @@ import BrowserMemoryStorageService from "../../platform/services/browser-memory- import { BrowserScriptInjectorService } from "../../platform/services/browser-script-injector.service"; import I18nService from "../../platform/services/i18n.service"; import { ForegroundPlatformUtilsService } from "../../platform/services/platform-utils/foreground-platform-utils.service"; -import { - BrowserSdkClientFactory, - BrowserSdkPureClientFactory, -} from "../../platform/services/sdk/browser-sdk-client-factory"; +import { BrowserSdkClientFactory } from "../../platform/services/sdk/browser-sdk-client-factory"; import { BrowserSdkLoadService } from "../../platform/services/sdk/browser-sdk-load.service"; import { ForegroundTaskSchedulerService } from "../../platform/services/task-scheduler/foreground-task-scheduler.service"; import { BrowserStorageServiceProvider } from "../../platform/storage/browser-storage-service.provider"; @@ -600,12 +591,6 @@ const safeProviders: SafeProvider[] = [ flagEnabled("sdk") ? new BrowserSdkClientFactory() : new NoopSdkClientFactory(), deps: [], }), - safeProvider({ - provide: SdkPureClientFactory, - useFactory: (logService) => - flagEnabled("sdk") ? new BrowserSdkPureClientFactory() : new NoopSdkPureClientFactory(), - deps: [LogService], - }), safeProvider({ provide: LoginEmailService, useClass: LoginEmailService, diff --git a/apps/web/src/app/core/core.module.ts b/apps/web/src/app/core/core.module.ts index 9e8b49c503a..6851387f37e 100644 --- a/apps/web/src/app/core/core.module.ts +++ b/apps/web/src/app/core/core.module.ts @@ -66,10 +66,7 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { - SdkClientFactory, - SdkPureClientFactory, -} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; +import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { ThemeType } from "@bitwarden/common/platform/enums"; @@ -78,10 +75,7 @@ import { MemoryStorageService } from "@bitwarden/common/platform/services/memory // eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service"; import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; -import { - NoopSdkClientFactory, - NoopSdkPureClientFactory, -} from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory"; +import { NoopSdkClientFactory } from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory"; import { NoopSdkLoadService } from "@bitwarden/common/platform/services/sdk/noop-sdk-load.service"; import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider"; /* eslint-disable import/no-restricted-paths -- Implementation for memory storage */ @@ -118,7 +112,7 @@ import { WebProcessReloadService } from "../key-management/services/web-process- import { WebBiometricsService } from "../key-management/web-biometric.service"; import { WebEnvironmentService } from "../platform/web-environment.service"; import { WebMigrationRunner } from "../platform/web-migration-runner"; -import { WebSdkClientFactory, WebSdkPureClientFactory } from "../platform/web-sdk-client-factory"; +import { WebSdkClientFactory } from "../platform/web-sdk-client-factory"; import { WebSdkLoadService } from "../platform/web-sdk-load.service"; import { WebStorageServiceProvider } from "../platform/web-storage-service.provider"; @@ -307,11 +301,6 @@ const safeProviders: SafeProvider[] = [ useClass: flagEnabled("sdk") ? WebSdkClientFactory : NoopSdkClientFactory, deps: [], }), - safeProvider({ - provide: SdkPureClientFactory, - useClass: flagEnabled("sdk") ? WebSdkPureClientFactory : NoopSdkPureClientFactory, - deps: [], - }), safeProvider({ provide: ProcessReloadServiceAbstraction, useClass: WebProcessReloadService, diff --git a/apps/web/src/app/platform/web-sdk-client-factory.ts b/apps/web/src/app/platform/web-sdk-client-factory.ts index f76b94a2433..917da45cfa6 100644 --- a/apps/web/src/app/platform/web-sdk-client-factory.ts +++ b/apps/web/src/app/platform/web-sdk-client-factory.ts @@ -1,15 +1,6 @@ -import { - SdkClientFactory, - SdkPureClientFactory, -} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; +import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; import * as sdk from "@bitwarden/sdk-internal"; -export class WebSdkPureClientFactory implements SdkPureClientFactory { - async createPureSdkClient(): Promise { - return Promise.resolve(new sdk.BitwardenPure()); - } -} - /** * SDK client factory with a js fallback for when WASM is not supported. */ diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index da01e31f91a..b8cc4373992 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -160,10 +160,7 @@ import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwar import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { - SdkClientFactory, - SdkPureClientFactory, -} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; +import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; @@ -890,7 +887,7 @@ const safeProviders: SafeProvider[] = [ safeProvider({ provide: EncryptService, useClass: EncryptServiceImplementation, - deps: [SdkPureClientFactory, CryptoFunctionServiceAbstraction, LogService, LOG_MAC_FAILURES], + deps: [CryptoFunctionServiceAbstraction, LogService, LOG_MAC_FAILURES], }), safeProvider({ provide: BulkEncryptService, diff --git a/libs/common/src/platform/abstractions/sdk/sdk-client-factory.ts b/libs/common/src/platform/abstractions/sdk/sdk-client-factory.ts index f3e9b4c1478..d684561dacd 100644 --- a/libs/common/src/platform/abstractions/sdk/sdk-client-factory.ts +++ b/libs/common/src/platform/abstractions/sdk/sdk-client-factory.ts @@ -1,4 +1,4 @@ -import type { BitwardenClient, BitwardenPure } from "@bitwarden/sdk-internal"; +import type { BitwardenClient } from "@bitwarden/sdk-internal"; /** * Factory for creating SDK clients. @@ -8,7 +8,3 @@ export abstract class SdkClientFactory { ...args: ConstructorParameters ): Promise; } - -export abstract class SdkPureClientFactory { - abstract createPureSdkClient(): Promise; -} diff --git a/libs/common/src/platform/services/cryptography/encrypt.service.implementation.ts b/libs/common/src/platform/services/cryptography/encrypt.service.implementation.ts index ea1cd461274..90030e0175e 100644 --- a/libs/common/src/platform/services/cryptography/encrypt.service.implementation.ts +++ b/libs/common/src/platform/services/cryptography/encrypt.service.implementation.ts @@ -1,8 +1,7 @@ // FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore -// eslint-disable-next-line no-restricted-imports -- TODO MDG: fix this -import { SdkPureClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; +import { BitwardenPure } from "@bitwarden/sdk-internal"; import { Utils } from "../../../platform/misc/utils"; import { CryptoFunctionService } from "../../abstractions/crypto-function.service"; @@ -19,7 +18,6 @@ import { SymmetricCryptoKey } from "../../models/domain/symmetric-crypto-key"; export class EncryptServiceImplementation implements EncryptService { constructor( - protected readonly sdkPureClientFactory: SdkPureClientFactory, protected cryptoFunctionService: CryptoFunctionService, protected logService: LogService, protected logMacFailures: boolean, @@ -81,8 +79,7 @@ export class EncryptServiceImplementation implements EncryptService { key = this.resolveLegacyKey(key, encString); - const pure = await this.sdkPureClientFactory.createPureSdkClient(); - const decrypted = pure.crypto().symmetric_decrypt(encString.encryptedString, key.keyB64); + const decrypted = BitwardenPure.symmetric_decrypt(encString.encryptedString, key.keyB64); return decrypted; } @@ -98,16 +95,16 @@ export class EncryptServiceImplementation implements EncryptService { key = this.resolveLegacyKey(key, encThing); - const pure = await this.sdkPureClientFactory.createPureSdkClient(); const encString = new EncString( encThing.encryptionType, Utils.fromBufferToB64(encThing.dataBytes), Utils.fromBufferToB64(encThing.ivBytes), Utils.fromBufferToB64(encThing.macBytes), ); - const decrypted = pure - .crypto() - .symmetric_decrypt_to_bytes(encString.encryptedString, key.keyB64); + const decrypted = BitwardenPure.symmetric_decrypt_to_bytes( + encString.encryptedString, + key.keyB64, + ); return decrypted ?? null; } @@ -175,9 +172,8 @@ export class EncryptServiceImplementation implements EncryptService { } private async aesEncrypt(data: Uint8Array, key: SymmetricCryptoKey): Promise { - const pure = await this.sdkPureClientFactory.createPureSdkClient(); const encString = new EncString( - pure.crypto().symmetric_encrypt(Utils.fromBufferToUtf8(data), key.keyB64), + BitwardenPure.symmetric_encrypt(Utils.fromBufferToUtf8(data), key.keyB64), ); const obj = new EncryptedObject(); obj.key = key; diff --git a/libs/common/src/platform/services/cryptography/encrypt.worker.ts b/libs/common/src/platform/services/cryptography/encrypt.worker.ts index 6d78edc92dc..a293e1c6bb0 100644 --- a/libs/common/src/platform/services/cryptography/encrypt.worker.ts +++ b/libs/common/src/platform/services/cryptography/encrypt.worker.ts @@ -2,9 +2,6 @@ // @ts-strict-ignore import { Jsonify } from "type-fest"; -// eslint-disable-next-line no-restricted-imports -- TODO MDG: this is a bug in the restricted import rule -import { DefaultSdkPureClientFactory } from "@bitwarden/common/platform/services/sdk/default-sdk-client-factory"; - import { Decryptable } from "../../interfaces/decryptable.interface"; import { SymmetricCryptoKey } from "../../models/domain/symmetric-crypto-key"; import { ConsoleLogService } from "../console-log.service"; @@ -25,13 +22,7 @@ let encryptService: EncryptServiceImplementation; export function init() { const cryptoFunctionService = new WebCryptoFunctionService(self); const logService = new ConsoleLogService(false); - const pureSdkFactory = new DefaultSdkPureClientFactory(); - encryptService = new EncryptServiceImplementation( - pureSdkFactory, - cryptoFunctionService, - logService, - true, - ); + encryptService = new EncryptServiceImplementation(cryptoFunctionService, logService, true); const bitwardenContainerService = new ContainerService(null, encryptService); bitwardenContainerService.attachToGlobal(self); diff --git a/libs/common/src/platform/services/encrypt.service.spec.ts b/libs/common/src/platform/services/encrypt.service.spec.ts index 609b5100a10..ca4442e4f81 100644 --- a/libs/common/src/platform/services/encrypt.service.spec.ts +++ b/libs/common/src/platform/services/encrypt.service.spec.ts @@ -1,3 +1,5 @@ +// FIXME: Update this file to be type safe and remove this and next line +// @ts-strict-ignore import { mockReset, mock } from "jest-mock-extended"; import { makeStaticByteArray } from "../../../spec"; diff --git a/libs/common/src/platform/services/sdk/default-sdk-client-factory.ts b/libs/common/src/platform/services/sdk/default-sdk-client-factory.ts index 4c690e3e198..8e99af2efed 100644 --- a/libs/common/src/platform/services/sdk/default-sdk-client-factory.ts +++ b/libs/common/src/platform/services/sdk/default-sdk-client-factory.ts @@ -1,15 +1,7 @@ import * as sdk from "@bitwarden/sdk-internal"; import * as module from "@bitwarden/sdk-internal/bitwarden_wasm_internal_bg.wasm"; -import { SdkClientFactory, SdkPureClientFactory } from "../../abstractions/sdk/sdk-client-factory"; - -export class DefaultSdkPureClientFactory implements SdkPureClientFactory { - async createPureSdkClient(): Promise { - (sdk as any).init(module); - - return Promise.resolve(new sdk.BitwardenPure()); - } -} +import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory"; /** * Directly imports the Bitwarden SDK and initializes it. diff --git a/libs/common/src/platform/services/sdk/default-sdk.service.spec.ts b/libs/common/src/platform/services/sdk/default-sdk.service.spec.ts index de8b079621a..91d9c37f80b 100644 --- a/libs/common/src/platform/services/sdk/default-sdk.service.spec.ts +++ b/libs/common/src/platform/services/sdk/default-sdk.service.spec.ts @@ -1,3 +1,5 @@ +// FIXME: Update this file to be type safe and remove this and next line +// @ts-strict-ignore import { mock, MockProxy } from "jest-mock-extended"; import { BehaviorSubject, firstValueFrom, of } from "rxjs"; diff --git a/libs/common/src/platform/services/sdk/noop-sdk-client-factory.ts b/libs/common/src/platform/services/sdk/noop-sdk-client-factory.ts index 31cb2a95117..d7eab7e8dc9 100644 --- a/libs/common/src/platform/services/sdk/noop-sdk-client-factory.ts +++ b/libs/common/src/platform/services/sdk/noop-sdk-client-factory.ts @@ -1,12 +1,6 @@ import type { BitwardenClient } from "@bitwarden/sdk-internal"; -import { SdkClientFactory, SdkPureClientFactory } from "../../abstractions/sdk/sdk-client-factory"; - -export class NoopSdkPureClientFactory implements SdkPureClientFactory { - createPureSdkClient(): Promise { - return Promise.reject(new Error("SDK not available")); - } -} +import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory"; /** * Noop SDK client factory.