Skip to content

fix(ssh): make PublicKey equality match OpenSSH sshkey_equal - #43

Merged
timweri merged 7 commits into
mainfrom
ignore-comment-for-sig-verify
Sep 24, 2026
Merged

timweri merged 7 commits into
mainfrom
ignore-comment-for-sig-verify

Conversation

@timweri

@timweri timweri commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

This is a bug flagged by Opus 5.5. PublicKey derived PartialEq over all of its fields, so the same key with a different comment (or ssh-rsa vs rsa-sha2-512 label) fails the equal check. Signature verification failed when the key has a comment.

The fix is a manual PartialEq that compares key_type.plain, key_type.is_cert and kind, matching OpenSSH's sshkey_equal.

BREAKING CHANGE: == on PublicKey now ignores comments.

Evidence

  • OpenSSH's struct sshkey has no comment field (sshkey.h), and sshd(8) says the comment "is not used for anything" (sshd.8).
  • RFC 8332 §3: rsa-sha2-256/rsa-sha2-512 "reuse the "ssh-rsa" public key format" (RFC 8332). OpenSSH maps all three to KEY_RSA (ssh-rsa.c).
  • sshkey_equal requires 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).

@timweri
timweri requested a balanced review from Copilot September 23, 2026 15:36
@timweri
timweri marked this pull request as ready for review September 23, 2026 15:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

All reviewed changes are covered by tests, with no unresolved issues.

Review effort: Balanced
Findings: None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The private-key integrity check must preserve exact key-type matching.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Comment thread src/ssh/privkey.rs Outdated
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 ==.
@timweri timweri changed the title fix: compare public keys by encoding, ignoring comment fix(ssh): make PublicKey equality match OpenSSH sshkey_equal Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

All reviewed changes are covered by regression tests, with no unresolved issues.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The implementation and regression coverage were fully reviewed with no unresolved issues.

Review effort: Balanced
Findings: None

@timweri
timweri requested a review from obelisk September 24, 2026 16:32
@timweri timweri added the conformance For issues or PRs that deal with conformance to the SSH standard label Sep 24, 2026
@timweri
timweri merged commit 645b528 into main Sep 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conformance For issues or PRs that deal with conformance to the SSH standard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants