1
0
mirror of https://github.com/bitwarden/mobile synced 2026-02-19 02:43:29 +00:00

Add HashPurpose parameter to HashPasswordAsync

This commit is contained in:
Thomas Rittson
2021-06-10 08:18:56 +10:00
parent 33791a03ac
commit aff8227989
3 changed files with 12 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ namespace Bit.Core.Abstractions
Task<byte[]> GetPrivateKeyAsync();
Task<byte[]> GetPublicKeyAsync();
Task<bool> HasEncKeyAsync();
Task<string> HashPasswordAsync(string password, SymmetricCryptoKey key);
Task<string> HashPasswordAsync(string password, SymmetricCryptoKey key, HashPurpose? hashPurpose);
Task<bool> HasKeyAsync();
Task<Tuple<SymmetricCryptoKey, EncString>> MakeEncKeyAsync(SymmetricCryptoKey key);
Task<SymmetricCryptoKey> MakeKeyAsync(string password, string salt, KdfType? kdf, int? kdfIterations);

View File

@@ -0,0 +1,8 @@
namespace Bit.Core.Enums
{
public enum HashPurpose : byte
{
ServerAuthorization = 1,
LocalAuthorization = 2,
}
}

View File

@@ -433,7 +433,7 @@ namespace Bit.Core.Services
return new SymmetricCryptoKey(sendKey);
}
public async Task<string> HashPasswordAsync(string password, SymmetricCryptoKey key)
public async Task<string> HashPasswordAsync(string password, SymmetricCryptoKey key, HashPurpose? hashPurpose)
{
if (key == null)
{
@@ -443,7 +443,8 @@ namespace Bit.Core.Services
{
throw new Exception("Invalid parameters.");
}
var hash = await _cryptoFunctionService.Pbkdf2Async(key.Key, password, CryptoHashAlgorithm.Sha256, 1);
var iterations = hashPurpose == HashPurpose.LocalAuthorization ? 2 : 1;
var hash = await _cryptoFunctionService.Pbkdf2Async(key.Key, password, CryptoHashAlgorithm.Sha256, iterations);
return Convert.ToBase64String(hash);
}