From 61aac20555ccf9f87ec17466b358adb5b187aa49 Mon Sep 17 00:00:00 2001 From: Jacob Fink Date: Tue, 1 Aug 2023 08:46:02 -0400 Subject: [PATCH] [PM-2713] rename state methods --- src/App/Pages/Accounts/LockPageViewModel.cs | 6 ++-- .../SettingsPage/SettingsPageViewModel.cs | 4 +-- src/Core/Abstractions/IStateService.cs | 12 ++++---- src/Core/Services/CryptoService.cs | 28 +++++++++---------- src/Core/Services/StateService.cs | 20 ++++++------- src/Core/Services/VaultTimeoutService.cs | 4 +-- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/App/Pages/Accounts/LockPageViewModel.cs b/src/App/Pages/Accounts/LockPageViewModel.cs index 775ab4cc0..b242e7fdb 100644 --- a/src/App/Pages/Accounts/LockPageViewModel.cs +++ b/src/App/Pages/Accounts/LockPageViewModel.cs @@ -163,7 +163,7 @@ namespace Bit.App.Pages { _pinStatus = await _vaultTimeoutService.GetPinLockTypeAsync(); - var ephemeralPinSet = await _stateService.GetUserKeyPinEphemeralAsync() + var ephemeralPinSet = await _stateService.GetPinKeyEncryptedUserKeyEphemeralAsync() ?? await _stateService.GetPinProtectedKeyAsync(); PinEnabled = (_pinStatus == PinLockType.Transient && ephemeralPinSet != null) || _pinStatus == PinLockType.Persistent; @@ -259,13 +259,13 @@ namespace Bit.App.Pages EncString oldPinProtected = null; if (_pinStatus == PinLockType.Persistent) { - userKeyPin = await _stateService.GetUserKeyPinAsync(); + userKeyPin = await _stateService.GetPinKeyEncryptedUserKeyAsync(); var oldEncryptedKey = await _stateService.GetPinProtectedAsync(); oldPinProtected = oldEncryptedKey != null ? new EncString(oldEncryptedKey) : null; } else if (_pinStatus == PinLockType.Transient) { - userKeyPin = await _stateService.GetUserKeyPinEphemeralAsync(); + userKeyPin = await _stateService.GetPinKeyEncryptedUserKeyEphemeralAsync(); oldPinProtected = await _stateService.GetPinProtectedKeyAsync(); } diff --git a/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs b/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs index 10339992d..46ce7a52e 100644 --- a/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs +++ b/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs @@ -446,11 +446,11 @@ namespace Bit.App.Pages if (masterPassOnRestart) { - await _stateService.SetUserKeyPinEphemeralAsync(protectedPinKey); + await _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(protectedPinKey); } else { - await _stateService.SetUserKeyPinAsync(protectedPinKey); + await _stateService.SetPinKeyEncryptedUserKeyAsync(protectedPinKey); } } else diff --git a/src/Core/Abstractions/IStateService.cs b/src/Core/Abstractions/IStateService.cs index 714c7345b..2f9c11be5 100644 --- a/src/Core/Abstractions/IStateService.cs +++ b/src/Core/Abstractions/IStateService.cs @@ -17,8 +17,8 @@ namespace Bit.Core.Abstractions Task SetUserKeyAsync(UserKey value, string userId = null); Task GetMasterKeyAsync(string userId = null); Task SetMasterKeyAsync(MasterKey value, string userId = null); - Task GetUserKeyMasterKeyAsync(string userId = null); - Task SetUserKeyMasterKeyAsync(string value, string userId = null); + Task GetMasterKeyEncryptedUserKeyAsync(string userId = null); + Task SetMasterKeyEncryptedUserKeyAsync(string value, string userId = null); Task GetActiveUserIdAsync(); Task GetActiveUserEmailAsync(); Task GetActiveUserCustomDataAsync(Func dataMapper); @@ -44,10 +44,10 @@ namespace Bit.Core.Abstractions Task CanAccessPremiumAsync(string userId = null); Task GetProtectedPinAsync(string userId = null); Task SetPersonalPremiumAsync(bool value, string userId = null); - Task GetUserKeyPinAsync(string userId = null); - Task SetUserKeyPinAsync(EncString value, string userId = null); - Task GetUserKeyPinEphemeralAsync(string userId = null); - Task SetUserKeyPinEphemeralAsync(EncString value, string userId = null); + Task GetPinKeyEncryptedUserKeyAsync(string userId = null); + Task SetPinKeyEncryptedUserKeyAsync(EncString value, string userId = null); + Task GetPinKeyEncryptedUserKeyEphemeralAsync(string userId = null); + Task SetPinKeyEncryptedUserKeyEphemeralAsync(EncString value, string userId = null); Task SetProtectedPinAsync(string value, string userId = null); [Obsolete("Use GetUserKeyPinAsync instead, left for migration purposes")] Task GetPinProtectedAsync(string userId = null); diff --git a/src/Core/Services/CryptoService.cs b/src/Core/Services/CryptoService.cs index d0d2ab52b..78fd431b2 100644 --- a/src/Core/Services/CryptoService.cs +++ b/src/Core/Services/CryptoService.cs @@ -60,8 +60,8 @@ namespace Bit.Core.Services } else { - await _stateService.SetUserKeyPinAsync(null, userId); - await _stateService.SetUserKeyPinEphemeralAsync(null, userId); + await _stateService.SetPinKeyEncryptedUserKeyAsync(null, userId); + await _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(null, userId); } } @@ -90,7 +90,7 @@ namespace Bit.Core.Services public async Task HasEncryptedUserKeyAsync(string userId = null) { - return await _stateService.GetUserKeyMasterKeyAsync(userId) != null; + return await _stateService.GetMasterKeyEncryptedUserKeyAsync(userId) != null; } public async Task MakeUserKeyAsync() @@ -105,7 +105,7 @@ namespace Bit.Core.Services public Task SetMasterKeyEncryptedUserKeyAsync(string value, string userId = null) { - return _stateService.SetUserKeyMasterKeyAsync(value, userId); + return _stateService.SetMasterKeyEncryptedUserKeyAsync(value, userId); } public Task SetMasterKeyAsync(MasterKey masterKey, string userId = null) @@ -154,7 +154,7 @@ namespace Bit.Core.Services if (encUserKey == null) { - var userKeyMasterKey = await _stateService.GetUserKeyMasterKeyAsync(userId); + var userKeyMasterKey = await _stateService.GetMasterKeyEncryptedUserKeyAsync(userId); if (userKeyMasterKey == null) { throw new Exception("No encrypted user key found"); @@ -429,16 +429,16 @@ namespace Bit.Core.Services public Task ClearPinKeysAsync(string userId = null) { return Task.WhenAll( - _stateService.SetUserKeyPinAsync(null, userId), - _stateService.SetUserKeyPinEphemeralAsync(null, userId), + _stateService.SetPinKeyEncryptedUserKeyAsync(null, userId), + _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(null, userId), _stateService.SetProtectedPinAsync(null, userId), ClearDeprecatedPinKeysAsync(userId)); } public async Task DecryptUserKeyWithPinAsync(string pin, string salt, KdfConfig kdfConfig, EncString pinProtectedUserKey = null) { - pinProtectedUserKey ??= await _stateService.GetUserKeyPinAsync(); - pinProtectedUserKey ??= await _stateService.GetUserKeyPinEphemeralAsync(); + pinProtectedUserKey ??= await _stateService.GetPinKeyEncryptedUserKeyAsync(); + pinProtectedUserKey ??= await _stateService.GetPinKeyEncryptedUserKeyEphemeralAsync(); if (pinProtectedUserKey == null) { throw new Exception("No PIN protected user key found."); @@ -683,12 +683,12 @@ namespace Bit.Core.Services ); var encPin = await EncryptAsync(userKey.Key, pinKey); - if (await _stateService.GetUserKeyPinAsync(userId) != null) + if (await _stateService.GetPinKeyEncryptedUserKeyAsync(userId) != null) { - await _stateService.SetUserKeyPinAsync(encPin, userId); + await _stateService.SetPinKeyEncryptedUserKeyAsync(encPin, userId); return; } - await _stateService.SetUserKeyPinEphemeralAsync(encPin, userId); + await _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(encPin, userId); } private async Task AesEncryptAsync(byte[] data, SymmetricCryptoKey key) @@ -964,12 +964,12 @@ namespace Bit.Core.Services if (masterPasswordOnRestart) { await _stateService.SetPinProtectedKeyAsync(null); - await _stateService.SetUserKeyPinEphemeralAsync(pinProtectedKey); + await _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(pinProtectedKey); } else { await _stateService.SetPinProtectedAsync(null); - await _stateService.SetUserKeyPinAsync(pinProtectedKey); + await _stateService.SetPinKeyEncryptedUserKeyAsync(pinProtectedKey); // We previously only set the protected pin if MP on Restart was enabled // now we set it regardless diff --git a/src/Core/Services/StateService.cs b/src/Core/Services/StateService.cs index 163f29d2a..2caa36144 100644 --- a/src/Core/Services/StateService.cs +++ b/src/Core/Services/StateService.cs @@ -334,12 +334,12 @@ namespace Bit.Core.Services await SaveAccountAsync(account, reconciledOptions); } - public async Task GetUserKeyMasterKeyAsync(string userId = null) + public async Task GetMasterKeyEncryptedUserKeyAsync(string userId = null) { return await _storageMediatorService.GetAsync(Constants.UserKeyKey(userId), false); } - public async Task SetUserKeyMasterKeyAsync(string value, string userId = null) + public async Task SetMasterKeyEncryptedUserKeyAsync(string value, string userId = null) { await _storageMediatorService.SaveAsync(Constants.UserKeyKey(userId), value, false); } @@ -395,25 +395,25 @@ namespace Bit.Core.Services await SetValueAsync(Constants.ProtectedPinKey(reconciledOptions.UserId), value, reconciledOptions); } - public async Task GetUserKeyPinAsync(string userId = null) + public async Task GetPinKeyEncryptedUserKeyAsync(string userId = null) { var key = await _storageMediatorService.GetAsync(Constants.UserKeyPinKey(userId), false); return key != null ? new EncString(key) : null; } - public async Task SetUserKeyPinAsync(EncString value, string userId = null) + public async Task SetPinKeyEncryptedUserKeyAsync(EncString value, string userId = null) { await _storageMediatorService.SaveAsync(Constants.UserKeyPinKey(userId), value?.EncryptedString, false); } - public async Task GetUserKeyPinEphemeralAsync(string userId = null) + public async Task GetPinKeyEncryptedUserKeyEphemeralAsync(string userId = null) { return (await GetAccountAsync( ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultInMemoryOptionsAsync()) ))?.VolatileData?.UserKeyPinEphemeral; } - public async Task SetUserKeyPinEphemeralAsync(EncString value, string userId = null) + public async Task SetPinKeyEncryptedUserKeyEphemeralAsync(EncString value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultInMemoryOptionsAsync()); @@ -422,7 +422,7 @@ namespace Bit.Core.Services await SaveAccountAsync(account, reconciledOptions); } - [Obsolete("Use GetUserKeyPinAsync instead, left for migration purposes")] + [Obsolete("Use GetPinKeyEncryptedUserKeyAsync instead, left for migration purposes")] public async Task GetPinProtectedAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, @@ -430,7 +430,7 @@ namespace Bit.Core.Services return await GetValueAsync(Constants.PinProtectedKey(reconciledOptions.UserId), reconciledOptions); } - [Obsolete("Use SetUserKeyPinAsync instead")] + [Obsolete("Use SetPinKeyEncryptedUserKeyAsync instead")] public async Task SetPinProtectedAsync(string value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, @@ -438,7 +438,7 @@ namespace Bit.Core.Services await SetValueAsync(Constants.PinProtectedKey(reconciledOptions.UserId), value, reconciledOptions); } - [Obsolete("Use GetUserKeyPinEphemeralAsync instead, left for migration purposes")] + [Obsolete("Use GetPinKeyEncryptedUserKeyEphemeralAsync instead, left for migration purposes")] public async Task GetPinProtectedKeyAsync(string userId = null) { return (await GetAccountAsync( @@ -446,7 +446,7 @@ namespace Bit.Core.Services ))?.VolatileData?.PinProtectedKey; } - [Obsolete("Use SetUserKeyPinEphemeralAsync instead")] + [Obsolete("Use SetPinKeyEncryptedUserKeyEphemeralAsync instead")] public async Task SetPinProtectedKeyAsync(EncString value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, diff --git a/src/Core/Services/VaultTimeoutService.cs b/src/Core/Services/VaultTimeoutService.cs index 28a46f7f7..28639aeea 100644 --- a/src/Core/Services/VaultTimeoutService.cs +++ b/src/Core/Services/VaultTimeoutService.cs @@ -171,7 +171,7 @@ namespace Bit.Core.Services if (await _keyConnectorService.GetUsesKeyConnector()) { var pinStatus = await GetPinLockTypeAsync(userId); - var ephemeralPinSet = await _stateService.GetUserKeyPinEphemeralAsync() + var ephemeralPinSet = await _stateService.GetPinKeyEncryptedUserKeyEphemeralAsync() ?? await _stateService.GetPinProtectedKeyAsync(); var pinEnabled = (pinStatus == PinLockType.Transient && ephemeralPinSet != null) || pinStatus == PinLockType.Persistent; @@ -230,7 +230,7 @@ namespace Bit.Core.Services // we can't depend on only the protected pin being set because old // versions only used it for MP on Restart var isPinEnabled = await _stateService.GetProtectedPinAsync(userId) != null; - var hasUserKeyPin = await _stateService.GetUserKeyPinAsync(userId) != null; + var hasUserKeyPin = await _stateService.GetPinKeyEncryptedUserKeyAsync(userId) != null; var hasOldUserKeyPin = await _stateService.GetPinProtectedAsync(userId) != null; if (hasUserKeyPin || hasOldUserKeyPin)