bring scripts and tests up to date
* use wormhole instead of transcribe.py * send() no longer waits * get_verifier -> verify * derive_key demands a length
This commit is contained in:
parent
e2aa43d0a9
commit
3a062eaa26
|
@ -3,7 +3,7 @@ import os, sys, json, binascii, six, tempfile, zipfile
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||||
from ..twisted.transcribe import wormhole
|
from ..wormhole import wormhole
|
||||||
from ..twisted.transit import TransitReceiver
|
from ..twisted.transit import TransitReceiver
|
||||||
from ..errors import TransferError
|
from ..errors import TransferError
|
||||||
|
|
||||||
|
@ -64,12 +64,12 @@ class TwistedReceiver:
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def _go(self, w, tor_manager):
|
def _go(self, w, tor_manager):
|
||||||
yield self.handle_code(w)
|
yield self.handle_code(w)
|
||||||
verifier = yield w.get_verifier()
|
verifier = yield w.verify()
|
||||||
self.show_verifier(verifier)
|
self.show_verifier(verifier)
|
||||||
them_d = yield self.get_data(w)
|
them_d = yield self.get_data(w)
|
||||||
try:
|
try:
|
||||||
if "message" in them_d:
|
if "message" in them_d:
|
||||||
yield self.handle_text(them_d, w)
|
self.handle_text(them_d, w)
|
||||||
returnValue(None)
|
returnValue(None)
|
||||||
if "file" in them_d:
|
if "file" in them_d:
|
||||||
f = self.handle_file(them_d)
|
f = self.handle_file(them_d)
|
||||||
|
@ -89,7 +89,7 @@ class TwistedReceiver:
|
||||||
raise RespondError("unknown offer type")
|
raise RespondError("unknown offer type")
|
||||||
except RespondError as r:
|
except RespondError as r:
|
||||||
data = json.dumps({"error": r.response}).encode("utf-8")
|
data = json.dumps({"error": r.response}).encode("utf-8")
|
||||||
yield w.send(data)
|
w.send(data)
|
||||||
raise TransferError(r.response)
|
raise TransferError(r.response)
|
||||||
returnValue(None)
|
returnValue(None)
|
||||||
|
|
||||||
|
@ -119,12 +119,11 @@ class TwistedReceiver:
|
||||||
raise TransferError(them_d["error"])
|
raise TransferError(them_d["error"])
|
||||||
returnValue(them_d)
|
returnValue(them_d)
|
||||||
|
|
||||||
@inlineCallbacks
|
|
||||||
def handle_text(self, them_d, w):
|
def handle_text(self, them_d, w):
|
||||||
# we're receiving a text message
|
# we're receiving a text message
|
||||||
self.msg(them_d["message"])
|
self.msg(them_d["message"])
|
||||||
data = json.dumps({"message_ack": "ok"}).encode("utf-8")
|
data = json.dumps({"message_ack": "ok"}).encode("utf-8")
|
||||||
yield w.send(data, wait=True)
|
w.send(data)
|
||||||
|
|
||||||
def handle_file(self, them_d):
|
def handle_file(self, them_d):
|
||||||
file_data = them_d["file"]
|
file_data = them_d["file"]
|
||||||
|
@ -183,12 +182,13 @@ class TwistedReceiver:
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def establish_transit(self, w, them_d, tor_manager):
|
def establish_transit(self, w, them_d, tor_manager):
|
||||||
transit_key = w.derive_key(APPID+u"/transit-key")
|
|
||||||
transit_receiver = TransitReceiver(self.args.transit_helper,
|
transit_receiver = TransitReceiver(self.args.transit_helper,
|
||||||
no_listen=self.args.no_listen,
|
no_listen=self.args.no_listen,
|
||||||
tor_manager=tor_manager,
|
tor_manager=tor_manager,
|
||||||
reactor=self._reactor,
|
reactor=self._reactor,
|
||||||
timing=self.args.timing)
|
timing=self.args.timing)
|
||||||
|
transit_key = w.derive_key(APPID+u"/transit-key",
|
||||||
|
transit_receiver.TRANSIT_KEY_LENGTH)
|
||||||
transit_receiver.set_transit_key(transit_key)
|
transit_receiver.set_transit_key(transit_key)
|
||||||
direct_hints = yield transit_receiver.get_direct_hints()
|
direct_hints = yield transit_receiver.get_direct_hints()
|
||||||
relay_hints = yield transit_receiver.get_relay_hints()
|
relay_hints = yield transit_receiver.get_relay_hints()
|
||||||
|
@ -199,7 +199,7 @@ class TwistedReceiver:
|
||||||
"relay_connection_hints": relay_hints,
|
"relay_connection_hints": relay_hints,
|
||||||
},
|
},
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
yield w.send(data)
|
w.send(data)
|
||||||
|
|
||||||
# now receive the rest of the owl
|
# now receive the rest of the owl
|
||||||
tdata = them_d["transit"]
|
tdata = them_d["transit"]
|
||||||
|
|
|
@ -5,7 +5,7 @@ from twisted.protocols import basic
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||||
from ..errors import TransferError
|
from ..errors import TransferError
|
||||||
from ..twisted.transcribe import wormhole
|
from ..wormhole import wormhole
|
||||||
from ..twisted.transit import TransitSender
|
from ..twisted.transit import TransitSender
|
||||||
|
|
||||||
APPID = u"lothar.com/wormhole/text-or-file-xfer"
|
APPID = u"lothar.com/wormhole/text-or-file-xfer"
|
||||||
|
@ -83,7 +83,7 @@ def _send(reactor, w, args, phase1, fd_to_send, tor_manager):
|
||||||
# get the verifier, because that also lets us derive the transit key,
|
# get the verifier, because that also lets us derive the transit key,
|
||||||
# which we want to set before revealing the connection hints to the far
|
# which we want to set before revealing the connection hints to the far
|
||||||
# side, so we'll be ready for them when they connect
|
# side, so we'll be ready for them when they connect
|
||||||
verifier_bytes = yield w.get_verifier()
|
verifier_bytes = yield w.verify()
|
||||||
verifier = binascii.hexlify(verifier_bytes).decode("ascii")
|
verifier = binascii.hexlify(verifier_bytes).decode("ascii")
|
||||||
|
|
||||||
if args.verify:
|
if args.verify:
|
||||||
|
@ -94,14 +94,15 @@ def _send(reactor, w, args, phase1, fd_to_send, tor_manager):
|
||||||
if ok.lower() == "no":
|
if ok.lower() == "no":
|
||||||
err = "sender rejected verification check, abandoned transfer"
|
err = "sender rejected verification check, abandoned transfer"
|
||||||
reject_data = json.dumps({"error": err}).encode("utf-8")
|
reject_data = json.dumps({"error": err}).encode("utf-8")
|
||||||
yield w.send(reject_data)
|
w.send(reject_data)
|
||||||
raise TransferError(err)
|
raise TransferError(err)
|
||||||
if fd_to_send is not None:
|
if fd_to_send is not None:
|
||||||
transit_key = w.derive_key(APPID+"/transit-key")
|
transit_key = w.derive_key(APPID+"/transit-key",
|
||||||
|
transit_sender.TRANSIT_KEY_LENGTH)
|
||||||
transit_sender.set_transit_key(transit_key)
|
transit_sender.set_transit_key(transit_key)
|
||||||
|
|
||||||
my_phase1_bytes = json.dumps(phase1).encode("utf-8")
|
my_phase1_bytes = json.dumps(phase1).encode("utf-8")
|
||||||
yield w.send(my_phase1_bytes)
|
w.send(my_phase1_bytes)
|
||||||
|
|
||||||
# this may raise WrongPasswordError
|
# this may raise WrongPasswordError
|
||||||
them_phase1_bytes = yield w.get()
|
them_phase1_bytes = yield w.get()
|
||||||
|
|
|
@ -453,7 +453,7 @@ class Cleanup(ServerBase, unittest.TestCase):
|
||||||
yield send_d
|
yield send_d
|
||||||
yield receive_d
|
yield receive_d
|
||||||
|
|
||||||
cids = self._rendezvous.get_app(cmd_send.APPID).get_claimed()
|
cids = self._rendezvous.get_app(cmd_send.APPID).get_nameplate_ids()
|
||||||
self.assertEqual(len(cids), 0)
|
self.assertEqual(len(cids), 0)
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
|
@ -482,6 +482,7 @@ class Cleanup(ServerBase, unittest.TestCase):
|
||||||
yield self.assertFailure(send_d, WrongPasswordError)
|
yield self.assertFailure(send_d, WrongPasswordError)
|
||||||
yield self.assertFailure(receive_d, WrongPasswordError)
|
yield self.assertFailure(receive_d, WrongPasswordError)
|
||||||
|
|
||||||
cids = self._rendezvous.get_app(cmd_send.APPID).get_claimed()
|
cids = self._rendezvous.get_app(cmd_send.APPID).get_nameplate_ids()
|
||||||
self.assertEqual(len(cids), 0)
|
self.assertEqual(len(cids), 0)
|
||||||
|
self.flushLoggedErrors(WrongPasswordError)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user