1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +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

@@ -2,11 +2,11 @@ import { MockProxy, mock } from "jest-mock-extended";
import { AccountApiService } from "@bitwarden/common/auth/abstractions/account-api.service";
import { DEFAULT_KDF_CONFIG } from "@bitwarden/common/auth/models/domain/kdf-config";
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { CsprngArray } from "@bitwarden/common/types/csprng";
import { MasterKey, UserKey } from "@bitwarden/common/types/key";
import { KeyService } from "@bitwarden/key-management";
import { PasswordInputResult } from "../../input-password/password-input-result";
@@ -15,14 +15,14 @@ import { DefaultRegistrationFinishService } from "./default-registration-finish.
describe("DefaultRegistrationFinishService", () => {
let service: DefaultRegistrationFinishService;
let cryptoService: MockProxy<CryptoService>;
let keyService: MockProxy<KeyService>;
let accountApiService: MockProxy<AccountApiService>;
beforeEach(() => {
cryptoService = mock<CryptoService>();
keyService = mock<KeyService>();
accountApiService = mock<AccountApiService>();
service = new DefaultRegistrationFinishService(cryptoService, accountApiService);
service = new DefaultRegistrationFinishService(keyService, accountApiService);
});
it("instantiates", () => {
@@ -76,7 +76,7 @@ describe("DefaultRegistrationFinishService", () => {
});
it("throws an error if the user key cannot be created", async () => {
cryptoService.makeUserKey.mockResolvedValue([null, null]);
keyService.makeUserKey.mockResolvedValue([null, null]);
await expect(service.finishRegistration(email, passwordInputResult)).rejects.toThrow(
"User key could not be created",
@@ -84,8 +84,8 @@ describe("DefaultRegistrationFinishService", () => {
});
it("registers the user and returns a captcha bypass token when given valid email verification input", async () => {
cryptoService.makeUserKey.mockResolvedValue([userKey, userKeyEncString]);
cryptoService.makeKeyPair.mockResolvedValue(userKeyPair);
keyService.makeUserKey.mockResolvedValue([userKey, userKeyEncString]);
keyService.makeKeyPair.mockResolvedValue(userKeyPair);
accountApiService.registerFinish.mockResolvedValue(capchaBypassToken);
const result = await service.finishRegistration(
@@ -96,8 +96,8 @@ describe("DefaultRegistrationFinishService", () => {
expect(result).toEqual(capchaBypassToken);
expect(cryptoService.makeUserKey).toHaveBeenCalledWith(masterKey);
expect(cryptoService.makeKeyPair).toHaveBeenCalledWith(userKey);
expect(keyService.makeUserKey).toHaveBeenCalledWith(masterKey);
expect(keyService.makeKeyPair).toHaveBeenCalledWith(userKey);
expect(accountApiService.registerFinish).toHaveBeenCalledWith(
expect.objectContaining({
email,

View File

@@ -2,8 +2,8 @@ import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/mod
import { AccountApiService } from "@bitwarden/common/auth/abstractions/account-api.service";
import { RegisterFinishRequest } from "@bitwarden/common/auth/models/request/registration/register-finish.request";
import { KeysRequest } from "@bitwarden/common/models/request/keys.request";
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
import { EncryptedString, EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { KeyService } from "@bitwarden/key-management";
import { PasswordInputResult } from "../../input-password/password-input-result";
@@ -11,7 +11,7 @@ import { RegistrationFinishService } from "./registration-finish.service";
export class DefaultRegistrationFinishService implements RegistrationFinishService {
constructor(
protected cryptoService: CryptoService,
protected keyService: KeyService,
protected accountApiService: AccountApiService,
) {}
@@ -31,14 +31,14 @@ export class DefaultRegistrationFinishService implements RegistrationFinishServi
acceptEmergencyAccessInviteToken?: string,
emergencyAccessId?: string,
): Promise<string> {
const [newUserKey, newEncUserKey] = await this.cryptoService.makeUserKey(
const [newUserKey, newEncUserKey] = await this.keyService.makeUserKey(
passwordInputResult.masterKey,
);
if (!newUserKey || !newEncUserKey) {
throw new Error("User key could not be created");
}
const userAsymmetricKeys = await this.cryptoService.makeKeyPair(newUserKey);
const userAsymmetricKeys = await this.keyService.makeKeyPair(newUserKey);
const registerRequest = await this.buildRegisterRequest(
email,