-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Team,
I need to convert SSH2-formatted public keys to the SSH format.
So far (by poking around) I managed to find out there's this public_bytes() method on the RSA type of keys (the ones which are put in the SSHKey.rsa attribute).
But I also need to support other key types (like ECDSA).
How should I serialize those into the SSH format?
The use case: original public keys are 'stored' in the 'plain text' (PEM? not much familiar w/the lingo) format containing those ---- BEGIN SSH2 PUBLIC KEY ---- markers. This format needs to be converted to the SSH (OpenSSH?) format like ssh-rsa <base64-encoded data>.
I tried to looks through the source code but am not sure about what to do w/apparently 'binary' string for a ECDSA public keys.
My current code looks like:
parsedKey = SSHKey(publicKey)
parsedKey.parse()
if parsedKey.rsa:
return (
parsedKey.rsa.public_bytes(
serialization.Encoding.OpenSSH,
serialization.PublicFormat.OpenSSH)).decode()
else:
# this is wrong data format. need help here
return parsedKey.ecdsa.to_string()Any help?