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:
@@ -177,8 +177,7 @@ export class AuthService implements AuthServiceAbstraction {
|
||||
this.messagingService,
|
||||
this.logService,
|
||||
this.stateService,
|
||||
this.twoFactorService,
|
||||
this
|
||||
this.twoFactorService
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
|
||||
}
|
||||
|
||||
await this.stateService.setEverBeenUnlocked(true, { userId: userId });
|
||||
await this.stateService.setUserSymKeyAuto(null, { userId: userId });
|
||||
await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId });
|
||||
|
||||
await this.cryptoService.clearUserKey(false, userId);
|
||||
|
||||
Reference in New Issue
Block a user