Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

decouple archive encryption from sync — fully independent keys

louis030195d7a9a0739ea5
diff --git a/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx b/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx
index 8cae7e02c..731ed5345 100644
--- a/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx
@@ -116,23 +116,14 @@ export function ArchiveSettings() {
try {
if (enabled) {
- // Pass sync password if available so archive can reuse the same
- // encryption keys (avoids "set up on another device" error).
- let syncPassword: string | undefined;
- try {
- const store = await getStore();
- syncPassword = (await store.get<string>("sync_password")) ?? undefined;
- } catch {
- // best effort
- }
-
+ // Initialize archive — encryption keys are derived locally from the
+ // token, completely independent of cloud sync.
const res = await fetch("http://localhost:3030/archive/init", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
token: settings.user?.token,
retention_days: retentionDays,
- ...(syncPassword ? { password: syncPassword } : {}),
}),
});
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index c84c4f09b..1f1db8917 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "2.2.233"
+version = "2.2.234"
description = "24/7 memory for your desktop. 100% local."
authors = ["you"]
license = ""
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/sync.rs
index 617c58df5..a52ab7b7e 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/sync.rs
@@ -639,26 +639,11 @@ pub async fn auto_start_archive(app: &AppHandle) {
}
};
- // Try to get the sync password so archive can reuse the same encryption keys
- // (avoids the "encryption keys set up on another device" error).
- let sync_password = match CloudSyncSettingsStore::get(app) {
- Ok(Some(s)) if !s.encrypted_password.is_empty() => {
- match BASE64.decode(&s.encrypted_password) {
- Ok(bytes) => String::from_utf8(bytes).ok(),
- Err(_) => None,
- }
- }
- _ => None,
- };
-
let client = reqwest::Client::new();
- let mut init_request = serde_json::json!({
+ let init_request = serde_json::json!({
"token": token,
"retention_days": archive_settings.retention_days,
});
- if let Some(ref pw) = sync_password {
- init_request["password"] = serde_json::json!(pw);
- }
// Retry up to 5 times with increasing delays if the server isn't ready yet.
// The server may still be starting when this runs (15s after app launch).
diff --git a/crates/screenpipe-core/src/sync/manager.rs b/crates/screenpipe-core/src/sync/manager.rs
index 824f5a9ec..3710eefad 100644
--- a/crates/screenpipe-core/src/sync/manager.rs
+++ b/crates/screenpipe-core/src/sync/manager.rs
@@ -51,6 +51,42 @@ impl SyncManager {
Ok(is_new)
}
+ /// Initialize encryption with a locally-derived key.
+ ///
+ /// Unlike `initialize()`, this does NOT contact the cloud server for key
+ /// management. Instead it derives a deterministic master key from the
+ /// password using a fixed domain-separated salt. This makes the keys
+ /// completely independent of cloud sync's key storage.
+ ///
+ /// Used by cloud archive so it doesn't conflict with sync's encryption
+ /// keys.
+ pub async fn initialize_local(&self, password: &str) -> SyncResult<()> {
+ use super::crypto::{derive_key_from_password, KEY_SIZE, SALT_SIZE};
+ use hmac::{Hmac, Mac};
+ use sha2::Sha256;
+
+ // Fixed domain-separated salt so the same password always produces
+ // the same master key, but a different one from sync's keys.
+ const ARCHIVE_DOMAIN: &[u8] = b"screenpipe-archive-local-keys-v1";
+
+ type HmacSha256 = Hmac<Sha256>;
+ let mut mac = <HmacSha256 as Mac>::new_from_slice(ARCHIVE_DOMAIN).unwrap();
+ mac.update(password.as_bytes());
+ let domain_hash = mac.finalize().into_bytes();
+
+ let mut salt = [0u8; SALT_SIZE];
+ salt.copy_from_slice(&domain_hash[..SALT_SIZE]);
+
+ // Derive master key from password + fixed salt
+ let master_key_zeroizing = derive_key_from_password(password, &salt)?;
+ let mut master_key = [0u8; KEY_SIZE];
+ master_key.copy_from_slice(master_key_zeroizing.as_ref());
+
+ let keys = SyncKeys::from_master_key(master_key, 1);
+ *self.keys.write().await = Some(keys);
+ Ok(())
+ }
+
/// Lock the manager (clear keys from memory).
///
/// Call this when the user logs out or the app is locked.
diff --git a/crates/screenpipe-engine/src/archive.rs b/crates/screenpipe-engine/src/archive.rs
index 2993c7a8a..7c7429a04 100644
--- a/crates/screenpipe-engine/src/archive.rs
+++ b/crates/screenpipe-engine/src/archive.rs
@@ -100,10 +100,6 @@ impl Default for ArchiveConfig {
pub struct ArchiveInitRequest {
pub token: String,
pub retention_days: Option<u32>,
- /// Optional sync password — if the user has cloud sync set up, pass the
- /// sync password so archive can reuse the same encryption keys without
- /// requiring sync to be running.
- pub password: Option<String>,
}
#[derive(Debug, Serialize)]
@@ -159,89 +155,46 @@ pub async fn archive_init(
// Use persistent machine ID
let machine_id = screenpipe_core::sync::get_or_create_machine_id();
- // Reuse the sync manager if sync is already initialized (same encryption keys).
- // If sync is not initialized, derive a deterministic password from the token.
- // This works for archive-only users but will fail if sync was set up on another
- // device with a different (random) password — in that case the user must enable
- // sync first so archive can reuse its manager.
+ // Archive uses its OWN encryption keys, completely independent of cloud sync.
+ // Keys are derived deterministically from the user's token so they're
+ // consistent across restarts without needing server-side key storage.
let manager = {
- let sync_guard = state.sync_state.read().await;
- if let Some(ref sync_rt) = *sync_guard {
- info!("archive: reusing sync manager (already initialized)");
- sync_rt.manager.clone()
- } else {
- drop(sync_guard);
-
- let device_name = hostname::get()
- .map(|h| h.to_string_lossy().to_string())
- .unwrap_or_else(|_| "Unknown".to_string());
- let device_os = std::env::consts::OS.to_string();
-
- let config = SyncClientConfig::new(
- request.token.clone(),
- machine_id.clone(),
- device_name,
- device_os,
- );
-
- let mgr = SyncManager::new(config).map_err(|e| {
- error!("archive: failed to create sync manager: {}", e);
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(json!({"error": format!("failed to create sync manager: {}", e)})),
- )
- })?;
-
- // Try passwords in order:
- // 1. Sync password passed by the caller (if user has sync set up)
- // 2. Deterministic password derived from token (for archive-only users)
- let deterministic_pw = format!(
- "screenpipe-archive-{:x}",
- md5::compute(request.token.as_bytes())
- );
-
- let passwords_to_try: Vec<&str> = match &request.password {
- Some(pw) if !pw.is_empty() => vec![pw.as_str(), &deterministic_pw],
- _ => vec![&deterministic_pw],
- };
-
- let mut last_err = None;
- let mut initialized = false;
-
- for pw in &passwords_to_try {
- match mgr.initialize(pw).await {
- Ok(_) => {
- initialized = true;
- break;
- }
- Err(e) => {
- let err_str = e.to_string();
- if err_str.contains("decryption failed") || err_str.contains("authentication error") {
- info!("archive: password attempt failed (key mismatch), trying next");
- last_err = Some(e);
- } else {
- return Err((
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(json!({"error": format!("failed to initialize encryption: {}", e)})),
- ));
- }
- }
- }
- }
-
- if !initialized {
- warn!("archive: all password attempts failed");
- return Err((
- StatusCode::PRECONDITION_FAILED,
- Json(json!({"error": format!(
- "encryption key mismatch — try enabling cloud sync first in Settings → Sync, then retry archive. ({})",
- last_err.map(|e| e.to_string()).unwrap_or_default()
- )})),
- ));
- }
-
- Arc::new(mgr)
- }
+ let device_name = hostname::get()
+ .map(|h| h.to_string_lossy().to_string())
+ .unwrap_or_else(|_| "Unknown".to_string());
+ let device_os = std::env::consts::OS.to_string();
+
+ let config = SyncClientConfig::new(
+ request.token.clone(),
+ machine_id.clone(),
+ device_name,
+ device_os,
+ );
+
+ let mgr = SyncManager::new(config).map_err(|e| {
+ error!("archive: failed to create sync manager: {}", e);
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(json!({"error": format!("failed to create sync manager: {}", e)})),
+ )
+ })?;
+
+ // Derive encryption keys locally from the token — no server call,
+ // no dependency on sync's key storage.
+ let password = format!(
+ "screenpipe-archive-{:x}",
+ md5::compute(request.token.as_bytes())
+ );
+
+ mgr.initialize_local(&password).await.map_err(|e| {
+ error!("archive: failed to derive encryption keys: {}", e);
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(json!({"error": format!("failed to initialize encryption: {}", e)})),
+ )
+ })?;
+
+ Arc::new(mgr)
};
let archive_config = ArchiveConfig {