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

Constant time base64 decoded_len returns InvalidLength on fully valid data #1609

Open
httpjamesm opened this issue Nov 16, 2024 · 1 comment

Comments

@httpjamesm
Copy link

httpjamesm commented Nov 16, 2024

I'm trying to parse an OpenSSH key using ssh_key with line lengths of 70, 70, 70, 70 and 64 without any padding, but the decoded_len (

fn decoded_len<E: Encoding>(&self) -> Result<usize, Error> {
) function in the base64ct crate returns InvalidLength for some reason. The process works without error on another key with line lengths of 70, 70, 70, 70 and 32 with padding. Decoding with the base64 crate and re-encoding with padding results in the same input string and the same error.

Here's the contents of the erroring key (not sensitive):

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACDctrRCQ6LEyzTbsXkAQ8mhdIOQZzP/XKcuplituD2PaQAAAKC+1uNjvtbj
YwAAAAtzc2gtZWQyNTUxOQAAACDctrRCQ6LEyzTbsXkAQ8mhdIOQZzP/XKcuplituD2PaQ
AAAEAyjynmk0ex/GrImDlAEN81gXGK4tWaq36kO+HRp8szLNy2tEJDosTLNNuxeQBDyaF0
g5BnM/9cpy6mWK24PY9pAAAAFEdlbmVyYXRlZCBCeSBUZXJtaXVzAQIDBAUGBwgJ
-----END OPENSSH PRIVATE KEY-----

It appears that the checks are a little too strict, especially when other tools, like ssh-keygen, have no issues with the key.

  • ssh-key 0.6.7
  • pem 0.7.0
  • base64ct 1.6.0
  • cargo 1.80.1
@httpjamesm
Copy link
Author

httpjamesm commented Nov 16, 2024

Re-encoding the key with ssh-keygen fixed it, but it doesn't explain why the key is being rejected by base64ct

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

No branches or pull requests

1 participant