manually set validity. no more crash emails

This commit is contained in:
Kyle Spearrin 2017-06-12 11:51:43 -04:00
parent 47ca483459
commit 65d2d45a82
1 changed files with 14 additions and 12 deletions

View File

@ -91,11 +91,11 @@ namespace Bit.Android.Services
{ {
return App.Utilities.Crypto.AesCbcDecrypt(new App.Models.CipherString(cs), aesKey); return App.Utilities.Crypto.AesCbcDecrypt(new App.Models.CipherString(cs), aesKey);
} }
catch(Exception e) catch(Exception)
{ {
Console.WriteLine("Failed to decrypt from secure storage."); Console.WriteLine("Failed to decrypt from secure storage.");
_settings.Remove(formattedKey); _settings.Remove(formattedKey);
Utilities.SendCrashEmail(e); //Utilities.SendCrashEmail(e);
return null; return null;
} }
} }
@ -121,10 +121,10 @@ namespace Bit.Android.Services
var cipherString = App.Utilities.Crypto.AesCbcEncrypt(dataBytes, aesKey); var cipherString = App.Utilities.Crypto.AesCbcEncrypt(dataBytes, aesKey);
_settings.AddOrUpdateValue(formattedKey, cipherString.EncryptedString); _settings.AddOrUpdateValue(formattedKey, cipherString.EncryptedString);
} }
catch(Exception e) catch(Exception)
{ {
Console.WriteLine("Failed to encrypt to secure storage."); Console.WriteLine("Failed to encrypt to secure storage.");
Utilities.SendCrashEmail(e); //Utilities.SendCrashEmail(e);
} }
} }
@ -135,18 +135,18 @@ namespace Bit.Android.Services
return; return;
} }
var end = Calendar.Instance;
end.Add(CalendarField.Year, 99);
if(_oldAndroid) if(_oldAndroid)
{ {
var subject = new X500Principal($"CN={KeyAlias}"); var subject = new X500Principal($"CN={KeyAlias}");
var start = Calendar.Instance;
var end = Calendar.Instance;
end.Add(CalendarField.Year, 30);
var spec = new KeyPairGeneratorSpec.Builder(Application.Context) var spec = new KeyPairGeneratorSpec.Builder(Application.Context)
.SetAlias(KeyAlias) .SetAlias(KeyAlias)
.SetSubject(subject) .SetSubject(subject)
.SetSerialNumber(BigInteger.Ten) .SetSerialNumber(BigInteger.Ten)
.SetStartDate(start.Time) .SetStartDate(new Date(0))
.SetEndDate(end.Time) .SetEndDate(end.Time)
.Build(); .Build();
@ -159,6 +159,8 @@ namespace Bit.Android.Services
var spec = new KeyGenParameterSpec.Builder(KeyAlias, KeyStorePurpose.Decrypt | KeyStorePurpose.Encrypt) var spec = new KeyGenParameterSpec.Builder(KeyAlias, KeyStorePurpose.Decrypt | KeyStorePurpose.Encrypt)
.SetBlockModes(KeyProperties.BlockModeGcm) .SetBlockModes(KeyProperties.BlockModeGcm)
.SetEncryptionPaddings(KeyProperties.EncryptionPaddingNone) .SetEncryptionPaddings(KeyProperties.EncryptionPaddingNone)
.SetKeyValidityStart(new Date(0))
.SetKeyValidityEnd(end.Time)
.Build(); .Build();
var gen = KeyGenerator.GetInstance(KeyProperties.KeyAlgorithmAes, AndroidKeyStore); var gen = KeyGenerator.GetInstance(KeyProperties.KeyAlgorithmAes, AndroidKeyStore);
@ -220,14 +222,14 @@ namespace Bit.Android.Services
return new App.Models.SymmetricCryptoKey(key); return new App.Models.SymmetricCryptoKey(key);
} }
} }
catch(Exception e) catch(Exception)
{ {
Console.WriteLine("Cannot get AesKey."); Console.WriteLine("Cannot get AesKey.");
_keyStore.DeleteEntry(KeyAlias); _keyStore.DeleteEntry(KeyAlias);
_settings.Remove(AesKey); _settings.Remove(AesKey);
if(!v1) if(!v1)
{ {
Utilities.SendCrashEmail(e); //Utilities.SendCrashEmail(e);
} }
return null; return null;
} }
@ -312,10 +314,10 @@ namespace Bit.Android.Services
catch catch
{ {
Console.WriteLine("Failed to decrypt v1 from secure storage."); Console.WriteLine("Failed to decrypt v1 from secure storage.");
_settings.Remove(formattedKeyV1);
return null;
} }
} }
_settings.Remove(formattedKeyV1);
} }
return null; return null;