mirror of
https://github.com/bitwarden/mobile
synced 2026-01-04 17:43:17 +00:00
memory stored pinProtectedKey
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Bit.Core.Abstractions
|
||||
Task<CipherString> EncryptAsync(byte[] plainValue, SymmetricCryptoKey key = null);
|
||||
Task<CipherString> EncryptAsync(string plainValue, SymmetricCryptoKey key = null);
|
||||
Task<byte[]> EncryptToBytesAsync(byte[] plainValue, SymmetricCryptoKey key = null);
|
||||
Task<SymmetricCryptoKey> GetEncKeyAsync();
|
||||
Task<SymmetricCryptoKey> GetEncKeyAsync(SymmetricCryptoKey key = null);
|
||||
Task<List<string>> GetFingerprintAsync(string userId, byte[] publicKey = null);
|
||||
Task<SymmetricCryptoKey> GetKeyAsync();
|
||||
Task<string> GetKeyHashAsync();
|
||||
@@ -35,7 +35,8 @@ namespace Bit.Core.Abstractions
|
||||
Task<bool> HasKeyAsync();
|
||||
Task<Tuple<SymmetricCryptoKey, CipherString>> MakeEncKeyAsync(SymmetricCryptoKey key);
|
||||
Task<SymmetricCryptoKey> MakeKeyAsync(string password, string salt, KdfType? kdf, int? kdfIterations);
|
||||
Task<SymmetricCryptoKey> MakeKeyFromPinAsync(string pin, string salt, KdfType kdf, int kdfIterations);
|
||||
Task<SymmetricCryptoKey> MakeKeyFromPinAsync(string pin, string salt, KdfType kdf, int kdfIterations,
|
||||
CipherString protectedKeyCs = null);
|
||||
Task<Tuple<string, CipherString>> MakeKeyPairAsync(SymmetricCryptoKey key = null);
|
||||
Task<SymmetricCryptoKey> MakePinKeyAysnc(string pin, string salt, KdfType kdf, int kdfIterations);
|
||||
Task<Tuple<CipherString, SymmetricCryptoKey>> MakeShareKeyAsync();
|
||||
@@ -49,4 +50,4 @@ namespace Bit.Core.Abstractions
|
||||
Task SetOrgKeysAsync(IEnumerable<ProfileOrganizationResponse> orgs);
|
||||
Task ToggleKeyAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Domain;
|
||||
|
||||
namespace Bit.Core.Abstractions
|
||||
{
|
||||
public interface ILockService
|
||||
{
|
||||
bool PinLocked { get; set; }
|
||||
CipherString PinProtectedKey { get; set; }
|
||||
bool FingerprintLocked { get; set; }
|
||||
|
||||
Task CheckLockAsync();
|
||||
@@ -16,4 +17,4 @@ namespace Bit.Core.Abstractions
|
||||
Task LockAsync(bool allowSoftLock = false, bool userInitiated = false);
|
||||
Task SetLockOptionAsync(int? lockOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace Bit.Core.Services
|
||||
return _keyHash;
|
||||
}
|
||||
|
||||
public Task<SymmetricCryptoKey> GetEncKeyAsync()
|
||||
public Task<SymmetricCryptoKey> GetEncKeyAsync(SymmetricCryptoKey key = null)
|
||||
{
|
||||
if(_encKey != null)
|
||||
{
|
||||
@@ -138,7 +138,10 @@ namespace Bit.Core.Services
|
||||
return null;
|
||||
}
|
||||
|
||||
var key = await GetKeyAsync();
|
||||
if(key == null)
|
||||
{
|
||||
key = await GetKeyAsync();
|
||||
}
|
||||
if(key == null)
|
||||
{
|
||||
return null;
|
||||
@@ -386,14 +389,17 @@ namespace Bit.Core.Services
|
||||
}
|
||||
|
||||
public async Task<SymmetricCryptoKey> MakeKeyFromPinAsync(string pin, string salt,
|
||||
KdfType kdf, int kdfIterations)
|
||||
KdfType kdf, int kdfIterations, CipherString protectedKeyCs = null)
|
||||
{
|
||||
var pinProtectedKey = await _storageService.GetAsync<string>(Constants.PinProtectedKey);
|
||||
if(pinProtectedKey == null)
|
||||
if(protectedKeyCs == null)
|
||||
{
|
||||
throw new Exception("No PIN protected key found.");
|
||||
var pinProtectedKey = await _storageService.GetAsync<string>(Constants.PinProtectedKey);
|
||||
if(pinProtectedKey == null)
|
||||
{
|
||||
throw new Exception("No PIN protected key found.");
|
||||
}
|
||||
protectedKeyCs = new CipherString(pinProtectedKey);
|
||||
}
|
||||
var protectedKeyCs = new CipherString(pinProtectedKey);
|
||||
var pinKey = await MakePinKeyAysnc(pin, salt, kdf, kdfIterations);
|
||||
var decKey = await DecryptToBytesAsync(protectedKeyCs, pinKey);
|
||||
return new SymmetricCryptoKey(decKey);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Models.Domain;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -41,7 +42,7 @@ namespace Bit.Core.Services
|
||||
_lockedCallback = lockedCallback;
|
||||
}
|
||||
|
||||
public bool PinLocked { get; set; }
|
||||
public CipherString PinProtectedKey { get; set; } = null;
|
||||
public bool FingerprintLocked { get; set; } = true;
|
||||
|
||||
public async Task<bool> IsLockedAsync()
|
||||
@@ -49,18 +50,11 @@ namespace Bit.Core.Services
|
||||
var hasKey = await _cryptoService.HasKeyAsync();
|
||||
if(hasKey)
|
||||
{
|
||||
if(PinLocked)
|
||||
var fingerprintSet = await IsFingerprintLockSetAsync();
|
||||
if(fingerprintSet && FingerprintLocked)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var fingerprintSet = await IsFingerprintLockSetAsync();
|
||||
if(fingerprintSet && FingerprintLocked)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return !hasKey;
|
||||
}
|
||||
@@ -111,13 +105,8 @@ namespace Bit.Core.Services
|
||||
}
|
||||
if(allowSoftLock)
|
||||
{
|
||||
var pinSet = await IsPinLockSetAsync();
|
||||
if(pinSet.Item1)
|
||||
{
|
||||
PinLocked = true;
|
||||
}
|
||||
FingerprintLocked = await IsFingerprintLockSetAsync();
|
||||
if(FingerprintLocked || PinLocked)
|
||||
if(FingerprintLocked)
|
||||
{
|
||||
_messagingService.Send("locked", userInitiated);
|
||||
_lockedCallback?.Invoke(userInitiated);
|
||||
@@ -159,6 +148,7 @@ namespace Bit.Core.Services
|
||||
|
||||
public async Task ClearAsync()
|
||||
{
|
||||
PinProtectedKey = null;
|
||||
await _storageService.RemoveAsync(Constants.ProtectedPin);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user