0z5a opened a new pull request, #2229:
URL: https://github.com/apache/libcloud/pull/2229

   ## Fix get_pubkey_openssh_fingerprint for Ed25519 and ECDSA keys
   
   ### Description
   
   `libcloud.utils.publickey.get_pubkey_openssh_fingerprint()` re-serializes 
the key in OpenSSH format and then drops the first 7 bytes before 
base64-decoding the rest. That only works for `ssh-rsa` keys, where the key 
type is exactly 7 characters long.
   
   For other key types the slice cuts in the wrong place:
   
   - Ed25519 (`ssh-ed25519 AAAA...`): the leftover `25519 AAAA...` still 
decodes, so the function silently returns a wrong fingerprint.
   - ECDSA (`ecdsa-sha2-nistp256 AAAA...`): decoding fails with 
`binascii.Error: Incorrect padding`.
   
   Example with an Ed25519 key, compared with `ssh-keygen -l -E md5 -f key.pub`:
   
   ```
   ssh-keygen:                       
MD5:b4:92:d5:74:2f:4f:b4:df:8a:a0:bf:8a:0c:56:ed:e8
   get_pubkey_openssh_fingerprint(): 
52:9e:09:2c:98:3e:2c:25:92:b4:df:a5:98:3c:3e:90
   ```
   
   RSA keys are fine, and the existing RSA test still gives the same value.
   
   This function sets the `fingerprint` attribute of the key pairs returned by 
the Vultr driver (`list_key_pairs()`, `get_key_pair()`, 
`import_key_pair_from_string()`). With an Ed25519 key on the account the 
fingerprint is wrong. With an ECDSA key the `binascii.Error` is not caught by 
the driver (it only catches `RuntimeError` for a missing `cryptography`), so 
`list_key_pairs()` fails.
   
   The fix splits the OpenSSH output on the space and decodes only the base64 
key blob, whatever the key type is. The fingerprint is then the MD5 of the key 
blob, which is what `ssh-keygen -E md5` reports.
   
   I added Ed25519 and ECDSA (nistp256) test cases next to the existing RSA 
one. The expected values come from `ssh-keygen -l -E md5`. Both new tests fail 
on trunk and pass with this change. I also added a CHANGES.rst entry.
   
   ### Status
   
   - done, ready for review
   
   ### Checklist (tick everything that applies)
   
   - [x] [Code 
linting](http://libcloud.readthedocs.org/en/latest/development.html#code-style-guide)
 (required, can be done after the PR checks)
   - [ ] Documentation
   - [x] [Tests](http://libcloud.readthedocs.org/en/latest/testing.html)
   - [ ] 
[ICLA](http://libcloud.readthedocs.org/en/latest/development.html#contributing-bigger-changes)
 (required for bigger changes)
   
   This change was drafted with Claude Code (claude-opus-5-5); the test results 
above are from the runs described.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to