Skip to content

Fix SSH agent losing track of keys after a database reload - #13705

Closed
underclockeddev wants to merge 1 commit into
keepassxreboot:developfrom
underclockeddev:fix/ssh-agent-reload-ownership
Closed

underclockeddev wants to merge 1 commit into
keepassxreboot:developfrom
underclockeddev:fix/ssh-agent-reload-ownership

Conversation

@underclockeddev

Copy link
Copy Markdown

Fixes #13704

DatabaseWidget::replaceDatabase() now calls a new SSHAgent::databaseReplaced(oldDb, newDb), which moves ownership of any keys recorded under the old database's uuid to the new one. Lock and unlock then find them as before.

The investigation, patch and tests were written with Claude Code (Claude Opus 5.5) and reviewed by me before submitting.

Screenshots

N/A

Testing strategy

  • Two new tests in TestSSHAgent: testRemoveOnLockAfterReload and testReaddOnUnlockAfterReload. Both fail on develop (the second with "Key identity ownership conflict. Refusing to add.") and pass with this change.
  • Full ctest suite (non-GUI, 41 tests) passes.
  • End to end against the built keepassxc and keepassxc-cli: unlock a database holding an SSH key, edit the file with keepassxc-cli, lock, check ssh-add -l, then clear the agent and unlock again. On develop the key stays after lock and is not re-added on unlock. With this change both work. Controls without the external edit behave the same on both builds.
    Script: https://gist.github.com/underclockeddev/4051fb85ea881fcdecc2841eacc692d1

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

Reloading a database from disk replaces its Database object, and every
Database has its own uuid. SSHAgent records key ownership by that uuid, so
after a reload, locking no longer removed the keys and unlocking was
refused as an ownership conflict. Hand ownership over to the replacement
in DatabaseWidget::replaceDatabase().

Fixes keepassxreboot#13704

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@varjolintu varjolintu added the pr: ai-assisted Pull request contains significant contributions by generative AI label Sep 25, 2026
@droidmonkey

Copy link
Copy Markdown
Member

As posted in the linked issue, this appears to be an issue on your end with your database files. The database uuid should not change on file reload. If it does, then you are actually loading a different database.

This fix is a decent safe guard for this happening, but it shouldn't happen under normal operating conditions.

@droidmonkey

Copy link
Copy Markdown
Member

I was mistaken, the stable uuid is the root group's which should have been used in the ssh code instead of database uuid which is a made up one for each database object created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: SSH agent pr: ai-assisted Pull request contains significant contributions by generative AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSH agent: after the database file is reloaded from disk, lock no longer removes keys and unlock no longer adds them

3 participants