-
Notifications
You must be signed in to change notification settings - Fork 40
ssh-key: support for undersized ECDSA/P-521 keys #351
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
Conversation
zaczkows
commented
Apr 15, 2025
- fixes Failed to process python's paramiko ecdsa key #350
- I still need to investigate key encoding to ensure code is even remotely correct
ssh-key/src/private/ecdsa.rs
Outdated
if len < SIZE { | ||
reader.read(&mut bytes[0..len])?; | ||
} else { | ||
reader.read(&mut bytes)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this could just be:
if len < SIZE { | |
reader.read(&mut bytes[0..len])?; | |
} else { | |
reader.read(&mut bytes)?; | |
} | |
reader.read(&mut bytes[..len])?; |
...but also it would be good to also check that len <= SIZE
? (unless that check is happening elsewhere)
It would also be good to enforce a minimum size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I'm trying to check and how much smaller the key can be.
// https://stackoverflow.com/questions/50002149/why-p-521-public-key-x-y-some-time-is-65-bytes-some-time-is-66-bytes | ||
// although lower keys than 64 are vanishingly possible, but lets stop here | ||
if len > 63 { | ||
reader.read(&mut bytes[..core::cmp::min(len, SIZE)])?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, upon further reflection this seems wrong: the key is supposed to be big endian, so the array should contain leading zeros, not trailing zeros, in the event the input document's key is too short.
It would also be good to add a test that the key is decoded correctly.
I'll try to take care of this in #356
Followup to #351 Also includes a fix and test to ensure that short keys zero-pad MSB rather than LSB, since they're encoded as big endian.
Followup to #351 Also includes a fix and test to ensure that short keys zero-pad MSB rather than LSB, since they're encoded as big endian.
Followup to #351 Also includes a fix and test to ensure that short keys zero-pad MSB rather than LSB, since they're encoded as big endian.