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

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