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()