π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Format Rust Markdown
Manav Rathib98df82061f7
diff --git a/rust/apps/ensu/README.md b/rust/apps/ensu/README.mdindex d3617255c3..eeaad9526f 100644--- a/rust/apps/ensu/README.md+++ b/rust/apps/ensu/README.md@@ -28,5 +28,6 @@ yarn build```## Notes+- The Tauri build uses the Ensu web app at `web/apps/ensu`.- Static export is enabled only when `ENTE_TAURI=1`.diff --git a/rust/crates/core/README.md b/rust/crates/core/README.mdindex 4a41056112..dd05a7dc10 100644--- a/rust/crates/core/README.md+++ b/rust/crates/core/README.md@@ -4,12 +4,12 @@ Common Rust code for Ente apps.## Modules-| Module | Description |-|--------|-------------|-| `auth` | Authentication helpers (signup/login/recovery, SRP credentials) |-| `crypto` | Cryptographic utilities (pure Rust, libsodium-wire-compatible) |-| `http` | HTTP client for Ente API |-| `urls` | URL construction utilities |+| Module | Description |+| -------- | --------------------------------------------------------------- |+| `auth` | Authentication helpers (signup/login/recovery, SRP credentials) |+| `crypto` | Cryptographic utilities (pure Rust, libsodium-wire-compatible) |+| `http` | HTTP client for Ente API |+| `urls` | URL construction utilities |## Auth@@ -26,16 +26,16 @@ High-level authentication helpers for Ente clients:Pure Rust cryptography, byte-compatible with JS/Dart clients.-| Submodule | Algorithm | Use Case |-|-----------|-----------|----------|-| `secretbox` | XSalsa20-Poly1305 | Encrypt keys, small data |-| `blob` | XChaCha20-Poly1305 | Encrypt metadata |-| `stream` | XChaCha20-Poly1305 | Encrypt large files (4MB chunks) |-| `sealed` | X25519 + XSalsa20-Poly1305 | Anonymous public-key encryption |-| `argon` | Argon2id | Password-based key derivation |-| `kdf` | BLAKE2b | Subkey derivation |-| `hash` | BLAKE2b | Cryptographic hashing |-| `keys` | - | Key generation |+| Submodule | Algorithm | Use Case |+| ----------- | -------------------------- | -------------------------------- |+| `secretbox` | XSalsa20-Poly1305 | Encrypt keys, small data |+| `blob` | XChaCha20-Poly1305 | Encrypt metadata |+| `stream` | XChaCha20-Poly1305 | Encrypt large files (4MB chunks) |+| `sealed` | X25519 + XSalsa20-Poly1305 | Anonymous public-key encryption |+| `argon` | Argon2id | Password-based key derivation |+| `kdf` | BLAKE2b | Subkey derivation |+| `hash` | BLAKE2b | Cryptographic hashing |+| `keys` | - | Key generation |### Quick Startdiff --git a/rust/crates/core/docs/auth.md b/rust/crates/core/docs/auth.mdindex b8e1e83136..069c6fb332 100644--- a/rust/crates/core/docs/auth.md+++ b/rust/crates/core/docs/auth.md@@ -7,10 +7,7 @@ The `auth` module provides high-level authentication operations for Ente clients- **Recovery**: Account recovery with recovery key- **SRP Login**: Client-side SRP exchange using derived credentials-SRP protocol exchange is orchestrated in the application layer (HTTP calls),-but `ente-core` provides `SrpSession` (behind the `srp` feature) to compute-SRP proofs and verify the server response. This module provides credential-derivation, SRP session helpers, and secret decryption.+SRP protocol exchange is orchestrated in the application layer (HTTP calls), but `ente-core` provides `SrpSession` (behind the `srp` feature) to compute SRP proofs and verify the server response. This module provides credential derivation, SRP session helpers, and secret decryption.## Architecture@@ -100,6 +97,7 @@ User App Server ente-core### Types#### `SrpAttributes`+Server-provided attributes for SRP authentication.```rust@@ -113,10 +111,10 @@ pub struct SrpAttributes {}```-If `is_email_mfa_enabled` is missing, clients should fall back to the email OTP-flow for safety (matching mobile/web behavior).+If `is_email_mfa_enabled` is missing, clients should fall back to the email OTP flow for safety (matching mobile/web behavior).#### `KeyAttributes`+Server-provided encrypted key material.```rust@@ -134,6 +132,7 @@ pub struct KeyAttributes {```#### `SrpCredentials`+Derived credentials for SRP authentication.```rust@@ -144,8 +143,8 @@ pub struct SrpCredentials {```#### `SrpSession`-Client-side SRP helper (requires the `srp` feature). It pads public values to-the 4096-bit group length and derives proofs as:++Client-side SRP helper (requires the `srp` feature). It pads public values to the 4096-bit group length and derives proofs as:- `M1 = H(A | B | S)`- `K = H(S)`@@ -159,6 +158,7 @@ session.verify_m2(&srp_m2)?; // optional```#### `DecryptedSecrets`+Result of successful decryption.```rust@@ -172,6 +172,7 @@ pub struct DecryptedSecrets {### Functions#### `derive_srp_credentials`+Derive both KEK and login key from password.```rust@@ -181,10 +182,10 @@ pub fn derive_srp_credentials() -> Result<SrpCredentials>```-Use `login_key` with `auth::SrpSession` to compute srpA/srpM1 (and optionally-verify srpM2). Keep `kek` for `decrypt_secrets`.+Use `login_key` with `auth::SrpSession` to compute srpA/srpM1 (and optionally verify srpM2). Keep `kek` for `decrypt_secrets`.#### `derive_kek`+Derive only the KEK (for email MFA flow).```rust@@ -197,6 +198,7 @@ pub fn derive_kek(```#### `decrypt_secrets`+Decrypt master key, secret key, and token.```rust@@ -226,15 +228,13 @@ pub enum AuthError {Ente uses Argon2id for password-based key derivation:-| Strength | Memory | Ops | Use Case |-|----------|--------|-----|----------|-| Interactive | 64 MB | 2 | Normal login |-| Moderate | 256 MB | 3 | Enhanced security |-| Sensitive | 1 GB | 4 | Maximum security |+| Strength | Memory | Ops | Use Case |+| ----------- | ------ | --- | ----------------- |+| Interactive | 64 MB | 2 | Normal login |+| Moderate | 256 MB | 3 | Enhanced security |+| Sensitive | 1 GB | 4 | Maximum security |-Sensitive derivation uses an adaptive mem/ops fallback that preserves the-same strength while reducing memory on constrained devices. The selected-`mem_limit` and `ops_limit` are stored in key attributes for other clients.+Sensitive derivation uses an adaptive mem/ops fallback that preserves the same strength while reducing memory on constrained devices. The selected `mem_limit` and `ops_limit` are stored in key attributes for other clients.The server specifies `mem_limit` and `ops_limit` in `SrpAttributes`.@@ -253,17 +253,17 @@ use ente_core::{auth, crypto};async fn login(email: &str, password: &str, api: &ApiClient) -> Result<Secrets> {// 1. Get SRP attributeslet srp_attrs = api.get_srp_attributes(email).await?;-+// 2. Check auth methodif srp_attrs.is_email_mfa_enabled {// Email MFA flowapi.send_otp(email).await?;let otp = prompt_user("Enter OTP:")?;let auth_resp = api.verify_email(email, &otp).await?;-+// Handle 2FA if requiredlet auth_resp = handle_2fa_if_needed(auth_resp, api).await?;-+// Derive KEK and decryptlet kek = auth::derive_kek(password,@@ -271,10 +271,10 @@ async fn login(email: &str, password: &str, api: &ApiClient) -> Result<Secrets>srp_attrs.mem_limit,srp_attrs.ops_limit,)?;-+let key_attrs = auth_resp.key_attributes.unwrap();let encrypted_token = auth_resp.encrypted_token.unwrap();-+auth::decrypt_secrets(&kek, &key_attrs, &encrypted_token)} else {// SRP flowdiff --git a/rust/crates/core/docs/crypto.md b/rust/crates/core/docs/crypto.mdindex fc2e99738b..c7d0727913 100644--- a/rust/crates/core/docs/crypto.md+++ b/rust/crates/core/docs/crypto.md@@ -10,20 +10,21 @@ use ente_core::crypto;crypto::init().unwrap(); // Optional (no-op for pure Rust)```-| Task | Module | Example |-|------|--------|---------|-| Encrypt keys/tokens | `secretbox` | `secretbox::encrypt(data, &key)` |-| Encrypt metadata | `blob` | `blob::encrypt(data, &key)` |-| Encrypt files | `stream` | `stream::encrypt_file(&mut src, &mut dst, None)` |-| Anonymous encrypt | `sealed` | `sealed::seal(data, &public_key)` |-| Password β Key | `argon` | `argon::derive_sensitive_key("password")` |-| Master β Subkey | `kdf` | `kdf::derive_login_key(&master_key)` |-| Hash data/files | `hash` | `hash::hash_reader(&mut file, None)` |-| Generate keys | `keys` | `keys::generate_key()` |+| Task | Module | Example |+| ------------------- | ----------- | ------------------------------------------------ |+| Encrypt keys/tokens | `secretbox` | `secretbox::encrypt(data, &key)` |+| Encrypt metadata | `blob` | `blob::encrypt(data, &key)` |+| Encrypt files | `stream` | `stream::encrypt_file(&mut src, &mut dst, None)` |+| Anonymous encrypt | `sealed` | `sealed::seal(data, &public_key)` |+| Password β Key | `argon` | `argon::derive_sensitive_key("password")` |+| Master β Subkey | `kdf` | `kdf::derive_login_key(&master_key)` |+| Hash data/files | `hash` | `hash::hash_reader(&mut file, None)` |+| Generate keys | `keys` | `keys::generate_key()` |## Common Patterns### Encrypt user data with password+```rustlet derived = argon::derive_sensitive_key("password")?;let encrypted = secretbox::encrypt(&user_data, &derived.key)?;@@ -31,6 +32,7 @@ let encrypted = secretbox::encrypt(&user_data, &derived.key)?;```### Encrypt a file+```rustlet mut src = File::open("photo.jpg")?;let mut dst = File::create("photo.enc")?;@@ -39,7 +41,9 @@ let (key, header) = stream::encrypt_file(&mut src, &mut dst, None)?;```### Encrypt a file with MD5+MD5 is computed over the encrypted output (header excluded).+```rustlet mut src = File::open("photo.jpg")?;let mut dst = File::create("photo.enc")?;@@ -48,6 +52,7 @@ let md5_b64 = crypto::encode_b64(&md5);```### Share data with public key+```rustlet sealed = sealed::seal(&secret_data, &recipient_public_key)?;// Only recipient can open with their secret key@@ -55,6 +60,7 @@ let opened = sealed::open(&sealed, &recipient_pk, &recipient_sk)?;```### Derive login key for SRP+```rustlet kek = argon::derive_key("password", &salt, mem_limit, ops_limit)?;let login_key = kdf::derive_login_key(&kek)?;@@ -62,37 +68,37 @@ let login_key = kdf::derive_login_key(&kek)?;## Dart β Rust Mapping-| Dart | Rust |-|------|------|-| `encryptSync()` / `decryptSync()` | `secretbox::encrypt()` / `decrypt_box()` |-| `encryptChaCha()` / `decryptChaCha()` | `blob::encrypt()` / `decrypt()` |-| `encryptFile()` / `decryptFile()` | `stream::encrypt_file()` / `decrypt_file()` |-| `encryptFileWithMD5()` | `stream::encrypt_file_with_md5()` |-| `sealSync()` / `openSealSync()` | `sealed::seal()` / `open()` |-| `deriveSensitiveKey()` | `argon::derive_sensitive_key_with_salt_adaptive(password.as_bytes(), &salt)` |-| `deriveInteractiveKey()` | `argon::derive_interactive_key_with_salt(password, &salt)` (`derive_interactive_key` generates salt) |-| `cryptoPwHash()` | `argon::derive_key(password, &salt, mem_limit, ops_limit)` |+| Dart | Rust |+| ----------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |+| `encryptSync()` / `decryptSync()` | `secretbox::encrypt()` / `decrypt_box()` |+| `encryptChaCha()` / `decryptChaCha()` | `blob::encrypt()` / `decrypt()` |+| `encryptFile()` / `decryptFile()` | `stream::encrypt_file()` / `decrypt_file()` |+| `encryptFileWithMD5()` | `stream::encrypt_file_with_md5()` |+| `sealSync()` / `openSealSync()` | `sealed::seal()` / `open()` |+| `deriveSensitiveKey()` | `argon::derive_sensitive_key_with_salt_adaptive(password.as_bytes(), &salt)` |+| `deriveInteractiveKey()` | `argon::derive_interactive_key_with_salt(password, &salt)` (`derive_interactive_key` generates salt) |+| `cryptoPwHash()` | `argon::derive_key(password, &salt, mem_limit, ops_limit)` || `pwhashMemLimitInteractive` / `pwhashMemLimitSensitive` / `pwhashOpsLimitInteractive` / `pwhashOpsLimitSensitive` | `argon::MEMLIMIT_INTERACTIVE`, `argon::MEMLIMIT_SENSITIVE`, `argon::OPSLIMIT_INTERACTIVE`, `argon::OPSLIMIT_SENSITIVE` |-| `deriveLoginKey()` | `kdf::derive_login_key()` |-| `getHash()` | `hash::hash_reader()` |-| `generateKey()` | `keys::generate_key()` |-| `strToBin()` | `str_to_bin(input)` |-| `base642bin()` / `bin2base64()` | `base642bin(input)` / `bin2base64(input, url_safe)` (`url_safe=false` for standard, `true` for URL-safe) |+| `deriveLoginKey()` | `kdf::derive_login_key()` |+| `getHash()` | `hash::hash_reader()` |+| `generateKey()` | `keys::generate_key()` |+| `strToBin()` | `str_to_bin(input)` |+| `base642bin()` / `bin2base64()` | `base642bin(input)` / `bin2base64(input, url_safe)` (`url_safe=false` for standard, `true` for URL-safe) |## Key Constants-| Constant | Value | Where |-|----------|-------|-------|-| `ENCRYPTION_CHUNK_SIZE` | 4 MB | stream |-| `KEY_BYTES` | 32 | all modules |-| `NONCE_BYTES` | 24 | secretbox |-| `HEADER_BYTES` | 24 | stream/blob |-| `SALT_BYTES` | 16 | argon/keys |-| `MEMLIMIT_INTERACTIVE` | 64 MB | argon |-| `MEMLIMIT_SENSITIVE` | 1 GB | argon |-| `OPSLIMIT_INTERACTIVE` | 2 | argon |-| `OPSLIMIT_SENSITIVE` | 4 | argon |-| `SEAL_OVERHEAD` | 48 | sealed |+| Constant | Value | Where |+| ----------------------- | ----- | ----------- |+| `ENCRYPTION_CHUNK_SIZE` | 4 MB | stream |+| `KEY_BYTES` | 32 | all modules |+| `NONCE_BYTES` | 24 | secretbox |+| `HEADER_BYTES` | 24 | stream/blob |+| `SALT_BYTES` | 16 | argon/keys |+| `MEMLIMIT_INTERACTIVE` | 64 MB | argon |+| `MEMLIMIT_SENSITIVE` | 1 GB | argon |+| `OPSLIMIT_INTERACTIVE` | 2 | argon |+| `OPSLIMIT_SENSITIVE` | 4 | argon |+| `SEAL_OVERHEAD` | 48 | sealed |## Wire Formatsdiff --git a/rust/crates/ensu/packaging.md b/rust/crates/ensu/packaging.mdindex bfd15283fc..40b1dbe312 100644--- a/rust/crates/ensu/packaging.md+++ b/rust/crates/ensu/packaging.md@@ -14,6 +14,7 @@ A map of Ensu related paths in the monorepo.Core rust crate is in `rust/crates/core`.Ensu specific Rust crates are in `rust/crates/ensu`+- Local chat database: `rust/crates/ensu/db`- Sync engine: `rust/crates/ensu/sync`- Inference runtime: `rust/crates/ensu/inference`@@ -23,6 +24,7 @@ Ensu specific Rust crates are in `rust/crates/ensu`Web app depends on shared WASM bindings at `web/packages/wasm`.Android and Apple native apps use UniFFI + adapters.+- Core UniFFI bindings: `rust/bindings/uniffi/core`- Ensu UniFFI bindings: `rust/bindings/uniffi/ensu`diff --git a/rust/e2e/COVERAGE.md b/rust/e2e/COVERAGE.mdindex 2bd2d11f45..55e972729f 100644--- a/rust/e2e/COVERAGE.md+++ b/rust/e2e/COVERAGE.md@@ -16,29 +16,29 @@ Shared setup and helpers:## Covered Scenarios-| Area | Covered behavior | Source |-| --- | --- | --- |-| Auth | fresh account creation for owner and trusted contact | [`tests/support/legacy.rs`](tests/support/legacy.rs), [`tests/support/auth.rs`](tests/support/auth.rs) |-| Auth | login with the initial password | [`run_auth_stage`](tests/full_e2e.rs), [`tests/support/auth.rs`](tests/support/auth.rs) |-| Auth | enable TOTP and login with TOTP | [`run_auth_stage`](tests/full_e2e.rs), [`tests/support/auth.rs`](tests/support/auth.rs) |-| Contacts | create a contact record | [`run_contacts_stage`](tests/full_e2e.rs) |-| Contacts | read back the contact record | [`run_contacts_stage`](tests/full_e2e.rs) |-| Contacts | update contact name and birth date | [`run_contacts_stage`](tests/full_e2e.rs) |-| Contacts | diff includes the created contact | [`run_contacts_stage`](tests/full_e2e.rs) |-| Contacts | contact isolation across accounts (`404` from trusted account) | [`run_contacts_stage`](tests/full_e2e.rs) |-| Contacts | delete the contact record | [`run_contacts_stage`](tests/full_e2e.rs) |-| Legacy | establish owner/trusted legacy relationship with accepted state | [`tests/support/legacy.rs`](tests/support/legacy.rs), [`tests/support/contacts.rs`](tests/support/contacts.rs) |-| Legacy | start recovery, owner rejects, recovery session disappears, accepted contact remains | [`run_legacy_reject_stage`](tests/full_e2e.rs) |-| Legacy | trusted contact stops recovery and both recovery-session views clear | [`run_legacy_stop_stage`](tests/full_e2e.rs) |-| Legacy | revoke and re-invite trusted contact back to accepted state | [`run_legacy_reinvite_stage`](tests/full_e2e.rs) |-| Legacy | full recovery flow to `READY` after owner approval | [`run_legacy_reset_stage`](tests/full_e2e.rs) |-| Recovery | recovered contact changes password through legacy recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |-| Recovery | old password login fails after recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |-| Recovery | new password login succeeds after recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |-| Recovery | recovered login keeps the same `user_id` and master key | [`run_legacy_reset_stage`](tests/full_e2e.rs) |-| Recovery | TOTP is cleared by recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |-| Recovery | recovery session is cleared after password reset | [`run_legacy_reset_stage`](tests/full_e2e.rs) |-| Recovery | legacy trusted contact remains configured after recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |+| Area | Covered behavior | Source |+| -------- | ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- |+| Auth | fresh account creation for owner and trusted contact | [`tests/support/legacy.rs`](tests/support/legacy.rs), [`tests/support/auth.rs`](tests/support/auth.rs) |+| Auth | login with the initial password | [`run_auth_stage`](tests/full_e2e.rs), [`tests/support/auth.rs`](tests/support/auth.rs) |+| Auth | enable TOTP and login with TOTP | [`run_auth_stage`](tests/full_e2e.rs), [`tests/support/auth.rs`](tests/support/auth.rs) |+| Contacts | create a contact record | [`run_contacts_stage`](tests/full_e2e.rs) |+| Contacts | read back the contact record | [`run_contacts_stage`](tests/full_e2e.rs) |+| Contacts | update contact name and birth date | [`run_contacts_stage`](tests/full_e2e.rs) |+| Contacts | diff includes the created contact | [`run_contacts_stage`](tests/full_e2e.rs) |+| Contacts | contact isolation across accounts (`404` from trusted account) | [`run_contacts_stage`](tests/full_e2e.rs) |+| Contacts | delete the contact record | [`run_contacts_stage`](tests/full_e2e.rs) |+| Legacy | establish owner/trusted legacy relationship with accepted state | [`tests/support/legacy.rs`](tests/support/legacy.rs), [`tests/support/contacts.rs`](tests/support/contacts.rs) |+| Legacy | start recovery, owner rejects, recovery session disappears, accepted contact remains | [`run_legacy_reject_stage`](tests/full_e2e.rs) |+| Legacy | trusted contact stops recovery and both recovery-session views clear | [`run_legacy_stop_stage`](tests/full_e2e.rs) |+| Legacy | revoke and re-invite trusted contact back to accepted state | [`run_legacy_reinvite_stage`](tests/full_e2e.rs) |+| Legacy | full recovery flow to `READY` after owner approval | [`run_legacy_reset_stage`](tests/full_e2e.rs) |+| Recovery | recovered contact changes password through legacy recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |+| Recovery | old password login fails after recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |+| Recovery | new password login succeeds after recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |+| Recovery | recovered login keeps the same `user_id` and master key | [`run_legacy_reset_stage`](tests/full_e2e.rs) |+| Recovery | TOTP is cleared by recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |+| Recovery | recovery session is cleared after password reset | [`run_legacy_reset_stage`](tests/full_e2e.rs) |+| Recovery | legacy trusted contact remains configured after recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |## Not Covered Yetdiff --git a/rust/e2e/README.md b/rust/e2e/README.mdindex 2cbe350473..ad5dc67aba 100644--- a/rust/e2e/README.md+++ b/rust/e2e/README.md@@ -4,9 +4,7 @@ Rust end-to-end tests that require a live Museum instance belong here.Current server-backed coverage in this crate:-- ignored stage tests that reuse shared fixtures inside one test binary:- `auth_contacts_e2e`, `legacy_contact_recovery_e2e`, and- `legacy_kit_recovery_e2e`+- ignored stage tests that reuse shared fixtures inside one test binary: `auth_contacts_e2e`, `legacy_contact_recovery_e2e`, and `legacy_kit_recovery_e2e`Detailed scenario coverage lives in [`COVERAGE.md`](COVERAGE.md).@@ -16,15 +14,13 @@ Preferred local runner:rust/e2e/scripts/run.sh```-GitHub Actions uses the same runner via-`.github/workflows/rust-e2e-test.yml`.+GitHub Actions uses the same runner via `.github/workflows/rust-e2e-test.yml`.That runner:- starts Museum in Docker with Postgres only- enables deterministic OTT for `@ente-rust-test.org`-- defaults to `http://localhost:18080` to avoid colliding with an already- running local Museum on `8080`+- defaults to `http://localhost:18080` to avoid colliding with an already running local Museum on `8080`- waits for `GET /ping`- runs this crate's ignored tests@@ -53,5 +49,4 @@ ENTE_E2E_SKIP=legacy_kit_recovery_e2e rust/e2e/scripts/run.shENTE_E2E_ONLY=legacy_contact_recovery_e2e rust/e2e/scripts/run.sh```-Attachment/object-store coverage can be added as a separate fixture later, but-it is intentionally not part of the baseline auth/recovery suite.+Attachment/object-store coverage can be added as a separate fixture later, but it is intentionally not part of the baseline auth/recovery suite.