|
@@ -2,8 +2,9 @@ from noise.connection import NoiseConnection, Keypair |
|
|
from cryptography.hazmat.primitives.kdf.hkdf import HKDF |
|
|
from cryptography.hazmat.primitives.kdf.hkdf import HKDF |
|
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes |
|
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes |
|
|
from cryptography.hazmat.primitives import hashes |
|
|
from cryptography.hazmat.primitives import hashes |
|
|
from twistednoise import genkeypair |
|
|
|
|
|
from cryptography.hazmat.backends import default_backend |
|
|
from cryptography.hazmat.backends import default_backend |
|
|
|
|
|
from cryptography.hazmat.primitives.asymmetric import x448 |
|
|
|
|
|
from cryptography.hazmat.primitives import serialization |
|
|
|
|
|
|
|
|
import asyncio |
|
|
import asyncio |
|
|
import os.path |
|
|
import os.path |
|
@@ -15,6 +16,22 @@ import unittest |
|
|
|
|
|
|
|
|
_backend = default_backend() |
|
|
_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): |
|
|
def _makefut(obj): |
|
|
loop = asyncio.get_running_loop() |
|
|
loop = asyncio.get_running_loop() |
|
|
fut = loop.create_future() |
|
|
fut = loop.create_future() |
|
|