mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
KeyStoreBackedStorageService email crash reports
This commit is contained in:
parent
71ad648331
commit
b139eadf0b
1 changed files with 57 additions and 11 deletions
|
@ -12,6 +12,7 @@ using Android.App;
|
|||
using Plugin.Settings.Abstractions;
|
||||
using Java.Util;
|
||||
using Javax.Crypto.Spec;
|
||||
using Android.Content;
|
||||
|
||||
namespace Bit.Android.Services
|
||||
{
|
||||
|
@ -30,17 +31,59 @@ namespace Bit.Android.Services
|
|||
|
||||
public KeyStoreBackedStorageService(ISettings settings)
|
||||
{
|
||||
_oldAndroid = Build.VERSION.SdkInt < BuildVersionCodes.M;
|
||||
_rsaMode = _oldAndroid ? "RSA/ECB/PKCS1Padding" : "RSA/ECB/OAEPWithSHA-1AndMGF1Padding";
|
||||
try
|
||||
{
|
||||
_oldAndroid = Build.VERSION.SdkInt < BuildVersionCodes.M;
|
||||
_rsaMode = _oldAndroid ? "RSA/ECB/PKCS1Padding" : "RSA/ECB/OAEPWithSHA-1AndMGF1Padding";
|
||||
|
||||
_oldKeyStorageService = new KeyStoreStorageService(new char[] { });
|
||||
_settings = settings;
|
||||
_oldKeyStorageService = new KeyStoreStorageService(new char[] { });
|
||||
_settings = settings;
|
||||
|
||||
_keyStore = KeyStore.GetInstance(AndroidKeyStore);
|
||||
_keyStore.Load(null);
|
||||
_keyStore = KeyStore.GetInstance(AndroidKeyStore);
|
||||
_keyStore.Load(null);
|
||||
|
||||
GenerateRsaKey();
|
||||
GenerateAesKey();
|
||||
GenerateRsaKey();
|
||||
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)
|
||||
|
@ -78,10 +121,11 @@ namespace Bit.Android.Services
|
|||
{
|
||||
return App.Utilities.Crypto.AesCbcDecrypt(new App.Models.CipherString(cs), aesKey);
|
||||
}
|
||||
catch
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("Failed to decrypt from secure storage.");
|
||||
_settings.Remove(formattedKey);
|
||||
SendEmail(e.Message + "\n\n" + e.StackTrace);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +151,10 @@ namespace Bit.Android.Services
|
|||
var cipherString = App.Utilities.Crypto.AesCbcEncrypt(dataBytes, aesKey);
|
||||
_settings.AddOrUpdateValue(formattedKey, cipherString.EncryptedString);
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
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);
|
||||
return new App.Models.SymmetricCryptoKey(key);
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Cannot get AesKey.");
|
||||
_keyStore.DeleteEntry(KeyAlias);
|
||||
_settings.Remove(AesKey);
|
||||
SendEmail(e.Message + "\n\n" + e.StackTrace);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue