Repository navigation
Keep key material out of SSH key errors and recipients-file errors - #144
Merged
Merged
Conversation
From the 2026-11-30 review. A passphrase-protected SSH key that decrypts to something unusable reported what SSH.NET said about it, and SSH.NET quotes the "key type" it read from the decrypted section. aes256-ctr, ssh-keygen's default, is not authenticated, so one damaged byte made that key type run on into the private key: half of an Ed25519 seed was readable in the message. The error now says only that the key is unusable, with no text and no inner exception from SSH.NET; a wrong passphrase for a legacy PEM key carries no inner exception either. Recipients.Parse repeated a line it could not read, which is often a secret key pasted into the wrong file. It now names the line by number, as Identities.Parse and go-age do. ParseOne still names its argument. An ssh-rsa line was parsed twice, and BouncyCastle validates the modulus each time it builds a key: a 16384-bit line took 20.5 s and now takes 9.8 s. A key SSH.NET decrypted was checked twice for the same reason. What remains is one validation per key, which only a smaller size limit would reduce.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #144 +/- ##
==========================================
- Coverage 97.51% 97.46% -0.06%
==========================================
Files 75 75
Lines 4998 5001 +3
Branches 686 688 +2
==========================================
Hits 4874 4874
- Misses 75 78 +3
Partials 49 49
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Three findings from the 2026-11-30 review, each with a test that failed before the change.
S1: SSH private key bytes in an exception message
A passphrase-protected SSH key that decrypts to something unusable reported what SSH.NET said about it, and SSH.NET quotes the "key type" it read from the decrypted section. aes256-ctr, ssh-keygen's default, is not authenticated, so one damaged byte made that key type run on into the private key. With
ed25519_aes256ctr, 16 of the seed's 32 bytes were readable inAgeException.Message.unreadable SSH private key: what the passphrase decrypts is not a usable key, with no text and no inner exception from SSH.NET.SshKeyErrorLeakTestsflips one ciphertext byte in the Ed25519 and RSA fixtures and checks that no 6-byte printable run of the private section appears anywhere inex.ToString().S3: a secret key pasted into a recipients file was echoed
Recipients.Parserepeated a line it could not read. It now names the line by number, asIdentities.Parseand go-age do.Recipients.ParseOnestill names its argument, which is the caller's own string.S2: an
ssh-rsaline was parsed twiceBouncyCastle validates the modulus every time it builds an RSA key, and that costs one full-size modular exponentiation.
Recipients.ParseOneon a 16,384-bit line: 20.5 s before, 9.8 s after (Debug build, M-series Mac).Behaviour changes
Noted in
TODO.mdfor the next release notes: the recipients-file message, the SSH key message, and the missing inner exceptions.Checked
dotnet test: 1,176 vectors and 1,598 unit tests pass.dotnet test -c Release -p:ForcePortableAead=true -p:TreatWarningsAsErrors=true: same counts, no warnings.Age.Fuzzonrecipients,sshpubandsshfor 25 s: no findings.