mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
migrate biometrics key
- migrate only on retrieval
This commit is contained in:
@@ -124,12 +124,27 @@ export abstract class StateService<T extends Account = Account> {
|
||||
) => Promise<void>;
|
||||
getCryptoMasterKey: (options?: StorageOptions) => Promise<SymmetricCryptoKey>;
|
||||
setCryptoMasterKey: (value: SymmetricCryptoKey, options?: StorageOptions) => Promise<void>;
|
||||
/**
|
||||
* @deprecated For migration purposes only, use getUserSymKeyAuto instead
|
||||
*/
|
||||
getCryptoMasterKeyAuto: (options?: StorageOptions) => Promise<string>;
|
||||
/**
|
||||
* @deprecated For migration purposes only, use setUserSymKeyAuto instead
|
||||
*/
|
||||
setCryptoMasterKeyAuto: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
getCryptoMasterKeyB64: (options?: StorageOptions) => Promise<string>;
|
||||
setCryptoMasterKeyB64: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
/**
|
||||
* @deprecated For migration purposes only, use getUserSymKeyBiometric instead
|
||||
*/
|
||||
getCryptoMasterKeyBiometric: (options?: StorageOptions) => Promise<string>;
|
||||
/**
|
||||
* @deprecated For migration purposes only, use hasUserSymKeyBiometric instead
|
||||
*/
|
||||
hasCryptoMasterKeyBiometric: (options?: StorageOptions) => Promise<boolean>;
|
||||
/**
|
||||
* @deprecated For migration purposes only, use setUserSymKeyBiometric instead
|
||||
*/
|
||||
setCryptoMasterKeyBiometric: (value: BiometricKey, options?: StorageOptions) => Promise<void>;
|
||||
// end deprecated keys
|
||||
|
||||
|
||||
@@ -136,14 +136,11 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
keySuffix: KeySuffixOptions.Auto | KeySuffixOptions.Biometric,
|
||||
userId?: string
|
||||
): Promise<boolean> {
|
||||
switch (keySuffix) {
|
||||
case KeySuffixOptions.Auto:
|
||||
return (await this.retrieveUserKeyFromStorage(keySuffix, userId)) != null;
|
||||
case KeySuffixOptions.Biometric:
|
||||
return (await this.stateService.hasUserSymKeyBiometric({ userId: userId })) === true;
|
||||
default:
|
||||
return false;
|
||||
if (keySuffix === KeySuffixOptions.Biometric) {
|
||||
const oldKey = await this.stateService.hasCryptoMasterKeyBiometric({ userId: userId });
|
||||
return oldKey || (await this.stateService.hasUserSymKeyBiometric({ userId: userId }));
|
||||
}
|
||||
return (await this.retrieveUserKeyFromStorage(keySuffix, userId)) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -947,22 +944,15 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
}
|
||||
|
||||
protected async retrieveUserKeyFromStorage(
|
||||
keySuffix: KeySuffixOptions.Auto | KeySuffixOptions.Biometric,
|
||||
keySuffix: KeySuffixOptions,
|
||||
userId?: string
|
||||
): Promise<UserSymKey> {
|
||||
let userKey: string;
|
||||
switch (keySuffix) {
|
||||
case KeySuffixOptions.Auto: {
|
||||
await this.migrateAutoKeyIfNeeded(userId);
|
||||
userKey = await this.stateService.getUserSymKeyAuto({ userId: userId });
|
||||
break;
|
||||
}
|
||||
case KeySuffixOptions.Biometric: {
|
||||
userKey = await this.stateService.getUserSymKeyBiometric({ userId: userId });
|
||||
break;
|
||||
}
|
||||
if (keySuffix === KeySuffixOptions.Pin) {
|
||||
await this.migrateAutoKeyIfNeeded(userId);
|
||||
const userKey = await this.stateService.getUserSymKeyAuto({ userId: userId });
|
||||
return new SymmetricCryptoKey(Utils.fromB64ToArray(userKey).buffer) as UserSymKey;
|
||||
}
|
||||
return new SymmetricCryptoKey(Utils.fromB64ToArray(userKey).buffer) as UserSymKey;
|
||||
return null;
|
||||
}
|
||||
|
||||
private async migrateAutoKeyIfNeeded(userId?: string) {
|
||||
|
||||
@@ -689,9 +689,6 @@ export class StateService<
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* User's encrypted symmetric key when using biometrics
|
||||
*/
|
||||
async hasUserSymKeyBiometric(options?: StorageOptions): Promise<boolean> {
|
||||
options = this.reconcileOptions(
|
||||
this.reconcileOptions(options, { keySuffix: "biometric" }),
|
||||
@@ -706,9 +703,6 @@ export class StateService<
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* User's encrypted symmetric key when using biometrics
|
||||
*/
|
||||
async setUserSymKeyBiometric(value: BiometricKey, options?: StorageOptions): Promise<void> {
|
||||
options = this.reconcileOptions(
|
||||
this.reconcileOptions(options, { keySuffix: "biometric" }),
|
||||
|
||||
Reference in New Issue
Block a user