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.messagingService,
|
||||||
this.logService,
|
this.logService,
|
||||||
this.stateService,
|
this.stateService,
|
||||||
this.twoFactorService,
|
this.twoFactorService
|
||||||
this
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
userKey = await this.stateService.getUserSymKeyAuto({ userId: userId });
|
case KeySuffixOptions.Auto: {
|
||||||
} else if (keySuffix === KeySuffixOptions.Biometric) {
|
// migrate if needed
|
||||||
userKey = await this.stateService.getUserSymKeyBiometric({ userId: userId });
|
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;
|
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.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);
|
||||||
|
|||||||
Reference in New Issue
Block a user