mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 23:31:52 +03:00
store previous key and userid so we can determine if stored crypto is usable before a sync
This commit is contained in:
parent
2d0bfe1a92
commit
d96a94b478
5 changed files with 63 additions and 1 deletions
|
@ -9,6 +9,8 @@ namespace Bit.App.Abstractions
|
||||||
bool IsAuthenticatedTwoFactor { get; }
|
bool IsAuthenticatedTwoFactor { get; }
|
||||||
string Token { get; set; }
|
string Token { get; set; }
|
||||||
string UserId { get; set; }
|
string UserId { get; set; }
|
||||||
|
string PreviousUserId { get; }
|
||||||
|
bool UserIdChanged { get; }
|
||||||
string Email { get; set; }
|
string Email { get; set; }
|
||||||
string PIN { get; set; }
|
string PIN { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ namespace Bit.App.Abstractions
|
||||||
{
|
{
|
||||||
string Base64Key { get; }
|
string Base64Key { get; }
|
||||||
byte[] Key { get; set; }
|
byte[] Key { get; set; }
|
||||||
|
byte[] PreviousKey { get; }
|
||||||
|
bool KeyChanged { get; }
|
||||||
|
|
||||||
string Decrypt(CipherString encyptedValue);
|
string Decrypt(CipherString encyptedValue);
|
||||||
CipherString Encrypt(string plaintextValue);
|
CipherString Encrypt(string plaintextValue);
|
||||||
|
|
|
@ -161,7 +161,11 @@ namespace Bit.App.Pages
|
||||||
var activatedButton = new Button
|
var activatedButton = new Button
|
||||||
{
|
{
|
||||||
Text = "See Supported Apps",
|
Text = "See Supported Apps",
|
||||||
Command = new Command(() => Device.OpenUri(new Uri("https://bitwarden.com"))),
|
Command = new Command(() =>
|
||||||
|
{
|
||||||
|
_googleAnalyticsService.TrackAppEvent("SeeSupportedApps");
|
||||||
|
Device.OpenUri(new Uri("https://bitwarden.com"));
|
||||||
|
}),
|
||||||
VerticalOptions = LayoutOptions.End,
|
VerticalOptions = LayoutOptions.End,
|
||||||
HorizontalOptions = LayoutOptions.Fill,
|
HorizontalOptions = LayoutOptions.Fill,
|
||||||
Style = (Style)Application.Current.Resources["btn-primary"]
|
Style = (Style)Application.Current.Resources["btn-primary"]
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace Bit.App.Services
|
||||||
private const string TokenKey = "token";
|
private const string TokenKey = "token";
|
||||||
private const string EmailKey = "email";
|
private const string EmailKey = "email";
|
||||||
private const string UserIdKey = "userId";
|
private const string UserIdKey = "userId";
|
||||||
|
private const string PreviousUserIdKey = "previousUserId";
|
||||||
private const string PinKey = "pin";
|
private const string PinKey = "pin";
|
||||||
|
|
||||||
private readonly ISecureStorageService _secureStorage;
|
private readonly ISecureStorageService _secureStorage;
|
||||||
|
@ -22,6 +23,7 @@ namespace Bit.App.Services
|
||||||
private string _token;
|
private string _token;
|
||||||
private string _email;
|
private string _email;
|
||||||
private string _userId;
|
private string _userId;
|
||||||
|
private string _previousUserId;
|
||||||
private string _pin;
|
private string _pin;
|
||||||
|
|
||||||
public AuthService(
|
public AuthService(
|
||||||
|
@ -90,6 +92,7 @@ namespace Bit.App.Services
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
PreviousUserId = _userId;
|
||||||
_settings.Remove(UserIdKey);
|
_settings.Remove(UserIdKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +100,30 @@ namespace Bit.App.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string PreviousUserId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(_previousUserId != null)
|
||||||
|
{
|
||||||
|
return _previousUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
_previousUserId = _settings.GetValueOrDefault<string>(PreviousUserIdKey);
|
||||||
|
return _previousUserId;
|
||||||
|
}
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
if(value != null)
|
||||||
|
{
|
||||||
|
_settings.AddOrUpdateValue(PreviousUserIdKey, value);
|
||||||
|
_previousUserId = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UserIdChanged => PreviousUserId != UserId;
|
||||||
|
|
||||||
public string Email
|
public string Email
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -4,18 +4,21 @@ using System.Text;
|
||||||
using Bit.App.Abstractions;
|
using Bit.App.Abstractions;
|
||||||
using Bit.App.Models;
|
using Bit.App.Models;
|
||||||
using PCLCrypto;
|
using PCLCrypto;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bit.App.Services
|
namespace Bit.App.Services
|
||||||
{
|
{
|
||||||
public class CryptoService : ICryptoService
|
public class CryptoService : ICryptoService
|
||||||
{
|
{
|
||||||
private const string KeyKey = "key";
|
private const string KeyKey = "key";
|
||||||
|
private const string PreviousKeyKey = "previousKey";
|
||||||
private const int InitializationVectorSize = 16;
|
private const int InitializationVectorSize = 16;
|
||||||
|
|
||||||
private readonly Random _random = new Random();
|
private readonly Random _random = new Random();
|
||||||
private readonly ISecureStorageService _secureStorage;
|
private readonly ISecureStorageService _secureStorage;
|
||||||
private readonly IKeyDerivationService _keyDerivationService;
|
private readonly IKeyDerivationService _keyDerivationService;
|
||||||
private byte[] _key;
|
private byte[] _key;
|
||||||
|
private byte[] _previousKey;
|
||||||
|
|
||||||
public CryptoService(
|
public CryptoService(
|
||||||
ISecureStorageService secureStorage,
|
ISecureStorageService secureStorage,
|
||||||
|
@ -44,6 +47,7 @@ namespace Bit.App.Services
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
PreviousKey = _key;
|
||||||
_secureStorage.Delete(KeyKey);
|
_secureStorage.Delete(KeyKey);
|
||||||
_key = null;
|
_key = null;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +67,29 @@ namespace Bit.App.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] PreviousKey
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(_previousKey == null)
|
||||||
|
{
|
||||||
|
_previousKey = _secureStorage.Retrieve(PreviousKeyKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _previousKey;
|
||||||
|
}
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
if(value != null)
|
||||||
|
{
|
||||||
|
_secureStorage.Store(PreviousKeyKey, value);
|
||||||
|
_previousKey = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool KeyChanged => !PreviousKey?.SequenceEqual(Key) ?? Key == null ? false : true;
|
||||||
|
|
||||||
public CipherString Encrypt(string plaintextValue)
|
public CipherString Encrypt(string plaintextValue)
|
||||||
{
|
{
|
||||||
if(Key == null)
|
if(Key == null)
|
||||||
|
|
Loading…
Reference in a new issue