1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

fix cli crypto service calls

This commit is contained in:
Jacob Fink
2023-06-20 11:49:54 -04:00
parent 690e9ffc4a
commit d16f76524c
5 changed files with 36 additions and 10 deletions

View File

@@ -82,6 +82,12 @@ export abstract class CryptoService {
* @param userId The desired user
*/
clearUserKey: (clearSecretStorage?: boolean, userId?: string) => Promise<void>;
/**
* Clears the user's stored version of the user symmetric key
* @param keySuffix The desired version of the key to clear
* @param userId The desired user
*/
clearStoredUserKey: (keySuffix: KeySuffixOptions, userId?: string) => Promise<void>;
/**
* Stores the master key encrypted user symmetric key
* @param userSymKeyMasterKey The master key encrypted user symmetric key to set

View File

@@ -76,7 +76,7 @@ export class CryptoService implements CryptoServiceAbstraction {
if (userKey != null) {
if (!(await this.validateUserKey(userKey))) {
this.logService.warning("Wrong key, throwing away stored key");
await this.clearStoredUserKeys(userId);
await this.clearAllStoredUserKeys(userId);
return null;
}
@@ -121,7 +121,21 @@ export class CryptoService implements CryptoServiceAbstraction {
async clearUserKey(clearStoredKeys = true, userId?: string): Promise<void> {
await this.stateService.setUserSymKey(null, { userId: userId });
if (clearStoredKeys) {
await this.clearStoredUserKeys(userId);
await this.clearAllStoredUserKeys(userId);
}
}
async clearStoredUserKey(keySuffix: KeySuffixOptions, userId?: string): Promise<void> {
switch (keySuffix) {
case KeySuffixOptions.Auto:
this.stateService.setUserSymKeyAuto(null, { userId: userId });
break;
case KeySuffixOptions.Biometric:
this.stateService.setUserSymKeyBiometric(null, { userId: userId });
break;
case KeySuffixOptions.Pin:
this.stateService.setUserSymKeyPinEphemeral(null, { userId: userId });
break;
}
}
@@ -813,7 +827,7 @@ export class CryptoService implements CryptoServiceAbstraction {
return [new SymmetricCryptoKey(newSymKey) as T, protectedSymKey];
}
private async clearStoredUserKeys(userId?: string): Promise<void> {
private async clearAllStoredUserKeys(userId?: string): Promise<void> {
await this.stateService.setUserSymKeyAuto(null, { userId: userId });
await this.stateService.setUserSymKeyBiometric(null, { userId: userId });
await this.stateService.setUserSymKeyPinEphemeral(null, { userId: userId });