From 19f547e638742646a8faf05729139822a1acc73d Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Mon, 30 Sep 2024 09:14:32 -0700 Subject: [PATCH] [PM-8836] Move ownership of biometrics to key-management (#10818) * Move ownership of biometrics to key-management * Move biometrics ipc ownership to km * Move further files to km; split off preload / ipc to km * Fix linting * Fix linting * Fix tests * Fix tests * Update .github/CODEOWNERS Co-authored-by: Maciej Zieniuk <167752252+mzieniukbw@users.noreply.github.com> * Update .github/CODEOWNERS Co-authored-by: Maciej Zieniuk <167752252+mzieniukbw@users.noreply.github.com> * Change ownership of native messaging to key-management * Move biometrics to libs/key-management * Add README to capital whitelist * Update package-lock.json * Move km to key-management * Move km to key-management * Fix build for cli * Import fixes * Apply prettier fix * Fix test * Import fixes * Import fixes * Update libs/key-management/README.md Co-authored-by: Maciej Zieniuk <167752252+mzieniukbw@users.noreply.github.com> * Update libs/key-management/package.json Co-authored-by: Maciej Zieniuk <167752252+mzieniukbw@users.noreply.github.com> * Update lock file * Change imports to top level km package --------- Co-authored-by: Maciej Zieniuk <167752252+mzieniukbw@users.noreply.github.com> --- .github/CODEOWNERS | 9 +-- .github/whitelist-capital-letters.txt | 1 + apps/browser/src/auth/popup/lock.component.ts | 3 +- .../settings/account-security-v1.component.ts | 3 +- .../settings/account-security.component.ts | 3 +- .../browser/src/background/main.background.ts | 12 ++-- .../background/nativeMessaging.background.ts | 2 +- .../background-browser-biometrics.service.ts | 0 .../biometrics}/browser-biometrics.service.ts | 4 +- .../foreground-browser-biometrics.ts | 2 +- .../services/browser-crypto.service.ts | 3 +- .../src/popup/services/services.module.ts | 5 +- apps/browser/tsconfig.json | 1 + .../service-container/service-container.ts | 5 +- apps/cli/tsconfig.json | 1 + .../src/app/accounts/settings.component.ts | 3 +- apps/desktop/src/app/app.component.ts | 2 +- .../src/app/services/services.module.ts | 5 +- apps/desktop/src/auth/lock.component.spec.ts | 14 +++-- apps/desktop/src/auth/lock.component.ts | 5 +- .../biometrics}/biometric.darwin.main.ts | 0 .../biometrics}/biometric.noop.main.ts | 0 .../biometric.renderer-ipc.listener.ts | 63 +++++++++++++++++++ .../biometrics}/biometric.unix.main.ts | 4 +- .../biometrics}/biometric.windows.main.ts | 2 +- .../biometrics}/biometrics.service.spec.ts | 4 +- .../biometrics}/biometrics.service.ts | 4 +- .../biometrics}/desktop.biometrics.service.ts | 2 +- .../electron-biometrics.service.ts | 14 ++--- .../biometrics}/index.ts | 0 apps/desktop/src/key-management/preload.ts | 39 ++++++++++++ apps/desktop/src/main.ts | 12 +++- apps/desktop/src/main/window.main.ts | 2 +- .../desktop-credential-storage-listener.ts | 51 +-------------- apps/desktop/src/platform/preload.ts | 34 +--------- .../services/electron-crypto.service.spec.ts | 2 +- .../services/electron-crypto.service.ts | 2 +- apps/desktop/src/preload.ts | 2 + .../src/services/native-messaging.service.ts | 3 +- apps/desktop/tsconfig.json | 1 + apps/web/.vscode/settings.json | 3 +- apps/web/src/app/app.component.ts | 2 +- apps/web/src/app/core/core.module.ts | 28 ++++----- .../web-biometric.service.ts | 2 +- apps/web/tsconfig.json | 1 + bitwarden_license/bit-cli/tsconfig.json | 1 + bitwarden_license/bit-common/tsconfig.json | 1 + bitwarden_license/bit-web/tsconfig.json | 1 + .../src/auth/components/lock.component.ts | 3 +- .../src/services/jslib-services.module.ts | 5 +- .../src/platform/services/system.service.ts | 3 +- .../vault-timeout-settings.service.spec.ts | 2 +- .../vault-timeout-settings.service.ts | 2 +- libs/key-management/README.md | 3 + libs/key-management/jest.config.js | 20 ++++++ libs/key-management/package.json | 25 ++++++++ .../biometric-state.service.spec.ts | 16 +++-- .../biometrics/biometric-state.service.ts | 6 +- .../src}/biometrics/biometric.service.ts | 0 .../src}/biometrics/biometric.state.spec.ts | 4 +- .../src}/biometrics/biometric.state.ts | 14 +++-- libs/key-management/src/index.ts | 6 ++ libs/key-management/test.setup.ts | 28 +++++++++ libs/key-management/tsconfig.json | 5 ++ libs/key-management/tsconfig.spec.json | 4 ++ libs/shared/tsconfig.libs.json | 1 + package-lock.json | 14 +++++ tsconfig.json | 1 + 68 files changed, 336 insertions(+), 189 deletions(-) rename apps/browser/src/{platform/services => key-management/biometrics}/background-browser-biometrics.service.ts (100%) rename apps/browser/src/{platform/services => key-management/biometrics}/browser-biometrics.service.ts (76%) rename apps/browser/src/{platform/services => key-management/biometrics}/foreground-browser-biometrics.ts (93%) rename apps/desktop/src/{platform/main/biometric => key-management/biometrics}/biometric.darwin.main.ts (100%) rename apps/desktop/src/{platform/main/biometric => key-management/biometrics}/biometric.noop.main.ts (100%) create mode 100644 apps/desktop/src/key-management/biometrics/biometric.renderer-ipc.listener.ts rename apps/desktop/src/{platform/main/biometric => key-management/biometrics}/biometric.unix.main.ts (97%) rename apps/desktop/src/{platform/main/biometric => key-management/biometrics}/biometric.windows.main.ts (99%) rename apps/desktop/src/{platform/main/biometric => key-management/biometrics}/biometrics.service.spec.ts (96%) rename apps/desktop/src/{platform/main/biometric => key-management/biometrics}/biometrics.service.ts (97%) rename apps/desktop/src/{platform/main/biometric => key-management/biometrics}/desktop.biometrics.service.ts (95%) rename apps/desktop/src/{platform/services => key-management/biometrics}/electron-biometrics.service.ts (67%) rename apps/desktop/src/{platform/main/biometric => key-management/biometrics}/index.ts (100%) create mode 100644 apps/desktop/src/key-management/preload.ts rename apps/web/src/app/{platform => key-management}/web-biometric.service.ts (87%) create mode 100644 libs/key-management/README.md create mode 100644 libs/key-management/jest.config.js create mode 100644 libs/key-management/package.json rename libs/{common/src/platform => key-management/src}/biometrics/biometric-state.service.spec.ts (95%) rename libs/{common/src/platform => key-management/src}/biometrics/biometric-state.service.ts (98%) rename libs/{common/src/platform => key-management/src}/biometrics/biometric.service.ts (100%) rename libs/{common/src/platform => key-management/src}/biometrics/biometric.state.spec.ts (87%) rename libs/{common/src/platform => key-management/src}/biometrics/biometric.state.ts (88%) create mode 100644 libs/key-management/src/index.ts create mode 100644 libs/key-management/test.setup.ts create mode 100644 libs/key-management/tsconfig.json create mode 100644 libs/key-management/tsconfig.spec.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9665d40b07..7a7bb31ea5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -19,9 +19,6 @@ apps/web/src/connectors @bitwarden/team-auth-dev bitwarden_license/bit-web/src/app/auth @bitwarden/team-auth-dev libs/angular/src/auth @bitwarden/team-auth-dev libs/common/src/auth @bitwarden/team-auth-dev -# biometrics -apps/desktop/src/services/native-messaging.service.ts @bitwarden/team-auth-dev -app/browser/src/background/nativeMessaging.background.ts @bitwarden/team-auth-dev ## Tools team files ## apps/browser/src/tools @bitwarden/team-tools-dev @@ -111,7 +108,11 @@ apps/desktop/src/key-management @bitwarden/team-key-management-dev apps/web/src/key-management @bitwarden/team-key-management-dev apps/browser/src/key-management @bitwarden/team-key-management-dev apps/cli/src/key-management @bitwarden/team-key-management-dev -libs/common/src/key-management @bitwarden/team-key-management-dev +libs/key-management @bitwarden/team-key-management-dev + +apps/desktop/destkop_native/core/src/biometric/ @bitwarden/team-key-management-dev +apps/desktop/src/services/native-messaging.service.ts @bitwarden/team-key-management-dev +apps/browser/src/background/nativeMessaging.background.ts @bitwarden/team-key-management-dev ## DevOps team files ## /.github/workflows @bitwarden/dept-devops diff --git a/.github/whitelist-capital-letters.txt b/.github/whitelist-capital-letters.txt index b09829f7f4..c38e0241f7 100644 --- a/.github/whitelist-capital-letters.txt +++ b/.github/whitelist-capital-letters.txt @@ -20,6 +20,7 @@ ./libs/billing/README.md ./libs/common/src/tools/integration/README.md ./libs/platform/README.md +./libs/key-management/README.md ./libs/tools/README.md ./libs/tools/export/vault-export/README.md ./libs/tools/send/README.md diff --git a/apps/browser/src/auth/popup/lock.component.ts b/apps/browser/src/auth/popup/lock.component.ts index f5413e4bea..96bda7012d 100644 --- a/apps/browser/src/auth/popup/lock.component.ts +++ b/apps/browser/src/auth/popup/lock.component.ts @@ -23,11 +23,10 @@ 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 { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { DialogService, ToastService } from "@bitwarden/components"; +import { BiometricsService, BiometricStateService } from "@bitwarden/key-management"; import { BiometricErrors, BiometricErrorTypes } from "../../models/biometricErrors"; import { BrowserRouterService } from "../../platform/popup/services/browser-router.service"; diff --git a/apps/browser/src/auth/popup/settings/account-security-v1.component.ts b/apps/browser/src/auth/popup/settings/account-security-v1.component.ts index 4975ba5f7a..d2a515b259 100644 --- a/apps/browser/src/auth/popup/settings/account-security-v1.component.ts +++ b/apps/browser/src/auth/popup/settings/account-security-v1.component.ts @@ -31,14 +31,13 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { VaultTimeout, VaultTimeoutOption, VaultTimeoutStringType, } from "@bitwarden/common/types/vault-timeout.type"; import { DialogService } from "@bitwarden/components"; +import { BiometricStateService, BiometricsService } from "@bitwarden/key-management"; import { BiometricErrors, BiometricErrorTypes } from "../../../models/biometricErrors"; import { BrowserApi } from "../../../platform/browser/browser-api"; diff --git a/apps/browser/src/auth/popup/settings/account-security.component.ts b/apps/browser/src/auth/popup/settings/account-security.component.ts index 8e0acc7d64..c546db3c97 100644 --- a/apps/browser/src/auth/popup/settings/account-security.component.ts +++ b/apps/browser/src/auth/popup/settings/account-security.component.ts @@ -33,8 +33,6 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { VaultTimeout, VaultTimeoutOption, @@ -54,6 +52,7 @@ import { TypographyModule, ToastService, } from "@bitwarden/components"; +import { BiometricsService, BiometricStateService } from "@bitwarden/key-management"; import { BiometricErrors, BiometricErrorTypes } from "../../../models/biometricErrors"; import { BrowserApi } from "../../../platform/browser/browser-api"; diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 43a6d5968e..7e9da00aba 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -95,11 +95,6 @@ import { ObservableStorageService, } from "@bitwarden/common/platform/abstractions/storage.service"; import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service"; -import { - BiometricStateService, - DefaultBiometricStateService, -} from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; // eslint-disable-next-line no-restricted-imports -- Used for dependency creation @@ -197,6 +192,11 @@ import { ImportService, ImportServiceAbstraction, } from "@bitwarden/importer/core"; +import { + BiometricStateService, + DefaultBiometricStateService, + BiometricsService, +} from "@bitwarden/key-management"; import { IndividualVaultExportService, IndividualVaultExportServiceAbstraction, @@ -225,6 +225,7 @@ import { BrowserFido2UserInterfaceService } from "../autofill/fido2/services/bro import { AutofillService as AutofillServiceAbstraction } from "../autofill/services/abstractions/autofill.service"; import AutofillService from "../autofill/services/autofill.service"; import { SafariApp } from "../browser/safariApp"; +import { BackgroundBrowserBiometricsService } from "../key-management/biometrics/background-browser-biometrics.service"; import { BrowserApi } from "../platform/browser/browser-api"; import { UpdateBadge } from "../platform/listeners/update-badge"; /* eslint-disable no-restricted-imports */ @@ -233,7 +234,6 @@ import { ChromeMessageSender } from "../platform/messaging/chrome-message.sender import { OffscreenDocumentService } from "../platform/offscreen-document/abstractions/offscreen-document"; import { DefaultOffscreenDocumentService } from "../platform/offscreen-document/offscreen-document.service"; import { BrowserTaskSchedulerService } from "../platform/services/abstractions/browser-task-scheduler.service"; -import { BackgroundBrowserBiometricsService } from "../platform/services/background-browser-biometrics.service"; import { BrowserCryptoService } from "../platform/services/browser-crypto.service"; import { BrowserEnvironmentService } from "../platform/services/browser-environment.service"; import BrowserLocalStorageService from "../platform/services/browser-local-storage.service"; diff --git a/apps/browser/src/background/nativeMessaging.background.ts b/apps/browser/src/background/nativeMessaging.background.ts index 68a43fbdfe..d483b10bc3 100644 --- a/apps/browser/src/background/nativeMessaging.background.ts +++ b/apps/browser/src/background/nativeMessaging.background.ts @@ -10,11 +10,11 @@ import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt. 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 { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { UserKey } from "@bitwarden/common/types/key"; +import { BiometricStateService } from "@bitwarden/key-management"; import { BrowserApi } from "../platform/browser/browser-api"; diff --git a/apps/browser/src/platform/services/background-browser-biometrics.service.ts b/apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts similarity index 100% rename from apps/browser/src/platform/services/background-browser-biometrics.service.ts rename to apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts diff --git a/apps/browser/src/platform/services/browser-biometrics.service.ts b/apps/browser/src/key-management/biometrics/browser-biometrics.service.ts similarity index 76% rename from apps/browser/src/platform/services/browser-biometrics.service.ts rename to apps/browser/src/key-management/biometrics/browser-biometrics.service.ts index 84734fb492..7ffbed4541 100644 --- a/apps/browser/src/platform/services/browser-biometrics.service.ts +++ b/apps/browser/src/key-management/biometrics/browser-biometrics.service.ts @@ -1,8 +1,8 @@ import { Injectable } from "@angular/core"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; +import { BiometricsService } from "@bitwarden/key-management"; -import { BrowserApi } from "../browser/browser-api"; +import { BrowserApi } from "../../platform/browser/browser-api"; @Injectable() export abstract class BrowserBiometricsService extends BiometricsService { diff --git a/apps/browser/src/platform/services/foreground-browser-biometrics.ts b/apps/browser/src/key-management/biometrics/foreground-browser-biometrics.ts similarity index 93% rename from apps/browser/src/platform/services/foreground-browser-biometrics.ts rename to apps/browser/src/key-management/biometrics/foreground-browser-biometrics.ts index ee55de2010..f50468c8b7 100644 --- a/apps/browser/src/platform/services/foreground-browser-biometrics.ts +++ b/apps/browser/src/key-management/biometrics/foreground-browser-biometrics.ts @@ -1,4 +1,4 @@ -import { BrowserApi } from "../browser/browser-api"; +import { BrowserApi } from "../../platform/browser/browser-api"; import { BrowserBiometricsService } from "./browser-biometrics.service"; diff --git a/apps/browser/src/platform/services/browser-crypto.service.ts b/apps/browser/src/platform/services/browser-crypto.service.ts index 1d61fb4c8e..d0b4e3add7 100644 --- a/apps/browser/src/platform/services/browser-crypto.service.ts +++ b/apps/browser/src/platform/services/browser-crypto.service.ts @@ -10,14 +10,13 @@ import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/ke import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { KeySuffixOptions } from "@bitwarden/common/platform/enums"; import { CryptoService } from "@bitwarden/common/platform/services/crypto.service"; import { USER_KEY } from "@bitwarden/common/platform/services/key-state/user-key.state"; import { StateProvider } from "@bitwarden/common/platform/state"; import { UserId } from "@bitwarden/common/types/guid"; import { UserKey } from "@bitwarden/common/types/key"; +import { BiometricsService, BiometricStateService } from "@bitwarden/key-management"; export class BrowserCryptoService extends CryptoService { constructor( diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index 129744fd3b..483bf86712 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -62,8 +62,6 @@ import { AbstractStorageService, ObservableStorageService, } from "@bitwarden/common/platform/abstractions/storage.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; // eslint-disable-next-line no-restricted-imports -- Used for dependency injection import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal"; @@ -89,6 +87,7 @@ import { FolderService as FolderServiceAbstraction } from "@bitwarden/common/vau import { TotpService as TotpServiceAbstraction } from "@bitwarden/common/vault/abstractions/totp.service"; import { TotpService } from "@bitwarden/common/vault/services/totp.service"; import { DialogService, ToastService } from "@bitwarden/components"; +import { BiometricsService, BiometricStateService } from "@bitwarden/key-management"; import { PasswordRepromptService } from "@bitwarden/vault"; import { ForegroundLockService } from "../../auth/popup/accounts/foreground-lock.service"; @@ -96,6 +95,7 @@ import { ExtensionAnonLayoutWrapperDataService } from "../../auth/popup/extensio import { AutofillService as AutofillServiceAbstraction } from "../../autofill/services/abstractions/autofill.service"; import AutofillService from "../../autofill/services/autofill.service"; import MainBackground from "../../background/main.background"; +import { ForegroundBrowserBiometricsService } from "../../key-management/biometrics/foreground-browser-biometrics"; import { BrowserApi } from "../../platform/browser/browser-api"; import { runInsideAngular } from "../../platform/browser/run-inside-angular.operator"; /* eslint-disable no-restricted-imports */ @@ -111,7 +111,6 @@ import { BrowserCryptoService } from "../../platform/services/browser-crypto.ser import { BrowserEnvironmentService } from "../../platform/services/browser-environment.service"; import BrowserLocalStorageService from "../../platform/services/browser-local-storage.service"; import { BrowserScriptInjectorService } from "../../platform/services/browser-script-injector.service"; -import { ForegroundBrowserBiometricsService } from "../../platform/services/foreground-browser-biometrics"; import I18nService from "../../platform/services/i18n.service"; import { ForegroundPlatformUtilsService } from "../../platform/services/platform-utils/foreground-platform-utils.service"; import { ForegroundTaskSchedulerService } from "../../platform/services/task-scheduler/foreground-task-scheduler.service"; diff --git a/apps/browser/tsconfig.json b/apps/browser/tsconfig.json index a6119a2e0a..c857d952ab 100644 --- a/apps/browser/tsconfig.json +++ b/apps/browser/tsconfig.json @@ -32,6 +32,7 @@ "@bitwarden/importer/ui": ["../../libs/importer/src/components"], "@bitwarden/platform": ["../../libs/platform/src"], "@bitwarden/send-ui": ["../../libs/tools/send/send-ui/src"], + "@bitwarden/key-management": ["../../libs/key-management/src"], "@bitwarden/vault": ["../../libs/vault/src"] }, "useDefineForClassFields": false diff --git a/apps/cli/src/service-container/service-container.ts b/apps/cli/src/service-container/service-container.ts index 98c5fc86b5..6f19081a73 100644 --- a/apps/cli/src/service-container/service-container.ts +++ b/apps/cli/src/service-container/service-container.ts @@ -61,10 +61,6 @@ import { ConfigApiServiceAbstraction } from "@bitwarden/common/platform/abstract import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service"; -import { - BiometricStateService, - DefaultBiometricStateService, -} from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { KeySuffixOptions, LogLevelType } from "@bitwarden/common/platform/enums"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { MessageSender } from "@bitwarden/common/platform/messaging"; @@ -142,6 +138,7 @@ import { ImportService, ImportServiceAbstraction, } from "@bitwarden/importer/core"; +import { BiometricStateService, DefaultBiometricStateService } from "@bitwarden/key-management"; import { NodeCryptoFunctionService } from "@bitwarden/node/services/node-crypto-function.service"; import { IndividualVaultExportService, diff --git a/apps/cli/tsconfig.json b/apps/cli/tsconfig.json index d84dcdaf67..eedf24179d 100644 --- a/apps/cli/tsconfig.json +++ b/apps/cli/tsconfig.json @@ -25,6 +25,7 @@ "@bitwarden/vault-export-core": [ "../../libs/tools/export/vault-export/vault-export-core/src" ], + "@bitwarden/key-management": ["../../libs/key-management/src"], "@bitwarden/node/*": ["../../libs/node/src/*"] } }, diff --git a/apps/desktop/src/app/accounts/settings.component.ts b/apps/desktop/src/app/accounts/settings.component.ts index 5ee7f955af..d65283598c 100644 --- a/apps/desktop/src/app/accounts/settings.component.ts +++ b/apps/desktop/src/app/accounts/settings.component.ts @@ -19,8 +19,6 @@ 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 { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { KeySuffixOptions, ThemeType } from "@bitwarden/common/platform/enums"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service"; @@ -31,6 +29,7 @@ import { VaultTimeoutStringType, } from "@bitwarden/common/types/vault-timeout.type"; import { DialogService } from "@bitwarden/components"; +import { BiometricsService, BiometricStateService } from "@bitwarden/key-management"; import { SetPinComponent } from "../../auth/components/set-pin.component"; import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service"; diff --git a/apps/desktop/src/app/app.component.ts b/apps/desktop/src/app/app.component.ts index b1f50a7b75..fee477e4ca 100644 --- a/apps/desktop/src/app/app.component.ts +++ b/apps/desktop/src/app/app.component.ts @@ -39,7 +39,6 @@ import { MessagingService } from "@bitwarden/common/platform/abstractions/messag import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { SystemService } from "@bitwarden/common/platform/abstractions/system.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { clearCaches } from "@bitwarden/common/platform/misc/sequentialize"; import { StateEventRunnerService } from "@bitwarden/common/platform/state"; import { SyncService } from "@bitwarden/common/platform/sync"; @@ -51,6 +50,7 @@ import { InternalFolderService } from "@bitwarden/common/vault/abstractions/fold import { CipherType } from "@bitwarden/common/vault/enums"; import { DialogService, ToastOptions, ToastService } from "@bitwarden/components"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; +import { BiometricStateService } from "@bitwarden/key-management"; import { DeleteAccountComponent } from "../auth/delete-account.component"; import { LoginApprovalComponent } from "../auth/login/login-approval.component"; diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index a6db7fe5db..c4d50f359a 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -55,8 +55,6 @@ import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwar import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; // eslint-disable-next-line no-restricted-imports -- Used for dependency injection import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal"; @@ -71,10 +69,11 @@ import { VaultTimeoutStringType } from "@bitwarden/common/types/vault-timeout.ty import { CipherService as CipherServiceAbstraction } from "@bitwarden/common/vault/abstractions/cipher.service"; import { DialogService } from "@bitwarden/components"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; +import { BiometricStateService, BiometricsService } from "@bitwarden/key-management"; import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service"; +import { ElectronBiometricsService } from "../../key-management/biometrics/electron-biometrics.service"; import { DesktopSettingsService } from "../../platform/services/desktop-settings.service"; -import { ElectronBiometricsService } from "../../platform/services/electron-biometrics.service"; import { ElectronCryptoService } from "../../platform/services/electron-crypto.service"; import { ElectronLogRendererService } from "../../platform/services/electron-log.renderer.service"; import { diff --git a/apps/desktop/src/auth/lock.component.spec.ts b/apps/desktop/src/auth/lock.component.spec.ts index d81f2a486f..2d867019a8 100644 --- a/apps/desktop/src/auth/lock.component.spec.ts +++ b/apps/desktop/src/auth/lock.component.spec.ts @@ -27,16 +27,18 @@ 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 { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService as AbstractBiometricService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec"; import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength"; import { UserId } from "@bitwarden/common/types/guid"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { DialogService, ToastService } from "@bitwarden/components"; +import { + BiometricsService as AbstractBiometricService, + BiometricStateService, +} from "@bitwarden/key-management"; -import { BiometricsService } from "src/platform/main/biometric"; +import { BiometricsService } from "../key-management/biometrics/biometrics.service"; import { LockComponent } from "./lock.component"; @@ -44,10 +46,12 @@ import { LockComponent } from "./lock.component"; const isWindowVisibleMock = jest.fn(); (global as any).ipc = { platform: { + isWindowVisible: isWindowVisibleMock, + }, + keyManagement: { biometric: { enabled: jest.fn(), }, - isWindowVisible: isWindowVisibleMock, }, }; @@ -461,7 +465,7 @@ describe("LockComponent", () => { stateServiceMock.getUserId.mockResolvedValue("userId"); await component["canUseBiometric"](); - expect(ipc.platform.biometric.enabled).toHaveBeenCalledWith("userId"); + expect(ipc.keyManagement.biometric.enabled).toHaveBeenCalledWith("userId"); }); }); diff --git a/apps/desktop/src/auth/lock.component.ts b/apps/desktop/src/auth/lock.component.ts index 350512b0f3..13451d402f 100644 --- a/apps/desktop/src/auth/lock.component.ts +++ b/apps/desktop/src/auth/lock.component.ts @@ -24,11 +24,10 @@ 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 { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { DialogService, ToastService } from "@bitwarden/components"; +import { BiometricsService, BiometricStateService } from "@bitwarden/key-management"; const BroadcasterSubscriptionId = "LockComponent"; @@ -184,7 +183,7 @@ export class LockComponent extends BaseLockComponent implements OnInit, OnDestro private async canUseBiometric() { const userId = await this.stateService.getUserId(); - return await ipc.platform.biometric.enabled(userId); + return await ipc.keyManagement.biometric.enabled(userId); } private focusInput() { diff --git a/apps/desktop/src/platform/main/biometric/biometric.darwin.main.ts b/apps/desktop/src/key-management/biometrics/biometric.darwin.main.ts similarity index 100% rename from apps/desktop/src/platform/main/biometric/biometric.darwin.main.ts rename to apps/desktop/src/key-management/biometrics/biometric.darwin.main.ts diff --git a/apps/desktop/src/platform/main/biometric/biometric.noop.main.ts b/apps/desktop/src/key-management/biometrics/biometric.noop.main.ts similarity index 100% rename from apps/desktop/src/platform/main/biometric/biometric.noop.main.ts rename to apps/desktop/src/key-management/biometrics/biometric.noop.main.ts diff --git a/apps/desktop/src/key-management/biometrics/biometric.renderer-ipc.listener.ts b/apps/desktop/src/key-management/biometrics/biometric.renderer-ipc.listener.ts new file mode 100644 index 0000000000..48b41881bd --- /dev/null +++ b/apps/desktop/src/key-management/biometrics/biometric.renderer-ipc.listener.ts @@ -0,0 +1,63 @@ +import { ipcMain } from "electron"; + +import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service"; + +import { BiometricMessage, BiometricAction } from "../../types/biometric-message"; + +import { DesktopBiometricsService } from "./desktop.biometrics.service"; + +export class BiometricsRendererIPCListener { + constructor( + private serviceName: string, + private biometricService: DesktopBiometricsService, + private logService: ConsoleLogService, + ) {} + + init() { + ipcMain.handle("biometric", async (event: any, message: BiometricMessage) => { + try { + let serviceName = this.serviceName; + message.keySuffix = "_" + (message.keySuffix ?? ""); + if (message.keySuffix !== "_") { + serviceName += message.keySuffix; + } + + let val: string | boolean = null; + + if (!message.action) { + return val; + } + + switch (message.action) { + case BiometricAction.EnabledForUser: + if (!message.key || !message.userId) { + break; + } + val = await this.biometricService.canAuthBiometric({ + service: serviceName, + key: message.key, + userId: message.userId, + }); + break; + case BiometricAction.OsSupported: + val = await this.biometricService.supportsBiometric(); + break; + case BiometricAction.NeedsSetup: + val = await this.biometricService.biometricsNeedsSetup(); + break; + case BiometricAction.Setup: + await this.biometricService.biometricsSetup(); + break; + case BiometricAction.CanAutoSetup: + val = await this.biometricService.biometricsSupportsAutoSetup(); + break; + default: + } + + return val; + } catch (e) { + this.logService.info(e); + } + }); + } +} diff --git a/apps/desktop/src/platform/main/biometric/biometric.unix.main.ts b/apps/desktop/src/key-management/biometrics/biometric.unix.main.ts similarity index 97% rename from apps/desktop/src/platform/main/biometric/biometric.unix.main.ts rename to apps/desktop/src/key-management/biometrics/biometric.unix.main.ts index c748276a6e..8962e7f3ec 100644 --- a/apps/desktop/src/platform/main/biometric/biometric.unix.main.ts +++ b/apps/desktop/src/key-management/biometrics/biometric.unix.main.ts @@ -4,8 +4,8 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; import { biometrics, passwords } from "@bitwarden/desktop-napi"; -import { WindowMain } from "../../../main/window.main"; -import { isFlatpak, isLinux, isSnapStore } from "../../../utils"; +import { WindowMain } from "../../main/window.main"; +import { isFlatpak, isLinux, isSnapStore } from "../../utils"; import { OsBiometricService } from "./desktop.biometrics.service"; diff --git a/apps/desktop/src/platform/main/biometric/biometric.windows.main.ts b/apps/desktop/src/key-management/biometrics/biometric.windows.main.ts similarity index 99% rename from apps/desktop/src/platform/main/biometric/biometric.windows.main.ts rename to apps/desktop/src/key-management/biometrics/biometric.windows.main.ts index 95f433c39e..abda9bf948 100644 --- a/apps/desktop/src/platform/main/biometric/biometric.windows.main.ts +++ b/apps/desktop/src/key-management/biometrics/biometric.windows.main.ts @@ -4,7 +4,7 @@ import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { biometrics, passwords } from "@bitwarden/desktop-napi"; -import { WindowMain } from "../../../main/window.main"; +import { WindowMain } from "../../main/window.main"; import { OsBiometricService } from "./desktop.biometrics.service"; diff --git a/apps/desktop/src/platform/main/biometric/biometrics.service.spec.ts b/apps/desktop/src/key-management/biometrics/biometrics.service.spec.ts similarity index 96% rename from apps/desktop/src/platform/main/biometric/biometrics.service.spec.ts rename to apps/desktop/src/key-management/biometrics/biometrics.service.spec.ts index 10ba1c83b6..d2ed648ba6 100644 --- a/apps/desktop/src/platform/main/biometric/biometrics.service.spec.ts +++ b/apps/desktop/src/key-management/biometrics/biometrics.service.spec.ts @@ -3,10 +3,10 @@ import { mock, MockProxy } from "jest-mock-extended"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { UserId } from "@bitwarden/common/types/guid"; +import { BiometricStateService } from "@bitwarden/key-management"; -import { WindowMain } from "../../../main/window.main"; +import { WindowMain } from "../../main/window.main"; import BiometricDarwinMain from "./biometric.darwin.main"; import BiometricWindowsMain from "./biometric.windows.main"; diff --git a/apps/desktop/src/platform/main/biometric/biometrics.service.ts b/apps/desktop/src/key-management/biometrics/biometrics.service.ts similarity index 97% rename from apps/desktop/src/platform/main/biometric/biometrics.service.ts rename to apps/desktop/src/key-management/biometrics/biometrics.service.ts index a8b6566c43..e7e0773ad1 100644 --- a/apps/desktop/src/platform/main/biometric/biometrics.service.ts +++ b/apps/desktop/src/key-management/biometrics/biometrics.service.ts @@ -1,10 +1,10 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { UserId } from "@bitwarden/common/types/guid"; +import { BiometricStateService } from "@bitwarden/key-management"; -import { WindowMain } from "../../../main/window.main"; +import { WindowMain } from "../../main/window.main"; import { DesktopBiometricsService, OsBiometricService } from "./desktop.biometrics.service"; diff --git a/apps/desktop/src/platform/main/biometric/desktop.biometrics.service.ts b/apps/desktop/src/key-management/biometrics/desktop.biometrics.service.ts similarity index 95% rename from apps/desktop/src/platform/main/biometric/desktop.biometrics.service.ts rename to apps/desktop/src/key-management/biometrics/desktop.biometrics.service.ts index c8e3a59612..eee3e5fc7f 100644 --- a/apps/desktop/src/platform/main/biometric/desktop.biometrics.service.ts +++ b/apps/desktop/src/key-management/biometrics/desktop.biometrics.service.ts @@ -1,4 +1,4 @@ -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; +import { BiometricsService } from "@bitwarden/key-management"; /** * This service extends the base biometrics service to provide desktop specific functions, diff --git a/apps/desktop/src/platform/services/electron-biometrics.service.ts b/apps/desktop/src/key-management/biometrics/electron-biometrics.service.ts similarity index 67% rename from apps/desktop/src/platform/services/electron-biometrics.service.ts rename to apps/desktop/src/key-management/biometrics/electron-biometrics.service.ts index 8e1b1f8a5d..226c914e6f 100644 --- a/apps/desktop/src/platform/services/electron-biometrics.service.ts +++ b/apps/desktop/src/key-management/biometrics/electron-biometrics.service.ts @@ -1,6 +1,6 @@ import { Injectable } from "@angular/core"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; +import { BiometricsService } from "@bitwarden/key-management"; /** * This service implement the base biometrics service to provide desktop specific functions, @@ -9,11 +9,11 @@ import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometr @Injectable() export class ElectronBiometricsService extends BiometricsService { async supportsBiometric(): Promise { - return await ipc.platform.biometric.osSupported(); + return await ipc.keyManagement.biometric.osSupported(); } async isBiometricUnlockAvailable(): Promise { - return await ipc.platform.biometric.osSupported(); + return await ipc.keyManagement.biometric.osSupported(); } /** This method is used to authenticate the user presence _only_. @@ -21,18 +21,18 @@ export class ElectronBiometricsService extends BiometricsService { * biometric keys, which has a separate authentication mechanism. * For biometric keys, invoke "keytar" with a biometric key suffix */ async authenticateBiometric(): Promise { - return await ipc.platform.biometric.authenticate(); + return await ipc.keyManagement.biometric.authenticate(); } async biometricsNeedsSetup(): Promise { - return await ipc.platform.biometric.biometricsNeedsSetup(); + return await ipc.keyManagement.biometric.biometricsNeedsSetup(); } async biometricsSupportsAutoSetup(): Promise { - return await ipc.platform.biometric.biometricsCanAutoSetup(); + return await ipc.keyManagement.biometric.biometricsCanAutoSetup(); } async biometricsSetup(): Promise { - return await ipc.platform.biometric.biometricsSetup(); + return await ipc.keyManagement.biometric.biometricsSetup(); } } diff --git a/apps/desktop/src/platform/main/biometric/index.ts b/apps/desktop/src/key-management/biometrics/index.ts similarity index 100% rename from apps/desktop/src/platform/main/biometric/index.ts rename to apps/desktop/src/key-management/biometrics/index.ts diff --git a/apps/desktop/src/key-management/preload.ts b/apps/desktop/src/key-management/preload.ts new file mode 100644 index 0000000000..ffb6159a46 --- /dev/null +++ b/apps/desktop/src/key-management/preload.ts @@ -0,0 +1,39 @@ +import { ipcRenderer } from "electron"; + +import { KeySuffixOptions } from "@bitwarden/common/platform/enums"; + +import { BiometricMessage, BiometricAction } from "../types/biometric-message"; + +const biometric = { + enabled: (userId: string): Promise => + ipcRenderer.invoke("biometric", { + action: BiometricAction.EnabledForUser, + key: `${userId}_user_biometric`, + keySuffix: KeySuffixOptions.Biometric, + userId: userId, + } satisfies BiometricMessage), + osSupported: (): Promise => + ipcRenderer.invoke("biometric", { + action: BiometricAction.OsSupported, + } satisfies BiometricMessage), + biometricsNeedsSetup: (): Promise => + ipcRenderer.invoke("biometric", { + action: BiometricAction.NeedsSetup, + } satisfies BiometricMessage), + biometricsSetup: (): Promise => + ipcRenderer.invoke("biometric", { + action: BiometricAction.Setup, + } satisfies BiometricMessage), + biometricsCanAutoSetup: (): Promise => + ipcRenderer.invoke("biometric", { + action: BiometricAction.CanAutoSetup, + } satisfies BiometricMessage), + authenticate: (): Promise => + ipcRenderer.invoke("biometric", { + action: BiometricAction.Authenticate, + } satisfies BiometricMessage), +}; + +export default { + biometric, +}; diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 86d07440a7..cf680c3bd9 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -5,7 +5,6 @@ import { Subject, firstValueFrom } from "rxjs"; import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service"; import { ClientType } from "@bitwarden/common/enums"; -import { DefaultBiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.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"; @@ -22,9 +21,12 @@ import { DefaultSingleUserStateProvider } from "@bitwarden/common/platform/state import { DefaultStateProvider } from "@bitwarden/common/platform/state/implementations/default-state.provider"; import { StateEventRegistrarService } from "@bitwarden/common/platform/state/state-event-registrar.service"; import { MemoryStorageService as MemoryStorageServiceForStateProviders } from "@bitwarden/common/platform/state/storage/memory-storage.service"; +import { DefaultBiometricStateService } from "@bitwarden/key-management"; /* eslint-enable import/no-restricted-paths */ import { DesktopAutofillSettingsService } from "./autofill/services/desktop-autofill-settings.service"; +import { BiometricsRendererIPCListener } from "./key-management/biometrics/biometric.renderer-ipc.listener"; +import { BiometricsService, DesktopBiometricsService } from "./key-management/biometrics/index"; import { MenuMain } from "./main/menu/menu.main"; import { MessagingMain } from "./main/messaging.main"; import { NativeMessagingMain } from "./main/native-messaging.main"; @@ -32,7 +34,6 @@ import { PowerMonitorMain } from "./main/power-monitor.main"; import { TrayMain } from "./main/tray.main"; import { UpdaterMain } from "./main/updater.main"; import { WindowMain } from "./main/window.main"; -import { BiometricsService, DesktopBiometricsService } from "./platform/main/biometric/index"; import { ClipboardMain } from "./platform/main/clipboard.main"; import { DesktopCredentialStorageListener } from "./platform/main/desktop-credential-storage-listener"; import { MainCryptoFunctionService } from "./platform/main/main-crypto-function.service"; @@ -54,6 +55,7 @@ export class Main { messagingService: MessageSender; environmentService: DefaultEnvironmentService; desktopCredentialStorageListener: DesktopCredentialStorageListener; + biometricsRendererIPCListener: BiometricsRendererIPCListener; desktopSettingsService: DesktopSettingsService; mainCryptoFunctionService: MainCryptoFunctionService; migrationRunner: MigrationRunner; @@ -214,6 +216,11 @@ export class Main { this.biometricsService, this.logService, ); + this.biometricsRendererIPCListener = new BiometricsRendererIPCListener( + "Bitwarden", + this.biometricsService, + this.logService, + ); this.nativeMessagingMain = new NativeMessagingMain( this.logService, @@ -233,6 +240,7 @@ export class Main { bootstrap() { this.desktopCredentialStorageListener.init(); + this.biometricsRendererIPCListener.init(); // Run migrations first, then other things this.migrationRunner.run().then( async () => { diff --git a/apps/desktop/src/main/window.main.ts b/apps/desktop/src/main/window.main.ts index 8c78f531d7..229bd1135c 100644 --- a/apps/desktop/src/main/window.main.ts +++ b/apps/desktop/src/main/window.main.ts @@ -7,8 +7,8 @@ import { firstValueFrom } from "rxjs"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { processisolations } from "@bitwarden/desktop-napi"; +import { BiometricStateService } from "@bitwarden/key-management"; import { WindowState } from "../platform/models/domain/window-state"; import { DesktopSettingsService } from "../platform/services/desktop-settings.service"; diff --git a/apps/desktop/src/platform/main/desktop-credential-storage-listener.ts b/apps/desktop/src/platform/main/desktop-credential-storage-listener.ts index 5f278b23a0..91aa2a7ad9 100644 --- a/apps/desktop/src/platform/main/desktop-credential-storage-listener.ts +++ b/apps/desktop/src/platform/main/desktop-credential-storage-listener.ts @@ -4,9 +4,7 @@ import { BiometricKey } from "@bitwarden/common/auth/types/biometric-key"; import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service"; import { passwords } from "@bitwarden/desktop-napi"; -import { BiometricMessage, BiometricAction } from "../../types/biometric-message"; - -import { DesktopBiometricsService } from "./biometric/index"; +import { DesktopBiometricsService } from "../../key-management/biometrics/index"; const AuthRequiredSuffix = "_biometric"; @@ -50,57 +48,12 @@ export class DesktopCredentialStorageListener { this.logService.info(e); } }); - - ipcMain.handle("biometric", async (event: any, message: BiometricMessage) => { - try { - let serviceName = this.serviceName; - message.keySuffix = "_" + (message.keySuffix ?? ""); - if (message.keySuffix !== "_") { - serviceName += message.keySuffix; - } - - let val: string | boolean = null; - - if (!message.action) { - return val; - } - - switch (message.action) { - case BiometricAction.EnabledForUser: - if (!message.key || !message.userId) { - break; - } - val = await this.biometricService.canAuthBiometric({ - service: serviceName, - key: message.key, - userId: message.userId, - }); - break; - case BiometricAction.OsSupported: - val = await this.biometricService.supportsBiometric(); - break; - case BiometricAction.NeedsSetup: - val = await this.biometricService.biometricsNeedsSetup(); - break; - case BiometricAction.Setup: - await this.biometricService.biometricsSetup(); - break; - case BiometricAction.CanAutoSetup: - val = await this.biometricService.biometricsSupportsAutoSetup(); - break; - default: - } - - return val; - } catch (e) { - this.logService.info(e); - } - }); } // Gracefully handle old keytar values, and if detected updated the entry to the proper format private async getPassword(serviceName: string, key: string, keySuffix: string) { let val: string; + // todo: remove this when biometrics has been migrated to desktop_native if (keySuffix === AuthRequiredSuffix) { val = (await this.biometricService.getBiometricKey(serviceName, key)) ?? null; } else { diff --git a/apps/desktop/src/platform/preload.ts b/apps/desktop/src/platform/preload.ts index c1c56c5522..bf02ca697f 100644 --- a/apps/desktop/src/platform/preload.ts +++ b/apps/desktop/src/platform/preload.ts @@ -1,7 +1,7 @@ import { ipcRenderer } from "electron"; import { DeviceType } from "@bitwarden/common/enums"; -import { ThemeType, KeySuffixOptions, LogLevelType } from "@bitwarden/common/platform/enums"; +import { ThemeType, LogLevelType } from "@bitwarden/common/platform/enums"; import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; import { @@ -10,7 +10,6 @@ import { Message, UnencryptedMessageResponse, } from "../models/native-messaging"; -import { BiometricMessage, BiometricAction } from "../types/biometric-message"; import { isAppImage, isDev, isFlatpak, isMacAppStore, isSnapStore, isWindowsStore } from "../utils"; import { ClipboardWriteMessage } from "./types/clipboard"; @@ -36,36 +35,6 @@ const passwords = { ipcRenderer.invoke("keytar", { action: "deletePassword", key, keySuffix }), }; -const biometric = { - enabled: (userId: string): Promise => - ipcRenderer.invoke("biometric", { - action: BiometricAction.EnabledForUser, - key: `${userId}_user_biometric`, - keySuffix: KeySuffixOptions.Biometric, - userId: userId, - } satisfies BiometricMessage), - osSupported: (): Promise => - ipcRenderer.invoke("biometric", { - action: BiometricAction.OsSupported, - } satisfies BiometricMessage), - biometricsNeedsSetup: (): Promise => - ipcRenderer.invoke("biometric", { - action: BiometricAction.NeedsSetup, - } satisfies BiometricMessage), - biometricsSetup: (): Promise => - ipcRenderer.invoke("biometric", { - action: BiometricAction.Setup, - } satisfies BiometricMessage), - biometricsCanAutoSetup: (): Promise => - ipcRenderer.invoke("biometric", { - action: BiometricAction.CanAutoSetup, - } satisfies BiometricMessage), - authenticate: (): Promise => - ipcRenderer.invoke("biometric", { - action: BiometricAction.Authenticate, - } satisfies BiometricMessage), -}; - const clipboard = { read: (): Promise => ipcRenderer.invoke("clipboard.read"), write: (message: ClipboardWriteMessage) => ipcRenderer.invoke("clipboard.write", message), @@ -180,7 +149,6 @@ export default { storage, passwords, - biometric, clipboard, powermonitor, nativeMessaging, diff --git a/apps/desktop/src/platform/services/electron-crypto.service.spec.ts b/apps/desktop/src/platform/services/electron-crypto.service.spec.ts index debbd0aa9b..0674151741 100644 --- a/apps/desktop/src/platform/services/electron-crypto.service.spec.ts +++ b/apps/desktop/src/platform/services/electron-crypto.service.spec.ts @@ -10,12 +10,12 @@ import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/ke import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { makeEncString } from "@bitwarden/common/spec"; import { CsprngArray } from "@bitwarden/common/types/csprng"; import { UserId } from "@bitwarden/common/types/guid"; import { UserKey } from "@bitwarden/common/types/key"; +import { BiometricStateService } from "@bitwarden/key-management"; import { FakeAccountService, diff --git a/apps/desktop/src/platform/services/electron-crypto.service.ts b/apps/desktop/src/platform/services/electron-crypto.service.ts index 8a6a51f4c0..b780f1ebc2 100644 --- a/apps/desktop/src/platform/services/electron-crypto.service.ts +++ b/apps/desktop/src/platform/services/electron-crypto.service.ts @@ -10,7 +10,6 @@ import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/ke import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { KeySuffixOptions } from "@bitwarden/common/platform/enums"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; @@ -19,6 +18,7 @@ import { StateProvider } from "@bitwarden/common/platform/state"; import { CsprngString } from "@bitwarden/common/types/csprng"; import { UserId } from "@bitwarden/common/types/guid"; import { UserKey } from "@bitwarden/common/types/key"; +import { BiometricStateService } from "@bitwarden/key-management"; export class ElectronCryptoService extends CryptoService { constructor( diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts index 6d708f1a20..57b20490a4 100644 --- a/apps/desktop/src/preload.ts +++ b/apps/desktop/src/preload.ts @@ -1,6 +1,7 @@ import { contextBridge } from "electron"; import auth from "./auth/preload"; +import keyManagement from "./key-management/preload"; import platform from "./platform/preload"; /** @@ -17,6 +18,7 @@ import platform from "./platform/preload"; export const ipc = { auth, platform, + keyManagement, }; contextBridge.exposeInMainWorld("ipc", ipc); diff --git a/apps/desktop/src/services/native-messaging.service.ts b/apps/desktop/src/services/native-messaging.service.ts index 2b21800194..7f707737c5 100644 --- a/apps/desktop/src/services/native-messaging.service.ts +++ b/apps/desktop/src/services/native-messaging.service.ts @@ -9,14 +9,13 @@ import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.se import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { KeySuffixOptions } from "@bitwarden/common/platform/enums"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { UserId } from "@bitwarden/common/types/guid"; import { DialogService } from "@bitwarden/components"; +import { BiometricsService, BiometricStateService } from "@bitwarden/key-management"; import { BrowserSyncVerificationDialogComponent } from "../app/components/browser-sync-verification-dialog.component"; import { LegacyMessage } from "../models/native-messaging/legacy-message"; diff --git a/apps/desktop/tsconfig.json b/apps/desktop/tsconfig.json index 19f7b8bf70..fe2c669dbc 100644 --- a/apps/desktop/tsconfig.json +++ b/apps/desktop/tsconfig.json @@ -28,6 +28,7 @@ "@bitwarden/vault-export-ui": ["../../libs/tools/export/vault-export/vault-export-ui/src"], "@bitwarden/importer/core": ["../../libs/importer/src"], "@bitwarden/importer/ui": ["../../libs/importer/src/components"], + "@bitwarden/key-management": ["../../libs/key-management/src"], "@bitwarden/node/*": ["../../libs/node/src/*"], "@bitwarden/platform": ["../../libs/platform/src"], "@bitwarden/send-ui": ["../../libs/tools/send/send-ui/src"], diff --git a/apps/web/.vscode/settings.json b/apps/web/.vscode/settings.json index 59b7b1b1e9..7527e4525c 100644 --- a/apps/web/.vscode/settings.json +++ b/apps/web/.vscode/settings.json @@ -2,5 +2,6 @@ "eslint.options": { "ignorePath": "${workspaceFolder}/../../../.eslintIgnore" }, - "prettier.ignorePath": "${workspaceFolder}/../../../.prettierignore" + "prettier.ignorePath": "${workspaceFolder}/../../../.prettierignore", + "cSpell.words": ["bitwarden"] } diff --git a/apps/web/src/app/app.component.ts b/apps/web/src/app/app.component.ts index 1314670c44..483e1a52c4 100644 --- a/apps/web/src/app/app.component.ts +++ b/apps/web/src/app/app.component.ts @@ -21,7 +21,6 @@ import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.se import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { StateEventRunnerService } from "@bitwarden/common/platform/state"; import { SyncService } from "@bitwarden/common/platform/sync"; import { UserId } from "@bitwarden/common/types/guid"; @@ -30,6 +29,7 @@ import { CollectionService } from "@bitwarden/common/vault/abstractions/collecti import { InternalFolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction"; import { DialogService, ToastOptions, ToastService } from "@bitwarden/components"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; +import { BiometricStateService } from "@bitwarden/key-management"; import { PolicyListService } from "./admin-console/core/policy-list.service"; import { diff --git a/apps/web/src/app/core/core.module.ts b/apps/web/src/app/core/core.module.ts index 5bf9373b03..c7d68856ea 100644 --- a/apps/web/src/app/core/core.module.ts +++ b/apps/web/src/app/core/core.module.ts @@ -4,23 +4,23 @@ import { APP_INITIALIZER, NgModule, Optional, SkipSelf } from "@angular/core"; import { OrganizationUserApiService } from "@bitwarden/admin-console/common"; import { SafeProvider, safeProvider } from "@bitwarden/angular/platform/utils/safe-provider"; import { - SECURE_STORAGE, - LOCALES_DIRECTORY, - SYSTEM_LANGUAGE, - MEMORY_STORAGE, - OBSERVABLE_MEMORY_STORAGE, - OBSERVABLE_DISK_STORAGE, - OBSERVABLE_DISK_LOCAL_STORAGE, - WINDOW, - SafeInjectionToken, - DEFAULT_VAULT_TIMEOUT, CLIENT_TYPE, + DEFAULT_VAULT_TIMEOUT, + LOCALES_DIRECTORY, + MEMORY_STORAGE, + OBSERVABLE_DISK_LOCAL_STORAGE, + OBSERVABLE_DISK_STORAGE, + OBSERVABLE_MEMORY_STORAGE, + SECURE_STORAGE, + SYSTEM_LANGUAGE, + SafeInjectionToken, + WINDOW, } from "@bitwarden/angular/services/injection-tokens"; import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module"; import { ModalService as ModalServiceAbstraction } from "@bitwarden/angular/services/modal.service"; import { - SetPasswordJitService, RegistrationFinishService as RegistrationFinishServiceAbstraction, + SetPasswordJitService, } from "@bitwarden/auth/angular"; import { InternalUserDecryptionOptionsServiceAbstraction } from "@bitwarden/auth/common"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; @@ -41,7 +41,6 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { ThemeType } from "@bitwarden/common/platform/enums"; import { AppIdService as DefaultAppIdService } from "@bitwarden/common/platform/services/app-id.service"; import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service"; @@ -59,13 +58,14 @@ import { ThemeStateService, } from "@bitwarden/common/platform/theming/theme-state.service"; import { VaultTimeout, VaultTimeoutStringType } from "@bitwarden/common/types/vault-timeout.type"; +import { BiometricsService } from "@bitwarden/key-management"; import { PolicyListService } from "../admin-console/core/policy-list.service"; -import { WebSetPasswordJitService, WebRegistrationFinishService } from "../auth"; +import { WebRegistrationFinishService, WebSetPasswordJitService } from "../auth"; import { AcceptOrganizationInviteService } from "../auth/organization-invite/accept-organization.service"; import { HtmlStorageService } from "../core/html-storage.service"; import { I18nService } from "../core/i18n.service"; -import { WebBiometricsService } from "../platform/web-biometric.service"; +import { WebBiometricsService } from "../key-management/web-biometric.service"; import { WebEnvironmentService } from "../platform/web-environment.service"; import { WebMigrationRunner } from "../platform/web-migration-runner"; import { WebStorageServiceProvider } from "../platform/web-storage-service.provider"; diff --git a/apps/web/src/app/platform/web-biometric.service.ts b/apps/web/src/app/key-management/web-biometric.service.ts similarity index 87% rename from apps/web/src/app/platform/web-biometric.service.ts rename to apps/web/src/app/key-management/web-biometric.service.ts index 3fb817ec5b..4681eb6fa4 100644 --- a/apps/web/src/app/platform/web-biometric.service.ts +++ b/apps/web/src/app/key-management/web-biometric.service.ts @@ -1,4 +1,4 @@ -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; +import { BiometricsService } from "@bitwarden/key-management"; export class WebBiometricsService extends BiometricsService { async supportsBiometric(): Promise { diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 5829e2f6ab..1e17de148f 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -23,6 +23,7 @@ "@bitwarden/vault-export-ui": ["../../libs/tools/export/vault-export/vault-export-ui/src"], "@bitwarden/importer/core": ["../../libs/importer/src"], "@bitwarden/importer/ui": ["../../libs/importer/src/components"], + "@bitwarden/key-management": ["../../libs/key-management/src"], "@bitwarden/platform": ["../../libs/platform/src"], "@bitwarden/send-ui": ["../../libs/tools/send/send-ui/src"], "@bitwarden/vault": ["../../libs/vault/src"], diff --git a/bitwarden_license/bit-cli/tsconfig.json b/bitwarden_license/bit-cli/tsconfig.json index 4012daac54..bb9986e6c9 100644 --- a/bitwarden_license/bit-cli/tsconfig.json +++ b/bitwarden_license/bit-cli/tsconfig.json @@ -23,6 +23,7 @@ "@bitwarden/generator-legacy": ["../../libs/tools/generator/extensions/legacy/src"], "@bitwarden/generator-history": ["../../libs/tools/generator/extensions/history/src"], "@bitwarden/generator-navigation": ["../../libs/tools/generator/extensions/navigation/src"], + "@bitwarden/key-management": ["../../libs/key-management/src"], "@bitwarden/vault-export-core": [ "../../libs/tools/export/vault-export/vault-export-core/src" ], diff --git a/bitwarden_license/bit-common/tsconfig.json b/bitwarden_license/bit-common/tsconfig.json index 21f57001ed..85ba8cbf60 100644 --- a/bitwarden_license/bit-common/tsconfig.json +++ b/bitwarden_license/bit-common/tsconfig.json @@ -21,6 +21,7 @@ ], "@bitwarden/vault-export-ui": ["../../libs/tools/export/vault-export/vault-export-core/src"], "@bitwarden/send-ui": ["../../libs/tools/send/send-ui/src"], + "@bitwarden/key-management": ["../../libs/key-management/src"], "@bitwarden/platform": ["../../libs/platform/src"], "@bitwarden/vault": ["../../libs/vault/src"], "@bitwarden/web-vault/*": ["../../apps/web/src/*"], diff --git a/bitwarden_license/bit-web/tsconfig.json b/bitwarden_license/bit-web/tsconfig.json index e05ae8018f..968744d796 100644 --- a/bitwarden_license/bit-web/tsconfig.json +++ b/bitwarden_license/bit-web/tsconfig.json @@ -23,6 +23,7 @@ "@bitwarden/vault-export-ui": ["../../libs/tools/export/vault-export/vault-export-ui/src"], "@bitwarden/importer/core": ["../../libs/importer/src"], "@bitwarden/importer/ui": ["../../libs/importer/src/components"], + "@bitwarden/key-management": ["../../libs/key-management/src"], "@bitwarden/platform": ["../../libs/platform/src"], "@bitwarden/send-ui": ["../../libs/tools/send/send-ui/src"], "@bitwarden/vault": ["../../libs/vault/src"], diff --git a/libs/angular/src/auth/components/lock.component.ts b/libs/angular/src/auth/components/lock.component.ts index 484e1c6346..5fc8f51d57 100644 --- a/libs/angular/src/auth/components/lock.component.ts +++ b/libs/angular/src/auth/components/lock.component.ts @@ -29,14 +29,13 @@ 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 { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service"; import { KeySuffixOptions } from "@bitwarden/common/platform/enums"; import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength"; import { UserId } from "@bitwarden/common/types/guid"; import { UserKey } from "@bitwarden/common/types/key"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { DialogService, ToastService } from "@bitwarden/components"; +import { BiometricStateService, BiometricsService } from "@bitwarden/key-management"; @Directive() export class LockComponent implements OnInit, OnDestroy { diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 734ae03d59..1ebaf34306 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -151,10 +151,6 @@ import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwar import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { ValidationService as ValidationServiceAbstraction } from "@bitwarden/common/platform/abstractions/validation.service"; -import { - BiometricStateService, - DefaultBiometricStateService, -} from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; // eslint-disable-next-line no-restricted-imports -- Used for dependency injection @@ -263,6 +259,7 @@ import { ImportService, ImportServiceAbstraction, } from "@bitwarden/importer/core"; +import { BiometricStateService, DefaultBiometricStateService } from "@bitwarden/key-management"; import { PasswordRepromptService } from "@bitwarden/vault"; import { VaultExportService, diff --git a/libs/common/src/platform/services/system.service.ts b/libs/common/src/platform/services/system.service.ts index 382b3bf8e8..357737391c 100644 --- a/libs/common/src/platform/services/system.service.ts +++ b/libs/common/src/platform/services/system.service.ts @@ -1,5 +1,7 @@ import { firstValueFrom, map, Subscription, timeout } from "rxjs"; +import { BiometricStateService } from "@bitwarden/key-management"; + import { PinServiceAbstraction } from "../../../../auth/src/common/abstractions"; import { VaultTimeoutSettingsService } from "../../abstractions/vault-timeout/vault-timeout-settings.service"; import { AccountService } from "../../auth/abstractions/account.service"; @@ -11,7 +13,6 @@ import { UserId } from "../../types/guid"; import { MessagingService } from "../abstractions/messaging.service"; import { PlatformUtilsService } from "../abstractions/platform-utils.service"; import { SystemService as SystemServiceAbstraction } from "../abstractions/system.service"; -import { BiometricStateService } from "../biometrics/biometric-state.service"; import { Utils } from "../misc/utils"; import { ScheduledTaskNames } from "../scheduling/scheduled-task-name.enum"; import { TaskSchedulerService } from "../scheduling/task-scheduler.service"; diff --git a/libs/common/src/services/vault-timeout/vault-timeout-settings.service.spec.ts b/libs/common/src/services/vault-timeout/vault-timeout-settings.service.spec.ts index 177c75ed5b..d90388f866 100644 --- a/libs/common/src/services/vault-timeout/vault-timeout-settings.service.spec.ts +++ b/libs/common/src/services/vault-timeout/vault-timeout-settings.service.spec.ts @@ -8,6 +8,7 @@ import { } from "@bitwarden/auth/common"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { UserId } from "@bitwarden/common/types/guid"; +import { BiometricStateService } from "@bitwarden/key-management"; import { FakeAccountService, mockAccountServiceWith, FakeStateProvider } from "../../../spec"; import { VaultTimeoutSettingsService as VaultTimeoutSettingsServiceAbstraction } from "../../abstractions/vault-timeout/vault-timeout-settings.service"; @@ -17,7 +18,6 @@ import { TokenService } from "../../auth/abstractions/token.service"; import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum"; import { CryptoService } from "../../platform/abstractions/crypto.service"; import { LogService } from "../../platform/abstractions/log.service"; -import { BiometricStateService } from "../../platform/biometrics/biometric-state.service"; import { VAULT_TIMEOUT, VAULT_TIMEOUT_ACTION, diff --git a/libs/common/src/services/vault-timeout/vault-timeout-settings.service.ts b/libs/common/src/services/vault-timeout/vault-timeout-settings.service.ts index e6587ade70..a90842b208 100644 --- a/libs/common/src/services/vault-timeout/vault-timeout-settings.service.ts +++ b/libs/common/src/services/vault-timeout/vault-timeout-settings.service.ts @@ -17,6 +17,7 @@ import { PinServiceAbstraction, UserDecryptionOptionsServiceAbstraction, } from "@bitwarden/auth/common"; +import { BiometricStateService } from "@bitwarden/key-management"; import { VaultTimeoutSettingsService as VaultTimeoutSettingsServiceAbstraction } from "../../abstractions/vault-timeout/vault-timeout-settings.service"; import { PolicyService } from "../../admin-console/abstractions/policy/policy.service.abstraction"; @@ -27,7 +28,6 @@ import { TokenService } from "../../auth/abstractions/token.service"; import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum"; import { CryptoService } from "../../platform/abstractions/crypto.service"; import { LogService } from "../../platform/abstractions/log.service"; -import { BiometricStateService } from "../../platform/biometrics/biometric-state.service"; import { StateProvider } from "../../platform/state"; import { UserId } from "../../types/guid"; import { VaultTimeout, VaultTimeoutStringType } from "../../types/vault-timeout.type"; diff --git a/libs/key-management/README.md b/libs/key-management/README.md new file mode 100644 index 0000000000..38351470a5 --- /dev/null +++ b/libs/key-management/README.md @@ -0,0 +1,3 @@ +# Key management + +This lib represents the public API of the Key management team at Bitwarden. Modules are imported using `@bitwarden/key-management`. diff --git a/libs/key-management/jest.config.js b/libs/key-management/jest.config.js new file mode 100644 index 0000000000..e20d02303d --- /dev/null +++ b/libs/key-management/jest.config.js @@ -0,0 +1,20 @@ +const { pathsToModuleNameMapper } = require("ts-jest"); + +const { compilerOptions } = require("../shared/tsconfig.libs"); + +const sharedConfig = require("../../libs/shared/jest.config.angular"); + +/** @type {import('jest').Config} */ +module.exports = { + ...sharedConfig, + displayName: "libs/key management tests", + preset: "jest-preset-angular", + setupFilesAfterEnv: ["/test.setup.ts"], + moduleNameMapper: pathsToModuleNameMapper( + // lets us use @bitwarden/common/spec in tests + { "@bitwarden/common/spec": ["../common/spec"], ...(compilerOptions?.paths ?? {}) }, + { + prefix: "/", + }, + ), +}; diff --git a/libs/key-management/package.json b/libs/key-management/package.json new file mode 100644 index 0000000000..083386cbc8 --- /dev/null +++ b/libs/key-management/package.json @@ -0,0 +1,25 @@ +{ + "name": "@bitwarden/key-management", + "version": "0.0.0", + "description": "Common code used across Bitwarden JavaScript projects.", + "keywords": [ + "bitwarden" + ], + "author": "Bitwarden Inc.", + "homepage": "https://bitwarden.com", + "repository": { + "type": "git", + "url": "https://github.com/bitwarden/clients" + }, + "license": "GPL-3.0", + "scripts": { + "clean": "rimraf dist", + "build": "npm run clean && tsc", + "build:watch": "npm run clean && tsc -watch" + }, + "dependencies": { + "@bitwarden/angular": "file:../angular", + "@bitwarden/common": "file:../common", + "@bitwarden/components": "file:../components" + } +} diff --git a/libs/common/src/platform/biometrics/biometric-state.service.spec.ts b/libs/key-management/src/biometrics/biometric-state.service.spec.ts similarity index 95% rename from libs/common/src/platform/biometrics/biometric-state.service.spec.ts rename to libs/key-management/src/biometrics/biometric-state.service.spec.ts index 56e9cb164f..2f11537127 100644 --- a/libs/common/src/platform/biometrics/biometric-state.service.spec.ts +++ b/libs/key-management/src/biometrics/biometric-state.service.spec.ts @@ -1,11 +1,15 @@ import { firstValueFrom } from "rxjs"; -import { makeEncString, trackEmissions } from "../../../spec"; -import { FakeAccountService, mockAccountServiceWith } from "../../../spec/fake-account-service"; -import { FakeGlobalState, FakeSingleUserState } from "../../../spec/fake-state"; -import { FakeStateProvider } from "../../../spec/fake-state-provider"; -import { UserId } from "../../types/guid"; -import { EncryptedString } from "../models/domain/enc-string"; +import { EncryptedString } from "@bitwarden/common/platform/models/domain/enc-string"; +import { UserId } from "@bitwarden/common/types/guid"; + +import { makeEncString, trackEmissions } from "../../../common/spec"; +import { + FakeAccountService, + mockAccountServiceWith, +} from "../../../common/spec/fake-account-service"; +import { FakeGlobalState, FakeSingleUserState } from "../../../common/spec/fake-state"; +import { FakeStateProvider } from "../../../common/spec/fake-state-provider"; import { BiometricStateService, DefaultBiometricStateService } from "./biometric-state.service"; import { diff --git a/libs/common/src/platform/biometrics/biometric-state.service.ts b/libs/key-management/src/biometrics/biometric-state.service.ts similarity index 98% rename from libs/common/src/platform/biometrics/biometric-state.service.ts rename to libs/key-management/src/biometrics/biometric-state.service.ts index 20bba49717..e815300739 100644 --- a/libs/common/src/platform/biometrics/biometric-state.service.ts +++ b/libs/key-management/src/biometrics/biometric-state.service.ts @@ -1,8 +1,8 @@ import { Observable, firstValueFrom, map, combineLatest } from "rxjs"; -import { UserId } from "../../types/guid"; -import { EncryptedString, EncString } from "../models/domain/enc-string"; -import { ActiveUserState, GlobalState, StateProvider } from "../state"; +import { EncryptedString, EncString } from "../../../common/src/platform/models/domain/enc-string"; +import { ActiveUserState, GlobalState, StateProvider } from "../../../common/src/platform/state"; +import { UserId } from "../../../common/src/types/guid"; import { BIOMETRIC_UNLOCK_ENABLED, diff --git a/libs/common/src/platform/biometrics/biometric.service.ts b/libs/key-management/src/biometrics/biometric.service.ts similarity index 100% rename from libs/common/src/platform/biometrics/biometric.service.ts rename to libs/key-management/src/biometrics/biometric.service.ts diff --git a/libs/common/src/platform/biometrics/biometric.state.spec.ts b/libs/key-management/src/biometrics/biometric.state.spec.ts similarity index 87% rename from libs/common/src/platform/biometrics/biometric.state.spec.ts rename to libs/key-management/src/biometrics/biometric.state.spec.ts index 7bcccd2ea9..94ae5217f4 100644 --- a/libs/common/src/platform/biometrics/biometric.state.spec.ts +++ b/libs/key-management/src/biometrics/biometric.state.spec.ts @@ -1,5 +1,5 @@ -import { EncryptedString } from "../models/domain/enc-string"; -import { KeyDefinition, UserKeyDefinition } from "../state"; +import { EncryptedString } from "@bitwarden/common/platform/models/domain/enc-string"; +import { KeyDefinition, UserKeyDefinition } from "@bitwarden/common/platform/state"; import { BIOMETRIC_UNLOCK_ENABLED, diff --git a/libs/common/src/platform/biometrics/biometric.state.ts b/libs/key-management/src/biometrics/biometric.state.ts similarity index 88% rename from libs/common/src/platform/biometrics/biometric.state.ts rename to libs/key-management/src/biometrics/biometric.state.ts index bcefb7b215..f88bd1da58 100644 --- a/libs/common/src/platform/biometrics/biometric.state.ts +++ b/libs/key-management/src/biometrics/biometric.state.ts @@ -1,6 +1,10 @@ -import { UserId } from "../../types/guid"; -import { EncryptedString } from "../models/domain/enc-string"; -import { KeyDefinition, BIOMETRIC_SETTINGS_DISK, UserKeyDefinition } from "../state"; +import { EncryptedString } from "../../../common/src/platform/models/domain/enc-string"; +import { + KeyDefinition, + BIOMETRIC_SETTINGS_DISK, + UserKeyDefinition, +} from "../../../common/src/platform/state"; +import { UserId } from "../../../common/src/types/guid"; /** * Indicates whether the user elected to store a biometric key to unlock their vault. @@ -9,7 +13,7 @@ export const BIOMETRIC_UNLOCK_ENABLED = new UserKeyDefinition( BIOMETRIC_SETTINGS_DISK, "biometricUnlockEnabled", { - deserializer: (obj) => obj, + deserializer: (obj: any) => obj, clearOn: [], }, ); @@ -23,7 +27,7 @@ export const REQUIRE_PASSWORD_ON_START = new UserKeyDefinition( BIOMETRIC_SETTINGS_DISK, "requirePasswordOnStart", { - deserializer: (value) => value, + deserializer: (value: any) => value, clearOn: [], }, ); diff --git a/libs/key-management/src/index.ts b/libs/key-management/src/index.ts new file mode 100644 index 0000000000..298ffd145f --- /dev/null +++ b/libs/key-management/src/index.ts @@ -0,0 +1,6 @@ +export { + BiometricStateService, + DefaultBiometricStateService, +} from "./biometrics/biometric-state.service"; +export { BiometricsService } from "./biometrics/biometric.service"; +export * from "./biometrics/biometric.state"; diff --git a/libs/key-management/test.setup.ts b/libs/key-management/test.setup.ts new file mode 100644 index 0000000000..6be6e7b8dd --- /dev/null +++ b/libs/key-management/test.setup.ts @@ -0,0 +1,28 @@ +import { webcrypto } from "crypto"; +import "jest-preset-angular/setup-jest"; + +Object.defineProperty(window, "CSS", { value: null }); +Object.defineProperty(window, "getComputedStyle", { + value: () => { + return { + display: "none", + appearance: ["-webkit-appearance"], + }; + }, +}); + +Object.defineProperty(document, "doctype", { + value: "", +}); +Object.defineProperty(document.body.style, "transform", { + value: () => { + return { + enumerable: true, + configurable: true, + }; + }, +}); + +Object.defineProperty(window, "crypto", { + value: webcrypto, +}); diff --git a/libs/key-management/tsconfig.json b/libs/key-management/tsconfig.json new file mode 100644 index 0000000000..6004a56fb5 --- /dev/null +++ b/libs/key-management/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../shared/tsconfig.libs", + "include": ["src", "spec"], + "exclude": ["node_modules", "dist"] +} diff --git a/libs/key-management/tsconfig.spec.json b/libs/key-management/tsconfig.spec.json new file mode 100644 index 0000000000..de184bd760 --- /dev/null +++ b/libs/key-management/tsconfig.spec.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] +} diff --git a/libs/shared/tsconfig.libs.json b/libs/shared/tsconfig.libs.json index 647b8a9c55..312a04f3b0 100644 --- a/libs/shared/tsconfig.libs.json +++ b/libs/shared/tsconfig.libs.json @@ -19,6 +19,7 @@ "@bitwarden/vault-export-ui": ["../tools/export/vault-export/vault-export-ui/src"], "@bitwarden/importer/core": ["../importer/src"], "@bitwarden/importer/ui": ["../importer/src/components"], + "@bitwarden/key-management": ["../key-management/src"], "@bitwarden/platform": ["../platform/src"], "@bitwarden/send-ui": ["../tools/send/send-ui/src"], "@bitwarden/node/*": ["../node/src/*"], diff --git a/package-lock.json b/package-lock.json index 39cfb49a54..f499f8bcb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -291,6 +291,16 @@ "@bitwarden/vault-export-core": "file:../tools/export/vault-export/vault-export-core" } }, + "libs/key-management": { + "name": "@bitwarden/key-management", + "version": "0.0.0", + "license": "GPL-3.0", + "dependencies": { + "@bitwarden/angular": "file:../angular", + "@bitwarden/common": "file:../common", + "@bitwarden/components": "file:../components" + } + }, "libs/node": { "name": "@bitwarden/node", "version": "0.0.0", @@ -4602,6 +4612,10 @@ "resolved": "libs/importer", "link": true }, + "node_modules/@bitwarden/key-management": { + "resolved": "libs/key-management", + "link": true + }, "node_modules/@bitwarden/node": { "resolved": "libs/node", "link": true diff --git a/tsconfig.json b/tsconfig.json index 46829a9c30..6764610d2f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -31,6 +31,7 @@ "@bitwarden/vault-export-ui": ["./libs/tools/export/vault-export/vault-export-ui/src"], "@bitwarden/importer/core": ["./libs/importer/src"], "@bitwarden/importer/ui": ["./libs/importer/src/components"], + "@bitwarden/key-management": ["./libs/key-management/src"], "@bitwarden/platform": ["./libs/platform/src"], "@bitwarden/send-ui": ["./libs/tools/send/send-ui/src"], "@bitwarden/node/*": ["./libs/node/src/*"],