tskagent: fix incorrect comment parsing from key files#1
Merged
Conversation
The code to pull comments out of key data made some heuristic (but incorrect) assumptions about the organization of the key. In particular, for keys where no comment is defined, it could incorrectly grab an earlier field (e.g., one of the key parameters) which would confuse a client expecting printable text. Correctly process the fields we care about, so that when an empty comment is set we don't grab the wrong thing by mistake. Also, update the tests to cover RSA as well as ED25519 keys, and generate test keys randomly. I ran the new tests 50,000 times under "stress" and was not able to produce any new failures. Thanks to @andrew-d for reporting this and for providing a failing test to debug from. Co-authored-by: Andrew Dunham <andrew@tailscale.com>
9f352e7 to
29cd974
Compare
andrew-d
approved these changes
Jun 6, 2026
| }, | ||
| { | ||
| name: "RSA/Comment", | ||
| input: mustGenerateKey(t, genRSA, "what year is it"), |
creachadair
added a commit
that referenced
this pull request
Jun 6, 2026
As noted in #1, we rely on the keys not being passphrase locked, since the agent has no way to prompt a user for the passphrase. Also add an example.
creachadair
added a commit
that referenced
this pull request
Jun 6, 2026
As noted in #1, we rely on the keys not being passphrase locked, since the agent has no way to prompt a user for the passphrase. Also add an example.
creachadair
added a commit
that referenced
this pull request
Jun 6, 2026
As noted in #1, we rely on the keys not being passphrase locked, since the agent has no way to prompt a user for the passphrase. Also add an example.
creachadair
added a commit
that referenced
this pull request
Jun 6, 2026
As noted in #1, we rely on the keys not being passphrase locked, since the agent has no way to prompt a user for the passphrase. Also add an example.
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.
The code to pull comments out of key data made some heuristic (but incorrect)
assumptions about the organization of the key. In particular, for keys where no
comment is defined, it could incorrectly grab an earlier field (e.g., one of
the key parameters) which would confuse a client expecting printable text.
Correctly process the fields we care about, so that when an empty comment is
set we don't grab the wrong thing by mistake.
Also, update the tests to cover RSA as well as ED25519 keys, and generate test
keys randomly. I ran the new tests 50,000 times under "stress" and was not able
to produce any new failures.
Thanks to @andrew-d for reporting this and for providing a failing test to
debug from.
Co-authored-by: Andrew Dunham andrew@tailscale.com