Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Centralize vault decryption logic into Rust Core
Leendert de Borst4f0208ed7dba
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 98f6eb925..00a1266aa 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@@ -8,12 +8,10 @@ import net.aliasvault.app.vaultstore.keystoreprovider.KeystoreProviderimport net.aliasvault.app.vaultstore.storageprovider.StorageProviderimport org.json.JSONObjectimport uniffi.aliasvault_core.KeyChainException-import java.security.SecureRandom-import javax.crypto.Cipher-import javax.crypto.spec.GCMParameterSpec-import javax.crypto.spec.SecretKeySpecimport uniffi.aliasvault_core.mobileLoginEncryptAccountKey as rustMobileLoginEncryptAccountKeyimport uniffi.aliasvault_core.openAccountKeyChain as rustOpenAccountKeyChain+import uniffi.aliasvault_core.vaultBlobDecrypt as rustVaultBlobDecrypt+import uniffi.aliasvault_core.vaultBlobEncrypt as rustVaultBlobEncrypt/*** Handles encryption, decryption, and key management for the vault.@@ -25,28 +23,6 @@ class VaultCrypto(companion object {private const val TAG = "VaultCrypto"private const val BIOMETRICS_AUTH_METHOD = "faceid"-- /**- * Raw AES-GCM decryption with a caller-supplied key.- * Decrypts data using AES-256-GCM with a provided key.- */- fun decrypt(encryptedData: ByteArray, key: ByteArray): ByteArray {- require(key.size == 32) { "Decryption key must be 32 bytes (256 bits)" }- require(encryptedData.size >= 12) { "Encrypted data too short" }-- // Extract nonce (first 12 bytes) and ciphertext (rest)- val nonce = encryptedData.sliceArray(0 until 12)- val ciphertext = encryptedData.sliceArray(12 until encryptedData.size)-- // Create cipher- val cipher = Cipher.getInstance("AES/GCM/NoPadding")- val secretKey = SecretKeySpec(key, "AES")- val gcmSpec = GCMParameterSpec(128, nonce)-- // Decrypt- cipher.init(Cipher.DECRYPT_MODE, secretKey, gcmSpec)- return cipher.doFinal(ciphertext)- }}/**@@ -309,16 +285,9 @@ class VaultCrypto(// region Encryption/Decryption/**- * Decrypt data to text.- */- fun decryptData(encryptedData: String, authMethods: String): String {- return String(decryptDataBytes(encryptedData, authMethods), Charsets.UTF_8)- }-- /**- * Decrypt data to raw bytes.+ * Decrypt the stored vault blob (base64) into the SQLite database bytes. This can trigger biometric authentication.*/- fun decryptDataBytes(encryptedData: String, authMethods: String): ByteArray {+ fun decryptVaultBlob(encryptedBlob: String, authMethods: String): ByteArray {var decryptedResult: ByteArray? = nullvar error: Exception? = null@@ -328,18 +297,7 @@ class VaultCrypto(object : CryptoOperationCallback {override fun onSuccess(result: String) {try {- val decoded = Base64.decode(encryptedData, Base64.NO_WRAP)-- val iv = decoded.copyOfRange(0, 12)- val encryptedContent = decoded.copyOfRange(12, decoded.size)-- val cipher = Cipher.getInstance("AES/GCM/NoPadding")- val keySpec = SecretKeySpec(encryptionKey!!, "AES")- val gcmSpec = GCMParameterSpec(128, iv)-- cipher.init(Cipher.DECRYPT_MODE, keySpec, gcmSpec)-- decryptedResult = cipher.doFinal(encryptedContent)+ decryptedResult = rustVaultBlobDecrypt(encryptedBlob, encryptionKey!!)} catch (e: Exception) {error = AppError.VaultDecryptFailed(cause = e)Log.e(TAG, "Error decrypting data", e)@@ -364,37 +322,10 @@ class VaultCrypto(}/**- * Encrypt text.+ * Encrypt the SQLite database bytes into the stored vault blob (base64).*/- fun encryptData(data: String): String {- return encryptBytes(data.toByteArray(Charsets.UTF_8))- }-- /**- * Encrypt raw bytes.- */- fun encryptBytes(data: ByteArray): String {- try {- val iv = ByteArray(12)- SecureRandom().nextBytes(iv)-- val cipher = Cipher.getInstance("AES/GCM/NoPadding")- val keySpec = SecretKeySpec(encryptionKey!!, "AES")- val gcmSpec = GCMParameterSpec(128, iv)-- cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmSpec)-- val encrypted = cipher.doFinal(data)-- val result = ByteArray(iv.size + encrypted.size)- System.arraycopy(iv, 0, result, 0, iv.size)- System.arraycopy(encrypted, 0, result, iv.size, encrypted.size)-- return Base64.encodeToString(result, Base64.NO_WRAP)- } catch (e: Exception) {- Log.e(TAG, "Error encrypting data", e)- throw e- }+ fun encryptVaultBlob(sqliteBytes: ByteArray): String {+ return rustVaultBlobEncrypt(sqliteBytes, encryptionKey!!)}// endregiondiff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultDatabase.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultDatabase.ktindex 3277e736b..335b42b7a 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultDatabase.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultDatabase.kt@@ -1,6 +1,5 @@package net.aliasvault.app.vaultstore-import android.util.Base64import android.util.Logimport net.aliasvault.app.rustcore.JnaInitializerimport net.aliasvault.app.vaultstore.models.VaultMutationScope@@ -56,7 +55,7 @@ class VaultDatabase(* Unlock the vault. This can trigger biometric authentication.*/fun unlockVault(authMethods: String) {- val decrypted = crypto.decryptDataBytes(getEncryptedDatabase(), authMethods)+ val decrypted = crypto.decryptVaultBlob(getEncryptedDatabase(), authMethods)try {open(decrypted)} catch (e: Exception) {@@ -78,21 +77,9 @@ class VaultDatabase(fun isOpen(): Boolean = db != null/**- * Open the decrypted vault in memory. The plaintext is either the raw SQLite bytes- * or base64 text of them (legacy pre-0.31.0).+ * Open the decrypted SQLite database bytes in memory.*/- private fun open(decrypted: ByteArray) {- val bytes = if (isSqliteDatabase(decrypted)) {- decrypted- } else {- try {- Base64.decode(String(decrypted, Charsets.UTF_8), Base64.NO_WRAP)- } catch (e: Exception) {- Log.e(TAG, "Failed to decode base64 data after decryption", e)- throw AppError.Base64DecodeFailed(cause = e)- }- }-+ private fun open(bytes: ByteArray) {close()JnaInitializer.ensureInitialized()db = try {@@ -209,7 +196,7 @@ class VaultDatabase(// End any open transactions.try { connection.executeBatch("END") } catch (_: Exception) {}try {- storeEncryptedDatabase(crypto.encryptBytes(export()))+ storeEncryptedDatabase(crypto.encryptVaultBlob(export()))} catch (e: Exception) {Log.e(TAG, "Error exporting and encrypting database", e)throw e@@ -237,12 +224,4 @@ class VaultDatabase(db?.destroy()db = null}-- /**- * Whether these plaintext bytes are a SQLite database rather than base64 text of one.- */- private fun isSqliteDatabase(bytes: ByteArray): Boolean {- val header = "SQLite format 3\u0000".toByteArray(Charsets.UTF_8)- return bytes.size >= header.size && header.indices.all { bytes[it] == header[it] }- }}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.ktindex 4651811f7..39cbdd92b 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@@ -21,10 +21,11 @@ import uniffi.aliasvault_core.ItemUsageActionimport uniffi.aliasvault_core.VaultExceptionimport uniffi.aliasvault_core.VaultItemimport uniffi.aliasvault_core.accountSigningKeyFingerprint-import uniffi.aliasvault_core.decryptManifestInvitationName as rustDecryptManifestInvitationNameimport java.util.Dateimport java.util.UUIDimport kotlin.coroutines.resume+import uniffi.aliasvault_core.decryptManifestInvitationName as rustDecryptManifestInvitationName+import uniffi.aliasvault_core.vaultBlobDecrypt as rustVaultBlobDecrypt/*** The vault store that manages the encrypted vault and all input/output operations on it.@@ -334,11 +335,7 @@ class VaultStore(val vaultEncryptionKey = crypto.openAccountKeyChain(derivedKey).vaultEncryptionKey// Try to decrypt the vault to verify the password is correct- val encryptedDb = database.getEncryptedDatabase()- val encryptedDbBytes = android.util.Base64.decode(encryptedDb, android.util.Base64.NO_WRAP)-- // Attempt decryption to verify password is correct- VaultCrypto.decrypt(encryptedDbBytes, vaultEncryptionKey)+ rustVaultBlobDecrypt(database.getEncryptedDatabase(), vaultEncryptionKey)// If decryption succeeded, return the unlock key as base64android.util.Base64.encodeToString(derivedKey, android.util.Base64.NO_WRAP)diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swiftindex 6884c6e1c..f3a57bf1f 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift@@ -1,5 +1,4 @@import Foundation-import CryptoKitimport LocalAuthenticationimport Securityimport RustCoreFramework@@ -178,15 +177,10 @@ extension VaultStore {let vaultEncryptionKey = try openAccountKeyChain(with: derivedKey).vaultEncryptionKey// Try to decrypt the vault to verify the password is correct- guard let encryptedDbBase64 = getEncryptedDatabase(),- let encryptedDbData = Data(base64Encoded: encryptedDbBase64, options: .ignoreUnknownCharacters) else {+ guard let encryptedDbBase64 = getEncryptedDatabase() else {return nil}-- // Test decryption- let key = SymmetricKey(data: vaultEncryptionKey)- let sealedBox = try AES.GCM.SealedBox(combined: encryptedDbData)- _ = try AES.GCM.open(sealedBox, using: key)+ _ = try RustCoreFramework.vaultBlobDecrypt(encryptedBlob: encryptedDbBase64, key: vaultEncryptionKey)// If decryption succeeded, return the unlock key as base64return derivedKey.base64EncodedString()@@ -196,23 +190,16 @@ extension VaultStore {}}- /// Encrypt the data using the encryption key- internal func encrypt(data: Data) throws -> Data {- let encryptionKey = try getEncryptionKey()-- let key = SymmetricKey(data: encryptionKey)- let sealedBox = try AES.GCM.seal(data, using: key)- return sealedBox.combined!+ /// Encrypt the SQLite database bytes into the stored vault blob (base64) with the encryption key.+ internal func encryptVaultBlob(_ sqliteBytes: Data) throws -> String {+ return try RustCoreFramework.vaultBlobEncrypt(sqliteBytes: sqliteBytes, key: try getEncryptionKey())}- /// Decrypt the data using the encryption key- internal func decrypt(data: Data) throws -> Data {+ /// Decrypt the stored vault blob (base64) into the SQLite database bytes with the encryption key.+ internal func decryptVaultBlob(_ encryptedBlob: String) throws -> Data {let encryptionKey = try getEncryptionKey()-- let key = SymmetricKey(data: encryptionKey)- let sealedBox = try AES.GCM.SealedBox(combined: data)do {- let decryptedData = try AES.GCM.open(sealedBox, using: key)+ let decryptedData = try RustCoreFramework.vaultBlobDecrypt(encryptedBlob: encryptedBlob, key: encryptionKey)/** If the decryption succeeds, try to persist the Account Key in the keychain.diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Database.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Database.swiftindex 91e20f07f..43c91c2b1 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Database.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Database.swift@@ -32,13 +32,8 @@ extension VaultStore {throw AppError.encryptionKeyNotFound}- guard let encryptedDbData = Data(base64Encoded: encryptedDbBase64, options: .ignoreUnknownCharacters) else {- throw AppError.base64DecodeFailed- }-do {- let decrypted = try decrypt(data: encryptedDbData)- try setupDatabaseWithDecryptedData(decrypted)+ try openDatabase(try decryptVaultBlob(encryptedDbBase64))loadedVaultStamp = stamp} catch let vaultError as AppError {// Pass through AppError types@@ -77,23 +72,8 @@ extension VaultStore {return containerURL.appendingPathComponent(VaultConstants.encryptedDbFileName)}- /// The bytes every SQLite database file begins with.- private static let sqliteHeader = Data("SQLite format 3\0".utf8)-- /// Setup the database connection with the decrypted data.- private func setupDatabaseWithDecryptedData(_ decrypted: Data) throws {- // Step 1: Take the SQLite bytes as-is, or decode the legacy base64 text.- let decryptedDbData: Data- if decrypted.starts(with: Self.sqliteHeader) {- decryptedDbData = decrypted- } else {- guard let decoded = Data(base64Encoded: decrypted, options: .ignoreUnknownCharacters) else {- throw AppError.base64DecodeFailed- }- decryptedDbData = decoded- }-- // Step 2: Open the bytes in the Rust core's memory directly without persisting to the filesystem.+ /// Open the decrypted SQLite database bytes in the Rust core's memory, without persisting them to the filesystem.+ private func openDatabase(_ decryptedDbData: Data) throws {self.dbConnection = nildo {let opened = try SqliteMemoryDatabase.fromBytes(bytes: decryptedDbData)diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swiftindex e3f87f4fb..4ec7f04c0 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift@@ -53,8 +53,7 @@ extension VaultStore {let database = try requireDatabase()// End any open transactions._ = try? database.executeBatch(sql: "END")- let encrypted = try encrypt(data: try exportDatabase())- try storeEncryptedDatabase(encrypted.base64EncodedString())+ try storeEncryptedDatabase(try encryptVaultBlob(try exportDatabase()))}/// The database as SQLite file bytes.diff --git a/core/client/src/crypto/VaultBlob.ts b/core/client/src/crypto/VaultBlob.tsindex d7184ef5c..59bc239f2 100644--- a/core/client/src/crypto/VaultBlob.ts+++ b/core/client/src/crypto/VaultBlob.ts@@ -1,5 +1,7 @@/*** The locally stored vault blob: AES-GCM over the raw bytes of the SQLite database.+ * Runs on WebCrypto for performance reasons because wasm AES-GCM has no hardware acceleration.+ * Other platform implementations: core/rust/src/crypto/vault_blob.rs (iOS and Android through uniffi).*/import { base64ToBytes } from '../utilities/Base64';diff --git a/core/rust/.cargo/config.toml b/core/rust/.cargo/config.tomlindex 645d25df7..9af439ac7 100644--- a/core/rust/.cargo/config.toml+++ b/core/rust/.cargo/config.toml@@ -1,3 +1,8 @@# getrandom 0.3 config[target.wasm32-unknown-unknown]rustflags = ['--cfg', 'getrandom_backend="wasm_js"']++# Hardware AES and GHASH (ARMv8 crypto extensions) in the aes and polyval crates, which use software otherwise.+# Android and macOS detect the CPU feature at runtime; iOS targets enable the `aes` target feature at compile time.+[target.'cfg(target_arch = "aarch64")']+rustflags = ['--cfg', 'aes_armv8', '--cfg', 'polyval_armv8']diff --git a/core/rust/src/bindings/uniffi_api.rs b/core/rust/src/bindings/uniffi_api.rsindex 3c40f090c..a59c0f11c 100644--- a/core/rust/src/bindings/uniffi_api.rs+++ b/core/rust/src/bindings/uniffi_api.rs@@ -205,6 +205,18 @@ pub fn symmetric_encrypt_bytes(plaintext: Vec<u8>, key_base64: String) -> Resultcrate::crypto::symmetric_encrypt_raw_with_aad(&plaintext, &key_base64, &[])}+/// Encrypt the SQLite database bytes into the locally stored vault blob (base64) under the raw 32-byte VEK.+#[uniffi::export]+pub fn vault_blob_encrypt(sqlite_bytes: Vec<u8>, key: Vec<u8>) -> Result<String, VaultError> {+ crate::crypto::vault_blob_encrypt(&sqlite_bytes, &zeroize::Zeroizing::new(crate::common::encoding::base64_encode(&key)))+}++/// Decrypt the locally stored vault blob (base64) into the SQLite database bytes under the raw 32-byte VEK.+#[uniffi::export]+pub fn vault_blob_decrypt(encrypted_blob: String, key: Vec<u8>) -> Result<Vec<u8>, VaultError> {+ crate::crypto::vault_blob_decrypt(&encrypted_blob, &zeroize::Zeroizing::new(crate::common::encoding::base64_encode(&key)))+}+/// The fingerprint of the account's own signing key, derived from its private key encrypted with the Account Key.#[uniffi::export]pub fn account_signing_key_fingerprint(encrypted_signing_private_key: String, account_key: Vec<u8>) -> Result<String, VaultError> {diff --git a/core/rust/src/crypto/mod.rs b/core/rust/src/crypto/mod.rsindex 1a353a7e5..f9227996a 100644--- a/core/rust/src/crypto/mod.rs+++ b/core/rust/src/crypto/mod.rs@@ -10,6 +10,7 @@//! - [`signing`]: Ed25519 (`ed25519-dalek`) account signatures over grants, public keys and invitation names.//! - [`srp`]: SRP-6a client (`srp`, SHA-256, 2048-bit group); login without sending the password.//! - [`tokens`]: the algorithm, key-type and KDF tokens stored or sent on the wire.+//! - [`vault_blob`]: the locally stored vault, AES-256-GCM over the SQLite database bytes.//!//! Randomness comes from `getrandom` via `common::rng`; `rsa` and `p256` use `rand_core` `OsRng`.@@ -23,6 +24,7 @@ pub mod rsa_oaep;pub mod signing;pub mod srp;pub mod tokens;+pub mod vault_blob;pub use aes_gcm::{generate_key_base64, symmetric_decrypt, symmetric_decrypt_bytes, symmetric_decrypt_bytes_with_aad, symmetric_decrypt_with_aad, symmetric_encrypt, symmetric_encrypt_bytes,@@ -35,4 +37,5 @@ pub use key_chain::{pub use pin::{pin_decrypt, pin_encrypt, pin_generate_salt, pin_is_locked, pin_register_failure, PinFailure};pub use rsa_oaep::{decrypt_manifest_invitation_name, decrypt_with_private_key, decrypt_with_private_key_and_label, encrypt_with_public_key_and_label, generate_rsa_key_pair, RsaKeyPair};pub use signing::generate_signing_key_pair;+pub use vault_blob::{vault_blob_decrypt, vault_blob_encrypt};diff --git a/core/rust/src/crypto/vault_blob.rs b/core/rust/src/crypto/vault_blob.rsnew file mode 100644index 000000000..b8fba6e55--- /dev/null+++ b/core/rust/src/crypto/vault_blob.rs@@ -0,0 +1,30 @@+//! The locally stored vault blob: base64 of AES-256-GCM `IV | ciphertext | tag` (no AAD) over the SQLite database bytes.+//!+//! The mobile apps call these through uniffi. The web app and the browser extension keep their own WebCrypto copy+//! (`core/client/src/crypto/VaultBlob.ts`) because wasm AES-GCM has no hardware acceleration.++use crate::common::encoding::base64_decode;+use crate::common::error::{VaultError, VaultResult};++use super::aes_gcm::{symmetric_decrypt_bytes, symmetric_encrypt_bytes};++/// The bytes every SQLite database file begins with. Base64 text cannot start with them (the space is not in its alphabet).+const SQLITE_HEADER: &[u8] = b"SQLite format 3\0";++/// Encrypt a plaintext SQLite database for local storage.+pub fn vault_blob_encrypt(sqlite_bytes: &[u8], key_base64: &str) -> VaultResult<String> {+ symmetric_encrypt_bytes(sqlite_bytes, key_base64)+}++/// Decrypt a stored vault blob into the SQLite database bytes. Also reads the base64 text of the database that builds+/// before 0.31.0 stored; the next write converts such a vault.+pub fn vault_blob_decrypt(encrypted_blob: &str, key_base64: &str) -> VaultResult<Vec<u8>> {+ let plaintext = symmetric_decrypt_bytes(&base64_decode(encrypted_blob.trim())?, key_base64)?;+ if plaintext.starts_with(SQLITE_HEADER) {+ return Ok(plaintext);+ }+ let not_a_database = || VaultError::General("vault blob plaintext is neither a database nor base64 text".to_string());+ let text = String::from_utf8(plaintext).map_err(|_| not_a_database())?;+ base64_decode(text.trim()).map_err(|_| not_a_database())+}+diff --git a/core/rust/src/vault_sync/state.rs b/core/rust/src/vault_sync/state.rsindex 99cef74ae..2a237bbc7 100644--- a/core/rust/src/vault_sync/state.rs+++ b/core/rust/src/vault_sync/state.rs@@ -233,22 +233,12 @@ pub(crate) async fn mark_clean(host: &Host, mutation_seq_at_start: u64) -> SyncROk(outcome.cleared)}-/// The bytes every SQLite database file begins with (the file header).-const SQLITE_HEADER: &[u8] = b"SQLite format 3\0";-/// Decrypt a stored vault blob into the plaintext SQLite database.pub(crate) fn decrypt_vault_blob(encrypted_blob: &str, key: &str) -> SyncResult<Vec<u8>> {- let ciphertext = crate::common::encoding::base64_decode(encrypted_blob)?;- let plaintext = crypto::symmetric_decrypt_bytes(&ciphertext, key).map_err(|e| SyncError::VaultDecryptFailed(e.to_string()))?;- if plaintext.starts_with(SQLITE_HEADER) {- return Ok(plaintext);- }- let not_a_database = || SyncError::VaultDecryptFailed("plaintext is neither a database nor base64 text".to_string());- let text = String::from_utf8(plaintext).map_err(|_| not_a_database())?;- crate::common::encoding::base64_decode(text.trim()).map_err(|_| not_a_database())+ crypto::vault_blob_decrypt(encrypted_blob, key).map_err(|e| SyncError::VaultDecryptFailed(e.to_string()))}/// Encrypt a plaintext SQLite database for local storage.pub(crate) fn encrypt_vault_blob(sqlite_bytes: &[u8], key: &str) -> SyncResult<String> {- Ok(crypto::symmetric_encrypt_bytes(sqlite_bytes, key)?)+ Ok(crypto::vault_blob_encrypt(sqlite_bytes, key)?)}diff --git a/docs/docs/security-whitepaper.mdx b/docs/docs/security-whitepaper.mdxindex ff4e67a96..53e1aa448 100644--- a/docs/docs/security-whitepaper.mdx+++ b/docs/docs/security-whitepaper.mdx@@ -31,7 +31,7 @@ AliasVault is a password and email alias manager with end-to-end encryption. It- **Server**: a .NET API, an admin portal, an SMTP service and a task runner, backed by PostgreSQL. The server stores encrypted vaults and emails, routes mail to aliases, authenticates users and keeps the metadata needed to do so.- **Clients**: a web app, browser extensions (Chrome, Firefox, Edge, Safari) and native iOS and Android apps.-- **Rust core**: one library, compiled to WebAssembly for the web app and browser extensions, and to native libraries for iOS and Android. This core implements key derivation, key encryption, signing, SRP, the vault format, sync and merge, passkeys and the email parser. Every client runs the same cryptographic code.+- **Rust core**: one library, compiled to WebAssembly for the web app and browser extensions, and to native libraries for iOS and Android. This core implements key derivation, key encryption, signing, SRP, the vault format, sync and merge, passkeys and the email parser. Every client runs the same cryptographic code, except the browser based apps which use WebCrypto for AES-256-GCM on the local vault and emails in order to benefit from hardware acceleration.All of it is open source under the AGPL-3.0 license in one repository: [github.com/aliasvault/aliasvault](https://github.com/aliasvault/aliasvault). The same code runs as AliasVault Cloud ([app.aliasvault.com](https://app.aliasvault.com)), operated by the AliasVault team, and as self-hosted instances. In this document "the server" means whichever of the two a user's clients talk to, and "the server operator" means the party running it; the threat model treats the server as untrusted in both cases.@@ -242,7 +242,7 @@ Your vaults are always encrypted on your device before they are uploaded. Each v- The encryption key is the vault's VEK (see [Key hierarchy](#41-key-hierarchy)), not the master password itself- Each manifest is encrypted with the VEK of its vault and bound to its manifest id, so the server cannot swap one vault's data for another's. Data that changes often, such as UI settings and usage statistics, is kept in separate *data buckets* that sync on their own, so a small change like a different sort order does not require uploading all items again; how a vault is split into manifests, data buckets and blobs is described in [Vault Format and Sync](./security-architecture/vault-format.mdx#the-storage-format).- Some content, such as the bytes of attachments and logos, is stored outside the manifest as separate blobs, each encrypted with its own random blob key; the blob key is encrypted with the VEK of the vault the blob belongs to. A blob is addressed by `HMAC-SHA256(manifest salt, plaintext)`, where the manifest salt is a random value that lives inside the encrypted manifest, so the server cannot recognize the same file across vaults while every member of a shared vault computes the same address-- On the device, the vault is only decrypted in memory while it is unlocked. The copy kept on disk stays encrypted with the VEK, together with the encrypted key hierarchy, so a device can unlock offline+- On the device, the vault is only decrypted in memory while it is unlocked. The copy kept on disk stays encrypted with the VEK (AES-256-GCM over the SQLite database), together with the encrypted key hierarchy, so a device can unlock offline. The mobile apps encrypt it with the Rust core; the web app and browser extensions use WebCrypto for speed, in the same format- The server keeps a limited number of older versions of each manifest and data bucket as a backup against potential client-side data corruption; a key rotation deletes the personal vault's older versions ([4.2](#42-key-rotation)). Blobs never change; a blob is deleted once no kept version refers to it anymore## 7. Email@@ -516,6 +516,7 @@ Where each part of this document lives in the repository, for reviewers.| Ed25519 signing and verification | `core/rust/src/crypto/signing.rs`, `apps/server/Utilities/AliasVault.Cryptography/Signing.cs` || Key rotation | `core/rust/src/crypto/key_chain.rs`, `core/rust/src/crypto/signing.rs`, `core/rust/src/vault_sync/rotation.rs`, `apps/server/AliasVault.Api/Controllers/V2/KeyRotationController.cs` || PIN encryption and attempt policy | `core/rust/src/crypto/pin.rs` |+| Local vault copy | `core/rust/src/crypto/vault_blob.rs` (mobile), `core/client/src/crypto/VaultBlob.ts` (web app and extensions, WebCrypto) || Vault format: canonicalize, materialize, integrity | `core/rust/src/vault_codec/` || Sync engine: pull, push, grants, sharing, delivery keys | `core/rust/src/vault_sync/` || Merge of concurrent changes | `core/rust/src/vault_merge/` |