mirror of
https://github.com/bitwarden/android.git
synced 2025-03-29 00:59:19 +03:00
remove old keystore storage service
This commit is contained in:
parent
1768e8cb62
commit
daf6d1936f
3 changed files with 1 additions and 130 deletions
|
@ -313,7 +313,6 @@
|
||||||
<Compile Include="Services\AppInfoService.cs" />
|
<Compile Include="Services\AppInfoService.cs" />
|
||||||
<Compile Include="Services\DeviceActionService.cs" />
|
<Compile Include="Services\DeviceActionService.cs" />
|
||||||
<Compile Include="Services\BouncyCastleKeyDerivationService.cs" />
|
<Compile Include="Services\BouncyCastleKeyDerivationService.cs" />
|
||||||
<Compile Include="Services\KeyStoreStorageService.cs" />
|
|
||||||
<Compile Include="MainActivity.cs" />
|
<Compile Include="MainActivity.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Services\LogService.cs" />
|
<Compile Include="Services\LogService.cs" />
|
||||||
|
|
|
@ -33,14 +33,12 @@ namespace Bit.Android.Services
|
||||||
private readonly bool _oldAndroid;
|
private readonly bool _oldAndroid;
|
||||||
private readonly ISettings _settings;
|
private readonly ISettings _settings;
|
||||||
private readonly KeyStore _keyStore;
|
private readonly KeyStore _keyStore;
|
||||||
private readonly ISecureStorageService _oldKeyStorageService;
|
|
||||||
|
|
||||||
public AndroidKeyStoreStorageService(ISettings settings)
|
public AndroidKeyStoreStorageService(ISettings settings)
|
||||||
{
|
{
|
||||||
_oldAndroid = Build.VERSION.SdkInt < BuildVersionCodes.M;
|
_oldAndroid = Build.VERSION.SdkInt < BuildVersionCodes.M;
|
||||||
_rsaMode = _oldAndroid ? "RSA/ECB/PKCS1Padding" : "RSA/ECB/OAEPWithSHA-1AndMGF1Padding";
|
_rsaMode = _oldAndroid ? "RSA/ECB/PKCS1Padding" : "RSA/ECB/OAEPWithSHA-1AndMGF1Padding";
|
||||||
|
|
||||||
_oldKeyStorageService = new KeyStoreStorageService(new char[] { });
|
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
|
||||||
_keyStore = KeyStore.GetInstance(AndroidKeyStore);
|
_keyStore = KeyStore.GetInstance(AndroidKeyStore);
|
||||||
|
@ -53,8 +51,7 @@ namespace Bit.Android.Services
|
||||||
public bool Contains(string key)
|
public bool Contains(string key)
|
||||||
{
|
{
|
||||||
return _settings.Contains(string.Format(SettingsFormat, key)) ||
|
return _settings.Contains(string.Format(SettingsFormat, key)) ||
|
||||||
_settings.Contains(string.Format(SettingsFormatV1, key)) ||
|
_settings.Contains(string.Format(SettingsFormatV1, key));
|
||||||
_oldKeyStorageService.Contains(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Delete(string key)
|
public void Delete(string key)
|
||||||
|
@ -297,13 +294,6 @@ namespace Bit.Android.Services
|
||||||
|
|
||||||
private byte[] TryGetAndMigrate(string key)
|
private byte[] TryGetAndMigrate(string key)
|
||||||
{
|
{
|
||||||
if(_oldKeyStorageService.Contains(key))
|
|
||||||
{
|
|
||||||
var value = _oldKeyStorageService.Retrieve(key);
|
|
||||||
Store(key, value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
var formattedKeyV1 = string.Format(SettingsFormatV1, key);
|
var formattedKeyV1 = string.Format(SettingsFormatV1, key);
|
||||||
if(_settings.Contains(formattedKeyV1))
|
if(_settings.Contains(formattedKeyV1))
|
||||||
{
|
{
|
||||||
|
@ -331,11 +321,6 @@ namespace Bit.Android.Services
|
||||||
|
|
||||||
private void CleanupOld(string key)
|
private void CleanupOld(string key)
|
||||||
{
|
{
|
||||||
if(_oldKeyStorageService.Contains(key))
|
|
||||||
{
|
|
||||||
_oldKeyStorageService.Delete(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
var formattedKeyV1 = string.Format(SettingsFormatV1, key);
|
var formattedKeyV1 = string.Format(SettingsFormatV1, key);
|
||||||
if(_settings.Contains(formattedKeyV1))
|
if(_settings.Contains(formattedKeyV1))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,113 +0,0 @@
|
||||||
using System.IO;
|
|
||||||
using System.IO.IsolatedStorage;
|
|
||||||
using Java.Lang;
|
|
||||||
using Java.Security;
|
|
||||||
using Javax.Crypto;
|
|
||||||
using Android.OS;
|
|
||||||
using Bit.App.Abstractions;
|
|
||||||
|
|
||||||
namespace Bit.Android.Services
|
|
||||||
{
|
|
||||||
[System.Obsolete]
|
|
||||||
public class KeyStoreStorageService : ISecureStorageService
|
|
||||||
{
|
|
||||||
private const string StorageFile = "Bit.Android.KeyStoreStorageService";
|
|
||||||
|
|
||||||
private static readonly object SaveLock = new object();
|
|
||||||
|
|
||||||
private readonly KeyStore _keyStore;
|
|
||||||
private readonly KeyStore.PasswordProtection _protection;
|
|
||||||
|
|
||||||
public KeyStoreStorageService()
|
|
||||||
: this(Build.Serial.ToCharArray()) { }
|
|
||||||
|
|
||||||
public KeyStoreStorageService(char[] password)
|
|
||||||
{
|
|
||||||
_keyStore = KeyStore.GetInstance(KeyStore.DefaultType);
|
|
||||||
_protection = new KeyStore.PasswordProtection(password);
|
|
||||||
|
|
||||||
if(File.FileExists(StorageFile))
|
|
||||||
{
|
|
||||||
using(var stream = new IsolatedStorageFileStream(StorageFile, FileMode.Open, FileAccess.Read, File))
|
|
||||||
{
|
|
||||||
_keyStore.Load(stream, password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_keyStore.Load(null, password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IsolatedStorageFile File
|
|
||||||
{
|
|
||||||
get { return IsolatedStorageFile.GetUserStoreForApplication(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Store(string key, byte[] dataBytes)
|
|
||||||
{
|
|
||||||
_keyStore.SetEntry(key, new KeyStore.SecretKeyEntry(new SecureData(dataBytes)), _protection);
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] Retrieve(string key)
|
|
||||||
{
|
|
||||||
var entry = _keyStore.GetEntry(key, _protection) as KeyStore.SecretKeyEntry;
|
|
||||||
if(entry == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry.SecretKey.GetEncoded();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Delete(string key)
|
|
||||||
{
|
|
||||||
_keyStore.DeleteEntry(key);
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Contains(string key)
|
|
||||||
{
|
|
||||||
return _keyStore.ContainsAlias(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Save()
|
|
||||||
{
|
|
||||||
lock(SaveLock)
|
|
||||||
{
|
|
||||||
using(var stream = new IsolatedStorageFileStream(StorageFile, FileMode.OpenOrCreate, FileAccess.Write, File))
|
|
||||||
{
|
|
||||||
_keyStore.Store(stream, _protection.GetPassword());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SecureData : Object, ISecretKey
|
|
||||||
{
|
|
||||||
private const string Raw = "RAW";
|
|
||||||
|
|
||||||
private readonly byte[] _data;
|
|
||||||
|
|
||||||
public SecureData(byte[] dataBytes)
|
|
||||||
{
|
|
||||||
_data = dataBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Algorithm
|
|
||||||
{
|
|
||||||
get { return Raw; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Format
|
|
||||||
{
|
|
||||||
get { return Raw; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] GetEncoded()
|
|
||||||
{
|
|
||||||
return _data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue