Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Updates tests (#2159)

Leendert de Borste93c6e48e663
diff --git a/apps/mobile-app/android/app/src/androidTest/java/net/aliasvault/app/TestUserRegistration.kt b/apps/mobile-app/android/app/src/androidTest/java/net/aliasvault/app/TestUserRegistration.kt
index 95aa07b06..4d5d61848 100644
--- a/apps/mobile-app/android/app/src/androidTest/java/net/aliasvault/app/TestUserRegistration.kt
+++ b/apps/mobile-app/android/app/src/androidTest/java/net/aliasvault/app/TestUserRegistration.kt
@@ -9,7 +9,7 @@ import net.aliasvault.app.vaultstore.models.VaultSql
import net.aliasvault.app.vaultstore.models.VaultVersions
import org.json.JSONArray
import org.json.JSONObject
-import uniffi.aliasvault_core.argon2HashPassword
+import uniffi.aliasvault_core.argon2DeriveKey
import uniffi.aliasvault_core.srpDerivePrivateKey
import uniffi.aliasvault_core.srpDeriveVerifier
import uniffi.aliasvault_core.srpGenerateSalt
@@ -89,18 +89,6 @@ object TestUserRegistration {
fun bytesToHex(data: ByteArray): String =
data.joinToString("") { "%02X".format(it) }
- /**
- * Convert hex string to ByteArray.
- */
- fun hexToBytes(hex: String): ByteArray {
- val cleanHex = hex.removePrefix("0x").removePrefix("0X").trim()
- require(cleanHex.length % 2 == 0) { "Invalid hex string length" }
-
- return ByteArray(cleanHex.length / 2) { i ->
- cleanHex.substring(i * 2, i * 2 + 2).toInt(16).toByte()
- }
- }
-
// endregion
// region Registration
@@ -120,8 +108,9 @@ object TestUserRegistration {
// Generate salt using Rust core
val salt = srpGenerateSalt()
- // Derive key from password using Rust core Argon2
- val passwordHashHex = argon2HashPassword(password, salt)
+ // Derive key from password using Rust core Argon2, against the parameters the request declares
+ val encryptionKey = argon2DeriveKey(password, salt, TestConfiguration.EncryptionDefaults.settingsJson)
+ val passwordHashHex = bytesToHex(encryptionKey)
// Derive SRP private key and verifier using Rust core
val privateKey = srpDerivePrivateKey(salt, normalizedUsername, passwordHashHex)
@@ -165,7 +154,6 @@ object TestUserRegistration {
)
// Upload initial empty vault
- val encryptionKey = hexToBytes(passwordHashHex)
uploadInitialVault(
apiBaseUrl = apiBaseUrl,
token = tokenResponse.token,
diff --git a/apps/mobile-app/ios/AliasVaultUITests/TestUserRegistration.swift b/apps/mobile-app/ios/AliasVaultUITests/TestUserRegistration.swift
index 113c2a91d..f6c4377c5 100644
--- a/apps/mobile-app/ios/AliasVaultUITests/TestUserRegistration.swift
+++ b/apps/mobile-app/ios/AliasVaultUITests/TestUserRegistration.swift
@@ -74,17 +74,15 @@ enum TestUserRegistration {
/// Derive encryption key from password using Argon2Id via Rust core.
///
- /// Uses the AliasVault default parameters:
- /// - Iterations: 2
- /// - Memory: 19456 KiB
- /// - Parallelism: 1
- /// - Output length: 32 bytes
+ /// Derives against the same parameters the registration request declares, so the account can be
+ /// opened again with the settings the server stored for it.
static func deriveKeyArgon2(_ password: String, salt: String) throws -> Data {
// Use the Rust core's Argon2 implementation
- let hashHex = try argon2HashPassword(password: password, salt: salt)
-
- // Convert hex string to Data
- return try hexToBytes(hashHex)
+ return try argon2DeriveKey(
+ password: password,
+ salt: salt,
+ encryptionSettings: EncryptionDefaults.settingsJson
+ )
}
// MARK: - Hex Conversion
@@ -94,32 +92,6 @@ enum TestUserRegistration {
return data.map { String(format: "%02X", $0) }.joined()
}
- /// Convert hex string to Data.
- static func hexToBytes(_ hex: String) throws -> Data {
- var hex = hex.trimmingCharacters(in: .whitespaces)
- if hex.hasPrefix("0x") || hex.hasPrefix("0X") {
- hex = String(hex.dropFirst(2))
- }
-
- guard hex.count % 2 == 0 else {
- throw NSError(domain: "TestUserRegistration", code: 3,
- userInfo: [NSLocalizedDescriptionKey: "Invalid hex string length"])
- }
-
- var data = Data()
- var index = hex.startIndex
- while index < hex.endIndex {
- let nextIndex = hex.index(index, offsetBy: 2)
- guard let byte = UInt8(hex[index..<nextIndex], radix: 16) else {
- throw NSError(domain: "TestUserRegistration", code: 4,
- userInfo: [NSLocalizedDescriptionKey: "Invalid hex character"])
- }
- data.append(byte)
- index = nextIndex
- }
- return data
- }
-
// MARK: - Registration
/// Register a new test user via the API using SRP protocol.