fix(keys/agent): forward full agent signature blob for sk-ecdsa/sk-ed25519 keys - #701
Merged
Conversation
Owner
|
Thank you! @all-contributors add @ztbh for code |
Contributor
|
I've put up a pull request to add @ztbh! 🎉 |
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.
Summary
Fixes authentication failures when using FIDO2/U2F SSH keys
(
sk-ecdsa-sha2-nistp256@openssh.com,sk-ssh-ed25519@openssh.com)through
ssh-agent.Problem
Per OpenSSH's
PROTOCOL.u2f, the signature blob forsk-*key types has the following format:The trailing
flagsandcounterfields are an integral part of thesignature blob and must be transmitted to the server, which feeds
them back into the FIDO signature verification (they are part of the
authenticator data hashed by the security key).
ssh-key::Signaturecorrectly models this: forsk-*algorithms, thesignature value carries the inner sig + flags + counter together.
However,
russh_keys::agent::client::AgentClient::write_signatureonly re-encodes the algorithm name (
t) and the inner signature(
sig) read from the agent'sSSH_AGENT_SIGN_RESPONSE, discardingthe trailing 5 bytes (1-byte
flags+ 4-bytecounter) when thesignature algorithm is
sk-*.The server then fails verification with:
because OpenSSH's
ssh_ecdsa_sk_verify()/ssh_ed25519_sk_verify()hits EOF when reading
flags.Reproduction (before this PR)
ssh-agentand add the public key to the server's~/.ssh/authorized_keys.invalid format; client seesMSG_USERAUTH_FAILURE.OpenSSH's own
ssh(1)client succeeds against the same server withthe same agent and key, confirming the issue is on the russh side.
Fix
In
AgentClient::write_signature, detectsk-*signature algorithmsby checking whether the algorithm name returned by the agent starts
with
"sk-". When it does:trailing
flags(1 byte) +counter(4 bytes).flagsbyte andcounteru32from the remaining agent responseand append them to the output buffer.
For non-
sk-*algorithms the behavior is unchanged.This matches OpenSSH's own behavior, where the agent-produced
signature blob is treated as opaque and forwarded verbatim — see
sshconnect2.c::sign_and_send_pubkey()andssh-agent.c.Changes
russh-keys/src/agent/client.rs:AgentClient::write_signaturenow preserves the trailingflags+counterforsk-*signatures and adjusts the outerlength prefix accordingly.
Testing
sk-ecdsa-sha2-nistp256@openssh.comvia OpenSSH
ssh-agentagainst OpenSSH 9.x server now succeeds.sk-ssh-ed25519@openssh.comalsosucceeds.