Skip to content

Any examples of SSH-formatted key output for all types of keys? #108

@nskmda

Description

@nskmda

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions