Skip to content

Throw the documented exception for a null, a small RSA key and a plugin's mistake - #147

Merged
pscheid92 merged 1 commit into
mainfrom
fix/review-s5-exception-types
Dec 2, 2026
Merged

pscheid92 merged 1 commit into
mainfrom
fix/review-s5-exception-types

Conversation

@pscheid92

Copy link
Copy Markdown
Owner

Finding S5 of the 2026-11-30 review. 25 of the 34 new tests failed before the change; a 35th was added for a case the tests then turned up.

A null argument

The review named the SSH parsers. The tests show it was wider: ten Parse methods and every identity's TryUnwrap threw NullReferenceException. They now throw ArgumentNullException, as the other nine parsers already did.

A small RSA key

  • SshRsaIdentity.Recipient threw ArgumentException for a key under 2,048 bits that Parse had accepted and that decrypts. The interface documents only ObjectDisposedException.
  • Found while fixing that: a passphrase-protected key of that size was refused when read (FormatException), so a file made for it could not be opened at all, while the same key unprotected opened it.

As in go-age (agessh.go: NewRSARecipient and Wrap check the size, RSAIdentity.Recipient does not), an identity of any size now has a recipient and decrypts. The size is checked where a key is read as a recipient (FormatException, as before) and again when wrapping to it (AgeException).

The new test key Age.Tests/TestData/EncryptedSsh/rsa_1024_aes256ctr was generated for this with ssh-keygen -t rsa -b 1024, passphrase hunter2 like the folder's other keys. The test builds the ssh-rsa stanza itself, since neither AgeSharp nor go-age writes one for such a key.

A plugin's mistake

  • A file key of the wrong size from a plugin was AgeFormatException ("file key must be 16 bytes"), which blames the file. It is now AgePluginException, thrown where the plugin's answer is read, which is also where the fuzzer's plugin-client target can see it.
  • An AgePlugin handler that returns null, or a recipient that wraps to a null stanza, was an exception out of Run. It is now that key's error to the client and exit code 3.

Behaviour changes

Noted in TODO.md for the next release notes. One existing test asserted the internal constructor's ArgumentException and now asserts the FormatException of the public Parse.

Checked

  • dotnet test and dotnet test -c Release -p:ForcePortableAead=true -p:TreatWarningsAsErrors=true: 1,176 vectors and 1,693 unit tests pass.
  • Age.Fuzz on ssh, sshpub, plugin, plugin-client, identities and recipients for 25 s: no findings.

…in's mistake

From the 2026-11-30 review (S5).

A null argument: ten Parse methods and every identity's TryUnwrap threw
NullReferenceException. They now throw ArgumentNullException, as the
others already did.

A small RSA key: SshRsaIdentity.Recipient threw ArgumentException for a
key under 2048 bits that Parse had accepted, and a passphrase-protected
one was refused when read, so a file made for it could not be opened. As
in go-age, an identity of any size now has a recipient and decrypts; the
size is checked where a key is read as a recipient, and again when
wrapping to it, which is an AgeException. The new test key
rsa_1024_aes256ctr was made for this (passphrase hunter2, as the others).

A plugin's file key of the wrong size was an AgeFormatException, a
malformed file; it is the plugin's mistake, an AgePluginException, and
is found where the fuzzer's plugin-client target can see it.

An AgePlugin handler that returns null, or a recipient that wraps to a
null stanza, was an exception out of Run. It is now that key's error to
the client and exit code 3.
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.55%. Comparing base (c1b7810) to head (caecebf).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #147      +/-   ##
==========================================
+ Coverage   97.54%   97.55%   +0.01%     
==========================================
  Files          76       76              
  Lines        5044     5074      +30     
  Branches      695      699       +4     
==========================================
+ Hits         4920     4950      +30     
  Misses         76       76              
  Partials       48       48              
Flag Coverage Δ
macos-latest 97.51% <100.00%> (+0.01%) ⬆️
ubuntu-latest 97.51% <100.00%> (+0.01%) ⬆️
windows-latest 97.45% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pscheid92
pscheid92 merged commit 043091f into main Dec 2, 2026
6 checks passed
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