1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 00:33:44 +00:00

update vault timeout service with new crypto service

This commit is contained in:
Jacob Fink
2023-05-30 13:11:10 -04:00
parent ffc23bfcdb
commit 46abba2135
3 changed files with 15 additions and 6 deletions

View File

@@ -34,6 +34,7 @@ export abstract class CryptoService {
kdf: KdfType, kdf: KdfType,
KdfConfig: KdfConfig KdfConfig: KdfConfig
) => Promise<MasterKey>; ) => Promise<MasterKey>;
clearMasterKey: (userId?: string) => Promise<void>;
encryptUserSymKeyWithMasterKey: ( encryptUserSymKeyWithMasterKey: (
masterKey: MasterKey, masterKey: MasterKey,
userSymKey?: UserSymKey userSymKey?: UserSymKey

View File

@@ -66,7 +66,7 @@ export class CryptoService implements CryptoServiceAbstraction {
*/ */
async setUserKey(key: UserSymKey, userId?: string): Promise<void> { async setUserKey(key: UserSymKey, userId?: string): Promise<void> {
await this.stateService.setUserSymKey(key, { userId: userId }); await this.stateService.setUserSymKey(key, { userId: userId });
// TODO: Should we include additional keys here? When we set the memory key from storage, // TODO(Jake): Should we include additional keys here? When we set the memory key from storage,
// it will reset the keys in storage as well // it will reset the keys in storage as well
await this.storeAdditionalKeys(key, userId); await this.storeAdditionalKeys(key, userId);
} }
@@ -181,7 +181,7 @@ export class CryptoService implements CryptoServiceAbstraction {
* @param userId The desired user * @param userId The desired user
*/ */
async setUserSymKeyMasterKey(userSymKeyMasterKey: string, userId?: string): Promise<void> { async setUserSymKeyMasterKey(userSymKeyMasterKey: string, userId?: string): Promise<void> {
// TODO: is this the best way to handle this from the identity token? // TODO(Jake): is this the best way to handle this from the identity token?
await this.stateService.setUserSymKeyMasterKey(userSymKeyMasterKey, { userId: userId }); await this.stateService.setUserSymKeyMasterKey(userSymKeyMasterKey, { userId: userId });
} }
@@ -219,6 +219,14 @@ export class CryptoService implements CryptoServiceAbstraction {
return (await this.makeKey(password, email, kdf, KdfConfig)) as MasterKey; return (await this.makeKey(password, email, kdf, KdfConfig)) as MasterKey;
} }
/**
* Clears the user's master key
* @param userId The desired user
*/
async clearMasterKey(userId?: string): Promise<void> {
await this.stateService.setMasterKey(null, { userId: userId });
}
/** /**
* Encrypts the existing (or provided) user symmetric key with the * Encrypts the existing (or provided) user symmetric key with the
* provided master key * provided master key
@@ -246,7 +254,7 @@ export class CryptoService implements CryptoServiceAbstraction {
throw new Error("No Master Key found."); throw new Error("No Master Key found.");
} }
// TODO: Do we need to let this be passed in as well? // TODO(Jake): Do we need to let this be passed in as well?
const userSymKeyMasterKey = await this.stateService.getUserSymKeyMasterKey({ userId: userId }); const userSymKeyMasterKey = await this.stateService.getUserSymKeyMasterKey({ userId: userId });
if (userSymKeyMasterKey == null) { if (userSymKeyMasterKey == null) {
throw new Error("No User Key found."); throw new Error("No User Key found.");
@@ -266,7 +274,7 @@ export class CryptoService implements CryptoServiceAbstraction {
return null; return null;
} }
// TODO: Do we want to set the user key here? // TODO(Jake): Do we want to set the user key here?
return new SymmetricCryptoKey(decUserKey) as UserSymKey; return new SymmetricCryptoKey(decUserKey) as UserSymKey;
} }

View File

@@ -87,10 +87,10 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
await this.stateService.setEverBeenUnlocked(true, { userId: userId }); await this.stateService.setEverBeenUnlocked(true, { userId: userId });
await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId }); await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId });
await this.cryptoService.clearKey(false, userId); await this.cryptoService.clearUserKey(false, userId);
await this.cryptoService.clearMasterKey(userId);
await this.cryptoService.clearOrgKeys(true, userId); await this.cryptoService.clearOrgKeys(true, userId);
await this.cryptoService.clearKeyPair(true, userId); await this.cryptoService.clearKeyPair(true, userId);
await this.cryptoService.clearEncKey(true, userId);
await this.cipherService.clearCache(userId); await this.cipherService.clearCache(userId);
await this.collectionService.clearCache(userId); await this.collectionService.clearCache(userId);