From 3d4f3309e5b61ad83451986aebd4769b3c9456cc Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Fri, 28 Mar 2025 14:02:53 -0400 Subject: [PATCH] Added implementation to cipher service --- .../src/vault/services/cipher.service.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index d774277c4a0..d6dd1d39ca4 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -15,6 +15,7 @@ import { import { SemVer } from "semver"; import { KeyService } from "@bitwarden/key-management"; +import { CipherView as SdkCipherView } from "@bitwarden/sdk-internal"; import { ApiService } from "../../abstractions/api.service"; import { SearchService } from "../../abstractions/search.service"; @@ -30,6 +31,7 @@ import { ListResponse } from "../../models/response/list.response"; import { View } from "../../models/view/view"; import { ConfigService } from "../../platform/abstractions/config/config.service"; import { I18nService } from "../../platform/abstractions/i18n.service"; +import { SdkService } from "../../platform/abstractions/sdk/sdk.service"; import { StateService } from "../../platform/abstractions/state.service"; import { sequentialize } from "../../platform/misc/sequentialize"; import { Utils } from "../../platform/misc/utils"; @@ -111,6 +113,7 @@ export class CipherService implements CipherServiceAbstraction { private configService: ConfigService, private stateProvider: StateProvider, private accountService: AccountService, + private sdkService: SdkService, ) {} localData$(userId: UserId): Observable> { @@ -156,6 +159,23 @@ export class CipherService implements CipherServiceAbstraction { ); } + /** + * {@link CipherServiceAbstraction.decrypt$} + */ + decrypt$(userId: UserId, cipher: Cipher): Observable { + return this.sdkService.userClient$(userId).pipe( + map((sdk) => { + if (!sdk) { + throw new Error("SDK is undefined"); + } + + using ref = sdk.take(); + + return ref.value.vault().ciphers().decrypt(cipher.toSdkCipher()); + }), + ); + } + async setDecryptedCipherCache(value: CipherView[], userId: UserId) { // Sometimes we might prematurely decrypt the vault and that will result in no ciphers // if we cache it then we may accidentally return it when it's not right, we'd rather try decryption again.