Skip to content

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

Cleanup mobile app native logic (#2468)

Leendert de Borste2ba34ddd7a3
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/UnlockCoordinator.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/UnlockCoordinator.kt
index 0a3565aa9..e6075de59 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/UnlockCoordinator.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/UnlockCoordinator.kt
@@ -16,9 +16,6 @@ import net.aliasvault.app.vaultstore.keystoreprovider.KeystoreOperationCallback
* Centralized coordinator for handling vault unlock flow in credential provider activities.
* This coordinator manages the unlock sequence, deciding whether to use PIN or biometric
* authentication based on what's enabled.
- *
- * Similar to iOS UnlockCoordinator.swift - provides a clean separation of unlock logic
- * from the main activity flows.
*/
class UnlockCoordinator(
private val activity: FragmentActivity,
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/pinunlock/PinUnlockActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/pinunlock/PinUnlockActivity.kt
index 101ca80e5..90e26153f 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/pinunlock/PinUnlockActivity.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/pinunlock/PinUnlockActivity.kt
@@ -44,7 +44,6 @@ import net.aliasvault.app.vaultstore.VaultStore
* // Setup mode
* val intent = Intent(context, PinUnlockActivity::class.java)
* intent.putExtra(PinUnlockActivity.EXTRA_MODE, PinUnlockActivity.MODE_SETUP)
- * intent.putExtra(PinUnlockActivity.EXTRA_SETUP_ACCOUNT_KEY, accountKey)
* startActivityForResult(intent, REQUEST_CODE)
* ```
*/
@@ -66,9 +65,6 @@ class PinUnlockActivity : AppCompatActivity() {
/** Intent extra key for the mode (unlock or setup). */
const val EXTRA_MODE = "mode"
- /** Intent extra key for the Account Key the PIN protects during setup. */
- const val EXTRA_SETUP_ACCOUNT_KEY = "setup_unlock_key"
-
/** Intent extra key for custom title (optional). */
const val EXTRA_CUSTOM_TITLE = "custom_title"
@@ -97,7 +93,6 @@ class PinUnlockActivity : AppCompatActivity() {
// State
private var configuration: PinConfiguration? = null
- private var setupAccountKey: String? = null
private var currentPin: String = ""
private var isProcessing: Boolean = false
@@ -118,12 +113,11 @@ class PinUnlockActivity : AppCompatActivity() {
)
viewModel = PinViewModel(this, vaultStore)
- // Get mode and Account Key from intent
+ // Get mode from intent
val mode = when (intent.getStringExtra(EXTRA_MODE)) {
MODE_SETUP -> PinMode.SETUP
else -> PinMode.UNLOCK
}
- setupAccountKey = intent.getStringExtra(EXTRA_SETUP_ACCOUNT_KEY)
val customTitle = intent.getStringExtra(EXTRA_CUSTOM_TITLE)
val customSubtitle = intent.getStringExtra(EXTRA_CUSTOM_SUBTITLE)
@@ -427,7 +421,7 @@ class PinUnlockActivity : AppCompatActivity() {
delay(50)
// Process the PIN
- val result = viewModel.processPin(currentPin, config, setupAccountKey)
+ val result = viewModel.processPin(currentPin, config)
// Handle result
handlePinResult(result)
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/pinunlock/PinViewModel.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/pinunlock/PinViewModel.kt
index d6c9e959c..dbc9383bd 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/pinunlock/PinViewModel.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/pinunlock/PinViewModel.kt
@@ -55,11 +55,10 @@ class PinViewModel(
suspend fun processPin(
pin: String,
configuration: PinConfiguration,
- setupAccountKey: String? = null,
): PinResult = withContext(Dispatchers.IO) {
return@withContext when (configuration.mode) {
PinMode.UNLOCK -> processUnlock(pin)
- PinMode.SETUP -> processSetup(pin, configuration, setupAccountKey)
+ PinMode.SETUP -> processSetup(pin, configuration)
}
}
@@ -93,7 +92,6 @@ class PinViewModel(
private fun processSetup(
pin: String,
configuration: PinConfiguration,
- setupAccountKey: String?,
): PinResult {
return when (configuration.setupStep) {
PinSetupStep.ENTER_NEW -> {
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/LegacyKeyConversion.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/LegacyKeyConversion.kt
index ba606b1d6..57e319c0f 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/LegacyKeyConversion.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/LegacyKeyConversion.kt
@@ -26,7 +26,7 @@ internal object LegacyKeyConversion {
return
}
try {
- pin.setupPin(pinValue, accountKey)
+ pin.encryptKeyWithPin(Base64.decode(accountKey, Base64.NO_WRAP), pinValue)
} catch (e: Exception) {
Log.w(TAG, "Could not re-encrypt the PIN key, will retry on the next PIN unlock", e)
}
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.kt
index 069b20f67..98f6eb925 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
@@ -26,30 +26,6 @@ class VaultCrypto(
private const val TAG = "VaultCrypto"
private const val BIOMETRICS_AUTH_METHOD = "faceid"
- /**
- * Raw AES-GCM encryption with a caller-supplied key.
- * Encrypts data using AES-256-GCM with a provided key.
- */
- fun encrypt(data: ByteArray, key: ByteArray): ByteArray {
- require(key.size == 32) { "Encryption key must be 32 bytes (256 bits)" }
-
- // Generate a random 12-byte nonce (IV)
- val nonce = ByteArray(12)
- SecureRandom().nextBytes(nonce)
-
- // Create cipher
- val cipher = Cipher.getInstance("AES/GCM/NoPadding")
- val secretKey = SecretKeySpec(key, "AES")
- val gcmSpec = GCMParameterSpec(128, nonce) // 128-bit auth tag
-
- // Encrypt
- cipher.init(Cipher.ENCRYPT_MODE, secretKey, gcmSpec)
- val ciphertext = cipher.doFinal(data)
-
- // Return: nonce + ciphertext + tag (tag is included in ciphertext by GCM)
- return nonce + ciphertext
- }
-
/**
* Raw AES-GCM decryption with a caller-supplied key.
* Decrypts data using AES-256-GCM with a provided key.
diff --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.kt
index 7326839ea..6c563b56f 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
@@ -124,17 +124,14 @@ class VaultPin(
// MARK: - PIN Setup Methods
/**
- * Setup PIN unlock.
- * Encrypts the Account Key with the PIN and stores it securely.
+ * Encrypt the Account Key with a key derived from the PIN and keep it in secure storage.
*
+ * @param accountKey The Account Key to protect
* @param pin The PIN to set (4+ digits)
- * @param accountKeyBase64 The base64-encoded Account Key to protect
- * @throws IllegalArgumentException if PIN format is invalid
* @throws Exception if encryption or storage fails
*/
@Throws(Exception::class)
- fun setupPin(pin: String, accountKeyBase64: String) {
- val accountKey = Base64.decode(accountKeyBase64, Base64.NO_WRAP)
+ fun encryptKeyWithPin(accountKey: ByteArray, pin: String) {
val salt = pinGenerateSalt()
val encryptedKey = pinEncrypt(pin, salt, accountKey)
@@ -218,6 +215,11 @@ class VaultPin(
// Remove failed attempts counter from Keystore
removePinFailedAttemptsFromKeystore()
+ // Remove the Keystore key that encrypted both
+ if (keyStore.containsAlias(KEYSTORE_ALIAS_DATA_ENCRYPTION)) {
+ keyStore.deleteEntry(KEYSTORE_ALIAS_DATA_ENCRYPTION)
+ }
+
// Clear PIN metadata from SharedPreferences
sharedPreferences.edit().apply {
remove(PIN_ENABLED_KEY)
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
index ac00ff6f7..bbb5cd8e7 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
@@ -768,8 +768,8 @@ class VaultStore(
/**
* Resolve and store the vault key right after login from the unlock key (see VaultSync.resolveVaultKey).
*/
- suspend fun resolveVaultKey(webApiService: net.aliasvault.app.webapi.WebApiService, derivedKeyBase64: String): String {
- return sync.resolveVaultKey(webApiService, derivedKeyBase64)
+ suspend fun resolveVaultKey(webApiService: net.aliasvault.app.webapi.WebApiService, derivedKeyBase64: String) {
+ sync.resolveVaultKey(webApiService, derivedKeyBase64)
}
/**
@@ -947,11 +947,12 @@ class VaultStore(
}
/**
- * Setup PIN unlock.
+ * Setup PIN unlock with the Account Key of the unlocked session (vault must be unlocked).
*/
@Throws(Exception::class)
- fun setupPin(pinValue: String, accountKeyBase64: String) {
- pin.setupPin(pinValue, accountKeyBase64)
+ fun setupPin(pinValue: String) {
+ val accountKey = crypto.accountKey ?: error("Account Key required for PIN setup")
+ pin.encryptKeyWithPin(accountKey, pinValue)
}
/**
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/TestKeystoreProvider.kt b/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/vaultstore/keystoreprovider/TestKeystoreProvider.kt
similarity index 100%
rename from apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/TestKeystoreProvider.kt
rename to apps/mobile-app/android/app/src/test/java/net/aliasvault/app/vaultstore/keystoreprovider/TestKeystoreProvider.kt
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/TestStorageProvider.kt b/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/vaultstore/storageprovider/TestStorageProvider.kt
similarity index 100%
rename from apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/TestStorageProvider.kt
rename to apps/mobile-app/android/app/src/test/java/net/aliasvault/app/vaultstore/storageprovider/TestStorageProvider.kt
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore.swift
index 681e41ea9..e5db72a98 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore.swift
@@ -3,7 +3,6 @@ import RustCoreFramework
import UIKit
import LocalAuthentication
import CryptoKit
-import CommonCrypto
import Security
import VaultModels
import VaultUtils
diff --git a/apps/mobile-app/types/react-native-argon2.d.ts b/apps/mobile-app/types/react-native-argon2.d.ts
deleted file mode 100644
index 7e47a6a53..000000000
--- a/apps/mobile-app/types/react-native-argon2.d.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-declare module 'react-native-argon2' {
- // eslint-disable-next-line @typescript-eslint/naming-convention
- interface Argon2Options {
- iterations?: number;
- memory?: number;
- parallelism?: number;
- hashLength?: number;
- mode?: 'argon2i' | 'argon2d' | 'argon2id';
- }
-
- // eslint-disable-next-line @typescript-eslint/naming-convention
- interface Argon2Result {
- encodedHash: string;
- rawHash: string;
- }
-
- function argon2(
- password: string,
- salt: string,
- options?: Argon2Options
- ): Promise<Argon2Result>;
-
- export default argon2;
-}