Add confirmed plaintext history migration

This commit is contained in:
2026-09-12 17:01:41 +02:00
parent bf403a9e3b
commit 937880fb59
3 changed files with 49 additions and 4 deletions

View File

@@ -22,9 +22,10 @@ Each bounded iteration must:
- [ ] Add first-run unlock, wrong-passphrase, locked-startup, and passphrase
change flows with memory-conscious handling and no clipboard content in
errors/logs.
- [ ] Migrate existing plaintext history only after explicit user confirmation,
- [x] Migrate existing plaintext history only after explicit user confirmation,
verify encrypted output, and document that old copies/backups remain
separately exposed until removed.
separately exposed until removed (31 GUI-feature tests and GUI build,
2026-09-12).
- [ ] Add black-box checks proving a copied database cannot be opened without
the passphrase and that the running app can read/write it after unlock.

View File

@@ -110,4 +110,9 @@ Runtime files follow XDG conventions:
- configuration: `~/.config/cliphoard/config.toml`
- log state: `~/.local/state/cliphoard/`
On first start, Cliphoard asks for a passphrase. The history database is
encrypted with SQLCipher and the passphrase is never stored. If an older
plaintext history is found, Cliphoard asks before migrating it and keeps the
original as a `.plaintext-backup` until you remove that backup yourself.
The full product contract is in [.agents/BIBLE.md](.agents/BIBLE.md).

View File

@@ -71,8 +71,17 @@ const HELP_ICON: &str = "❓";
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 database_path = Database::default_path();
let database = if Database::is_plaintext(&database_path)? {
if !confirm_plaintext_migration()? {
anyhow::bail!("plaintext history migration was declined")
}
Database::migrate_plaintext(&database_path, &passphrase)
.context("could not encrypt existing Cliphoard history")?
} else {
Database::open_encrypted(&database_path, &passphrase)
.context("could not unlock Cliphoard history; check the passphrase")?
};
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
@@ -195,6 +204,36 @@ fn prompt_for_passphrase() -> Result<String> {
result
}
fn confirm_plaintext_migration() -> Result<bool> {
let application = Application::new(Some("io.cliphoard.Cliphoard.Migrate"), Default::default());
let migrate = Rc::new(RefCell::new(false));
let result = Rc::clone(&migrate);
application.connect_activate(move |application| {
let dialog = gtk4::Dialog::builder()
.application(application)
.title("Encrypt existing Cliphoard history?")
.modal(true)
.default_width(520)
.build();
dialog.content_area().append(&Label::new(Some(
"An unencrypted Cliphoard history was found. Migrate it to an encrypted database? The original will be retained as a backup until you remove it.",
)));
dialog.add_button("Cancel", ResponseType::Cancel);
dialog.add_button("Migrate and encrypt", ResponseType::Accept);
let result_for_response = Rc::clone(&result);
let application_for_response = application.clone();
dialog.connect_response(move |dialog, response| {
*result_for_response.borrow_mut() = response == ResponseType::Accept;
dialog.close();
application_for_response.quit();
});
dialog.present();
});
application.run_with_args(&["cliphoard-migrate"]);
let result = *migrate.borrow();
Ok(result)
}
fn build_window(
application: &Application,
config: &Config,