Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nskmda opened this issue Jan 23, 2025 · 0 comments
Open

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

nskmda opened this issue Jan 23, 2025 · 0 comments

Comments

@nskmda
Copy link

nskmda commented Jan 23, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant