Browse Source

get data flowing in the opposite direction... now we need to work

on the client part of things..
tags/v0.1.0
John-Mark Gurney 5 years ago
parent
commit
d8407f7ef1
1 changed files with 25 additions and 2 deletions
  1. +25
    -2
      twistednoise.py

+ 25
- 2
twistednoise.py View File

@@ -58,6 +58,9 @@ class TwistedNoiseServerProtocol(twisted.internet.protocol.Protocol):
# Start Handshake
noise.start_handshake()

def encData(self, data):
self.transport.write(self.noise.encrypt(data))

def dataReceived(self, data):
if not self.noise.handshake_finished:
self.noise.read_message(data)
@@ -80,7 +83,8 @@ class TwistedNoiseServerProtocol(twisted.internet.protocol.Protocol):
self.transport.resumeProducing()

class ClientProxyProtocol(twisted.internet.protocol.Protocol):
pass
def dataReceived(self, data):
self.factory.noiseproto.encData(data)

class ClientProxyFactory(Factory):
protocol = ClientProxyProtocol
@@ -144,6 +148,14 @@ class TNServerTest(unittest.TestCase):

@defer.inlineCallbacks
def test_testprotocol(self):
#
# How this test is plumbed:
#
# proto (NoiseConnection) -> self.tr (StringTransport) ->
# self.proto (TwistedNoiseServerProtocol) ->
# self.proto.endpoint (ClientProxyProtocol) -> unix sock ->
# self.protos[0] (AccumulatingProtocol)
#
# Create client
proto = NoiseConnection.from_name(b'Noise_XK_448_ChaChaPoly_SHA256')
proto.set_as_initiator()
@@ -195,9 +207,20 @@ class TNServerTest(unittest.TestCase):
# wait to pass it through
d = yield task.deferLater(reactor, .1, bool, 1)

# fetch it out
# fetch remote end out
clientend = self.protos[0]
self.assertEqual(clientend.data, ptmsg)

# send a message the other direction
rptmsg = b'this is a different test message going the other way'
clientend.transport.write(rptmsg)

# wait to pass it through
d = yield task.deferLater(reactor, .1, bool, 1)

# receive it and decrypt it
resp = self.tr.value()
self.assertEqual(proto.decrypt(resp), rptmsg)

# clean up connection
clientend.transport.loseConnection()

Loading…
Cancel
Save