1
0
mirror of https://github.com/bitwarden/mobile synced 2024-12-29 10:13:48 +01:00

catch decrypt migrate exceptions

This commit is contained in:
Kyle Spearrin 2017-06-12 10:45:57 -04:00
parent ee759af078
commit 47ca483459

View File

@ -1,4 +1,3 @@
using System.IO;
using Java.Security; using Java.Security;
using Javax.Crypto; using Javax.Crypto;
using Android.OS; using Android.OS;
@ -189,8 +188,14 @@ namespace Bit.Android.Services
{ {
try try
{ {
var encKey = _settings.GetValueOrDefault<string>(v1 ? AesKeyV1 : AesKey); var aesKey = v1 ? AesKeyV1 : AesKey;
if(encKey == null) if(!_settings.Contains(aesKey))
{
return null;
}
var encKey = _settings.GetValueOrDefault<string>(aesKey);
if(string.IsNullOrWhiteSpace(encKey))
{ {
return null; return null;
} }
@ -220,7 +225,10 @@ namespace Bit.Android.Services
Console.WriteLine("Cannot get AesKey."); Console.WriteLine("Cannot get AesKey.");
_keyStore.DeleteEntry(KeyAlias); _keyStore.DeleteEntry(KeyAlias);
_settings.Remove(AesKey); _settings.Remove(AesKey);
if(!v1)
{
Utilities.SendCrashEmail(e); Utilities.SendCrashEmail(e);
}
return null; return null;
} }
} }
@ -293,12 +301,21 @@ namespace Bit.Android.Services
{ {
var aesKeyV1 = GetAesKey(true); var aesKeyV1 = GetAesKey(true);
if(aesKeyV1 != null) if(aesKeyV1 != null)
{
try
{ {
var cs = _settings.GetValueOrDefault<string>(formattedKeyV1); var cs = _settings.GetValueOrDefault<string>(formattedKeyV1);
var value = App.Utilities.Crypto.AesCbcDecrypt(new App.Models.CipherString(cs), aesKeyV1); var value = App.Utilities.Crypto.AesCbcDecrypt(new App.Models.CipherString(cs), aesKeyV1);
Store(key, value); Store(key, value);
return value; return value;
} }
catch
{
Console.WriteLine("Failed to decrypt v1 from secure storage.");
_settings.Remove(formattedKeyV1);
return null;
}
}
} }
return null; return null;