Repository navigation
Conversation
a33c2de to
ba91dca
Compare
|
@bitprophet maybe someone can review this pr? |
|
The next unit of work for paramiko is planned to be the drop of Python 2 and older 3.x, after which will be the major key/auth overhaul indicated by #387. Please correct me if I'm wrong, but it looks like this PR would be under the umbrella of the auth overhaul? If so, we'll flag this as something to consider as part of that effort. Either way, thank you for the contribution! We'll get it worked in as soon as possible...no firm idea of what that timeline will be, though. |
|
I figured I'd add the following over here too in case someone is searching for a way to go ahead and generate ed25519 keys and use the result with The following code snippet works for ed25519 key generation using 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)This and other info is over in And just in case it's not crystal clear what is happening in that code, the So, you would use it as expected: ssh_client.connect(hostname=ip, username='ubuntu', pkey=pkey) |
|
I don't think much needs to be done to change No worries tho. Proceed as you see fit. |
|
Nod, it does seem like a fairly small, straightforward change. But, I'm not deeply familiar with the codebase---I'm just helping triage---so I hesitate to say anything authoritative. In any event, it'll be bitprophet's call how he wants to tackle it. If the key handling system is going to be substantially different from the current version, I could see it making more sense only taking the time to implement and release it the new way. |
|
Totally understand. I can see that the PR that we're taking under touches quite a few things. I would propose a much more narrow PR that simply adds a But again, no worries. There is always monkey patching. Which is what I'm looking at next. |
|
I am incorrect about the above. All the |
|
Thanks again for all your work here, @utkonos -- it'll be a big help. |
|
Curious how this and #1806 overlap 🤔 I may try folding this or that, into the 3.0 release after all (it'd let us remove a dependency outright!), but per Brian's notes, this may instead wait for a later feature-oriented release. |
837d814 to
9d79ba6
Compare
|
@bitprophet just rebased on v4.0. can we review this after years? :D |
Ed25519 support arrived in 2.2 (paramiko#325 via paramiko#972) backed by PyNaCl, because Cryptography had no Ed25519 primitive at the time; it landed in Cryptography 2.6, roughly two years later. Our floor is already 3.3, so the primitive has been available across the entire supported range, and Ed25519Key was the last remaining user of PyNaCl. Beyond dropping a C-extension dependency, this puts Ed25519 under the same OpenSSL configuration that already governs every other key type, cipher and KEX we use -- including any algorithm policy the host OpenSSL enforces, which a separately bundled libsodium cannot participate in. Compare KexCurve25519.is_available(), which already defers to Cryptography for exactly that reason. Implementation notes: * Uses public_bytes(Encoding.Raw, PublicFormat.Raw) rather than the tidier public_bytes_raw(), which only exists as of Cryptography 40. The older spelling works across our whole supported range, including the 3.3.2 and 39.0.0 cells in CI. * Ed25519Key._fields now holds the key's raw bytes rather than the key object itself. Cryptography's key objects compare by identity on older versions (3.3.2, 39.0.0) and are unhashable on newer ones, so neither is safe for the equality and hashing contract PKey relies on here; raw bytes are exact on every version. test_ed25519_compare gains a hash() assertion so it covers both failure modes. * Cryptography's verify() takes (signature, data), the reverse of PyNaCl's verify(smessage, signature). Wire format is unchanged. Ed25519 is deterministic, so the new test_sign_and_verify_ed25519 pins the exact signature bytes the PyNaCl implementation produced for the existing test key. The one user-visible change is Ed25519Key.verifying_key, which now returns an Ed25519PublicKey rather than a nacl.signing.VerifyKey. Refs paramiko#1419, paramiko#2527. Builds on the earlier attempts by @adiroiban in paramiko#1806 and @boyxuper in paramiko#2103.
Ed25519 support arrived in 2.2 (paramiko#325 via paramiko#972) backed by PyNaCl, because Cryptography had no Ed25519 primitive at the time; it landed in Cryptography 2.6, roughly two years later. Our floor is already 3.3, so the primitive has been available across the entire supported range, and Ed25519Key was the last remaining user of PyNaCl. Beyond dropping a C-extension dependency, this puts Ed25519 under the same OpenSSL configuration that already governs every other key type, cipher and KEX we use -- including any algorithm policy the host OpenSSL enforces, which a separately bundled libsodium cannot participate in. Compare KexCurve25519.is_available(), which already defers to Cryptography for exactly that reason. Implementation notes: * Uses public_bytes(Encoding.Raw, PublicFormat.Raw) rather than the tidier public_bytes_raw(), which only exists as of Cryptography 40. The older spelling works across our whole supported range, including the 3.3.2 and 39.0.0 cells in CI. * Ed25519Key._fields now holds the key's raw bytes rather than the key object itself. Cryptography's key objects compare by identity on older versions (3.3.2, 39.0.0) and are unhashable on newer ones, so neither is safe for the equality and hashing contract PKey relies on here; raw bytes are exact on every version. test_ed25519_compare gains a hash() assertion so it covers both failure modes. * Cryptography's verify() takes (signature, data), the reverse of PyNaCl's verify(smessage, signature). Wire format is unchanged. Ed25519 is deterministic, so the new test_sign_and_verify_ed25519 pins the exact signature bytes the PyNaCl implementation produced for the existing test key. The one user-visible change is Ed25519Key.verifying_key, which now returns an Ed25519PublicKey rather than a nacl.signing.VerifyKey. Refs paramiko#1419, paramiko#2527. Builds on the earlier attempts by @adiroiban in paramiko#1806 and @boyxuper in paramiko#2103.
Ed25519Key was the last thing using PyNaCl, and only did so because Cryptography had no Ed25519 primitive back when 2.2 shipped; it grew one in 2.6 and our floor is already 3.3. Wire format is unchanged. _fields now holds the key's raw bytes rather than the key object, since Cryptography's key objects compare by identity on older versions and are unhashable on newer ones. verifying_key returns an Ed25519PublicKey rather than a nacl.signing.VerifyKey, which is the one API change. Refs paramiko#1419, paramiko#2527. Same approach as paramiko#1806 and paramiko#2103.
Ed25519Key was the last thing using PyNaCl, and only did so because Cryptography had no Ed25519 primitive back when 2.2 shipped; it grew one in 2.6 and our floor is already 3.3. Wire format is unchanged. _fields now holds the key's raw bytes rather than the key object, since Cryptography's key objects compare by identity on older versions and are unhashable on newer ones. verifying_key returns an Ed25519PublicKey rather than a nacl.signing.VerifyKey, which is the one API change. Refs paramiko#1419, paramiko#2527. Same approach as paramiko#1806 and paramiko#2103.
| filename=None, | ||
| password=None, | ||
| file_obj=None, | ||
| vals=None, |
There was a problem hiding this comment.
do we really need vals here and change the constructor signature?
| from paramiko.util import b | ||
|
|
||
|
|
||
| def public_bytes_raw(verify_key): |
There was a problem hiding this comment.
this is not required I think. it simply calls
self.public_bytes(
_serialization.Encoding.Raw, _serialization.PublicFormat.Raw
)
so we can either do the same or create our own helper method instead of calling a private method.
|
@boyxuper could you rebase? @bitprophet is this something that would be accepted? |
|
friendly ping. it would be really cool to get rid of nacl and only include a single crypto lib. |
|
@boyxuper are you still interested in this change? |
|
@boyxuper thx for updating but CI fails now. could you fix it please? (eg. by running |



note: cryptography>=2.6 has ed25519 support, so maybe we can boost the version requirement to 2.6 for merge test?