Skip to content

Remove pynacl dependency. - #1806

Open
adiroiban wants to merge 1 commit into
paramiko:mainfrom
chevah:remove-pynacl-deps
Open

adiroiban wants to merge 1 commit into
paramiko:mainfrom
chevah:remove-pynacl-deps

Conversation

@adiroiban

@adiroiban adiroiban commented Jan 30, 2021 •

Copy link
Copy Markdown

Scope

The pynacl is only used for ED keys.

cryptography starting with 2.6 supports ED signing.

I think that by removing the pynacl and libsodium deps, it will be much easier to deploy paramiko.
I saw a few issues about failing to use paramiko due to the pynacl deps.

Changes

Update requirements from cryptography 2.5 to 2.6 for ED support.

I think that bcrypt will remain a main deps as it is used in the new OpenSSH v1 private key format.

I kept the ed25519 extra requirement for backward compatibility.

Use cryptography to sign and validate SSH data.

Update the automated tests to include a quick sign / verify test.

Update the www docs to remove paramiko[ed25519] or pynacl deps.
Update bcrypt to informa that it's used for OpenSSH v1 private key format.

Follow up

As a followup it would be nice to refactor and remove Ed25519Key._parse_signing_key_data and instead try to usePKey._read_private_key_openssh`

How to test

In the dev environment install cryptography 2.6 and make sure pynacl is removed and run the tests

pip install -r dev-requirements.txt
pip install cryptography==2.6
pip uninstall pynacl
invoke test
flake8

Check extra requirement still works for backward compatibility:

pip install .[ed25519]

@adiroiban

Copy link
Copy Markdown
Author

Tests are failing, but I got the same failures when I run inv sites on master.

I think that paramiko automated tests should be migrated to GitHub Actions first.

Let me know if you need help with the GitHub Actions migration.

@ash-cryptocom

Copy link
Copy Markdown

Any updates? Because we are trying to install paramiko with ARM64 chip but encountered issue with pynacl: pyca/pynacl#654

@adiroiban

Copy link
Copy Markdown
Author

@ash-cryptocom you can try to the patch and see if it works for you.
I am using a forked paramiko with this patch and I have not observed any issues... but I am using paramiko only as tool to support the testing process and not for production.

@jzaleski

jzaleski commented Jul 2, 2021

Copy link
Copy Markdown

@ash-cryptocom / @adiroiban I can confirm success w/ this patch.


In addition to the patch I needed to get cffi to build the correct native-extension for my M1 mac

You can confirm you're having the same issue with the following:

> file .venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so
.venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so: Mach-O 64-bit bundle x86_64

To fix the issue run the following:

> pip[3] uninstall cffi -y && arch -arm64 pip install cffi --no-binary :all:

Verify the native-extension architecture (it should be arm64):

> file .venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so
.venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so: Mach-O 64-bit bundle arm64

I hope this helps.

@FelixSchwarz

Copy link
Copy Markdown

Probably I'm misunderstanding something but I think the minimum version of cryptography should be 2.7 as that is the first release which contains pyca/cryptography@a453d87.

jzaleski pushed a commit to jzaleski/paramiko that referenced this pull request Oct 23, 2021
@ploxiln

ploxiln commented Nov 28, 2021

Copy link
Copy Markdown
Contributor

This doesn't use cryptography for key serialization, it only uses the ed25519 signing functions added in cryptography-2.6

@ploxiln

ploxiln commented Nov 28, 2021

Copy link
Copy Markdown
Contributor

(... more accurately: this uses Raw serialization, not openssh format serialization, from cryptography, so cryptography version 2.6 should be sufficient)

toabctl added a commit to toabctl/paramiko that referenced this pull request Aug 26, 2026
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.
toabctl added a commit to toabctl/paramiko that referenced this pull request Aug 26, 2026
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.
toabctl added a commit to toabctl/paramiko that referenced this pull request Aug 26, 2026
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.
toabctl added a commit to toabctl/paramiko that referenced this pull request Aug 31, 2026
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.
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

Successfully merging this pull request may close these issues.

5 participants