Repository navigation
Conversation
Replace AllowedSignerSplitter with a parser that follows OpenSSH's parse_principals_key_and_options() and sshsigopt_parse() (sshsig.c). Its helpers port strdelimw() (misc.c), sshkey_advance_past_options() (sshkey.c), and opt_flag(), opt_match() and opt_dequote() (auth-options.c). Options are one comma-separated field with double-quoted values, as OpenSSH requires. Space-separated options and unquoted values, which OpenSSH rejects, are now rejected too. Like OpenSSH 10.2, valid-after and valid-before must be after the epoch, and the timestamp suffix (Z or UTC) is case-insensitive. AllowedSignerParsingError::UnexpectedEnd is removed: like OpenSSH, any text after the key is a comment.
Display wrote space-separated options with unquoted values and raw UNIX timestamps, which OpenSSH rejects. Add AllowedSigner::to_line(), which writes one comma-separated options field with quoted values, timestamps as YYYYMMDDHHMMSSZ, and quotes the principals when needed. Display writes the same line. to_line() fails when OpenSSH would read a field back differently, such as a comma inside a principal or a timestamp that isn't after the epoch. It also fails for a certificate key, which PublicKey can't encode. The key's comment is left out. from_string() ignores it, and a line break in it would add another entry to the file. DateTime::from_timestamp() needs chrono 0.4.31.
from_string() accepted a few entries that to_line() can't write, so to_string() panicked on them. Reject them when parsing instead: - a line feed or NUL in a principal or namespace. OpenSSH would read a line feed as the start of a new entry, and reads a line as a C string. - a certificate as the key. PublicKey reads the wrong bytes as the key. Mark AllowedSignerParsingError as #[non_exhaustive]. Add a test that checks lines written by to_line() with ssh-keygen -Y verify. It's skipped when ssh-keygen isn't installed.
timweri
force-pushed
the
fix/allowed-signer-display
branch
from
November 10, 2026 01:14
74e1294 to
bff1450
Compare
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.
Why
AllowedSigner'sDisplaywrote lines that OpenSSH rejects: options were space-separated, values were unquoted, and timestamps were raw UNIX seconds. The parser had the same problems in reverse. It accepted lines OpenSSH rejects, and read some lines differently from OpenSSH.What
Three commits, each green on its own:
AllowedSignerSplitterwith a parser that follows OpenSSH's code:from_stringfollowsparse_principals_key_and_options()and the option loop insshsigopt_parse()(sshsig.c).strdelimw()(misc.c),advance_past_options()forsshkey_advance_past_options()(sshkey.c), andopt_flag()/opt_match()/opt_dequote()(auth-options.c).AllowedSigner::to_line() -> Result<String>;Displaywrites the same line. The format isprincipals [cert-authority,namespaces="…",valid-after="…Z",valid-before="…Z"] keytype base64. Principals are quoted when needed.to_line()fails, rather than writing something OpenSSH would read back differently. The key's comment is left out:from_stringignores it, and a line break in it would add another entry.from_stringrejects whatto_linecan't write: a line feed or NUL in a principal or namespace, and a certificate as the key. Adds an interop test that checksto_line()output withssh-keygen -Y verify. The test is skipped whenssh-keygenisn't installed.Breaking changes (for the 0.16.0 release notes)
namespaces=git,valid-after=20240101)valid-after/valid-beforeat or before the epochDisplaywith namespaces or timestamps no longer parse, andAllowedSignersfails the whole file on the first bad line. Rewrite those lines in the format above.Z/UTCsuffix in any case\"inside a quoted valueDisplaycan fail, soto_string()panics, for entries built by hand that can't be written. Useto_line()to check first.AllowedSignerParsingErroris now#[non_exhaustive], andUnexpectedEndis removed.Verification
cargo test, including:regress/unittests/misc/test_strdelim.candtest_convtime.c, and the allowed-signers lines inregress/sshsig.shtests/allowed-signer-interop.rsagainstssh-keygen(OpenSSH 10.2p1 locally)ssh-keygen -Y verify/find-principalson crafted lines.Known gaps / follow-ups (not in this PR)
AllowedSignersfails the whole file on one bad line; OpenSSH'sverifyandfind-principalsskip it. A lenient API could return the signers plus per-line errors. The error's line number also counts from 0.PublicKeyreads and writes certificates correctly."2020 101Z")20230231Z, second 60/61)a,,b); we reject them.AllowedSignerstrims Unicode whitespace from each line; OpenSSH trims only space, tab, CR and LF.*,?,!), not literal names. The field docs don't say so yet.