Skip to content

fix(auth): verify user signatures with verify_strict - #176

Merged
gonzafg2 merged 5 commits into
mainfrom
fix/auth-verify-strict
Oct 11, 2026
Merged

gonzafg2 merged 5 commits into
mainfrom
fix/auth-verify-strict

Conversation

@gonzafg2

Copy link
Copy Markdown
Owner

Summary

verify_auth_signature (crates/quantumssh-core/src/auth.rs) checked the publickey signature with ed25519-dalek's non-strict verify. That check accepts signatures under a small-order ("weak") public key, and those signatures can be forged by anyone.

  • With A the identity point, R' = [S]B − [k]A = [S]B, so R = B, S = 1 verifies for every message.
  • authorized_keys entries are parsed with VerifyingKey::from_bytes (auth.rs:264), which does not reject weak keys.
  • So a weak key in authorized_keys would let any peer authenticate as that user.

This PR switches the call to verify_strict. ed25519-dalek 2.2.0's VerifyingKey docs describe it as performing both signature-malleability checks: S reduced mod ℓ, and the small-torsion check on R. The same page says of is_weak: "A weak public key can be used to generate a signature that's valid for almost every message."

Legitimate clients are unaffected. OpenSSH (ssh-keygen) never produces small-order keys and emits canonical signatures. The CI interop gate drives a real OpenSSH 10.x publickey login end to end.

Threat-model anchor: the user-authentication path that every connection reaches before it is authenticated (docs/threat-model.md §4.1 is the pre-auth trust surface). The rule applied is the CLAUDE.md "Fail closed" hard rule.

Scope

  • Changed: auth.rs:332, the only first-party Ed25519 verification of peer-controlled input. The doc comment now explains why it uses verify_strict.
  • Unchanged: the other verify calls (host_key.rs:360 and tests/accept.rs:290/1353) verify the server's own host-key signatures inside tests.
  • Independent of the planned dalek 3.x bump: verify and verify_strict semantics are the same in ed25519-dalek 3.0.0.

Test

auth::tests::small_order_key_forgery_is_rejected builds the identity key (01 00…00, and asserts is_weak()) and the forged signature R = basepoint (58 66…66) ‖ S = 1. Then:

  • VerifyingKey::verify accepts it, which documents the bug class;
  • verify_auth_signature rejects it.

I checked that the test fails if the call goes back to verify: it panics at the final assertion.

Local validation: cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings (clean), cargo test --workspace (34 + 104 + 35 passed), cargo build --workspace --release.

No issue tracks this. It came out of the dalek 3.x research for #109, as a finding independent of that bump.

https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW

verify_auth_signature checked the publickey signature with ed25519-dalek's
non-strict verify, which accepts signatures under a small-order (weak)
public key that anyone can forge: with A the identity point,
R' = [S]B - [k]A = [S]B, so R = B and S = 1 verify for every message. A
weak key in authorized_keys (parsed by VerifyingKey::from_bytes, which
does not reject weak keys) would therefore let any peer authenticate as
that user.

verify_strict rejects weak keys and a non-canonical or small-order R.
OpenSSH never generates small-order keys and emits canonical signatures,
so legitimate clients are unaffected.

Adds small_order_key_forgery_is_rejected, which shows the non-strict
check accepting the forged signature and verify_auth_signature rejecting
it; it fails if the call goes back to verify. The other ed25519 verify
calls (host_key.rs and tests/accept.rs) check the server's own host-key
signatures in tests and are unchanged.

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
@claude

claude Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

What was reviewed:

  • crates/quantumssh-core/src/auth.rs — the one-line verify → verify_strict change and the new small_order_key_forgery_is_rejected regression test

What was verified:

  • ed25519_dalek 2.2.0's verify_strict rejects signatures under weak (small-order) public keys, not just non-canonical signatures — the fix closes the forgery path
  • The forged signature in the test (R = basepoint, S = 1, A = identity point) correctly demonstrates the bug class: with A as the identity, [S]B − [k]A = [S]B = B = R for any message, so the non-strict path accepts it universally
  • Moving Verifier import from production scope to #[cfg(test)] is correct — verify_strict is an inherent method, so production code no longer needs the trait; it also prevents non-strict .verify from being called accidentally in production code
  • No unsafe, no new dependencies, no legacy crypto introduced; all five MANIFIESTO commitments satisfied; commit message follows Conventional Commits (fix(auth): …)
  • Key material handling is intact: error paths return Err(()), Zeroizing wrapper on signed-data buffer is preserved

🤖 Generated with Claude Code

@opencode-agent

Copy link
Copy Markdown

PR Review: fix(auth): verify user signatures with verify_strict (#176)

Decision: 🟢 Approved
Iteration: First review
Lenses applied: Rust under crates/ (threat model §4.1 pre-auth surface, CLAUDE.md "Fail closed")

Executive summary

The PR is a one-line security fix plus a regression test: verify_auth_signature now calls verify_strict instead of verify. I confirmed against the pinned ed25519-dalek 2.2.0 source that verify_strict rejects a small-order public key (self.point.is_small_order(), verifying.rs:370) and a small-order R, so the identity-key forgery the PR describes is genuinely closed. The change is correct, minimal, and I verified the new test passes locally. No blocking issues.

Verification performed

  • Read ed25519-dalek 2.2.0 verifying.rs from docs.rs: verify_strict returns Err when signature_R.is_small_order() || self.point.is_small_order() (verifying.rs:364-372), and InternalSignature::try_from rejects non-canonical S. The PR's stated fix is exact.
  • Ran cargo test -p quantumssh-core --lib auth::tests::small_order_key_forgery_is_rejected → 1 passed. The verify-accepts / verify_strict-rejects pair in the test is a valid regression guard.
  • Grepped all .verify( / Verifier uses in crates/: the only non-test calls are auth.rs:338 (this fix) and the two host-key test verifications the PR lists (host_key.rs:360, tests/accept.rs:290,1353). The scope claim is accurate — there is no second peer-controlled Ed25519 verification left on verify.

New findings

No findings reach the 🔴 or 🟡 threshold. The change introduces no unsafe, no dependency, no legacy primitive, and no scope creep; verify_strict is the documented, recommended remedy and is compatible with canonical OpenSSH signatures.

💡 Suggestions (nice to have)

  • crates/quantumssh-core/src/auth.rs:263-267 — defense in depth: AuthorizedKeys::load still stores a weak key (its VerifyingKey::from_bytes does not run is_weak). The vulnerability is now closed at verification, so this is not required, but rejecting is_weak keys at load would fail a misconfigured authorized_keys loudly at startup and avoid depending on verify_strict being the sole guard if the call site is ever changed.

    Anchor: threat model §4.1 (highest-trust surface) / CLAUDE.md "Fail closed".

github run

opencode review #1 on #176 (suggestion, applied): defense in depth on top of verify_strict. AuthorizedKeys::load now rejects a key whose VerifyingKey::is_weak() is true with MalformedLine, the same fail-closed path every other malformed line already takes, so a bad authorized_keys fails loudly instead of keeping a forgeable key loaded. Adds reject_small_order_key.

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
@gonzafg2

Copy link
Copy Markdown
Owner Author

Reviewer findings: round 1 summary

Source Finding Action Commit
claude-review None ("No issues found") — —
opencode #1 No 🔴/🟡 findings. Suggestion: AuthorizedKeys::load still stores a weak key; reject is_weak() at load as defense in depth Applied: a small-order key is now a MalformedLine on the same fail-closed path every other malformed line takes, so a bad authorized_keys fails loudly instead of keeping a forgeable key loaded. New test: reject_small_order_key 292783d

The Codex review job is red for an infrastructure reason unrelated to this PR: the OpenAI API account behind OPENAI_API_KEY has no credits.

@opencode-agent

Copy link
Copy Markdown

PR Review: fix(auth): verify user signatures with verify_strict (#176)

Decision: 🟢 Approved
Iteration: Review #2 (1 resolved, 0 open)
Lenses applied: Rust under crates/ (threat model §4.1 pre-auth surface; CLAUDE.md "Fail closed", "Zero legacy", "Small surface")

Executive summary

Two commits harden the single first-party verification of peer-controlled Ed25519 signatures: verify_auth_signature now uses verify_strict (commit 26ee947), and AuthorizedKeys::load refuses small-order keys (commit 292783d, applying the previous review's suggestion). I confirmed against the pinned ed25519-dalek 2.2.0 source that verify_strict rejects self.point.is_small_order() and signature_R.is_small_order(), closing the identity-key forgery, that no other peer-controlled verify call remains, and that the change cannot reject legitimate OpenSSH signatures. No blocking or important findings.

Previous issues

# Issue Status Notes
1 opencode #1 (💡): AuthorizedKeys::load still stored a weak key; reject is_weak() at load as defense in depth ✅ resolved commit 292783d; auth.rs:272-277 now returns MalformedLine for is_weak(), with regression test reject_small_order_key (auth.rs:528-536)
— claude-review: "No issues found" — no actionable items to track

New findings

No findings reach the 🔴/🟡 threshold. Verified independently: the only production verification of attacker-controlled Ed25519 input is auth.rs:348 (now verify_strict); host_key.rs:360 and tests/accept.rs:290,1353 verify the server's own host-key signatures in tests and are out of scope. The verify_strict rejection is exercised by small_order_key_forgery_is_rejected (auth.rs:807-829), which asserts the non-strict path accepts the forgery before confirming verify_auth_signature rejects it, so it cannot pass vacuously. No unsafe, no new dependency, no legacy primitive, no scope creep; cargo clippy --workspace --all-targets -- -D warnings is clean and the 21 auth::tests pass. Both commits report .commit.verification.verified = true.

💡 Suggestions (nice to have)

  • crates/quantumssh-core/src/auth.rs:61-67 and :170-175 — the AuthError::MalformedLine doc and the load # Errors section still describe the cause as a key that "does not contain a parsable ssh-ed25519 key" / "base64 blob cannot be decoded or its wire format is invalid". A small-order key is well-formed and parsable, so the doc contract no longer matches the new rejection path.

    Anchor: AGENTS.md code conventions (every fallible function's # Errors must describe its failure modes); threat model §4.3/§4.1 documentation accuracy.

github run

opencode review #2 on #176 (suggestion, applied): the MalformedLine variant doc and AuthorizedKeys::load's # Errors section now name the small-order key case added in 292783d.

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
@gonzafg2

Copy link
Copy Markdown
Owner Author

Round 2: opencode review #2 approved with one suggestion: the MalformedLine doc and the load # Errors section did not name the weak-key case. Applied in 808c8f9. claude-review reviews once per PR, and its round-1 report ("No issues found") stands.

@opencode-agent

Copy link
Copy Markdown

PR Review: fix(auth): verify user signatures with verify_strict (#176)

Decision: 🟢 Approved
Iteration: Review #3 (2 resolved, 0 open)
Lenses applied: Rust under crates/ (threat model §4.1 pre-auth/highest-trust surface; CLAUDE.md "Fail closed", "Zero legacy", "Small surface")

Executive summary

Three commits harden the single first-party verification of peer-controlled Ed25519 input: verify_auth_signature now uses verify_strict (26ee947), AuthorizedKeys::load refuses small-order keys (292783d), and the MalformedLine/load docs name the weak-key case (808c8f9). I confirmed against the pinned ed25519-dalek 2.2.0 source that from_bytes does not reject small-order points, is_weak() is point.is_small_order(), and verify_strict rejects signature_R.is_small_order() || self.point.is_small_order() (verifying.rs:165-192, 357-380). The forgery is genuinely closed, no other peer-controlled verify remains, and the change is correct, minimal, and cannot reject canonical OpenSSH signatures. No blocking or important findings.

Previous issues

# Issue Status Notes
1 opencode #1 (💡): AuthorizedKeys::load still stored a weak key; reject is_weak() at load ✅ resolved 292783d; auth.rs:270-279 returns MalformedLine for is_weak(), regression test reject_small_order_key (auth.rs:530-538)
2 opencode #2 (💡): MalformedLine doc and load # Errors did not name the weak-key case ✅ resolved 808c8f9; auth.rs:61-62 and auth.rs:172-174 now name the small-order case
— claude-review: "No issues found" — no actionable items to track

New findings

No findings reach the 🔴 (≥90) or 🟡 (≥80) threshold. Verified independently:

  • Forgery closed. verify_strict rejects self.point.is_small_order(), and the identity-key forgery (A = identity, R = B, S = 1, so [S]B = R + [k]A for every message) is exactly that case. auth.rs:350.
  • No other peer-controlled non-strict verify. Every other .verify( is test-only, checking the server's own host-key signature: host_key.rs:360, tests/accept.rs:290, tests/accept.rs:1353. The sole production peer-controlled path (transport.rs:843 → auth.rs:350) is strict.
  • Tests are non-vacuous. small_order_key_forgery_is_rejected (auth.rs:808-831) asserts the non-strict verify accepts the forgery before asserting verify_auth_signature rejects it, so the second assertion exercises strictness rather than a generic failure. cargo test -p quantumssh-core --lib auth → 22 passed.
  • No unsafe, no new dependency, no legacy primitive, no scope creep. Diff confined to auth.rs; unsafe_code = "forbid" untouched; fail-closed preserved (MalformedLine on the same path every other bad line takes).
  • All three commits report .commit.verification.verified = true via the GitHub API.

The upstream limitation that is_weak()/verify_strict reject small-order but not general mixed-order (torsion-coset) keys is irrelevant to this forgery and matches the audited primitive's documented semantics, so it is not raised as a finding.

github run

@gonzafg2
gonzafg2 merged commit dc667bc into main Oct 11, 2026
12 of 13 checks passed
@gonzafg2
gonzafg2 deleted the fix/auth-verify-strict branch October 11, 2026 23:31
@opencode-agent

Copy link
Copy Markdown

PR Review: fix(auth): verify user signatures with verify_strict (#176)

Decision: 🟢 Approved
Iteration: Review #4 (2 resolved, 0 open)
Lenses applied: Rust under crates/ (threat model §4.1 pre-auth/highest-trust surface; CLAUDE.md "Fail closed", "Zero legacy", "Small surface", "Memory-safe by construction")

Executive summary

Four commits (three substantive plus a main merge) harden the single first-party verification of peer-controlled Ed25519 input: verify_auth_signature now uses verify_strict (26ee947), AuthorizedKeys::load refuses small-order keys (292783d), and the docs name the weak-key case (808c8f9). I re-verified against the version the repo now actually resolves — ed25519-dalek 3.0.0 / curve25519-dalek 5.0.0 (ADR-0036, merged into the base) — that verify_strict rejects both a small-order R and a small-order public key, that the forgery test is non-vacuous, and that no other production peer-controlled verify remains. The fix is correct, minimal, and cannot reject canonical OpenSSH signatures. No blocking or important findings.

Previous issues

# Issue Status Notes
1 opencode #1 (💡): AuthorizedKeys::load still stored a weak key; reject is_weak() at load ✅ resolved 292783d; auth.rs:274-279 returns MalformedLine, regression test reject_small_order_key (auth.rs:529-538)
2 opencode #2 (💡): MalformedLine doc and load # Errors did not name the weak-key case ✅ resolved 808c8f9; auth.rs:61-62 and auth.rs:172-174 now name the small-order case
— claude-review: "No issues found" — no actionable items to track

New findings

No findings reach the 🔴 (≥90) or 🟡 (≥80) threshold. Verified independently:

  • Forgery closed, against the resolved version. ed25519-dalek 3.0.0 VerifyingKey::verify_strict (verifying.rs:367-391) returns Err when signature_R.is_small_order() || self.point.is_small_order(), and is_weak() (verifying.rs:200) is exactly self.point.is_small_order(). The identity-key forgery (A = identity, R = B, S = 1) is precisely that case; auth.rs:350 now calls verify_strict.
  • The regression test is non-vacuous. small_order_key_forgery_is_rejected (auth.rs:807-831) first asserts the non-strict weak.verify(...) accepts the forgery, then asserts verify_auth_signature rejects it. Running cargo test -p quantumssh-core --lib auth:: → 21 passed (including both new tests), so the first assertion genuinely holds and the second exercises strictness rather than a generic failure.
  • No other peer-controlled non-strict verify. The only production call is auth.rs:350; host_key.rs:360, auth.rs:827, and tests/accept.rs:290,1353 are all #[cfg(test)]/integration checks of the server's own host-key signature.
  • Fail-closed preserved; no scope creep. is_weak() is checked on the decoded key before the entry is pushed, and only the eight torsion points are small-order, so no legitimate key is rejected; a bad authorized_keys fails with the same MalformedLine path every other malformed line takes. No unsafe, no dependency change, no legacy primitive, no key material in the new reason string.
  • All four commits report .commit.verification.verified = true via the GitHub API; the openssh-interop CI check is green on HEAD, covering the end-to-end "legitimate OpenSSH signatures still verify" claim.

💡 Suggestions (nice to have)

  • crates/quantumssh-core/src/auth.rs:350 / docs/adr/0036-dalek-3x-coordinated-bump.md:165-167 — ADR-0036 explicitly deferred this exact question ("Whether user authentication should use verify_strict is a separate hardening question, not decided here"). This PR now makes that locked-in cryptographic-verification decision in code only, with no ADR/errata and no cross-reference either way. A one-line errata on ADR-0036 (or a short standalone ADR) would record it where the decision was deferred.

    Anchor: CLAUDE.md "RFC vs ADR vs plain PR" (a locked-in operational decision goes to an ADR; CLAUDE.md:111 "a plan is never the sole record of a locked-in decision").

  • docs/plans/m4-authentication.md:237 — still documents the auth step as verifying_key.verify(), now contradicted by the code. The file is non-authoritative (ADR-0027), so this is drift, not a defect, but a one-word update keeps it honest.

    Anchor: ADR-0027 (plans are mutable and non-authoritative).

Limitations: I could not run the ADR-0020 interop gate locally (the runner's OpenSSH 9.6 has no ML-KEM), so the end-to-end claim rests on the green openssh-interop CI job rather than a local reproduction. The Codex review check is red for an infrastructure reason (the API account behind OPENAI_API_KEY has no credits), unrelated to this PR.

github run

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant