mirror of
https://github.com/bitwarden/mobile
synced 2025-12-10 13:23:39 +00:00
[PM-2713] rename state methods
This commit is contained in:
@@ -163,7 +163,7 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
_pinStatus = await _vaultTimeoutService.GetPinLockTypeAsync();
|
_pinStatus = await _vaultTimeoutService.GetPinLockTypeAsync();
|
||||||
|
|
||||||
var ephemeralPinSet = await _stateService.GetUserKeyPinEphemeralAsync()
|
var ephemeralPinSet = await _stateService.GetPinKeyEncryptedUserKeyEphemeralAsync()
|
||||||
?? await _stateService.GetPinProtectedKeyAsync();
|
?? await _stateService.GetPinProtectedKeyAsync();
|
||||||
PinEnabled = (_pinStatus == PinLockType.Transient && ephemeralPinSet != null) ||
|
PinEnabled = (_pinStatus == PinLockType.Transient && ephemeralPinSet != null) ||
|
||||||
_pinStatus == PinLockType.Persistent;
|
_pinStatus == PinLockType.Persistent;
|
||||||
@@ -259,13 +259,13 @@ namespace Bit.App.Pages
|
|||||||
EncString oldPinProtected = null;
|
EncString oldPinProtected = null;
|
||||||
if (_pinStatus == PinLockType.Persistent)
|
if (_pinStatus == PinLockType.Persistent)
|
||||||
{
|
{
|
||||||
userKeyPin = await _stateService.GetUserKeyPinAsync();
|
userKeyPin = await _stateService.GetPinKeyEncryptedUserKeyAsync();
|
||||||
var oldEncryptedKey = await _stateService.GetPinProtectedAsync();
|
var oldEncryptedKey = await _stateService.GetPinProtectedAsync();
|
||||||
oldPinProtected = oldEncryptedKey != null ? new EncString(oldEncryptedKey) : null;
|
oldPinProtected = oldEncryptedKey != null ? new EncString(oldEncryptedKey) : null;
|
||||||
}
|
}
|
||||||
else if (_pinStatus == PinLockType.Transient)
|
else if (_pinStatus == PinLockType.Transient)
|
||||||
{
|
{
|
||||||
userKeyPin = await _stateService.GetUserKeyPinEphemeralAsync();
|
userKeyPin = await _stateService.GetPinKeyEncryptedUserKeyEphemeralAsync();
|
||||||
oldPinProtected = await _stateService.GetPinProtectedKeyAsync();
|
oldPinProtected = await _stateService.GetPinProtectedKeyAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -446,11 +446,11 @@ namespace Bit.App.Pages
|
|||||||
|
|
||||||
if (masterPassOnRestart)
|
if (masterPassOnRestart)
|
||||||
{
|
{
|
||||||
await _stateService.SetUserKeyPinEphemeralAsync(protectedPinKey);
|
await _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(protectedPinKey);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _stateService.SetUserKeyPinAsync(protectedPinKey);
|
await _stateService.SetPinKeyEncryptedUserKeyAsync(protectedPinKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ namespace Bit.Core.Abstractions
|
|||||||
Task SetUserKeyAsync(UserKey value, string userId = null);
|
Task SetUserKeyAsync(UserKey value, string userId = null);
|
||||||
Task<MasterKey> GetMasterKeyAsync(string userId = null);
|
Task<MasterKey> GetMasterKeyAsync(string userId = null);
|
||||||
Task SetMasterKeyAsync(MasterKey value, string userId = null);
|
Task SetMasterKeyAsync(MasterKey value, string userId = null);
|
||||||
Task<string> GetUserKeyMasterKeyAsync(string userId = null);
|
Task<string> GetMasterKeyEncryptedUserKeyAsync(string userId = null);
|
||||||
Task SetUserKeyMasterKeyAsync(string value, string userId = null);
|
Task SetMasterKeyEncryptedUserKeyAsync(string value, string userId = null);
|
||||||
Task<string> GetActiveUserIdAsync();
|
Task<string> GetActiveUserIdAsync();
|
||||||
Task<string> GetActiveUserEmailAsync();
|
Task<string> GetActiveUserEmailAsync();
|
||||||
Task<T> GetActiveUserCustomDataAsync<T>(Func<Account, T> dataMapper);
|
Task<T> GetActiveUserCustomDataAsync<T>(Func<Account, T> dataMapper);
|
||||||
@@ -44,10 +44,10 @@ namespace Bit.Core.Abstractions
|
|||||||
Task<bool> CanAccessPremiumAsync(string userId = null);
|
Task<bool> CanAccessPremiumAsync(string userId = null);
|
||||||
Task<string> GetProtectedPinAsync(string userId = null);
|
Task<string> GetProtectedPinAsync(string userId = null);
|
||||||
Task SetPersonalPremiumAsync(bool value, string userId = null);
|
Task SetPersonalPremiumAsync(bool value, string userId = null);
|
||||||
Task<EncString> GetUserKeyPinAsync(string userId = null);
|
Task<EncString> GetPinKeyEncryptedUserKeyAsync(string userId = null);
|
||||||
Task SetUserKeyPinAsync(EncString value, string userId = null);
|
Task SetPinKeyEncryptedUserKeyAsync(EncString value, string userId = null);
|
||||||
Task<EncString> GetUserKeyPinEphemeralAsync(string userId = null);
|
Task<EncString> GetPinKeyEncryptedUserKeyEphemeralAsync(string userId = null);
|
||||||
Task SetUserKeyPinEphemeralAsync(EncString value, string userId = null);
|
Task SetPinKeyEncryptedUserKeyEphemeralAsync(EncString value, string userId = null);
|
||||||
Task SetProtectedPinAsync(string value, string userId = null);
|
Task SetProtectedPinAsync(string value, string userId = null);
|
||||||
[Obsolete("Use GetUserKeyPinAsync instead, left for migration purposes")]
|
[Obsolete("Use GetUserKeyPinAsync instead, left for migration purposes")]
|
||||||
Task<string> GetPinProtectedAsync(string userId = null);
|
Task<string> GetPinProtectedAsync(string userId = null);
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _stateService.SetUserKeyPinAsync(null, userId);
|
await _stateService.SetPinKeyEncryptedUserKeyAsync(null, userId);
|
||||||
await _stateService.SetUserKeyPinEphemeralAsync(null, userId);
|
await _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(null, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
public async Task<bool> HasEncryptedUserKeyAsync(string userId = null)
|
public async Task<bool> HasEncryptedUserKeyAsync(string userId = null)
|
||||||
{
|
{
|
||||||
return await _stateService.GetUserKeyMasterKeyAsync(userId) != null;
|
return await _stateService.GetMasterKeyEncryptedUserKeyAsync(userId) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserKey> MakeUserKeyAsync()
|
public async Task<UserKey> MakeUserKeyAsync()
|
||||||
@@ -105,7 +105,7 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
public Task SetMasterKeyEncryptedUserKeyAsync(string value, string userId = null)
|
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)
|
public Task SetMasterKeyAsync(MasterKey masterKey, string userId = null)
|
||||||
@@ -154,7 +154,7 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
if (encUserKey == null)
|
if (encUserKey == null)
|
||||||
{
|
{
|
||||||
var userKeyMasterKey = await _stateService.GetUserKeyMasterKeyAsync(userId);
|
var userKeyMasterKey = await _stateService.GetMasterKeyEncryptedUserKeyAsync(userId);
|
||||||
if (userKeyMasterKey == null)
|
if (userKeyMasterKey == null)
|
||||||
{
|
{
|
||||||
throw new Exception("No encrypted user key found");
|
throw new Exception("No encrypted user key found");
|
||||||
@@ -429,16 +429,16 @@ namespace Bit.Core.Services
|
|||||||
public Task ClearPinKeysAsync(string userId = null)
|
public Task ClearPinKeysAsync(string userId = null)
|
||||||
{
|
{
|
||||||
return Task.WhenAll(
|
return Task.WhenAll(
|
||||||
_stateService.SetUserKeyPinAsync(null, userId),
|
_stateService.SetPinKeyEncryptedUserKeyAsync(null, userId),
|
||||||
_stateService.SetUserKeyPinEphemeralAsync(null, userId),
|
_stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(null, userId),
|
||||||
_stateService.SetProtectedPinAsync(null, userId),
|
_stateService.SetProtectedPinAsync(null, userId),
|
||||||
ClearDeprecatedPinKeysAsync(userId));
|
ClearDeprecatedPinKeysAsync(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserKey> DecryptUserKeyWithPinAsync(string pin, string salt, KdfConfig kdfConfig, EncString pinProtectedUserKey = null)
|
public async Task<UserKey> DecryptUserKeyWithPinAsync(string pin, string salt, KdfConfig kdfConfig, EncString pinProtectedUserKey = null)
|
||||||
{
|
{
|
||||||
pinProtectedUserKey ??= await _stateService.GetUserKeyPinAsync();
|
pinProtectedUserKey ??= await _stateService.GetPinKeyEncryptedUserKeyAsync();
|
||||||
pinProtectedUserKey ??= await _stateService.GetUserKeyPinEphemeralAsync();
|
pinProtectedUserKey ??= await _stateService.GetPinKeyEncryptedUserKeyEphemeralAsync();
|
||||||
if (pinProtectedUserKey == null)
|
if (pinProtectedUserKey == null)
|
||||||
{
|
{
|
||||||
throw new Exception("No PIN protected user key found.");
|
throw new Exception("No PIN protected user key found.");
|
||||||
@@ -683,12 +683,12 @@ namespace Bit.Core.Services
|
|||||||
);
|
);
|
||||||
var encPin = await EncryptAsync(userKey.Key, pinKey);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
await _stateService.SetUserKeyPinEphemeralAsync(encPin, userId);
|
await _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(encPin, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<EncryptedObject> AesEncryptAsync(byte[] data, SymmetricCryptoKey key)
|
private async Task<EncryptedObject> AesEncryptAsync(byte[] data, SymmetricCryptoKey key)
|
||||||
@@ -964,12 +964,12 @@ namespace Bit.Core.Services
|
|||||||
if (masterPasswordOnRestart)
|
if (masterPasswordOnRestart)
|
||||||
{
|
{
|
||||||
await _stateService.SetPinProtectedKeyAsync(null);
|
await _stateService.SetPinProtectedKeyAsync(null);
|
||||||
await _stateService.SetUserKeyPinEphemeralAsync(pinProtectedKey);
|
await _stateService.SetPinKeyEncryptedUserKeyEphemeralAsync(pinProtectedKey);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _stateService.SetPinProtectedAsync(null);
|
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
|
// We previously only set the protected pin if MP on Restart was enabled
|
||||||
// now we set it regardless
|
// now we set it regardless
|
||||||
|
|||||||
@@ -334,12 +334,12 @@ namespace Bit.Core.Services
|
|||||||
await SaveAccountAsync(account, reconciledOptions);
|
await SaveAccountAsync(account, reconciledOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetUserKeyMasterKeyAsync(string userId = null)
|
public async Task<string> GetMasterKeyEncryptedUserKeyAsync(string userId = null)
|
||||||
{
|
{
|
||||||
return await _storageMediatorService.GetAsync<string>(Constants.UserKeyKey(userId), false);
|
return await _storageMediatorService.GetAsync<string>(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);
|
await _storageMediatorService.SaveAsync(Constants.UserKeyKey(userId), value, false);
|
||||||
}
|
}
|
||||||
@@ -395,25 +395,25 @@ namespace Bit.Core.Services
|
|||||||
await SetValueAsync(Constants.ProtectedPinKey(reconciledOptions.UserId), value, reconciledOptions);
|
await SetValueAsync(Constants.ProtectedPinKey(reconciledOptions.UserId), value, reconciledOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<EncString> GetUserKeyPinAsync(string userId = null)
|
public async Task<EncString> GetPinKeyEncryptedUserKeyAsync(string userId = null)
|
||||||
{
|
{
|
||||||
var key = await _storageMediatorService.GetAsync<string>(Constants.UserKeyPinKey(userId), false);
|
var key = await _storageMediatorService.GetAsync<string>(Constants.UserKeyPinKey(userId), false);
|
||||||
return key != null ? new EncString(key) : null;
|
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);
|
await _storageMediatorService.SaveAsync(Constants.UserKeyPinKey(userId), value?.EncryptedString, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<EncString> GetUserKeyPinEphemeralAsync(string userId = null)
|
public async Task<EncString> GetPinKeyEncryptedUserKeyEphemeralAsync(string userId = null)
|
||||||
{
|
{
|
||||||
return (await GetAccountAsync(
|
return (await GetAccountAsync(
|
||||||
ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultInMemoryOptionsAsync())
|
ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultInMemoryOptionsAsync())
|
||||||
))?.VolatileData?.UserKeyPinEphemeral;
|
))?.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 },
|
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
|
||||||
await GetDefaultInMemoryOptionsAsync());
|
await GetDefaultInMemoryOptionsAsync());
|
||||||
@@ -422,7 +422,7 @@ namespace Bit.Core.Services
|
|||||||
await SaveAccountAsync(account, reconciledOptions);
|
await SaveAccountAsync(account, reconciledOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("Use GetUserKeyPinAsync instead, left for migration purposes")]
|
[Obsolete("Use GetPinKeyEncryptedUserKeyAsync instead, left for migration purposes")]
|
||||||
public async Task<string> GetPinProtectedAsync(string userId = null)
|
public async Task<string> GetPinProtectedAsync(string userId = null)
|
||||||
{
|
{
|
||||||
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
|
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
|
||||||
@@ -430,7 +430,7 @@ namespace Bit.Core.Services
|
|||||||
return await GetValueAsync<string>(Constants.PinProtectedKey(reconciledOptions.UserId), reconciledOptions);
|
return await GetValueAsync<string>(Constants.PinProtectedKey(reconciledOptions.UserId), reconciledOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("Use SetUserKeyPinAsync instead")]
|
[Obsolete("Use SetPinKeyEncryptedUserKeyAsync instead")]
|
||||||
public async Task SetPinProtectedAsync(string value, string userId = null)
|
public async Task SetPinProtectedAsync(string value, string userId = null)
|
||||||
{
|
{
|
||||||
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
|
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
|
||||||
@@ -438,7 +438,7 @@ namespace Bit.Core.Services
|
|||||||
await SetValueAsync(Constants.PinProtectedKey(reconciledOptions.UserId), value, reconciledOptions);
|
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<EncString> GetPinProtectedKeyAsync(string userId = null)
|
public async Task<EncString> GetPinProtectedKeyAsync(string userId = null)
|
||||||
{
|
{
|
||||||
return (await GetAccountAsync(
|
return (await GetAccountAsync(
|
||||||
@@ -446,7 +446,7 @@ namespace Bit.Core.Services
|
|||||||
))?.VolatileData?.PinProtectedKey;
|
))?.VolatileData?.PinProtectedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("Use SetUserKeyPinEphemeralAsync instead")]
|
[Obsolete("Use SetPinKeyEncryptedUserKeyEphemeralAsync instead")]
|
||||||
public async Task SetPinProtectedKeyAsync(EncString value, string userId = null)
|
public async Task SetPinProtectedKeyAsync(EncString value, string userId = null)
|
||||||
{
|
{
|
||||||
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
|
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ namespace Bit.Core.Services
|
|||||||
if (await _keyConnectorService.GetUsesKeyConnector())
|
if (await _keyConnectorService.GetUsesKeyConnector())
|
||||||
{
|
{
|
||||||
var pinStatus = await GetPinLockTypeAsync(userId);
|
var pinStatus = await GetPinLockTypeAsync(userId);
|
||||||
var ephemeralPinSet = await _stateService.GetUserKeyPinEphemeralAsync()
|
var ephemeralPinSet = await _stateService.GetPinKeyEncryptedUserKeyEphemeralAsync()
|
||||||
?? await _stateService.GetPinProtectedKeyAsync();
|
?? await _stateService.GetPinProtectedKeyAsync();
|
||||||
var pinEnabled = (pinStatus == PinLockType.Transient && ephemeralPinSet != null) ||
|
var pinEnabled = (pinStatus == PinLockType.Transient && ephemeralPinSet != null) ||
|
||||||
pinStatus == PinLockType.Persistent;
|
pinStatus == PinLockType.Persistent;
|
||||||
@@ -230,7 +230,7 @@ namespace Bit.Core.Services
|
|||||||
// we can't depend on only the protected pin being set because old
|
// we can't depend on only the protected pin being set because old
|
||||||
// versions only used it for MP on Restart
|
// versions only used it for MP on Restart
|
||||||
var isPinEnabled = await _stateService.GetProtectedPinAsync(userId) != null;
|
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;
|
var hasOldUserKeyPin = await _stateService.GetPinProtectedAsync(userId) != null;
|
||||||
|
|
||||||
if (hasUserKeyPin || hasOldUserKeyPin)
|
if (hasUserKeyPin || hasOldUserKeyPin)
|
||||||
|
|||||||
Reference in New Issue
Block a user