Skip to content

Conversation

s-hamann
Copy link
Contributor

I found a bug in check_sshkey. Key using algorithms with long names (longer than 0x1F characters) get incorrectly rejected.
One example for such an algorithm is [email protected] (0x22 characters). This results in an extra " in $check, which then obviously does not match $algorithm.

The first four bytes of the decoded public key specify the length of the following algorithm name.
preg_replace removes these four bytes if they are in the non-printable range. Otherwise some of the length bytes end up in $check.

This PR fixes this by always discarding the first four bytes and comparing the expected number of bytes.

Previously, the algorithm name was not correctly parsed from the base64
encoded public key if the name was longer than 0x1F bytes.

The first four bytes of the decoded public key specify the length of the
following algorithm name. Since we already know the expected length, we
do not need to parse this and can directly get the algorithm name
starting at the fifth (decoded) byte.
@coudot coudot added this to the 1.8.0 milestone Aug 28, 2025
@coudot
Copy link
Member

coudot commented Aug 28, 2025

We may find a cleaner way to check if the key is valid.

Maybe with phpseclib: https://stackoverflow.com/a/65993238

@s-hamann
Copy link
Contributor Author

Using a proper library for the purpose certainly makes sense.
In the mean time, would you consider merging this PR? It turns a flawed validity check into one that does not reject valid keys. I think that's an improvement ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants