Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

docs(rust): Update conversion plan with completed features

Manav Rathif5347e7436bf
diff --git a/rust/CONVERSION_PLAN.md b/rust/CONVERSION_PLAN.md
index d468b87645..d06c0df2ef 100644
--- a/rust/CONVERSION_PLAN.md
+++ b/rust/CONVERSION_PLAN.md
@@ -1,199 +1,198 @@
# Ente CLI Rust Conversion Plan
## Current Status
-The foundation is complete with crypto, storage, and CLI framework. The next critical step is implementing the API client to enable authentication and data sync.
+The Rust CLI now has a **fully functional export capability** with proper file decryption! The API client, authentication flow (using stored credentials), and streaming decryption are all working. Files can be successfully exported from Ente with their original names.
-## Completed Components
+## Completed Components βœ…
+
+### Core Infrastructure
- βœ… Project structure and dependencies (libsodium-sys-stable for crypto)
-- βœ… Cryptography module (Argon2, ChaCha20-Poly1305, Blake2b KDF)
- βœ… SQLite storage layer with schema for accounts, files, collections
- βœ… Data models (Account, File, Collection, Error types)
- βœ… CLI command structure (account, export, version commands)
-## Immediate Next Step: API Client Implementation
-
-### 1. API Client Base Structure (`/rust/src/api/client.rs`)
-**Current State**: Stub with basic struct definition
-**To Do**:
-- Add token storage HashMap for multi-account support
-- Implement request builder with common headers (X-Auth-Token, X-Client-Package)
-- Add retry logic with exponential backoff for failed requests
-- Implement debug/trace logging for requests/responses
-- Add rate limiting handling (429 status codes)
-
-### 2. Request/Response Models (`/rust/src/api/models.rs`)
-Create structs matching the Go implementation:
-- `SrpAttributes` - For SRP auth setup (srpUserID, srpSalt, memLimit, opsLimit, kekSalt)
-- `CreateSrpSessionRequest/Response` - SRP session creation
-- `VerifySrpSessionRequest/Response` - SRP verification
-- `AuthResponse` - Final auth response with token and key attributes
-- `GetFilesRequest/Response` - File listing with pagination
-- `GetCollectionsResponse` - Collections/albums listing
-- `GetDiffResponse` - For incremental sync
-
-### 3. Authentication Module (`/rust/src/api/auth.rs`)
-Implement the complete SRP authentication flow:
-- `get_srp_attributes(email)` - Get SRP params for user
-- `create_srp_session(srp_user_id, client_pub)` - Start SRP
-- `verify_srp_session(srp_user_id, session_id, client_proof)` - Complete SRP
-- Key derivation from password using stored Argon2 params
-- Login key derivation using Blake2b KDF
-- Token extraction and storage
-
-### 4. API Methods (`/rust/src/api/methods.rs`)
-Core API endpoints to implement:
-- `get_user_details()` - Fetch user info
-- `get_collections(since_time)` - Fetch collections with changes
-- `get_files(limit, since_time)` - Fetch file metadata
-- `get_diff(since_time, limit)` - Get incremental changes
-- `get_file_url(file_id)` - Get download URL for file
-- `get_thumbnail_url(file_id)` - Get thumbnail URL
-
-## Remaining Major Components
-
-### 5. Account Management Commands (`/rust/src/commands/account.rs`)
-**account add**:
-- Prompt for email and password
-- Perform SRP authentication
-- Decrypt and store master key, secret key, token
-- Prompt for export directory
-- Save account to SQLite
-
-**account list**:
-- Query all accounts from SQLite
-- Display email, app type, export directory
-
-**account update**:
-- Update export directory for existing account
-- Validate directory exists and is writable
-
-### 6. Sync Engine (`/rust/src/sync/engine.rs`)
-Core sync logic:
-- Fetch remote collections and store in SQLite
-- Fetch remote files with pagination (500 per batch)
-- Track sync state with timestamps
-- Handle deleted files/collections
-- Implement incremental sync using diff API
-
-### 7. File Processing (`/rust/src/sync/files.rs`)
-- Decrypt file metadata using collection keys
-- Extract file creation time, location, type
-- Build local file path based on date/album structure
-- Check if file already exists locally (deduplication)
-- Queue files for download
-
-### 8. Download Manager (`/rust/src/sync/download.rs`)
-- Fetch file download URL from API
-- Download encrypted file to temp location
-- Decrypt file using file key (decrypt with ChaCha20-Poly1305)
-- Move to final location with proper filename
-- Handle resume for partial downloads
-- Parallel downloads with configurable concurrency
-
-### 9. Export Command (`/rust/src/commands/export.rs`)
-Main export workflow:
-- Load all configured accounts
-- For each account:
- - Load stored credentials
- - Initialize API client with token
- - Run sync engine
- - Download new/modified files
- - Create album folders and symlinks
- - Update sync timestamps
-
-### 10. Metadata Handling (`/rust/src/models/metadata.rs`)
-- Parse encrypted metadata JSON
-- Extract EXIF data (camera, location, timestamp)
-- Handle live photos (pair image + video)
-- Extract and apply file creation/modification times
-
-## Testing Strategy
-
-### Unit Tests
-- Crypto operations (compare outputs with Go implementation)
-- Storage layer CRUD operations
-- API request/response serialization
-
-### Integration Tests
-- Full authentication flow with test account
-- File download and decryption
-- Sync state management
+### Cryptography Module (`/rust/src/crypto/`)
+- βœ… Argon2 key derivation (`argon.rs`)
+- βœ… Blake2b login key derivation (`kdf.rs`)
+- βœ… XSalsa20-Poly1305 (secret_box) for key decryption (`chacha.rs`)
+- βœ… **Streaming XChaCha20-Poly1305** for file decryption (`stream.rs`)
+- βœ… Chunked decryption for large files (4MB chunks)
+- βœ… libsodium initialization and helpers
+
+### API Client (`/rust/src/api/`)
+- βœ… **Base HTTP client with token management** (`client.rs`)
+- βœ… **Request/Response models** (`models.rs`)
+ - βœ… Collection models
+ - βœ… File models with metadata
+ - βœ… User and auth response models
+- βœ… **Core API methods** (`methods.rs`)
+ - βœ… `get_collections()` - Fetch collections
+ - βœ… `get_collection_files()` - Fetch files with pagination
+ - βœ… `download_file()` - Download encrypted files
+
+### Export Command (`/rust/src/commands/export.rs`)
+- βœ… **Full export workflow implemented**
+- βœ… Load stored credentials from SQLite
+- βœ… Decrypt collection keys using master key
+- βœ… Decrypt file keys using collection keys
+- βœ… Decrypt file data using streaming XChaCha20-Poly1305
+- βœ… Decrypt and parse metadata for original filenames
+- βœ… Create date-based directory structure (YYYY/MM-Month/)
+- βœ… Skip already exported files (deduplication)
+- βœ… Progress indicators with file counts
+- βœ… Beautiful export summary with emojis
+
+### Account Management (`/rust/src/commands/account.rs`)
+- βœ… **Account list** - Display all configured accounts
+- βœ… **Account add** (partial) - Add account with stored credentials
+- βœ… Store encrypted credentials in SQLite
+
+### Metadata Handling (`/rust/src/models/metadata.rs`)
+- βœ… **Metadata decryption and parsing**
+- βœ… Extract original filenames
+- βœ… File type detection (Image, Video, LivePhoto)
+- βœ… Public metadata support
+
+## In Progress 🚧
+
+### Authentication Module (`/rust/src/api/auth.rs`)
+- ⚠️ Currently using stored tokens (not implementing full SRP flow yet)
+- Need to implement:
+ - Full SRP authentication flow
+ - Password-based key derivation
+ - Token refresh logic
+
+## Remaining Components πŸ“
+
+### Account Management Enhancements
+- [ ] **Account add with authentication**
+ - Prompt for password
+ - Perform SRP authentication
+ - Derive and store keys
+- [ ] **Account update** - Change export directory
+- [ ] **Account remove** - Delete account and credentials
+
+### Sync Engine (`/rust/src/sync/`)
+- [ ] Fix model mismatches in sync modules
+- [ ] Implement incremental sync with timestamps
+- [ ] Store sync state in SQLite
+- [ ] Handle deleted files/collections
+- [ ] Track download progress
+
+### Advanced Export Features
+- [ ] Export filters (by album, date range)
+- [ ] Shared album support
+- [ ] Hidden album handling
+- [ ] Live photos (ZIP file extraction)
+- [ ] Thumbnail generation
+- [ ] Export to different formats
+
+### API Client Enhancements
+- [ ] Retry logic with exponential backoff
+- [ ] Rate limiting (429 status codes)
+- [ ] Request/response logging
+- [ ] Error recovery
+- [ ] Connection pooling
+
+### File Processing
+- [ ] EXIF data extraction
+- [ ] Location data handling
+- [ ] Creation/modification time preservation
+- [ ] Symlink creation for albums
+- [ ] Duplicate detection by hash
+
+### Download Manager
+- [ ] Parallel downloads
+- [ ] Resume interrupted downloads
+- [ ] Bandwidth throttling
+- [ ] Progress tracking per file
+- [ ] Temp file management
+
+## Testing Status πŸ§ͺ
+
+### Successfully Tested βœ…
+- βœ… Export with real account ([email protected])
+- βœ… Small file decryption (JPEG images)
+- βœ… Large file decryption (33MB RAW file)
+- βœ… Metadata extraction for filenames
+- βœ… Date-based directory creation
+- βœ… File deduplication
### Manual Testing Checklist
-- [ ] Can authenticate with existing Ente account
-- [ ] Lists all albums/collections correctly
-- [ ] Downloads files to correct folder structure (YYYY/MM-Month/)
+- [x] Can export from existing Ente account
+- [x] Lists all albums/collections correctly
+- [x] Downloads files to correct folder structure (YYYY/MM-Month/)
+- [x] Correctly decrypts files
+- [x] Extracts original filenames from metadata
- [ ] Handles incremental sync (only new files)
- [ ] Resumes interrupted downloads
-- [ ] Multi-account support works
+- [ ] Multi-account export works
- [ ] Export filters (by album, date range) work
## Migration from Go CLI
-### Data Migration
-- BoltDB to SQLite migration tool (optional, for existing users)
-- Preserve sync state to avoid re-downloading everything
-- Migrate account credentials (re-encrypt with user confirmation)
-
-### Feature Parity Checklist
-- [ ] SRP authentication
-- [ ] Multi-account support
-- [ ] Photos export
+### Feature Parity Progress
+- [x] Multi-account support (storage)
+- [x] Photos export (basic)
+- [ ] SRP authentication (using stored tokens currently)
- [ ] Locker export
- [ ] Auth (2FA) export
-- [ ] Album organization
-- [ ] Deduplicated storage
+- [x] Album organization
+- [x] Deduplicated storage
- [ ] Incremental sync
- [ ] Export filters (albums, shared, hidden)
-## File Structure Reference
-
-```
-/home/m/p/ente/rust/src/
-β”œβ”€β”€ api/
-β”‚ β”œβ”€β”€ mod.rs
-β”‚ β”œβ”€β”€ client.rs # HTTP client with retry/auth
-β”‚ β”œβ”€β”€ models.rs # Request/response structs
-β”‚ β”œβ”€β”€ auth.rs # SRP authentication
-β”‚ └── methods.rs # API endpoint implementations
-β”œβ”€β”€ commands/
-β”‚ β”œβ”€β”€ mod.rs
-β”‚ β”œβ”€β”€ account.rs # Account management
-β”‚ └── export.rs # Export orchestration
-β”œβ”€β”€ sync/
-β”‚ β”œβ”€β”€ mod.rs
-β”‚ β”œβ”€β”€ engine.rs # Sync orchestration
-β”‚ β”œβ”€β”€ files.rs # File processing
-β”‚ └── download.rs # Download management
-└── models/
- └── metadata.rs # Metadata parsing
-
-```
+### Data Migration
+- [ ] BoltDB to SQLite migration tool
+- [ ] Preserve sync state
+- [ ] Migrate account credentials
-## Key Implementation Notes
+## Recent Achievements πŸŽ‰
+
+1. **Streaming XChaCha20-Poly1305 Implementation**
+ - Correctly implemented libsodium's secretstream API
+ - Matches Go implementation exactly
+ - Handles both small and large files
+
+2. **Chunked Decryption for Large Files**
+ - 4MB chunk size matching Go implementation
+ - Successfully tested with 33MB RAW files
+ - Memory efficient processing
+
+3. **Complete Export Flow**
+ - Collection key decryption (XSalsa20-Poly1305)
+ - File key decryption (XSalsa20-Poly1305)
+ - File data decryption (Streaming XChaCha20-Poly1305)
+ - Metadata decryption and parsing
-1. **Crypto**: All crypto operations MUST use libsodium-sys-stable
-2. **Errors**: Use proper error propagation with `?` operator
-3. **Async**: Use tokio for all async operations
-4. **Storage**: All persistent data goes through SQLite
-5. **Memory**: Use `zeroize` for sensitive data cleanup
-6. **Compatibility**: Ensure file paths work on Windows/Mac/Linux
+## Next Actions πŸš€
+
+1. **Fix sync module compilation issues**
+ - Resolve model mismatches between API and storage types
+ - Implement proper sync state tracking
+
+2. **Implement full SRP authentication**
+ - Add password prompt to account add
+ - Implement SRP protocol
+ - Store derived keys securely
+
+3. **Add export filters**
+ - Filter by album name
+ - Filter by date range
+ - Handle shared/hidden albums
+
+4. **Improve error handling**
+ - Better error messages for users
+ - Retry failed downloads
+ - Handle network interruptions
## Environment Variables
- `ENTE_CLI_CONFIG_DIR` - Override config directory location
-- `ENTE_LOG` - Set log level (debug, info, warn, error)
-
-## Dependencies to Watch
-- `libsodium-sys-stable` - Must match crypto operations with Go version
-- `rusqlite` - Bundled SQLite for portability
-- `reqwest` - Configure with proper timeouts and retry
-- `tokio` - Use current_thread runtime for CLI app
-
-## Next Action
-Start with implementing the API client base structure in `/rust/src/api/client.rs`, focusing on:
-1. Token management for multi-account
-2. Request builder with proper headers
-3. Error handling for API responses
-4. Retry logic for network failures
-
-This will unblock the authentication flow and allow testing with real Ente servers.
\ No newline at end of file
+- `ENTE_LOG` / `RUST_LOG` - Set log level (debug, info, warn, error)
+
+## Key Implementation Notes
+1. **Crypto**: Successfully using libsodium-sys-stable for all operations
+2. **Streaming**: Proper streaming XChaCha20-Poly1305 implementation
+3. **Storage**: SQLite working well for account and credential storage
+4. **Async**: Tokio runtime properly configured
+5. **Memory**: Chunked processing prevents memory issues with large files
\ No newline at end of file