Skip to content

Feature: SSH Agent – Add support for certificates#13077

Open
AlexpFr wants to merge 16 commits intokeepassxreboot:developfrom
AlexpFr:feature/sshAgent-add-certificates
Open

Feature: SSH Agent – Add support for certificates#13077
AlexpFr wants to merge 16 commits intokeepassxreboot:developfrom
AlexpFr:feature/sshAgent-add-certificates

Conversation

@AlexpFr
Copy link
Contributor

@AlexpFr AlexpFr commented Feb 21, 2026

SSH Agent – Add support for certificates

This implements the requested feature discussed in issue #5486.

If you have an externally generated OpenSSH certificate file associated with your SSH key, you can configure it in the "Certificate" tab. When the key is loaded, if "Use certificate" is checked, both the key and certificate are added to the agent.

$ ssh-add -l
256 SHA256:cBSn4LZHggKywgcMJPymH3H4GXJyHeo8JDoB2u+7fNo User key (ED25519)
256 SHA256:cBSn4LZHggKywgcMJPymH3H4GXJyHeo8JDoB2u+7fNo User key (ED25519-CERT)

The certificate selection logic strictly mirrors the SSH private key selection logic.

Backward Compatibility

In the KeeAgent.settings file, certificate support has been implemented by adding a separated <LocationCertificate> node with dedicated element names and <UseCertificate> for "Use certificate" checkbox.

Older versions of KeePassXC that do not implement certificate support will ignore these additional XML nodes. Therefore, configuration files containing certificate settings remain fully backward compatible.

Screenshots

Private key tab:
Private key tab

Certificate tab:
Certificate tab

Testing strategy

  • ✅ Adding private key only (existing functionality)
  • ✅ Adding private key + certificate from attachment or external file
  • ✅ Switching between attachment/file modes
  • ✅ Adding/removing key to/from agent when database is opened/closed and unlocked/locked
  • ✅ Editing existing entries
  • ✅ Adding/removing attachments dynamically

Quick certificate generation for testing

$ ssh-keygen -f ca_key -C "Certificate Authority"
$ ssh-keygen -f user_key -C "User key"
$ ssh-keygen -s ca_key -I "cert-test-1" -n user user_key.pub

The certificate for user_key is user_key-cert.pub

Type of change

  • ✅ New feature (change that adds functionality)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds OpenSSH certificate support to the SSH Agent integration, allowing a configured *-cert.pub to be loaded alongside the private key when an entry is unlocked/opened.

Changes:

  • Extend KeeAgentSettings and OpenSSHKey to store/load/serialize certificate configuration and data (attachment or external file).
  • Update the SSH Agent add/remove flows to handle an optional certificate identity.
  • Update the entry editor UI (new “Certificate” tab), documentation, and translation sources for the new feature.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/sshagent/SSHAgent.cpp Adds agent requests for adding/removing a certificate identity alongside the key.
src/sshagent/OpenSSHKey.h Adds certificate parsing/writing APIs and storage fields.
src/sshagent/OpenSSHKey.cpp Implements certificate parsing and binary serialization for agent messages.
src/sshagent/KeeAgentSettings.h Adds certificate-related settings getters/setters and env substitution.
src/sshagent/KeeAgentSettings.cpp Adds XML read/write for certificate settings and loads certificate data into OpenSSHKey.
src/gui/entry/EditEntryWidgetSSHAgent.ui Introduces a new “Certificate” tab and related widgets for certificate selection.
src/gui/entry/EditEntryWidget.h Adds slots/members for certificate UI interaction.
src/gui/entry/EditEntryWidget.cpp Wires certificate UI controls into settings and key info refresh; adds file browsing for cert.
share/translations/keepassxc_en.ts Adds new translatable strings for certificate UI and errors.
docs/topics/SSHAgent.adoc Documents how to associate a certificate with an SSH key in the UI.

You can also share your feedback on Copilot code review. Take the survey.

@varjolintu
Copy link
Member

The changes here makes this one obsolete? #13068

AlexpFr added 2 commits March 9, 2026 11:49
- Add #define SSH_MAX_LOCAL_KEY_SIZE (1 MiB) in KeeAgentSettings.h
- Replace magic value "1024 * 1024" with this constant
Copy link
Contributor Author

@AlexpFr AlexpFr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this pull request already integrates #13068. I had created it to clearly separate the feature from the bug/improvement.
If the separation is not necessary, we can close #13068.

AlexpFr added 10 commits March 9, 2026 12:40
attachmentCertificateComboBox and attachmentComboBox are
already cleared in updateSSHAgentAttachments().
- Check elements non-empty before accessing first()
- Validate minimum 2 elements (type + nonce)
- Reject invalid/unsupported certificate types
- Verify Base64 nonce decoding success
Move m_addedKeys insertion after key add success but before optional cert add.
Ensures keys are always tracked (and auto-removed) even if cert fails.
Validate `stream.writeString(m_certificateType)` success and set m_error on
failure, consistent with other write*() calls. Prevents partial stream writes
Avoid sending invalid SSH_AGENTC_REMOVE_IDENTITY to agent when KeePassXC
cannot read the certificate data itself.

Prevents malformed removal requests for unreadable certificates.
Copy link
Contributor Author

@AlexpFr AlexpFr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For unit tests: I haven't written them yet as I'm not comfortable with the test framework yet. Are tests required for this new certificate handling path

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

Labels

feature: SSH agent pr: new feature Pull request adds a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants