Restoring data onto a new mobile device is an inherently vulnerable moment.
Consider what happens when you upgrade your phone:
- You sit in a crowded carrier store, coffee shop, or living room.
- A store technician or friend might be looking at the screen helping you transfer files.
- You download your finance app and select your encrypted backup file (
finledger_backup.enc). - You type your master backup passphrase to decrypt the payload.
- The database writes thousands of transactions, accounts, and secret vault records to local flash storage.
Now ask a critical security question:
What state should the application be in the exact millisecond after the restore completes?
In poorly designed applications, the restore engine navigates straight to the most recently active screen or mounts all restored data directly on the dashboard. If your backup contained a secret emergency vault, those confidential balances suddenly flash onto the screen in full view of everyone standing around you!
In FinLedger, backup and restore operates under a strict, non-negotiable security invariant:
A restored vault must unconditionally awaken in a LOCKED state.
Here is how FinLedger architected safe backup restoration (VaultBackupRestoreTest.kt, BackupRestoreManager.kt) to guarantee zero exposure during device migrations.
The Post-Restore Exposure Threat
flowchart TD
subgraph InsecureRestore["The Insecure Post-Restore Vulnerability"]
User["User Decrypts Backup on New Phone in Carrier Store"] --> Restore["Database Restores 10,000 Transactions + Secret Vault"]
Restore --> NaiveNav["Naive Navigation:
App navigates to 'Last Active Screen'
or displays 'Restored Summary: Secret Vault (Rs. 1.5L)'!"]
NaiveNav --> VisualLeak["Catastrophic Privacy Leak:
Technician or bystander sees secret emergency balance!
Secrecy destroyed on day one of new phone."]
end
The dangerous assumption is conflating Backup Decryption Authorization with Vault Access Authorization:
- Just because you entered the backup password to transfer your database does not mean you want your secret vault opened right now in a public space.
- The master ledger and the secret vault serve different security tiers.
The Hardened Restore Lifecycle (VaultBackupRestoreTest.kt)
In FinLedger, the restore engine decomposes backup ingestion into strict isolation boundaries:
flowchart TD
subgraph HardenedRestore["FinLedger Locked-State Restore Architecture"]
EncryptedFile["Encrypted Backup File (.enc)"] --> DecryptEngine["1. PBKDF2 Key Derivation & AES-256 Decryption:
Verify HMAC integrity checksum"]
DecryptEngine --> AtomicTx["2. Open Atomic SQLite withTransaction Block"]
AtomicTx --> WritePublic["3. Populate Public Tables:
accounts, transactions, categories, lending"]
AtomicTx --> WriteVault["4. Populate Isolated Vault Tables:
vault_accounts, vault_transactions, vault_transfers"]
AtomicTx --> EnforceLock["5. HARDENED LOCK ENFORCEMENT:
- Set VaultSecurityState = LOCKED
- Purge all volatile session tokens from RAM
- Unmount all vault composables"]
EnforceLock --> Commit["6. Commit Database Transaction"]
Commit --> NavPublic["7. Navigate STRICTLY to Main Public Dashboard:
Public checking accounts render normally.
Secret Vault is 100% invisible and sealed."]
end
Let's examine the specific rules that guarantee safety during restore:
1. Atomic Multi-Schema Restoration
The backup payload contains both public and vault entities, but they are restored within a single database.withTransaction block:
- If decryption fails or if the JSON payload is truncated halfway through, the entire database rolls back.
- You can never end up with public accounts restored while vault accounts are lost, or vice versa.
2. Unconditional Session Invalidation
Before the restore engine notifies the UI that the import succeeded:
- It calls
VaultSecurityManager.lockImmediately(). - Any existing in-memory session tokens, biometric ciphers, or cached coordinates are overwritten with zeros.
- The reactive
VaultSecurityStateemitsVaultSecurityState.Locked.
3. Public-Only Landing Screen
When the restore finishes:
- The app displays a clean, discreet confirmation dialog: "Data restored successfully (842 transactions imported)."
- It does not mention the existence of the secret vault.
- It navigates exclusively to the public Dashboard.
- The only way to access the restored vault is to perform the secret gesture on the new device, enter the dedicated vault passcode, and pass physical geofencing checks.
Automated Verification in Test Suites
To ensure that future UI redesigns or database schema updates can never accidentally bypass this protection, FinLedger maintains automated integration tests in VaultBackupRestoreTest.kt:
-
Test Scenario 1: Restoring an encrypted backup file containing active vault accounts and transactions asserts that
vaultSecurityManager.securityState.valueis strictlyVaultSecurityState.Locked. -
Test Scenario 2: Inspecting the navigation back-stack after restore asserts that the top-most route is
Screen.Dashboard, with zero vault routes present in memory. -
Test Scenario 3: Querying the public accounts DAO after restore asserts that vault balances contribute
0.00to the restored net worth.
Key Takeaway
Security is not just how hard your database is encrypted; it is how thoughtfully your software behaves during vulnerable transitions.
By guaranteeing that restored vaults awaken in an unconditionally locked state, FinLedger ensures that setting up a new device or recovering from a hardware failure never exposes your confidential reserves to curious eyes.
FinLedger is a privacy-first, offline-first personal finance application for Android that models bank accounts, credit cards, and cash without double-counting.
Explore FinLedger on Google Play: https://play.google.com/store/apps/details?id=com.devanshufinance.app

Top comments (0)