Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Replace Argon2id mobile app lib with Rust implementation (#2159)
Leendert de Borst85dc731e1082
diff --git a/apps/mobile-app/android/app/build.gradle b/apps/mobile-app/android/app/build.gradleindex 758901361..6fa0aff6d 100644--- a/apps/mobile-app/android/app/build.gradle+++ b/apps/mobile-app/android/app/build.gradle@@ -209,9 +209,6 @@ dependencies {// Do NOT remove: it has no direct code reference here, so it can look unused.implementation("androidx.exifinterface:exifinterface:1.4.2")- // Add Argon2 library for password key derivation- implementation("com.lambdapioneer.argon2kt:argon2kt:1.6.0")-// Add modern SQLite library with VACUUM INTO and backup API supportimplementation("com.github.requery:sqlite-android:3.49.0")diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultCrypto.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultCrypto.ktindex 4689ed036..a62a09356 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultCrypto.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultCrypto.kt@@ -2,9 +2,6 @@ package net.aliasvault.app.vaultstoreimport android.util.Base64import android.util.Log-import com.lambdapioneer.argon2kt.Argon2Kt-import com.lambdapioneer.argon2kt.Argon2Mode-import com.lambdapioneer.argon2kt.Argon2Versionimport net.aliasvault.app.vaultstore.interfaces.CryptoOperationCallbackimport net.aliasvault.app.vaultstore.keystoreprovider.KeystoreOperationCallbackimport net.aliasvault.app.vaultstore.keystoreprovider.KeystoreProvider@@ -92,25 +89,7 @@ class VaultCrypto(): ByteArray {require(encryptionType == "Argon2Id") { "Unsupported encryption type: $encryptionType" }- val settings = JSONObject(encryptionSettings)- val iterations = settings.getInt("Iterations")- val memorySize = settings.getInt("MemorySize")- val parallelism = settings.getInt("DegreeOfParallelism")-- val argon2 = Argon2Kt()-- val hashResult = argon2.hash(- mode = Argon2Mode.ARGON2_ID,- password = password.toByteArray(Charsets.UTF_8),- salt = salt.toByteArray(Charsets.UTF_8),- tCostInIterations = iterations,- mCostInKibibyte = memorySize,- parallelism = parallelism,- hashLengthInBytes = 32,- version = Argon2Version.V13,- )-- return hashResult.rawHashAsByteArray()+ return uniffi.aliasvault_core.argon2DeriveKey(password, salt, encryptionSettings)}// endregiondiff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultPin.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultPin.ktindex f4710d010..24ffebbea 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultPin.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultPin.kt@@ -6,9 +6,6 @@ import android.security.keystore.KeyGenParameterSpecimport android.security.keystore.KeyPropertiesimport android.util.Base64import android.util.Log-import com.lambdapioneer.argon2kt.Argon2Kt-import com.lambdapioneer.argon2kt.Argon2Mode-import com.lambdapioneer.argon2kt.Argon2Versionimport org.json.JSONObjectimport java.security.KeyStoreimport java.security.SecureRandom@@ -85,17 +82,9 @@ class VaultPin(private const val KEYSTORE_ALIAS_DATA_ENCRYPTION = "aliasvault_pin_data_encryption_key"/**- * Argon2id parameters for PIN key derivation.- * These parameters are chosen for security against brute-force attacks:- * - Memory: 65536 KB (64 MB) - makes GPU attacks much harder- * - Iterations: 3 - standard for Argon2id- * - Parallelism: 1 - suitable for mobile environment- * - Output: 32 bytes for AES-256-GCM+ * Argon2id settings for PIN unlock.*/- private const val ARGON2_ITERATIONS = 3- private const val ARGON2_MEMORY_KB = 65536 // 64 MB- private const val ARGON2_PARALLELISM = 1- private const val ARGON2_OUTPUT_LENGTH = 32+ private const val ARGON2_SETTINGS = """{"MemorySize":65536,"Iterations":3,"DegreeOfParallelism":1}"""/*** AES-GCM parameters.@@ -299,21 +288,7 @@ class VaultPin(@Throws(Exception::class)private fun derivePinKey(pin: String, salt: ByteArray): ByteArray {try {- val pinBytes = pin.toByteArray(Charsets.UTF_8)- val argon2 = Argon2Kt()-- val hashResult = argon2.hash(- mode = Argon2Mode.ARGON2_ID,- password = pinBytes,- salt = salt,- tCostInIterations = ARGON2_ITERATIONS,- mCostInKibibyte = ARGON2_MEMORY_KB,- parallelism = ARGON2_PARALLELISM,- hashLengthInBytes = ARGON2_OUTPUT_LENGTH,- version = Argon2Version.V13,- )-- return hashResult.rawHashAsByteArray()+ return uniffi.aliasvault_core.argon2DeriveKeyBytes(pin.toByteArray(Charsets.UTF_8), salt, ARGON2_SETTINGS)} catch (e: Exception) {Log.e(TAG, "Argon2 PIN hashing failed", e)throw Exception("Argon2 PIN hashing failed", e)diff --git a/apps/mobile-app/ios/Podfile b/apps/mobile-app/ios/Podfileindex 4334707f1..bba4dbcfd 100644--- a/apps/mobile-app/ios/Podfile+++ b/apps/mobile-app/ios/Podfile@@ -18,7 +18,6 @@ target 'AliasVault' dopod 'SQLite.swift', '~> 0.14.0'pod 'SwiftLint', :configurations => ['Debug']pod 'Macaw', '~> 0.9.7'- pod 'SignalArgon2', '~> 1.3.2'pod 'ExpoModulesJSI', :path => '../node_modules/expo-modules-jsi/apple'pod 'ExpoModulesCore', :path => '../node_modules/expo-modules-core'@@ -98,17 +97,14 @@ endtarget 'Autofill' dopod 'SQLite.swift', '~> 0.14.0'pod 'Macaw', '~> 0.9.7'- pod 'SignalArgon2', '~> 1.3.2'endtarget 'VaultStoreKit' dopod 'SQLite.swift', '~> 0.14.0'- pod 'SignalArgon2', '~> 1.3.2'endtarget 'VaultStoreKitTests' dopod 'SQLite.swift', '~> 0.14.0'- pod 'SignalArgon2', '~> 1.3.2'endtarget 'VaultUI' dodiff --git a/apps/mobile-app/ios/Podfile.lock b/apps/mobile-app/ios/Podfile.lockindex 15b05b613..40c2b1e65 100644--- a/apps/mobile-app/ios/Podfile.lock+++ b/apps/mobile-app/ios/Podfile.lock@@ -2367,7 +2367,6 @@ PODS:- ReactCommon/turbomodule/core- ReactNativeDependencies- Yoga- - SignalArgon2 (1.3.2)- SQLite.swift (0.14.1):- SQLite.swift/standard (= 0.14.1)- SQLite.swift/standard (0.14.1)@@ -2492,7 +2491,6 @@ DEPENDENCIES:- RNScreens (from `../node_modules/react-native-screens`)- RNSVG (from `../node_modules/react-native-svg`)- RNWorklets (from `../node_modules/react-native-worklets`)- - SignalArgon2 (~> 1.3.2)- SQLite.swift (~> 0.14.0)- SwiftLint- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)@@ -2501,7 +2499,6 @@ SPEC REPOS:trunk:- Macaw- OpenSSL-Universal- - SignalArgon2- SQLite.swift- SwiftLint- SWXMLHash@@ -2856,12 +2853,11 @@ SPEC CHECKSUMS:RNScreens: 991cc417cd396602a6cf59a42139e5a9d91462a9RNSVG: 04044c3abcf177fd674a1a3d13097efa1adebcbeRNWorklets: 4931990f73bc8f347586918b2e13f11dfadf3b75- SignalArgon2: 1c24183835ca861e6af06631c18b1671cdf35571SQLite.swift: 2992550ebf3c5b268bf4352603e3df87d2a4ed72SwiftLint: f84fc7d844e9cde0dc4f5013af608a269e317abaSWXMLHash: dd733a457e9c4fe93b1538654057aefae4acb382Yoga: 77dfa8673de2874e1855002ae59c68b8be9b007b-PODFILE CHECKSUM: 0ca3b97c7d314c366f932396ff15a5318564a137+PODFILE CHECKSUM: c259fdf017060f6f592731838af8fe1d2eab07d0COCOAPODS: 1.16.2diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swiftindex 41a2316b3..d2a73c453 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift@@ -2,7 +2,7 @@ import Foundationimport CryptoKitimport LocalAuthenticationimport Security-import SignalArgon2+import RustCoreFrameworkimport VaultUtils/// Extension for the VaultStore class to handle encryption/decryption@@ -16,40 +16,11 @@ extension VaultStore {throw NSError(domain: "VaultStore", code: 13, userInfo: [NSLocalizedDescriptionKey: "Unsupported encryption type: \(encryptionType)"])}- // Parse encryption settings JSON- guard let settingsData = encryptionSettings.data(using: .utf8),- let settings = try? JSONSerialization.jsonObject(with: settingsData, options: []) as? [String: Any],- let iterations = settings["Iterations"] as? UInt32,- let memorySize = settings["MemorySize"] as? UInt32,- let parallelism = settings["DegreeOfParallelism"] as? UInt32 else {- throw NSError(domain: "VaultStore", code: 14, userInfo: [NSLocalizedDescriptionKey: "Invalid encryption settings"])- }-- // Convert password and salt to Data- guard let passwordData = password.data(using: .utf8) else {- throw NSError(domain: "VaultStore", code: 16, userInfo: [NSLocalizedDescriptionKey: "Invalid password"])- }-- guard let saltData = salt.data(using: .utf8) else {- throw NSError(domain: "VaultStore", code: 15, userInfo: [NSLocalizedDescriptionKey: "Invalid salt"])- }-- // Use SignalArgon2 to hash the password via Argon2id- guard let derivedKeyTuple = try? Argon2.hash(- iterations: iterations,- memoryInKiB: memorySize,- threads: parallelism,- password: passwordData,- salt: saltData,- desiredLength: 32,- variant: .id,- version: .v13- ) else {+ guard let derivedKey = try? RustCoreFramework.argon2DeriveKey(password: password, salt: salt, encryptionSettings: encryptionSettings) else {throw NSError(domain: "VaultStore", code: 17, userInfo: [NSLocalizedDescriptionKey: "Argon2 hashing failed"])}- // Return only the raw Data from the tuple- return derivedKeyTuple.raw+ return derivedKey}/// Store the encryption key in memory only (no keychain persistence).diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Pin.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Pin.swiftindex c8147faac..429ec7baa 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Pin.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Pin.swift@@ -1,7 +1,7 @@import Foundationimport CryptoKitimport Security-import SignalArgon2+import RustCoreFrameworkimport VaultModelsimport VaultUtils@@ -15,6 +15,9 @@ extension VaultStore {private static let pinFailedAttemptsKey = "pinFailedAttempts"private static let maxPinAttempts = 4+ /// Argon2id cost parameters for PIN key derivation.+ private static let pinArgon2Settings = "{\"MemorySize\":65536,\"Iterations\":3,\"DegreeOfParallelism\":1}"+// MARK: - PIN Status Methods/// Check if PIN unlock is enabled@@ -169,21 +172,11 @@ extension VaultStore {throw NSError(domain: "VaultStore", code: 28, userInfo: [NSLocalizedDescriptionKey: "Failed to convert PIN to data"])}- // Use SignalArgon2 to hash PIN via Argon2id- guard let derivedKeyTuple = try? Argon2.hash(- iterations: 3,- memoryInKiB: 65536, // 64 MB- threads: 1,- password: pinData,- salt: salt,- desiredLength: 32,- variant: .id,- version: .v13- ) else {+ guard let derivedKey = try? RustCoreFramework.argon2DeriveKeyBytes(password: pinData, salt: salt, encryptionSettings: Self.pinArgon2Settings) else {throw NSError(domain: "VaultStore", code: 29, userInfo: [NSLocalizedDescriptionKey: "Argon2 PIN hashing failed"])}- return derivedKeyTuple.raw+ return derivedKey}/// Store PIN encrypted data in keychain (without biometric protection)diff --git a/core/rust/src/argon2/mod.rs b/core/rust/src/argon2/mod.rsindex e15aa2f45..14c0a3c98 100644--- a/core/rust/src/argon2/mod.rs+++ b/core/rust/src/argon2/mod.rs@@ -205,6 +205,19 @@ mod tests {assert!(matches!(Argon2Params::from_settings_json("{\"MemorySize\":\"lots\"}"), Err(Argon2Error::InvalidSettings(_))));}+ /// Known-answer vectors for the byte-salt path the mobile PIN unlock takes.+ #[test]+ fn test_known_answer_byte_salt() {+ const SALT: &[u8] = &[0x00, 0xFF, 0x80, 0x01, 0xC0, 0xAF, 0x7F, 0xFE, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80];++ let cheap = argon2_derive_key(b"123456", SALT, CHEAP).unwrap();+ assert_eq!(bytes_to_hex(&cheap), "27BA8FB75AA770D41358073B80AE7F411B1C1EC5AA25F342473BC479B721485D");++ let pin_params = Argon2Params { memory_kib: 65536, iterations: 3, parallelism: 1 };+ let pin = argon2_derive_key(b"123456", SALT, pin_params).unwrap();+ assert_eq!(bytes_to_hex(&pin), "98130FBB995A7BCE6937911146E95D92752716BF3CB0445A221C5439CB587679");+ }+/// The salt is hashed as the characters of the string, never as decoded bytes.#[test]fn test_salt_is_hashed_as_utf8_bytes() {diff --git a/core/rust/src/uniffi_api.rs b/core/rust/src/uniffi_api.rsindex 6d116908e..61415fc3e 100644--- a/core/rust/src/uniffi_api.rs+++ b/core/rust/src/uniffi_api.rs@@ -354,6 +354,24 @@ pub fn argon2_derive_key(password: String, salt: String, encryption_settings: Stcrate::argon2::argon2_derive_key_from_settings(&password, &salt, &encryption_settings)}+/// Derive a key from a password using Argon2id, taking the password and salt as raw bytes.+///+/// Note: the mobile PIN unlock draws its salt from the Keychain/Keystore as random bytes, which are+/// not valid UTF-8 and require this direct byte-salt entry point.+///+/// # Arguments+/// * `password` - The password bytes+/// * `salt` - The salt bytes, at least 8 bytes long+/// * `encryption_settings` - The `EncryptionSettings` JSON, or an empty string for the defaults+///+/// # Returns+/// The derived key as 32 bytes+#[uniffi::export]+pub fn argon2_derive_key_bytes(password: Vec<u8>, salt: Vec<u8>, encryption_settings: String) -> Result<Vec<u8>, Argon2Error> {+ let params = crate::argon2::Argon2Params::from_settings_json(&encryption_settings)?;+ crate::argon2::argon2_derive_key(&password, &salt, params)+}+// ═══════════════════════════════════════════════════════════════════════════════// SRP (Secure Remote Password) Functions// ═══════════════════════════════════════════════════════════════════════════════