1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[Pm-13097] Rename cryptoservice to keyservice and move it to km ownership (#11358)

* Rename cryptoservice to keyservice

* Rename cryptoservice to keyservice

* Move key service to key management ownership

* Remove accidentally added file

* Fix cli build

* Fix browser build

* Run prettier

* Fix builds

* Fix cli build

* Fix tests

* Fix incorrect renames

* Rename webauthn-login-crypto-service

* Fix build errors due to merge conflicts

* Fix linting
This commit is contained in:
Bernd Schoolmann
2024-10-24 19:41:30 +02:00
committed by GitHub
parent 554171b688
commit b486fcc689
229 changed files with 1385 additions and 1446 deletions

View File

@@ -3,8 +3,8 @@ import { mock } from "jest-mock-extended";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { UserKey } from "@bitwarden/common/types/key";
import { KeyService } from "../../../../../../key-management/src/abstractions/key.service";
import { makeStaticByteArray, mockEnc } from "../../../../../spec";
import { CryptoService } from "../../../../platform/abstractions/crypto.service";
import { EncryptService } from "../../../../platform/abstractions/encrypt.service";
import { ContainerService } from "../../../../platform/services/container.service";
import { SendType } from "../../enums/send-type";
@@ -111,14 +111,14 @@ describe("Send", () => {
send.hideEmail = true;
const encryptService = mock<EncryptService>();
const cryptoService = mock<CryptoService>();
const keyService = mock<KeyService>();
encryptService.decryptToBytes
.calledWith(send.key, userKey)
.mockResolvedValue(makeStaticByteArray(32));
cryptoService.makeSendKey.mockResolvedValue("cryptoKey" as any);
cryptoService.getUserKey.mockResolvedValue(userKey);
keyService.makeSendKey.mockResolvedValue("cryptoKey" as any);
keyService.getUserKey.mockResolvedValue(userKey);
(window as any).bitwardenContainerService = new ContainerService(cryptoService, encryptService);
(window as any).bitwardenContainerService = new ContainerService(keyService, encryptService);
const view = await send.decrypt();

View File

@@ -72,13 +72,13 @@ export class Send extends Domain {
async decrypt(): Promise<SendView> {
const model = new SendView(this);
const cryptoService = Utils.getContainerService().getCryptoService();
const keyService = Utils.getContainerService().getKeyService();
const encryptService = Utils.getContainerService().getEncryptService();
try {
const sendKeyEncryptionKey = await cryptoService.getUserKey();
const sendKeyEncryptionKey = await keyService.getUserKey();
model.key = await encryptService.decryptToBytes(this.key, sendKeyEncryptionKey);
model.cryptoKey = await cryptoService.makeSendKey(model.key);
model.cryptoKey = await keyService.makeSendKey(model.key);
} catch (e) {
// TODO: error?
}

View File

@@ -4,6 +4,7 @@ import { firstValueFrom, of } from "rxjs";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { SelfHostedEnvironment } from "@bitwarden/common/platform/services/default-environment.service";
import { KeyService } from "../../../../../key-management/src/abstractions/key.service";
import {
FakeAccountService,
FakeActiveUserState,
@@ -11,7 +12,6 @@ import {
awaitAsync,
mockAccountServiceWith,
} from "../../../../spec";
import { CryptoService } from "../../../platform/abstractions/crypto.service";
import { EncryptService } from "../../../platform/abstractions/encrypt.service";
import { I18nService } from "../../../platform/abstractions/i18n.service";
import { KeyGenerationService } from "../../../platform/abstractions/key-generation.service";
@@ -40,7 +40,7 @@ import {
} from "./test-data/send-tests.data";
describe("SendService", () => {
const cryptoService = mock<CryptoService>();
const keyService = mock<KeyService>();
const i18nService = mock<I18nService>();
const keyGenerationService = mock<KeyGenerationService>();
const encryptService = mock<EncryptService>();
@@ -65,7 +65,7 @@ describe("SendService", () => {
get: () => of(new SelfHostedEnvironment({ webVault: "https://example.com" })),
});
(window as any).bitwardenContainerService = new ContainerService(cryptoService, encryptService);
(window as any).bitwardenContainerService = new ContainerService(keyService, encryptService);
accountService.activeAccountSubject.next({
id: mockUserId,
@@ -84,7 +84,7 @@ describe("SendService", () => {
decryptedState.nextState([testSendViewData("1", "Test Send")]);
sendService = new SendService(
cryptoService,
keyService,
i18nService,
keyGenerationService,
sendStateProvider,

View File

@@ -1,7 +1,7 @@
import { Observable, concatMap, distinctUntilChanged, firstValueFrom, map } from "rxjs";
import { KeyService } from "../../../../../key-management/src/abstractions/key.service";
import { PBKDF2KdfConfig } from "../../../auth/models/domain/kdf-config";
import { CryptoService } from "../../../platform/abstractions/crypto.service";
import { EncryptService } from "../../../platform/abstractions/encrypt.service";
import { I18nService } from "../../../platform/abstractions/i18n.service";
import { KeyGenerationService } from "../../../platform/abstractions/key-generation.service";
@@ -37,7 +37,7 @@ export class SendService implements InternalSendServiceAbstraction {
);
constructor(
private cryptoService: CryptoService,
private keyService: KeyService,
private i18nService: I18nService,
private keyGenerationService: KeyGenerationService,
private stateProvider: SendStateProvider,
@@ -77,7 +77,7 @@ export class SendService implements InternalSendServiceAbstraction {
send.password = passwordKey.keyB64;
}
if (key == null) {
key = await this.cryptoService.getUserKey();
key = await this.keyService.getUserKey();
}
send.key = await this.encryptService.encrypt(model.key, key);
send.name = await this.encryptService.encrypt(model.name, model.cryptoKey);
@@ -197,7 +197,7 @@ export class SendService implements InternalSendServiceAbstraction {
}
decSends = [];
const hasKey = await this.cryptoService.hasUserKey();
const hasKey = await this.keyService.hasUserKey();
if (!hasKey) {
throw new Error("No user key found.");
}
@@ -322,7 +322,7 @@ export class SendService implements InternalSendServiceAbstraction {
key: SymmetricCryptoKey,
): Promise<[EncString, EncArrayBuffer]> {
if (key == null) {
key = await this.cryptoService.getUserKey();
key = await this.keyService.getUserKey();
}
const encFileName = await this.encryptService.encrypt(fileName, key);
const encFileData = await this.encryptService.encryptToBytes(new Uint8Array(data), key);