mirror of
https://github.com/bitwarden/mobile.git
synced 2024-09-10 01:08:23 +02:00
KeyStoreBackedStorageService email crash reports
This commit is contained in:
parent
71ad648331
commit
b139eadf0b
@ -12,6 +12,7 @@ using Android.App;
|
|||||||
using Plugin.Settings.Abstractions;
|
using Plugin.Settings.Abstractions;
|
||||||
using Java.Util;
|
using Java.Util;
|
||||||
using Javax.Crypto.Spec;
|
using Javax.Crypto.Spec;
|
||||||
|
using Android.Content;
|
||||||
|
|
||||||
namespace Bit.Android.Services
|
namespace Bit.Android.Services
|
||||||
{
|
{
|
||||||
@ -30,17 +31,59 @@ namespace Bit.Android.Services
|
|||||||
|
|
||||||
public KeyStoreBackedStorageService(ISettings settings)
|
public KeyStoreBackedStorageService(ISettings settings)
|
||||||
{
|
{
|
||||||
_oldAndroid = Build.VERSION.SdkInt < BuildVersionCodes.M;
|
try
|
||||||
_rsaMode = _oldAndroid ? "RSA/ECB/PKCS1Padding" : "RSA/ECB/OAEPWithSHA-1AndMGF1Padding";
|
{
|
||||||
|
_oldAndroid = Build.VERSION.SdkInt < BuildVersionCodes.M;
|
||||||
|
_rsaMode = _oldAndroid ? "RSA/ECB/PKCS1Padding" : "RSA/ECB/OAEPWithSHA-1AndMGF1Padding";
|
||||||
|
|
||||||
_oldKeyStorageService = new KeyStoreStorageService(new char[] { });
|
_oldKeyStorageService = new KeyStoreStorageService(new char[] { });
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
|
||||||
_keyStore = KeyStore.GetInstance(AndroidKeyStore);
|
_keyStore = KeyStore.GetInstance(AndroidKeyStore);
|
||||||
_keyStore.Load(null);
|
_keyStore.Load(null);
|
||||||
|
|
||||||
GenerateRsaKey();
|
GenerateRsaKey();
|
||||||
GenerateAesKey();
|
GenerateAesKey();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
SendEmail(e.Message + "\n\n" + e.StackTrace);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendEmail(string text, bool includeSecurityProviders = true)
|
||||||
|
{
|
||||||
|
var crashMessage = "bitwarden has crashed. Please send this email to our support team so that we can help " +
|
||||||
|
"resolve the problem for you. Thank you.";
|
||||||
|
|
||||||
|
text = crashMessage + "\n\n =============================================== \n\n" + text;
|
||||||
|
|
||||||
|
if(includeSecurityProviders)
|
||||||
|
{
|
||||||
|
text += "\n\n";
|
||||||
|
var providers = Security.GetProviders();
|
||||||
|
foreach(var provider in providers)
|
||||||
|
{
|
||||||
|
text += ("provider: " + provider.Name + "\n");
|
||||||
|
var services = provider.Services;
|
||||||
|
foreach(var service in provider.Services)
|
||||||
|
{
|
||||||
|
text += ("- alg: " + service.Algorithm + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
text += "\n\n ==================================================== \n\n" + crashMessage;
|
||||||
|
|
||||||
|
var emailIntent = new Intent(Intent.ActionSend);
|
||||||
|
|
||||||
|
emailIntent.SetType("plain/text");
|
||||||
|
emailIntent.PutExtra(Intent.ExtraEmail, new String[] { "hello@bitwarden.com" });
|
||||||
|
emailIntent.PutExtra(Intent.ExtraSubject, "bitwarden Crash Report");
|
||||||
|
emailIntent.PutExtra(Intent.ExtraText, text);
|
||||||
|
|
||||||
|
Application.Context.StartActivity(Intent.CreateChooser(emailIntent, "Send mail..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains(string key)
|
public bool Contains(string key)
|
||||||
@ -78,10 +121,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
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to decrypt from secure storage.");
|
Console.WriteLine("Failed to decrypt from secure storage.");
|
||||||
_settings.Remove(formattedKey);
|
_settings.Remove(formattedKey);
|
||||||
|
SendEmail(e.Message + "\n\n" + e.StackTrace);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,9 +151,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
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to encrypt to secure storage.");
|
Console.WriteLine("Failed to encrypt to secure storage.");
|
||||||
|
SendEmail(e.Message + "\n\n" + e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,11 +228,12 @@ 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
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Cannot get AesKey.");
|
Console.WriteLine("Cannot get AesKey.");
|
||||||
_keyStore.DeleteEntry(KeyAlias);
|
_keyStore.DeleteEntry(KeyAlias);
|
||||||
_settings.Remove(AesKey);
|
_settings.Remove(AesKey);
|
||||||
|
SendEmail(e.Message + "\n\n" + e.StackTrace);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user