From 741214a1ccec890174f0e553679a43c0ef41a50a Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Thu, 14 Dec 2023 17:32:43 -0300 Subject: [PATCH] PM-3349 PM-3350 Enabled argon2id and fixed one issue with the Uris when getting the icon image --- .../Android/Services/CryptoPrimitiveService.cs | 10 +++++----- src/Core/Utilities/IconImageConverter.cs | 2 +- src/iOS.Core/Services/CryptoPrimitiveService.cs | 15 +++++++-------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/App/Platforms/Android/Services/CryptoPrimitiveService.cs b/src/App/Platforms/Android/Services/CryptoPrimitiveService.cs index 82f8c2038..5dec269fe 100644 --- a/src/App/Platforms/Android/Services/CryptoPrimitiveService.cs +++ b/src/App/Platforms/Android/Services/CryptoPrimitiveService.cs @@ -41,13 +41,13 @@ namespace Bit.Droid.Services JavaSystem.LoadLibrary("argon2"); int keySize = 32; var key = new byte[keySize]; - //argon2id_hash_raw(iterations, memory, parallelism, - // password, password.Length, salt, salt.Length, key, key.Length); + argon2id_hash_raw(iterations, memory, parallelism, + password, password.Length, salt, salt.Length, key, key.Length); return key; } - //[DllImport("argon2", EntryPoint = "argon2id_hash_raw")] - //private static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, - // byte[] pwd, int pwdlen, byte[] salt, int saltlen, byte[] hash, int hashlen); + [DllImport("argon2", EntryPoint = "argon2id_hash_raw")] + private static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, + byte[] pwd, int pwdlen, byte[] salt, int saltlen, byte[] hash, int hashlen); } } diff --git a/src/Core/Utilities/IconImageConverter.cs b/src/Core/Utilities/IconImageConverter.cs index 70225579a..d860aa3d8 100644 --- a/src/Core/Utilities/IconImageConverter.cs +++ b/src/Core/Utilities/IconImageConverter.cs @@ -40,7 +40,7 @@ namespace Bit.App.Utilities string image = null; if (cipher.Login.HasUris) { - foreach (var uri in cipher.Login.Uris) + foreach (var uri in cipher.Login.Uris.Where(u => u.Uri != null)) { var hostnameUri = uri.Uri; var isWebsite = false; diff --git a/src/iOS.Core/Services/CryptoPrimitiveService.cs b/src/iOS.Core/Services/CryptoPrimitiveService.cs index 96d4c00f3..e74432dd5 100644 --- a/src/iOS.Core/Services/CryptoPrimitiveService.cs +++ b/src/iOS.Core/Services/CryptoPrimitiveService.cs @@ -1,8 +1,7 @@ -using Bit.Core.Abstractions; +using System.Runtime.InteropServices; +using Bit.Core.Abstractions; using Bit.Core.Enums; using Foundation; -using System; -using System.Runtime.InteropServices; namespace Bit.iOS.Core.Services { @@ -48,8 +47,8 @@ namespace Bit.iOS.Core.Services var passwordData = NSData.FromArray(password); var saltData = NSData.FromArray(salt); - //argon2id_hash_raw(iterations, memory, parallelism, passwordData.Bytes, passwordData.Length, - // saltData.Bytes, saltData.Length, keyData.MutableBytes, keyData.Length); + argon2id_hash_raw(iterations, memory, parallelism, passwordData.Bytes, passwordData.Length, + saltData.Bytes, saltData.Length, keyData.MutableBytes, keyData.Length); var keyBytes = new byte[keyData.Length]; Marshal.Copy(keyData.Bytes, keyBytes, 0, Convert.ToInt32(keyData.Length)); @@ -61,8 +60,8 @@ namespace Bit.iOS.Core.Services private static extern int CCKeyCerivationPBKDF(uint algorithm, IntPtr password, nuint passwordLen, IntPtr salt, nuint saltLen, uint prf, nuint rounds, IntPtr derivedKey, nuint derivedKeyLength); - //[DllImport("__Internal", EntryPoint = "argon2id_hash_raw")] - //private static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, IntPtr pwd, - // nuint pwdlen, IntPtr salt, nuint saltlen, IntPtr hash, nuint hashlen); + [DllImport("__Internal", EntryPoint = "argon2id_hash_raw")] + private static extern int argon2id_hash_raw(int timeCost, int memoryCost, int parallelism, IntPtr pwd, + nuint pwdlen, IntPtr salt, nuint saltlen, IntPtr hash, nuint hashlen); } }