From a1a6b65e48222ce775f5932e3505cc2f8e0e73bd Mon Sep 17 00:00:00 2001 From: Dmitrii Date: Wed, 22 Apr 2026 09:33:23 -0400 Subject: [PATCH] fix: support cryptography < 3.0 API for X25519 key serialization private_bytes_raw() was added later; fall back to private_bytes(Raw) for older system packages (e.g. Debian Bookworm python3-cryptography). Co-Authored-By: Claude Sonnet 4.6 --- scripts/setup_cell.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/setup_cell.py b/scripts/setup_cell.py index 148527d..39510bd 100644 --- a/scripts/setup_cell.py +++ b/scripts/setup_cell.py @@ -100,9 +100,15 @@ def _gen_keys_python(): """Generate WireGuard keypair using the cryptography library (no wg binary needed).""" import base64 from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey + from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat, PrivateFormat, NoEncryption private_key = X25519PrivateKey.generate() - private_bytes = private_key.private_bytes_raw() - public_bytes = private_key.public_key().public_bytes_raw() + try: + # private_bytes_raw() available in cryptography >= 3.0 + private_bytes = private_key.private_bytes_raw() + public_bytes = private_key.public_key().public_bytes_raw() + except AttributeError: + private_bytes = private_key.private_bytes(Encoding.Raw, PrivateFormat.Raw, NoEncryption()) + public_bytes = private_key.public_key().public_bytes(Encoding.Raw, PublicFormat.Raw) return base64.b64encode(private_bytes).decode(), base64.b64encode(public_bytes).decode()