1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-03 08:39:46 +01:00

KeyGenParameterSpec options added back. cleanup.

This commit is contained in:
Kyle Spearrin 2017-06-07 00:10:31 -04:00
parent 724ae51110
commit 76652f6c6b

View File

@ -11,7 +11,6 @@ using Android.Security.Keystore;
using Android.App; using Android.App;
using Plugin.Settings.Abstractions; using Plugin.Settings.Abstractions;
using Java.Util; using Java.Util;
using Android.Content;
using Javax.Crypto.Spec; using Javax.Crypto.Spec;
namespace Bit.Android.Services namespace Bit.Android.Services
@ -79,12 +78,10 @@ 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
{ {
Console.WriteLine("Failed to decrypt from secure storage."); Console.WriteLine("Failed to decrypt from secure storage.");
_settings.Remove(formattedKey); _settings.Remove(formattedKey);
//throw;
SendEmail(e.Message + "\n\n" + e.StackTrace);
return null; return null;
} }
} }
@ -110,11 +107,9 @@ 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
{ {
Console.WriteLine("Failed to encrypt to secure storage."); Console.WriteLine("Failed to encrypt to secure storage.");
SendEmail(e.Message + "\n\n" + e.StackTrace);
//throw;
} }
} }
@ -146,6 +141,10 @@ namespace Bit.Android.Services
else else
{ {
var spec = new KeyGenParameterSpec.Builder(KeyAlias, KeyStorePurpose.Decrypt | KeyStorePurpose.Encrypt) var spec = new KeyGenParameterSpec.Builder(KeyAlias, KeyStorePurpose.Decrypt | KeyStorePurpose.Encrypt)
.SetCertificateSubject(subject)
.SetCertificateSerialNumber(BigInteger.Ten)
.SetKeyValidityStart(start.Time)
.SetKeyValidityEnd(end.Time)
.SetDigests(KeyProperties.DigestSha1) .SetDigests(KeyProperties.DigestSha1)
.SetEncryptionPaddings(KeyProperties.EncryptionPaddingRsaOaep) .SetEncryptionPaddings(KeyProperties.EncryptionPaddingRsaOaep)
.Build(); .Build();
@ -187,13 +186,11 @@ namespace Bit.Android.Services
var key = RsaDecrypt(encKeyBytes); var key = RsaDecrypt(encKeyBytes);
return new App.Models.SymmetricCryptoKey(key); return new App.Models.SymmetricCryptoKey(key);
} }
catch(Exception e) catch
{ {
Console.WriteLine("Cannot get AesKey."); Console.WriteLine("Cannot get AesKey.");
_keyStore.DeleteEntry(KeyAlias); _keyStore.DeleteEntry(KeyAlias);
_settings.Remove(AesKey); _settings.Remove(AesKey);
//throw;
SendEmail(e.Message + "\n\n" + e.StackTrace);
return null; return null;
} }
} }
@ -240,17 +237,5 @@ namespace Bit.Android.Services
_oldKeyStorageService.Delete(key); _oldKeyStorageService.Delete(key);
} }
} }
private void SendEmail(string text)
{
var emailIntent = new Intent(Intent.ActionSend);
emailIntent.SetType("plain/text");
emailIntent.PutExtra(Intent.ExtraEmail, new String[] { "hello@bitwarden.com" });
emailIntent.PutExtra(Intent.ExtraSubject, "Crash Report");
emailIntent.PutExtra(Intent.ExtraText, text);
Application.Context.StartActivity(Intent.CreateChooser(emailIntent, "Send mail..."));
}
} }
} }