Skip to content

Ed25519 key generation support #1136

Open

Description

@max-wittig

Nearly every key, exept the Ed25519 key offers a generate function in paramiko, which is used to generate a new key pair.

Is there a reason why the ed25519 keytype doesn't have this class method?

From the documentation:
http://docs.paramiko.org/en/2.4/api/keys.html

image

Activity

  1. max-wittig commented on May 7, 2018

    @max-wittig
    Author

    Any updates on this?

  2. dopaminereceptionist commented on May 9, 2018

    @dopaminereceptionist

    Also interested in this. Should be reasonably straight forward.

  3. johnnybubonic commented on Aug 10, 2018

    @johnnybubonic

    for reference:

    here's a python 2 implementation: https://github.com/pts/py_ssh_keygen_ed25519

    here's an implementation in Go (do NOT use this one as the only reference since it purposely generates deterministic keys; just including for your reference): https://github.com/joonakannisto/determin-ed

    here's an implementation in Haskell (do NOT use this one's examples either; another deterministic-on-purpose implementation): https://github.com/mithrandi/ssh-key-generator

    here's the overview of the new "openssh-key-v1" format that ssh_ed25519 always uses: https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key
    (which you should add support for for RSA and ECDSA keys as well, since openssh has announced that'll be the default at some time in the future anyways)

    further information on the new key format:

    https://github.com/openssh/openssh-portable/blob/master/sshkey.c
    https://peterlyons.com/problog/2017/12/openssh-ed25519-private-key-file-format

    hope that helps.

  4. dopaminereceptionist commented on Oct 4, 2018

    @dopaminereceptionist

    Thank you, that's very helpful.

  5. johnnybubonic commented on Feb 27, 2019

    @johnnybubonic

    @bitprophet looks like this should be much more simplified since the cryptography module has now implemented ed25519.

  6. added this to the p1 milestone on Dec 3, 2019
  7. paprickar commented on Mar 2, 2022

    @paprickar

    @bitprophet do you have a gut feeling when this can be implemented?

  8. bitprophet commented on Mar 4, 2022

    @bitprophet
    Member

    I actually saw this independently the other day when digging into an unrelated key issue - I had need to run basic key generation and reached for Ed25519 out of "this is the current 'good key type' to use in a vacuum". And yup. It's missing this! Good to know Cryptography added it a while back.

    I see I added it to the feature milestone some time ago. I have no firm ETA for it but see https://bitprophet.org/projects/#roadmap - this one absolutely qualifies for my next set of feature-adds. Expect I'd hope to get to this after the Python 2 removal release (again per that roadmap).

  9. utkonos commented on Jun 20, 2022

    @utkonos

    For anyone that needs to just do it, the following code snippet works for ed25519 key generation using cryptography and then using io.StringIO as an interface to get the generated key into paramiko. From there, you're off to the races.

    import io
    
    from cryptography.hazmat.primitives import serialization
    from cryptography.hazmat.primitives import asymmetric
    import paramiko
    
    c_ed25519key = asymmetric.ed25519.Ed25519PrivateKey.generate()
    privpem = c_ed25519key.private_bytes(encoding=serialization.Encoding.PEM,
                                         format=serialization.PrivateFormat.OpenSSH,
                                         encryption_algorithm=serialization.NoEncryption())
    print(privpem.decode())
    
    priv_obj = io.StringIO(privpem.decode())
    p_ed25519key = paramiko.ed25519key.Ed25519Key.from_private_key(priv_obj)
    print(p_ed25519key.get_base64())
    
    pub = c_ed25519key.public_key()
    openssh_pub = pub.public_bytes(encoding=serialization.Encoding.OpenSSH,
                                   format=serialization.PublicFormat.OpenSSH)
    print(openssh_pub)

    image

  10. utkonos commented on Jun 20, 2022

    @utkonos

    Could the cryptography .generate() just be wrapped/used directly using some of the code I wrote there? Unless I'm totally mistaken, this issue could be solved with a few lines of code and a few unit tests, no?

    I can definitely write the code and PR to close this issue, I just want to make sure I'm on the right path before committing.

    BTW: there's no bits or curve selection needed for generating ed25519. The method would just be .generate() and boom, it's done.

  11. utkonos commented on Dec 27, 2022

    @utkonos

    I've been running the just do it code in production for 6 months with no issues. I looked even more closely at the dir() of the cryptography private key object and the paramiko key object. Basically c_pkey._raw_private_bytes() results in the private key raw bytes from the cryptography key. That data is exactly what needs to go in Ed25519Key._signing_key. There is literally nothing else. All the other steps are to use existing paramiko code. If the Ed25519Key class just had a raw_key parameter and didn't have the exeption, there wouldn't be much else to do. You don't even need to wait for a generate() method to pass policy decisions.

    if signing_key is None and verifying_key is None:
    raise ValueError("need a key")

    Here is the cryptography data:
    image

    Here is the paramiko data using the code I wrote to Rube Goldberg it into the format the current paramiko code can use.
    image

  12. dd-ssc commented on Jun 8, 2023

    @dd-ssc

    Any updates on this ?

    Incidentally, I was looking for a python package to generate ed25519 keys and was going to choose paramiko (mostly as I'd already heard the name from Ansible, Boto, Fabric, etc.). I'll go ahead with @utkonos code for the moment and look forward to turning that into a pure paramiko implementation at some stage in the future ✅

    Thanks for the hard work everyone - much appreciated! 👍

  13. bskinn commented on Jun 8, 2023

    @bskinn
    Contributor

    @dd-ssc -- bitprophet has been working extensively on a new architecture for #387 and #23, but I believe that's more for authentication workflows rather than key generation.

    Check out the 3.2 CHANGELOG to see the (experimental) additions in that release. I know he's planning staged addition and rollout of these features through multiple releases, so auth is going to be the focus for some time yet.

    Once that's solidified, then AFAIK he's going to turn to other fixes and features.

  14. evan0greenup commented on Mar 25, 2024

    @evan0greenup

    I've been running the just do it code in production for 6 months with no issues. I looked even more closely at the dir() of the cryptography private key object and the paramiko key object. Basically c_pkey._raw_private_bytes() results in the private key raw bytes from the cryptography key. That data is exactly what needs to go in Ed25519Key._signing_key. There is literally nothing else. All the other steps are to use existing paramiko code. If the Ed25519Key class just had a raw_key parameter and didn't have the exeption, there wouldn't be much else to do. You don't even need to wait for a generate() method to pass policy decisions.

    if signing_key is None and verifying_key is None:
    raise ValueError("need a key")

    Here is the cryptography data: image

    Here is the paramiko data using the code I wrote to Rube Goldberg it into the format the current paramiko code can use. image

    When using this method to generate ed25519 key, the key file is not passphrase protected.

  15. utkonos commented on Mar 25, 2024

    @utkonos

    When using this method to generate ed25519 key, the key file is not passphrase protected.

    Yes, that's correct. If you have a suggestion for adding password protection, please go ahead.

    On a side note: I think the probability of ed25519 key generation being supported by paramiko is zero, so please help where you are able to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions