diff --git a/src/App/Abstractions/Services/IAuthService.cs b/src/App/Abstractions/Services/IAuthService.cs index 615c8c4e7..ce267daa5 100644 --- a/src/App/Abstractions/Services/IAuthService.cs +++ b/src/App/Abstractions/Services/IAuthService.cs @@ -9,6 +9,8 @@ namespace Bit.App.Abstractions bool IsAuthenticatedTwoFactor { get; } string Token { get; set; } string UserId { get; set; } + string PreviousUserId { get; } + bool UserIdChanged { get; } string Email { get; set; } string PIN { get; set; } diff --git a/src/App/Abstractions/Services/ICryptoService.cs b/src/App/Abstractions/Services/ICryptoService.cs index efa657b1d..566fea572 100644 --- a/src/App/Abstractions/Services/ICryptoService.cs +++ b/src/App/Abstractions/Services/ICryptoService.cs @@ -6,6 +6,8 @@ namespace Bit.App.Abstractions { string Base64Key { get; } byte[] Key { get; set; } + byte[] PreviousKey { get; } + bool KeyChanged { get; } string Decrypt(CipherString encyptedValue); CipherString Encrypt(string plaintextValue); diff --git a/src/App/Pages/Tools/ToolsExtensionPage.cs b/src/App/Pages/Tools/ToolsExtensionPage.cs index 09a840f37..bc284790c 100644 --- a/src/App/Pages/Tools/ToolsExtensionPage.cs +++ b/src/App/Pages/Tools/ToolsExtensionPage.cs @@ -161,7 +161,11 @@ namespace Bit.App.Pages var activatedButton = new Button { 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, HorizontalOptions = LayoutOptions.Fill, Style = (Style)Application.Current.Resources["btn-primary"] diff --git a/src/App/Services/AuthService.cs b/src/App/Services/AuthService.cs index 1c28b4ed2..ef22a2c98 100644 --- a/src/App/Services/AuthService.cs +++ b/src/App/Services/AuthService.cs @@ -12,6 +12,7 @@ namespace Bit.App.Services private const string TokenKey = "token"; private const string EmailKey = "email"; private const string UserIdKey = "userId"; + private const string PreviousUserIdKey = "previousUserId"; private const string PinKey = "pin"; private readonly ISecureStorageService _secureStorage; @@ -22,6 +23,7 @@ namespace Bit.App.Services private string _token; private string _email; private string _userId; + private string _previousUserId; private string _pin; public AuthService( @@ -90,6 +92,7 @@ namespace Bit.App.Services } else { + PreviousUserId = _userId; _settings.Remove(UserIdKey); } @@ -97,6 +100,30 @@ namespace Bit.App.Services } } + public string PreviousUserId + { + get + { + if(_previousUserId != null) + { + return _previousUserId; + } + + _previousUserId = _settings.GetValueOrDefault(PreviousUserIdKey); + return _previousUserId; + } + private set + { + if(value != null) + { + _settings.AddOrUpdateValue(PreviousUserIdKey, value); + _previousUserId = value; + } + } + } + + public bool UserIdChanged => PreviousUserId != UserId; + public string Email { get diff --git a/src/App/Services/CryptoService.cs b/src/App/Services/CryptoService.cs index 5bf814581..ee4860934 100644 --- a/src/App/Services/CryptoService.cs +++ b/src/App/Services/CryptoService.cs @@ -4,18 +4,21 @@ using System.Text; using Bit.App.Abstractions; using Bit.App.Models; using PCLCrypto; +using System.Linq; namespace Bit.App.Services { public class CryptoService : ICryptoService { private const string KeyKey = "key"; + private const string PreviousKeyKey = "previousKey"; private const int InitializationVectorSize = 16; private readonly Random _random = new Random(); private readonly ISecureStorageService _secureStorage; private readonly IKeyDerivationService _keyDerivationService; private byte[] _key; + private byte[] _previousKey; public CryptoService( ISecureStorageService secureStorage, @@ -44,6 +47,7 @@ namespace Bit.App.Services } else { + PreviousKey = _key; _secureStorage.Delete(KeyKey); _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) { if(Key == null)