diff --git a/src/Core/Abstractions/IStateService.cs b/src/Core/Abstractions/IStateService.cs index e98936863..140d0b5bf 100644 --- a/src/Core/Abstractions/IStateService.cs +++ b/src/Core/Abstractions/IStateService.cs @@ -20,7 +20,7 @@ namespace Bit.Core.Abstractions Task GetMasterKeyEncryptedUserKeyAsync(string userId = null); Task SetMasterKeyEncryptedUserKeyAsync(string value, string userId = null); Task GetUserKeyAutoUnlockAsync(string userId = null); - Task SetUserKeyAutoUnlockAsync(string value, string userId = null); + Task SetUserKeyAutoUnlockAsync(UserKey value, string userId = null); Task GetActiveUserIdAsync(); Task GetActiveUserEmailAsync(); Task GetActiveUserCustomDataAsync(Func dataMapper); @@ -35,6 +35,8 @@ namespace Bit.Core.Abstractions Task GetPreAuthEnvironmentUrlsAsync(); Task SetPreAuthEnvironmentUrlsAsync(EnvironmentUrlData value); Task GetEnvironmentUrlsAsync(string userId = null); + Task GetUserKeyBiometricUnlockAsync(string userId = null); + Task SetUserKeyBiometricUnlockAsync(UserKey value, string userId = null); Task GetBiometricUnlockAsync(string userId = null); Task SetBiometricUnlockAsync(bool? value, string userId = null); Task GetBiometricLockedAsync(string userId = null); diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 608b1845c..1cfd4fe44 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -83,6 +83,7 @@ namespace Bit.Core public static string VaultTimeoutActionKey(string userId) => $"vaultTimeoutAction_{userId}"; public static string MasterKeyEncryptedUserKeyKey(string userId) => $"masterKeyEncryptedUserKey_{userId}"; public static string UserKeyAutoUnlockKey(string userId) => $"autoUnlock_{userId}"; + public static string UserKeyBiometricUnlockKey(string userId) => $"biometricUnlock_{userId}"; public static string CiphersKey(string userId) => $"ciphers_{userId}"; public static string FoldersKey(string userId) => $"folders_{userId}"; public static string CollectionsKey(string userId) => $"collections_{userId}"; diff --git a/src/Core/Services/CryptoService.cs b/src/Core/Services/CryptoService.cs index dbfe99b74..425719d9c 100644 --- a/src/Core/Services/CryptoService.cs +++ b/src/Core/Services/CryptoService.cs @@ -684,7 +684,7 @@ namespace Bit.Core.Services // Refresh, set, or clear the auto key if (await _stateService.GetVaultTimeoutAsync(userId) == null) { - await _stateService.SetUserKeyAutoUnlockAsync(userKey.KeyB64, userId); + await _stateService.SetUserKeyAutoUnlockAsync(userKey, userId); } else { @@ -971,7 +971,7 @@ namespace Bit.Core.Services new EncString(encryptedUserKey), userId); // Migrate - await _stateService.SetUserKeyAutoUnlockAsync(userKey.KeyB64, userId); + await _stateService.SetUserKeyAutoUnlockAsync(userKey, userId); await _stateService.SetKeyEncryptedAsync(null, userId); // Set encrypted user key just in case the user locks without syncing await SetMasterKeyEncryptedUserKeyAsync(encryptedUserKey); diff --git a/src/Core/Services/StateService.cs b/src/Core/Services/StateService.cs index b8f505dba..9e5fb3a06 100644 --- a/src/Core/Services/StateService.cs +++ b/src/Core/Services/StateService.cs @@ -241,6 +241,19 @@ namespace Bit.Core.Services ))?.Settings?.EnvironmentUrls; } + public async Task GetUserKeyBiometricUnlockAsync(string userId = null) + { + var keyB64 = await _storageMediatorService.GetAsync( + await ComposeKeyAsync(Constants.UserKeyBiometricUnlockKey, userId), true); + return keyB64 == null ? null : new UserKey(Convert.FromBase64String(keyB64)); + } + + public async Task SetUserKeyBiometricUnlockAsync(UserKey value, string userId = null) + { + await _storageMediatorService.SaveAsync( + await ComposeKeyAsync(Constants.UserKeyBiometricUnlockKey, userId), value, true); + } + public async Task GetBiometricUnlockAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, @@ -353,10 +366,10 @@ namespace Bit.Core.Services return keyB64 == null ? null : new UserKey(Convert.FromBase64String(keyB64)); } - public async Task SetUserKeyAutoUnlockAsync(string value, string userId = null) + public async Task SetUserKeyAutoUnlockAsync(UserKey value, string userId = null) { await _storageMediatorService.SaveAsync( - await ComposeKeyAsync(Constants.UserKeyAutoUnlockKey, userId), value, true); + await ComposeKeyAsync(Constants.UserKeyAutoUnlockKey, userId), value.KeyB64, true); } public async Task CanAccessPremiumAsync(string userId = null)