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

migrate auto key

- add helper to internal crypto service method to migrate
This commit is contained in:
Jacob Fink
2023-06-07 13:24:27 -04:00
parent 9ce3b4976b
commit c2893bd0a8
3 changed files with 22 additions and 7 deletions

View File

@@ -177,8 +177,7 @@ export class AuthService implements AuthServiceAbstraction {
this.messagingService, this.messagingService,
this.logService, this.logService,
this.stateService, this.stateService,
this.twoFactorService, this.twoFactorService
this
); );
break; break;
} }

View File

@@ -133,7 +133,7 @@ export class CryptoService implements CryptoServiceAbstraction {
): Promise<boolean> { ): Promise<boolean> {
switch (keySuffix) { switch (keySuffix) {
case KeySuffixOptions.Auto: case KeySuffixOptions.Auto:
return (await this.stateService.getUserSymKeyAuto({ userId: userId })) != null; return (await this.retrieveUserKeyFromStorage(keySuffix, userId)) != null;
case KeySuffixOptions.Biometric: case KeySuffixOptions.Biometric:
return (await this.stateService.hasUserSymKeyBiometric({ userId: userId })) === true; return (await this.stateService.hasUserSymKeyBiometric({ userId: userId })) === true;
default: default:
@@ -889,6 +889,7 @@ export class CryptoService implements CryptoServiceAbstraction {
await this.stateService.setUserSymKeyAuto(key.keyB64, { userId: userId }); await this.stateService.setUserSymKeyAuto(key.keyB64, { userId: userId });
} else { } else {
await this.stateService.setUserSymKeyAuto(null, { userId: userId }); await this.stateService.setUserSymKeyAuto(null, { userId: userId });
await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId });
} }
const storePin = await this.shouldStoreKey(KeySuffixOptions.Pin, userId); const storePin = await this.shouldStoreKey(KeySuffixOptions.Pin, userId);
@@ -896,6 +897,7 @@ export class CryptoService implements CryptoServiceAbstraction {
await this.storePinKey(key); await this.storePinKey(key);
} else { } else {
await this.stateService.setUserSymKeyPin(null, { userId: userId }); await this.stateService.setUserSymKeyPin(null, { userId: userId });
await this.stateService.setEncryptedPinProtected(null, { userId: userId });
} }
} }
@@ -941,10 +943,23 @@ export class CryptoService implements CryptoServiceAbstraction {
userId?: string userId?: string
): Promise<UserSymKey> { ): Promise<UserSymKey> {
let userKey: string; let userKey: string;
if (keySuffix === KeySuffixOptions.Auto) { switch (keySuffix) {
case KeySuffixOptions.Auto: {
// migrate if needed
const oldAutoKey = await this.stateService.getCryptoMasterKeyAuto({ userId: userId });
if (oldAutoKey) {
await this.stateService.setUserSymKeyAuto(oldAutoKey, { userId: userId });
await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId });
userKey = oldAutoKey;
} else {
userKey = await this.stateService.getUserSymKeyAuto({ userId: userId }); userKey = await this.stateService.getUserSymKeyAuto({ userId: userId });
} else if (keySuffix === KeySuffixOptions.Biometric) { }
break;
}
case KeySuffixOptions.Biometric: {
userKey = await this.stateService.getUserSymKeyBiometric({ userId: userId }); userKey = await this.stateService.getUserSymKeyBiometric({ userId: userId });
break;
}
} }
return new SymmetricCryptoKey(Utils.fromB64ToArray(userKey).buffer) as UserSymKey; return new SymmetricCryptoKey(Utils.fromB64ToArray(userKey).buffer) as UserSymKey;
} }

View File

@@ -87,6 +87,7 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
} }
await this.stateService.setEverBeenUnlocked(true, { userId: userId }); await this.stateService.setEverBeenUnlocked(true, { userId: userId });
await this.stateService.setUserSymKeyAuto(null, { userId: userId });
await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId }); await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId });
await this.cryptoService.clearUserKey(false, userId); await this.cryptoService.clearUserKey(false, userId);