mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-22 11:35:21 +01:00
rename CryptoKey to SymmetricCryptoKey
This commit is contained in:
parent
b26c3d050c
commit
27e0c7421b
@ -15,6 +15,6 @@ namespace Bit.App.Abstractions
|
||||
bool BelongsToOrganization(string orgId);
|
||||
void LogOut();
|
||||
Task<FullLoginResult> TokenPostAsync(string email, string masterPassword);
|
||||
Task<LoginResult> TokenPostTwoFactorAsync(string token, string email, string masterPasswordHash, CryptoKey key);
|
||||
Task<LoginResult> TokenPostTwoFactorAsync(string token, string email, string masterPasswordHash, SymmetricCryptoKey key);
|
||||
}
|
||||
}
|
||||
|
@ -6,24 +6,24 @@ namespace Bit.App.Abstractions
|
||||
{
|
||||
public interface ICryptoService
|
||||
{
|
||||
CryptoKey Key { get; set; }
|
||||
CryptoKey PreviousKey { get; }
|
||||
SymmetricCryptoKey Key { get; set; }
|
||||
SymmetricCryptoKey PreviousKey { get; }
|
||||
bool KeyChanged { get; }
|
||||
byte[] PrivateKey { get; }
|
||||
IDictionary<string, CryptoKey> OrgKeys { get; set; }
|
||||
IDictionary<string, SymmetricCryptoKey> OrgKeys { get; set; }
|
||||
|
||||
void SetPrivateKey(CipherString privateKeyEnc, CryptoKey key);
|
||||
CryptoKey GetOrgKey(string orgId);
|
||||
void SetPrivateKey(CipherString privateKeyEnc, SymmetricCryptoKey key);
|
||||
SymmetricCryptoKey GetOrgKey(string orgId);
|
||||
void ClearOrgKey(string orgId);
|
||||
void ClearKeys();
|
||||
CryptoKey AddOrgKey(string orgId, CipherString encOrgKey, byte[] privateKey);
|
||||
string Decrypt(CipherString encyptedValue, CryptoKey key = null);
|
||||
byte[] DecryptToBytes(CipherString encyptedValue, CryptoKey key = null);
|
||||
SymmetricCryptoKey AddOrgKey(string orgId, CipherString encOrgKey, byte[] privateKey);
|
||||
string Decrypt(CipherString encyptedValue, SymmetricCryptoKey key = null);
|
||||
byte[] DecryptToBytes(CipherString encyptedValue, SymmetricCryptoKey key = null);
|
||||
byte[] RsaDecryptToBytes(CipherString encyptedValue, byte[] privateKey);
|
||||
CipherString Encrypt(string plaintextValue, CryptoKey key = null);
|
||||
CryptoKey MakeKeyFromPassword(string password, string salt);
|
||||
CipherString Encrypt(string plaintextValue, SymmetricCryptoKey key = null);
|
||||
SymmetricCryptoKey MakeKeyFromPassword(string password, string salt);
|
||||
string MakeKeyFromPasswordBase64(string password, string salt);
|
||||
byte[] HashPassword(CryptoKey key, string password);
|
||||
string HashPasswordBase64(CryptoKey key, string password);
|
||||
byte[] HashPassword(SymmetricCryptoKey key, string password);
|
||||
string HashPasswordBase64(SymmetricCryptoKey key, string password);
|
||||
}
|
||||
}
|
@ -112,7 +112,7 @@
|
||||
<Compile Include="Models\Api\LoginDataModel.cs" />
|
||||
<Compile Include="Models\Cipher.cs" />
|
||||
<Compile Include="Models\CipherString.cs" />
|
||||
<Compile Include="Models\CryptoKey.cs" />
|
||||
<Compile Include="Models\SymmetricCryptoKey.cs" />
|
||||
<Compile Include="Models\Data\SettingsData.cs" />
|
||||
<Compile Include="Models\Data\FolderData.cs" />
|
||||
<Compile Include="Abstractions\IDataObject.cs" />
|
||||
|
@ -9,7 +9,7 @@
|
||||
public class FullLoginResult : LoginResult
|
||||
{
|
||||
public bool TwoFactorRequired { get; set; }
|
||||
public CryptoKey Key { get; set; }
|
||||
public SymmetricCryptoKey Key { get; set; }
|
||||
public string MasterPasswordHash { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ using System.Linq;
|
||||
|
||||
namespace Bit.App.Models
|
||||
{
|
||||
public class CryptoKey
|
||||
public class SymmetricCryptoKey
|
||||
{
|
||||
public CryptoKey(byte[] rawBytes, EncryptionType? encType = null)
|
||||
public SymmetricCryptoKey(byte[] rawBytes, EncryptionType? encType = null)
|
||||
{
|
||||
if(rawBytes == null || rawBytes.Length == 0)
|
||||
{
|
@ -20,9 +20,9 @@ namespace Bit.App.Pages
|
||||
private IPushNotification _pushNotification;
|
||||
private readonly string _email;
|
||||
private readonly string _masterPasswordHash;
|
||||
private readonly CryptoKey _key;
|
||||
private readonly SymmetricCryptoKey _key;
|
||||
|
||||
public LoginTwoFactorPage(string email, string masterPasswordHash, CryptoKey key)
|
||||
public LoginTwoFactorPage(string email, string masterPasswordHash, SymmetricCryptoKey key)
|
||||
: base(updateActivity: false)
|
||||
{
|
||||
_email = email;
|
||||
|
@ -245,7 +245,7 @@ namespace Bit.App.Services
|
||||
}
|
||||
|
||||
public async Task<LoginResult> TokenPostTwoFactorAsync(string token, string email, string masterPasswordHash,
|
||||
CryptoKey key)
|
||||
SymmetricCryptoKey key)
|
||||
{
|
||||
var result = new LoginResult();
|
||||
|
||||
@ -271,7 +271,7 @@ namespace Bit.App.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ProcessLoginSuccessAsync(CryptoKey key, TokenResponse response)
|
||||
private async Task ProcessLoginSuccessAsync(SymmetricCryptoKey key, TokenResponse response)
|
||||
{
|
||||
if(response.PrivateKey != null)
|
||||
{
|
||||
@ -288,7 +288,7 @@ namespace Bit.App.Services
|
||||
if(response.PrivateKey != null)
|
||||
{
|
||||
var profile = await _accountsApiRepository.GetProfileAsync();
|
||||
var orgKeysDict = new Dictionary<string, CryptoKey>();
|
||||
var orgKeysDict = new Dictionary<string, SymmetricCryptoKey>();
|
||||
|
||||
if(profile.Succeeded && (profile.Result.Organizations?.Any() ?? false))
|
||||
{
|
||||
@ -297,7 +297,7 @@ namespace Bit.App.Services
|
||||
try
|
||||
{
|
||||
var decBytes = _cryptoService.RsaDecryptToBytes(new CipherString(org.Key), null);
|
||||
orgKeysDict.Add(org.Id, new CryptoKey(decBytes));
|
||||
orgKeysDict.Add(org.Id, new SymmetricCryptoKey(decBytes));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -21,10 +21,10 @@ namespace Bit.App.Services
|
||||
|
||||
private readonly ISecureStorageService _secureStorage;
|
||||
private readonly IKeyDerivationService _keyDerivationService;
|
||||
private CryptoKey _key;
|
||||
private CryptoKey _legacyEtmKey;
|
||||
private CryptoKey _previousKey;
|
||||
private IDictionary<string, CryptoKey> _orgKeys;
|
||||
private SymmetricCryptoKey _key;
|
||||
private SymmetricCryptoKey _legacyEtmKey;
|
||||
private SymmetricCryptoKey _previousKey;
|
||||
private IDictionary<string, SymmetricCryptoKey> _orgKeys;
|
||||
private byte[] _privateKey;
|
||||
|
||||
public CryptoService(
|
||||
@ -35,7 +35,7 @@ namespace Bit.App.Services
|
||||
_keyDerivationService = keyDerivationService;
|
||||
}
|
||||
|
||||
public CryptoKey Key
|
||||
public SymmetricCryptoKey Key
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -44,7 +44,7 @@ namespace Bit.App.Services
|
||||
var keyBytes = _secureStorage.Retrieve(KeyKey);
|
||||
if(keyBytes != null)
|
||||
{
|
||||
_key = new CryptoKey(keyBytes);
|
||||
_key = new SymmetricCryptoKey(keyBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ namespace Bit.App.Services
|
||||
}
|
||||
}
|
||||
|
||||
public CryptoKey PreviousKey
|
||||
public SymmetricCryptoKey PreviousKey
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -75,7 +75,7 @@ namespace Bit.App.Services
|
||||
var keyBytes = _secureStorage.Retrieve(PreviousKeyKey);
|
||||
if(keyBytes != null)
|
||||
{
|
||||
_previousKey = new CryptoKey(keyBytes);
|
||||
_previousKey = new SymmetricCryptoKey(keyBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ namespace Bit.App.Services
|
||||
}
|
||||
}
|
||||
|
||||
public IDictionary<string, CryptoKey> OrgKeys
|
||||
public IDictionary<string, SymmetricCryptoKey> OrgKeys
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -147,11 +147,11 @@ namespace Bit.App.Services
|
||||
var orgKeysDictJson = Encoding.UTF8.GetString(orgKeysDictBytes, 0, orgKeysDictBytes.Length);
|
||||
if(!string.IsNullOrWhiteSpace(orgKeysDictJson))
|
||||
{
|
||||
_orgKeys = new Dictionary<string, CryptoKey>();
|
||||
_orgKeys = new Dictionary<string, SymmetricCryptoKey>();
|
||||
var orgKeysDict = JsonConvert.DeserializeObject<IDictionary<string, byte[]>>(orgKeysDictJson);
|
||||
foreach(var item in orgKeysDict)
|
||||
{
|
||||
_orgKeys.Add(item.Key, new CryptoKey(item.Value));
|
||||
_orgKeys.Add(item.Key, new SymmetricCryptoKey(item.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,13 +182,13 @@ namespace Bit.App.Services
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPrivateKey(CipherString privateKeyEnc, CryptoKey key)
|
||||
public void SetPrivateKey(CipherString privateKeyEnc, SymmetricCryptoKey key)
|
||||
{
|
||||
var bytes = DecryptToBytes(privateKeyEnc, key);
|
||||
PrivateKey = bytes;
|
||||
}
|
||||
|
||||
public CryptoKey GetOrgKey(string orgId)
|
||||
public SymmetricCryptoKey GetOrgKey(string orgId)
|
||||
{
|
||||
if(OrgKeys == null || !OrgKeys.ContainsKey(orgId))
|
||||
{
|
||||
@ -218,13 +218,13 @@ namespace Bit.App.Services
|
||||
PrivateKey = null;
|
||||
}
|
||||
|
||||
public CryptoKey AddOrgKey(string orgId, CipherString encOrgKey, byte[] privateKey)
|
||||
public SymmetricCryptoKey AddOrgKey(string orgId, CipherString encOrgKey, byte[] privateKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
var localOrgKeys = OrgKeys;
|
||||
var decBytes = RsaDecryptToBytes(encOrgKey, privateKey);
|
||||
var key = new CryptoKey(decBytes);
|
||||
var key = new SymmetricCryptoKey(decBytes);
|
||||
if(localOrgKeys.ContainsKey(orgId))
|
||||
{
|
||||
localOrgKeys[orgId] = key;
|
||||
@ -245,7 +245,7 @@ namespace Bit.App.Services
|
||||
}
|
||||
}
|
||||
|
||||
public CipherString Encrypt(string plaintextValue, CryptoKey key = null)
|
||||
public CipherString Encrypt(string plaintextValue, SymmetricCryptoKey key = null)
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
@ -270,10 +270,11 @@ namespace Bit.App.Services
|
||||
var encryptedBytes = WinRTCrypto.CryptographicEngine.Encrypt(cryptoKey, plaintextBytes, iv);
|
||||
var mac = key.MacKey != null ? ComputeMac(encryptedBytes, iv, key.MacKey) : null;
|
||||
|
||||
return new CipherString(key.EncryptionType, Convert.ToBase64String(iv), Convert.ToBase64String(encryptedBytes), mac);
|
||||
return new CipherString(key.EncryptionType, Convert.ToBase64String(iv),
|
||||
Convert.ToBase64String(encryptedBytes), mac);
|
||||
}
|
||||
|
||||
public string Decrypt(CipherString encyptedValue, CryptoKey key = null)
|
||||
public string Decrypt(CipherString encyptedValue, SymmetricCryptoKey key = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -287,7 +288,7 @@ namespace Bit.App.Services
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] DecryptToBytes(CipherString encyptedValue, CryptoKey key = null)
|
||||
public byte[] DecryptToBytes(CipherString encyptedValue, SymmetricCryptoKey key = null)
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
@ -310,7 +311,7 @@ namespace Bit.App.Services
|
||||
// Old encrypt-then-mac scheme, swap out the key
|
||||
if(_legacyEtmKey == null)
|
||||
{
|
||||
_legacyEtmKey = new CryptoKey(key.Key, Enums.EncryptionType.AesCbc128_HmacSha256_B64);
|
||||
_legacyEtmKey = new SymmetricCryptoKey(key.Key, Enums.EncryptionType.AesCbc128_HmacSha256_B64);
|
||||
}
|
||||
|
||||
key = _legacyEtmKey;
|
||||
@ -392,7 +393,7 @@ namespace Bit.App.Services
|
||||
return Convert.ToBase64String(mac);
|
||||
}
|
||||
|
||||
public CryptoKey MakeKeyFromPassword(string password, string salt)
|
||||
public SymmetricCryptoKey MakeKeyFromPassword(string password, string salt)
|
||||
{
|
||||
if(password == null)
|
||||
{
|
||||
@ -408,7 +409,7 @@ namespace Bit.App.Services
|
||||
var saltBytes = Encoding.UTF8.GetBytes(salt);
|
||||
|
||||
var keyBytes = _keyDerivationService.DeriveKey(passwordBytes, saltBytes, 5000);
|
||||
return new CryptoKey(keyBytes);
|
||||
return new SymmetricCryptoKey(keyBytes);
|
||||
}
|
||||
|
||||
public string MakeKeyFromPasswordBase64(string password, string salt)
|
||||
@ -417,7 +418,7 @@ namespace Bit.App.Services
|
||||
return Convert.ToBase64String(key.Key);
|
||||
}
|
||||
|
||||
public byte[] HashPassword(CryptoKey key, string password)
|
||||
public byte[] HashPassword(SymmetricCryptoKey key, string password)
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
@ -434,7 +435,7 @@ namespace Bit.App.Services
|
||||
return hash;
|
||||
}
|
||||
|
||||
public string HashPasswordBase64(CryptoKey key, string password)
|
||||
public string HashPasswordBase64(SymmetricCryptoKey key, string password)
|
||||
{
|
||||
var hash = HashPassword(key, password);
|
||||
return Convert.ToBase64String(hash);
|
||||
|
@ -391,7 +391,7 @@ namespace Bit.App.Services
|
||||
|
||||
private void SyncOrgKeys(ProfileResponse profile)
|
||||
{
|
||||
var orgKeysDict = new Dictionary<string, CryptoKey>();
|
||||
var orgKeysDict = new Dictionary<string, SymmetricCryptoKey>();
|
||||
|
||||
if(profile.Organizations != null)
|
||||
{
|
||||
@ -400,7 +400,7 @@ namespace Bit.App.Services
|
||||
try
|
||||
{
|
||||
var decBytes = _cryptoService.RsaDecryptToBytes(new CipherString(org.Key), null);
|
||||
orgKeysDict.Add(org.Id, new CryptoKey(decBytes));
|
||||
orgKeysDict.Add(org.Id, new SymmetricCryptoKey(decBytes));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user