Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add key format option #96

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

Open
afaranha opened this issue Apr 25, 2025 · 3 comments
Open

Add key format option #96

afaranha opened this issue Apr 25, 2025 · 3 comments

Comments

@afaranha
Copy link

I'd like to be able to choose the format of the key Im generating, for example: ssh-keygen -m PEM`, but I can't see how to do it on the library.
I was also trying other types of rsa keys (Maybe the default format would be the one I'm looking for), and it seems that they don't work:

https://github.com/ParallelSSH/ssh-python/blob/master/ssh/keytypes.pyx#L53-L60

key_type = keytypes.RSAKey()
print(key_type)

Outputs:
ssh-rsa

key_type = keytypes.RSA1Key()
print(key_type)

Outputs:
unknown

@enkore
Copy link
Member

enkore commented Apr 25, 2025

That's basically just the wrapper for an enum, see examples/keygen.py for how to use the ssh.key.generate API.

https://github.com/ParallelSSH/ssh-python/blob/master/examples/keygen.py

@enkore enkore closed this as completed Apr 25, 2025
@afaranha
Copy link
Author

Sorry if I wasn't clear when I opened the issue, but that enum if for the key type, not the key format, for example, using the terminal I can do this to generate a RSA key:

$ ssh-keygen -f test -t rsa
$ head test
-----BEGIN OPENSSH PRIVATE KEY-----

or

$ ssh-keygen -f test -t rsa -m PEM
$ head test
-----BEGIN RSA PRIVATE KEY-----

The key type is the same but the format is different.

https://man.openbsd.org/ssh-keygen.1

-m Specify a key format for key generation, the -i (import), -e (export) conversion options, and the -p change passphrase operation. The latter may be used to convert between OpenSSH private key and PEM private key formats. The supported key formats are: “RFC4716” (RFC 4716/SSH2 public or private key), “PKCS8” (PKCS8 public or private key) or “PEM” (PEM public key). By default OpenSSH will write newly-generated private keys in its own format, but when converting public keys for export the default format is “RFC4716”. Setting a format of “PEM” when generating or updating a supported private key type will cause the key to be stored in the legacy PEM private key format.

Do we have a way how to choose a different key format? On the generate function we can only pass the bits and the key type, not the key format.

@enkore
Copy link
Member

enkore commented Apr 25, 2025

Apologies. No, ssh_pki_export_privkey_file_format isn't wrapped by this library.

@enkore enkore reopened this Apr 25, 2025
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

2 participants