mirror of
https://github.com/bitwarden/browser
synced 2026-02-15 07:54:55 +00:00
Remove introduced function
This commit is contained in:
@@ -84,6 +84,7 @@ export abstract class InternalMasterPasswordServiceAbstraction extends MasterPas
|
||||
/**
|
||||
* Set the master key for the user.
|
||||
* Note: Use {@link clearMasterKey} to clear the master key.
|
||||
* @deprecated
|
||||
* @param masterKey The master key.
|
||||
* @param userId The user ID.
|
||||
* @throws If the user ID or master key is missing.
|
||||
@@ -91,6 +92,7 @@ export abstract class InternalMasterPasswordServiceAbstraction extends MasterPas
|
||||
abstract setMasterKey: (masterKey: MasterKey, userId: UserId) => Promise<void>;
|
||||
/**
|
||||
* Clear the master key for the user.
|
||||
* @deprecated
|
||||
* @param userId The user ID.
|
||||
* @throws If the user ID is missing.
|
||||
*/
|
||||
@@ -98,6 +100,7 @@ export abstract class InternalMasterPasswordServiceAbstraction extends MasterPas
|
||||
/**
|
||||
* Set the master key hash for the user.
|
||||
* Note: Use {@link clearMasterKeyHash} to clear the master key hash.
|
||||
* @deprecated
|
||||
* @param masterKeyHash The master key hash.
|
||||
* @param userId The user ID.
|
||||
* @throws If the user ID or master key hash is missing.
|
||||
@@ -105,6 +108,7 @@ export abstract class InternalMasterPasswordServiceAbstraction extends MasterPas
|
||||
abstract setMasterKeyHash: (masterKeyHash: string, userId: UserId) => Promise<void>;
|
||||
/**
|
||||
* Clear the master key hash for the user.
|
||||
* @deprecated
|
||||
* @param userId The user ID.
|
||||
* @throws If the user ID is missing.
|
||||
*/
|
||||
|
||||
@@ -287,30 +287,4 @@ describe("MasterPasswordService", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDecryptedUserKeyWithMasterPassword", () => {
|
||||
const password = "test-password";
|
||||
const kdfConfig = new PBKDF2KdfConfig(600_000);
|
||||
const userKey = makeSymmetricCryptoKey(64, 2) as UserKey;
|
||||
|
||||
beforeEach(() => {
|
||||
kdfConfigService.getKdfConfig$.mockReturnValue(of(kdfConfig));
|
||||
jest.spyOn(sut, "unwrapUserKeyFromMasterPasswordUnlockData").mockResolvedValue(userKey);
|
||||
});
|
||||
|
||||
it("throws if password is null or empty", async () => {
|
||||
await expect(
|
||||
sut.getDecryptedUserKeyWithMasterPassword(null as unknown as string, userId),
|
||||
).rejects.toThrow("Password is required.");
|
||||
await expect(sut.getDecryptedUserKeyWithMasterPassword("", userId)).rejects.toThrow(
|
||||
"Password is required.",
|
||||
);
|
||||
});
|
||||
|
||||
it("throws if userId is null", async () => {
|
||||
await expect(
|
||||
sut.getDecryptedUserKeyWithMasterPassword(password, null as unknown as UserId),
|
||||
).rejects.toThrow("User ID is required.");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -109,9 +109,6 @@ export class MasterPasswordService implements InternalMasterPasswordServiceAbstr
|
||||
}
|
||||
|
||||
// TODO: Remove this method and decrypt directly in the service instead
|
||||
/**
|
||||
* @deprecated This will be made private
|
||||
*/
|
||||
async getMasterKeyEncryptedUserKey(userId: UserId): Promise<EncString> {
|
||||
if (userId == null) {
|
||||
throw new Error("User ID is required.");
|
||||
@@ -122,31 +119,6 @@ export class MasterPasswordService implements InternalMasterPasswordServiceAbstr
|
||||
return EncString.fromJSON(key);
|
||||
}
|
||||
|
||||
async getDecryptedUserKeyWithMasterPassword(password: string, userId: UserId): Promise<UserKey> {
|
||||
if (password == null || password === "") {
|
||||
throw new Error("Password is required.");
|
||||
}
|
||||
if (userId == null) {
|
||||
throw new Error("User ID is required.");
|
||||
}
|
||||
|
||||
const masterKeyWrappedUserKey = (await this.getMasterKeyEncryptedUserKey(
|
||||
userId,
|
||||
)) as MasterKeyWrappedUserKey;
|
||||
const kdf = await firstValueFrom(this.kdfConfigService.getKdfConfig$(userId));
|
||||
const salt = this.emailToSalt(
|
||||
await firstValueFrom(
|
||||
this.accountService.accounts$.pipe(map((accounts) => accounts[userId].email)),
|
||||
),
|
||||
);
|
||||
|
||||
return this.unwrapUserKeyFromMasterPasswordUnlockData(password, {
|
||||
salt,
|
||||
kdf,
|
||||
masterKeyWrappedUserKey,
|
||||
});
|
||||
}
|
||||
|
||||
emailToSalt(email: string): MasterPasswordSalt {
|
||||
return email.toLowerCase().trim() as MasterPasswordSalt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user