diff --git a/ntunnel.py b/ntunnel.py index e012e4d..3736243 100644 --- a/ntunnel.py +++ b/ntunnel.py @@ -2,8 +2,9 @@ from noise.connection import NoiseConnection, Keypair from cryptography.hazmat.primitives.kdf.hkdf import HKDF from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives import hashes -from twistednoise import genkeypair from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.asymmetric import x448 +from cryptography.hazmat.primitives import serialization import asyncio import os.path @@ -15,6 +16,22 @@ import unittest _backend = default_backend() +def genkeypair(): + '''Generates a keypair, and returns a tuple of (public, private). + They are encoded as raw bytes, and sutible for use w/ Noise.''' + + key = x448.X448PrivateKey.generate() + + enc = serialization.Encoding.Raw + pubformat = serialization.PublicFormat.Raw + privformat = serialization.PrivateFormat.Raw + encalgo = serialization.NoEncryption() + + pub = key.public_key().public_bytes(encoding=enc, format=pubformat) + priv = key.private_bytes(encoding=enc, format=privformat, encryption_algorithm=encalgo) + + return pub, priv + def _makefut(obj): loop = asyncio.get_running_loop() fut = loop.create_future() diff --git a/requirements.txt b/requirements.txt index 54f5c36..8c1878d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,2 @@ coverage -e git+https://github.com/jmgurney/noiseprotocol.git@ab6f8ebe0e28f5a4105928c13baddcfdc43b7e82#egg=noiseprotocol -twisted -mock