diff --git a/bin/receive_file.py b/bin/receive_file.py index 00c3b08..f30ce2f 100644 --- a/bin/receive_file.py +++ b/bin/receive_file.py @@ -1,9 +1,8 @@ from __future__ import print_function -import os, sys, json +import os, json from binascii import unhexlify from nacl.secret import SecretBox from wormhole.blocking.transcribe import Receiver -from wormhole.codes import input_code_with_completion from wormhole.blocking.transit import TransitReceiver APPID = "lothar.com/wormhole/file-xfer" @@ -18,7 +17,7 @@ mydata = json.dumps({ }, }).encode("utf-8") r = Receiver(APPID, mydata) -r.set_code(r.input_code("Enter receive-text wormhole code: ")) +r.set_code(r.input_code("Enter receive-file wormhole code: ")) data = json.loads(r.get_data().decode("utf-8")) print("their data: %r" % (data,)) @@ -30,11 +29,12 @@ filesize = file_data["filesize"] # now receive the rest of the owl tdata = data["transit"] +print("calling tr.set_transit_key()") transit_receiver.set_transit_key(tdata["key"]) transit_receiver.add_sender_direct_hints(tdata["direct_connection_hints"]) transit_receiver.add_sender_relay_hints(tdata["relay_connection_hints"]) -transit_receiver.establish_connection() -encrypted = transit_receiver.receive() +skt = transit_receiver.establish_connection() +encrypted = skt.recv(filesize) decrypted = SecretBox(xfer_key).decrypt(encrypted) diff --git a/bin/receive_text.py b/bin/receive_text.py index 3a3a712..4090190 100644 --- a/bin/receive_text.py +++ b/bin/receive_text.py @@ -1,7 +1,6 @@ from __future__ import print_function import time, json from wormhole.blocking.transcribe import Receiver -from wormhole.codes import input_code_with_completion APPID = "lothar.com/wormhole/text-xfer" diff --git a/bin/send_file.py b/bin/send_file.py index 9f7537c..e5c1951 100644 --- a/bin/send_file.py +++ b/bin/send_file.py @@ -41,12 +41,13 @@ print("them: %r" % (them_d,)) box = SecretBox(xfer_key) with open(filename, "rb") as f: plaintext = f.read() -nonce = utils.random(SecretBox.NONCE_SIZE) +nonce = os.urandom(SecretBox.NONCE_SIZE) encrypted = box.encrypt(plaintext, nonce) -transit_sender.add_receiver_hints(them_d["direct_connection_hints"]) -transit_sender.establish_connection() -transit_sender.write(encrypted) -transit_sender.close() +tdata = them_d["transit"] +transit_sender.add_receiver_hints(tdata["direct_connection_hints"]) +skt = transit_sender.establish_connection() +skt.write(encrypted) +skt.close() print("file sent") diff --git a/src/wormhole/blocking/transit.py b/src/wormhole/blocking/transit.py index cd35b23..d950b1d 100644 --- a/src/wormhole/blocking/transit.py +++ b/src/wormhole/blocking/transit.py @@ -116,6 +116,8 @@ class BadHandshake(Exception): pass def connector(owner, hint, send_handshake, expected_handshake): + if isinstance(hint, type(u"")): + hint = hint.encode("ascii") addr,port = hint.split(",") skt = socket.create_connection((addr,port)) # timeout here skt.settimeout(TIMEOUT) @@ -168,7 +170,7 @@ class MyTCPServer(SocketServer.TCPServer): allow_reuse_address = True def process_request(self, request, client_address): if not self.owner.key: - raise BadHandshake("connection received before set_key()") + raise BadHandshake("connection received before set_transit_key()") t = threading.Thread(target=handle, args=(request, client_address, self.owner, @@ -181,6 +183,7 @@ class TransitReceiver: def __init__(self): self.winning = threading.Event() self._negotiation_check_lock = threading.Lock() + self.key = None server = MyTCPServer(("",9999), None) _, port = server.server_address self.my_direct_hints = ["%s,%d" % (addr, port)