Dispatch recipients on bech32 HRP instead of string prefixes#16
Merged
Conversation
ParseRecipientLine matched "age1pq" as a string prefix, but 'p' and 'q' are bech32 data characters: roughly 1 in 1024 X25519 recipients legitimately starts with "age1pq" and was misrouted to the ML-KEM parser, surfacing as random test failures (most recently ParseRecipientsFile_MixedWithPlugin on CI). Plugins whose name starts with "pq" hit the same misroute. Split at the last '1' (BIP-173: data never contains '1') and dispatch on the true HRP, mirroring what Bech32.Decode does. The CLI carried its own copy of the prefix dispatch; it now delegates to AgeKeygen.ParseRecipientLine so both paths share the fix.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16 +/- ##
==========================================
+ Coverage 91.97% 91.99% +0.01%
==========================================
Files 41 41
Lines 2381 2385 +4
Branches 312 312
==========================================
+ Hits 2190 2194 +4
Misses 133 133
Partials 58 58 ☔ 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.
Summary
ParseRecipientLine(and its duplicate in the CLI) matchedage1pqas a string prefix to detect ML-KEM recipients. Butpandqare bech32 data characters, so roughly 1 in 1024 X25519 recipients legitimately starts withage1pqand was misrouted to the ML-KEM parser, failing withexpected HRP 'age1pq', got 'age'. This is what broke theParseRecipientsFile_MixedWithPluginubuntu leg on main (run 30005527741) and explains the sporadic local test failures seen during earlier work — the test generates a fresh random key each run. Plugins whose name starts withpq(age1pqfoo1...) were misrouted the same way.Fix
1(BIP-173 — data never contains1), mirroringBech32.Decode.age→ X25519,age1pq→ ML-KEM,age1<name>→ plugin.AgeKeygen.ParseRecipientLine(madeinternal+InternalsVisibleTo("Age.Cli")), so the two sites can't drift again.unrecognized recipient: ...from both paths (previously two different messages).A plugin literally named
pqshares the ML-KEM HRP and remains resolved as native ML-KEM, same precedence as before.Verification
age1pq(parses as X25519, round-trips encrypt/decrypt) plus apqtest-named plugin recipient. The vector test reproduces the exact CI failure on the old code.