An stunnel like program that utilizes the Noise protocol.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 lines
920 B

  1. from twistednoise import genkeypair
  2. from noise.connection import NoiseConnection, Keypair
  3. server_key_pair = genkeypair()
  4. client_key_pair = genkeypair()
  5. init = NoiseConnection.from_name(b'Noise_XK_448_ChaChaPoly_SHA256')
  6. init.set_as_initiator()
  7. init.set_keypair_from_private_bytes(Keypair.STATIC, client_key_pair[1])
  8. init.set_keypair_from_public_bytes(Keypair.REMOTE_STATIC, server_key_pair[0])
  9. resp = NoiseConnection.from_name(b'Noise_XK_448_ChaChaPoly_SHA256')
  10. resp.set_as_responder()
  11. resp.set_keypair_from_private_bytes(Keypair.STATIC, server_key_pair[1])
  12. init.start_handshake()
  13. resp.start_handshake()
  14. messages = []
  15. cursend, currecv = init, resp
  16. while not init.handshake_finished and not resp.handshake_finished:
  17. # send a message
  18. msg = cursend.write_message()
  19. currecv.read_message(msg)
  20. # record it
  21. messages.append(msg)
  22. # swap roles
  23. cursend, currecv = currecv, cursend
  24. print(list(map(len, messages)))