Test private key parsing for commentless edge case #216
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.
If a "PEM-like" OpenSSH format private key:
=
bytes for padding;then
ssh_key::private::PrivateKey::from_openssh
fails to successfully parse the key.The root cause is
base64ct
(prior to RustCrypto/formats#1387) incorrectly rejecting zero-length reads when the base64-encoded buffer was empty. This wouldn't happen if:=
padding characters, because those would cause the decoder to believe a read would succeed (even though it wouldn't if the read was longer than zero bytes).Debugging this was... an amusement.
The most reliable way to demonstrate this is with an ECDSA P-256 key without a comment (easily generated with
ssh-keygen -t ecdsa -b 256 -C '' -N '' -f <file>
), because they usually (but not always) are of an appropriate length to trigger the bug. Amusingly (cough), the existing ECDSA P-256 key inssh-key/tests/examples/id_ecdsa_p256
is one of the outliers, as itsd
is 33 bytes, rather than 32, which means that key (when stripped of its comment) doesn't trigger the bug.This PR is marked as "Draft" because while it adds a test case for the bug, which I believe is valuable, the actual fix is in
base64ct
, which I've referenced as aCargo.toml
patch.Thus in its current form, presumably, this PR is not suitable for merge.
It is possible to work around the bug in
base64ct
by guarding reads withreader.remaining_len() > 0
tests in various places, but to me that seems far uglier than just updatingbase64ct
and depending on a fixed version.However, if you'd like to keep the
base64ct
dependency open, I can rework this PR to include guards in the appropriate spot(s).