Giter VIP home page Giter VIP logo

Comments (2)

aafanasyev avatar aafanasyev commented on June 14, 2024

Dear Piotr,

I am trying to create a server according your main example. However, I believe my code is missing something:

#!/usr/bin/env python

import socket
from noise.builder import NoiseBuilder

host = '127.0.1.1'  
port = 8888
payload = 1500
server_address = (host, port)

def start_TCP_server():
    proto = NoiseBuilder.from_name(b'Noise_NN_25519_ChaChaPoly_SHA256')
    proto.get_handshake_hash()
    proto.set_as_responder()
    proto.start_handshake()
    
    message = proto.write_message()

    socket_Noise = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    socket_Noise.bind(server_address)
    socket_Noise.listen(1)

    print("Noise server is running...")

    while True:    
        client, client_address = socket_Noise.accept()
        print(client_address)

        while True:
            data = client.recv(payload)
            if not data: 
                break
            client.sendall(data)

if __name__ == "__main__":
    start_TCP_server()

May you help me out?

Thank you.

from noiseprotocol.

plizonczyk avatar plizonczyk commented on June 14, 2024

Hello Andrey,
I've updated the readme in trunk branch of the repository: https://github.com/plizonczyk/noiseprotocol/tree/trunk

Regarding the code snippet you've pasted:

  1. proto.get_handshake_hash() statement has no effect
  2. you can't write message before reading a message from initiator if in the responder role - NoiseBuilder would raise a NoiseHandshakeError in this case.
Traceback (most recent call last):
...
noise.exceptions.NoiseHandshakeError: NoiseBuilder.read_message has to be called now
  1. you need to use proto you've created to encrypt data sent to the other party. So, instead of client.sendall(data) you should use client.sendall(proto.write_message(data)). By the way, you need to feed the data received from the initiator into proto first in order to decrypt it - so after data = client.recv(payload) you should do plaintext = proto.read_message(data).
  2. after finishing handshake (in case of this pattern (NN) - after one cycle of read/write) - you should use proto.encrypt and proto.decrypt.

If you won't be able to figure it out based on the updated readme - please let me know and we'll fix up your code.

Kind regards,
Piotr

from noiseprotocol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.