Require passphrase to unlock history

This commit is contained in:
2026-09-12 16:58:22 +02:00
parent 0205df79fd
commit 5a45e7d4e1
4 changed files with 74 additions and 23 deletions

View File

@@ -16,8 +16,9 @@ Each bounded iteration must:
## Privacy and data protection
- [ ] Replace plaintext SQLite with SQLCipher-backed storage unlocked by a
manually entered passphrase; never persist the passphrase or database key.
- [x] Replace the production plaintext SQLite open path with SQLCipher-backed
storage unlocked by a manually entered passphrase; the passphrase/key is not
persisted (30 GUI-feature tests and GUI build, 2026-09-12).
- [ ] Add first-run unlock, wrong-passphrase, locked-startup, and passphrase
change flows with memory-conscious handling and no clipboard content in
errors/logs.

View File

@@ -8,7 +8,7 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};
use anyhow::Result;
use anyhow::{Context, Result};
use gtk4::prelude::*;
use gtk4::{
Application, ApplicationWindow, Box as GtkBox, Button, Entry, Label, ListBox, ListBoxRow,
@@ -69,12 +69,15 @@ const PAUSE_ICON: &str = "⏸";
const PLAY_ICON: &str = "▶";
const HELP_ICON: &str = "❓";
pub fn run(
config: Config,
database: Database,
instance: InstanceGuard,
show_on_start: bool,
) -> Result<()> {
pub fn run(config: Config, instance: InstanceGuard, show_on_start: bool) -> Result<()> {
let passphrase = prompt_for_passphrase()?;
let database = Database::open_encrypted(Database::default_path(), &passphrase)
.context("could not unlock Cliphoard history; check the passphrase")?;
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64;
database.prune_expired(now, config.history_retention_days)?;
database.trim_unpinned(config.history_limit)?;
let application = Application::new(Some("io.cliphoard.Cliphoard"), Default::default());
let clipboard_watcher = match X11ClipboardWatcher::start() {
@@ -140,6 +143,58 @@ pub fn run(
Ok(())
}
fn prompt_for_passphrase() -> Result<String> {
let application = Application::new(Some("io.cliphoard.Cliphoard.Unlock"), Default::default());
let passphrase = Rc::new(RefCell::new(None));
let result = Rc::clone(&passphrase);
application.connect_activate(move |application| {
let window = ApplicationWindow::builder()
.application(application)
.title("Unlock Cliphoard")
.default_width(420)
.default_height(140)
.build();
let content = GtkBox::new(Orientation::Vertical, 10);
content.set_margin_top(18);
content.set_margin_bottom(18);
content.set_margin_start(18);
content.set_margin_end(18);
content.append(&Label::new(Some("Enter your Cliphoard passphrase:")));
let input = Entry::new();
input.set_visibility(false);
input.set_activates_default(true);
content.append(&input);
let unlock = Button::with_label("Unlock");
unlock.set_receives_default(true);
content.append(&unlock);
window.set_child(Some(&content));
window.set_default_widget(Some(&unlock));
let application_for_unlock = application.clone();
let result_for_unlock = Rc::clone(&result);
let input_for_unlock = input.clone();
unlock.connect_clicked(move |_| {
let value = input_for_unlock.text().to_string();
if !value.is_empty() {
*result_for_unlock.borrow_mut() = Some(value);
application_for_unlock.quit();
}
});
let application_for_close = application.clone();
window.connect_close_request(move |_| {
application_for_close.quit();
glib::Propagation::Stop
});
window.present();
input.grab_focus();
});
application.run_with_args(&["cliphoard-unlock"]);
let result = passphrase
.borrow_mut()
.take()
.context("Cliphoard unlock was cancelled");
result
}
fn build_window(
application: &Application,
config: &Config,

View File

@@ -12,7 +12,6 @@ mod tray;
use anyhow::{Context, Result};
use config::Config;
use storage::Database;
fn main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
@@ -48,16 +47,9 @@ fn main() -> Result<()> {
.context("failed to start the background Cliphoard process")?;
return Ok(());
}
let database = Database::open_default()?;
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64;
database.prune_expired(now, config.history_retention_days)?;
if args.iter().any(|arg| arg == "--diagnostics") {
println!("Version: {}", env!("CARGO_PKG_VERSION"));
println!("Database: OK ({})", database.path().display());
println!("Database: locked storage (see ~/.local/share/cliphoard/cliphoard.db)");
println!("Config: OK");
println!(
"Instance: {}",
@@ -94,7 +86,7 @@ fn main() -> Result<()> {
};
#[cfg(feature = "gui")]
return gui::run(config, database, instance, show_on_start);
return gui::run(config, instance, show_on_start);
#[cfg(not(feature = "gui"))]
{

View File

@@ -16,11 +16,14 @@ pub struct Database {
}
impl Database {
pub fn open_default() -> Result<Self> {
let path = dirs::data_local_dir()
pub fn default_path() -> PathBuf {
dirs::data_local_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join("cliphoard/cliphoard.db");
Self::open(path)
.join("cliphoard/cliphoard.db")
}
pub fn open_default() -> Result<Self> {
Self::open(Self::default_path())
}
pub fn open(path: impl AsRef<Path>) -> Result<Self> {