Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh-key: fix parsing comments with whitespace in AuthorizedKeys #289

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

mkeeter
Copy link
Contributor

@mkeeter mkeeter commented Aug 28, 2024

ssh_key::PublicKey::read_openssh_file can read the following key:

ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBN76zuqnjypL54/w4763l7q1Sn3IBYHptJ5wcYfEWkzeNTvpexr05Z18m2yPT2SWRd1JJ8Aj5TYidG9MdSS5J78= hello world

However, if I treat it as a single-line authorized_keys and read it with ssh_key::AuthorizedKeys::read_file, it fails:

  --- stderr
  Error: failed to read authorized keys from: "authorized_keys"

  Caused by:
      0: Base64 encoding error: invalid Base64 encoding
      1: Base64 encoding error: invalid Base64 encoding
      2: invalid Base64 encoding

This is because the authorized_keys parser doesn't respect spaces in the comment field, so it's trying to parse ecdsa-sha2-nistp256 as the options and hello as the key material.


This PR fixes the issue, and also adds a unit test for authorized_keys with whitespace in their comments.

@mkeeter mkeeter changed the title Fix parsing comments with whitespace in AuthorizedKeys ssh-key: fix parsing comments with whitespace in AuthorizedKeys Aug 29, 2024
@tarcieri tarcieri merged commit bac2931 into RustCrypto:master Sep 5, 2024
14 checks passed
mkeeter added a commit to oxidecomputer/SSH that referenced this pull request Oct 4, 2024
labbott added a commit to oxidecomputer/sshauth that referenced this pull request Oct 8, 2024
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.

2 participants