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:
Brian Warner 2016-05-24 00:00:44 -07:00
parent e2aa43d0a9
commit 3a062eaa26
3 changed files with 17 additions and 15 deletions

View File

@ -3,7 +3,7 @@ import os, sys, json, binascii, six, tempfile, zipfile
from tqdm import tqdm
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from ..twisted.transcribe import wormhole
from ..wormhole import wormhole
from ..twisted.transit import TransitReceiver
from ..errors import TransferError
@ -64,12 +64,12 @@ class TwistedReceiver:
@inlineCallbacks
def _go(self, w, tor_manager):
yield self.handle_code(w)
verifier = yield w.get_verifier()
verifier = yield w.verify()
self.show_verifier(verifier)
them_d = yield self.get_data(w)
try:
if "message" in them_d:
yield self.handle_text(them_d, w)
self.handle_text(them_d, w)
returnValue(None)
if "file" in them_d:
f = self.handle_file(them_d)
@ -89,7 +89,7 @@ class TwistedReceiver:
raise RespondError("unknown offer type")
except RespondError as r:
data = json.dumps({"error": r.response}).encode("utf-8")
yield w.send(data)
w.send(data)
raise TransferError(r.response)
returnValue(None)
@ -119,12 +119,11 @@ class TwistedReceiver:
raise TransferError(them_d["error"])
returnValue(them_d)
@inlineCallbacks
def handle_text(self, them_d, w):
# we're receiving a text message
self.msg(them_d["message"])
data = json.dumps({"message_ack": "ok"}).encode("utf-8")
yield w.send(data, wait=True)
w.send(data)
def handle_file(self, them_d):
file_data = them_d["file"]
@ -183,12 +182,13 @@ class TwistedReceiver:
@inlineCallbacks
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,
no_listen=self.args.no_listen,
tor_manager=tor_manager,
reactor=self._reactor,
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)
direct_hints = yield transit_receiver.get_direct_hints()
relay_hints = yield transit_receiver.get_relay_hints()
@ -199,7 +199,7 @@ class TwistedReceiver:
"relay_connection_hints": relay_hints,
},
}).encode("utf-8")
yield w.send(data)
w.send(data)
# now receive the rest of the owl
tdata = them_d["transit"]

View File

@ -5,7 +5,7 @@ from twisted.protocols import basic
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from ..errors import TransferError
from ..twisted.transcribe import wormhole
from ..wormhole import wormhole
from ..twisted.transit import TransitSender
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,
# which we want to set before revealing the connection hints to the far
# 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")
if args.verify:
@ -94,14 +94,15 @@ def _send(reactor, w, args, phase1, fd_to_send, tor_manager):
if ok.lower() == "no":
err = "sender rejected verification check, abandoned transfer"
reject_data = json.dumps({"error": err}).encode("utf-8")
yield w.send(reject_data)
w.send(reject_data)
raise TransferError(err)
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)
my_phase1_bytes = json.dumps(phase1).encode("utf-8")
yield w.send(my_phase1_bytes)
w.send(my_phase1_bytes)
# this may raise WrongPasswordError
them_phase1_bytes = yield w.get()

View File

@ -453,7 +453,7 @@ class Cleanup(ServerBase, unittest.TestCase):
yield send_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)
@inlineCallbacks
@ -482,6 +482,7 @@ class Cleanup(ServerBase, unittest.TestCase):
yield self.assertFailure(send_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.flushLoggedErrors(WrongPasswordError)