Repository navigation
fix(ssh): make PublicKey equality match OpenSSH sshkey_equal - #43
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The new signature comparison can panic on valid caller-controlled input and needs a non-panicking implementation.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes public-key comparisons so differing comments do not cause false mismatches.
Changes:
- Compares encoded keys during signature and private-key validation.
- Adds regression tests for commented and mismatched keys.
| File | Review |
|---|---|
tests/signature.rs |
Adds public-key verification regression coverage. |
src/ssh/signature.rs |
Uses encoded-key comparison, but introduces a moderate panic path for caller-constructed security keys. |
src/ssh/privkey.rs |
Uses encoded-key comparison; nit: add coverage for RSA algorithm aliases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
encode() panics on sk keys built without an application, and would make such keys equal to keys with an empty application. Comparing the plain key type and key data still ignores the comment, without either issue.
Compare the plain key type, cert-ness and key data, ignoring the comment and RSA signature algorithm names (rsa-sha2-256/512), which share the ssh-rsa key format per RFC 8332. Replaces PublicKey::equal_public, so both call sites go back to using ==.
obelisk
approved these changes
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This is a bug flagged by Opus 5.5.
PublicKeyderivedPartialEqover all of its fields, so the same key with a differentcomment(orssh-rsavsrsa-sha2-512label) fails the equal check. Signature verification failed when the key has a comment.The fix is a manual
PartialEqthat compareskey_type.plain,key_type.is_certandkind, matching OpenSSH'ssshkey_equal.BREAKING CHANGE:
==onPublicKeynow ignores comments.Evidence
struct sshkeyhas no comment field (sshkey.h), and sshd(8) says the comment "is not used for anything" (sshd.8).rsa-sha2-256/rsa-sha2-512"reuse the "ssh-rsa" public key format" (RFC 8332). OpenSSH maps all three toKEY_RSA(ssh-rsa.c).sshkey_equalrequires the same type (cert != plain), then compares key material (sshkey.c). OpenSSH uses it for the private-key envelope check (sshkey.c) and sshsig signer matching (sshsig.c).