CLI: don't hide errors, fuss with verifier API

This commit is contained in:
Brian Warner 2017-03-08 08:46:15 +01:00
parent 921228a702
commit 29f467e9d8
2 changed files with 47 additions and 20 deletions

View File

@ -76,17 +76,33 @@ class TwistedReceiver:
# as coming from the "yield self._go" line, which wasn't very useful # as coming from the "yield self._go" line, which wasn't very useful
# for tracking it down. # for tracking it down.
d = self._go(w) d = self._go(w)
# if we succeed, we should close and return the w.close results
# (which might be an error)
@inlineCallbacks @inlineCallbacks
def _close(res): def _good(res):
yield w.close() yield w.close() # wait for ack
returnValue(res) returnValue(res)
d.addBoth(_close)
# if we raise an error, we should close and then return the original
# error (the close might give us an error, but it isn't as important
# as the original one)
@inlineCallbacks
def _bad(f):
log.err(f)
try:
yield w.close() # might be an error too
except:
pass
returnValue(f)
d.addCallbacks(_good, _bad)
yield d yield d
@inlineCallbacks @inlineCallbacks
def _go(self, w): def _go(self, w):
yield self._handle_code(w) yield self._handle_code(w)
verifier = yield w.when_verifier() verifier = yield w.when_verified()
def on_slow_connection(): def on_slow_connection():
print(u"Key established, waiting for confirmation...", print(u"Key established, waiting for confirmation...",
file=self.args.stderr) file=self.args.stderr)

View File

@ -57,11 +57,27 @@ class Sender:
tor_manager=self._tor_manager, tor_manager=self._tor_manager,
timing=self._timing) timing=self._timing)
d = self._go(w) d = self._go(w)
# if we succeed, we should close and return the w.close results
# (which might be an error)
@inlineCallbacks @inlineCallbacks
def _close(res): def _good(res):
yield w.close() # must wait for ack from close() yield w.close() # wait for ack
returnValue(res) returnValue(res)
d.addBoth(_close)
# if we raise an error, we should close and then return the original
# error (the close might give us an error, but it isn't as important
# as the original one)
@inlineCallbacks
def _bad(f):
log.err(f)
try:
yield w.close() # might be an error too
except:
pass
returnValue(f)
d.addCallbacks(_good, _bad)
yield d yield d
def _send_data(self, data, w): def _send_data(self, data, w):
@ -98,23 +114,18 @@ class Sender:
args.stderr.flush() args.stderr.flush()
print(u"", file=args.stderr) print(u"", file=args.stderr)
verifier_bytes = yield w.when_verifier()
# we've seen PAKE, but not yet VERSION, so we don't know if they got
# the right password or not
def on_slow_connection(): def on_slow_connection():
print(u"Key established, waiting for confirmation...", print(u"Key established, waiting for confirmation...",
file=args.stderr) file=args.stderr)
notify = self._reactor.callLater(VERIFY_TIMER, on_slow_connection) #notify = self._reactor.callLater(VERIFY_TIMER, on_slow_connection)
# TODO: maybe don't stall for VERSION, if they don't want # TODO: don't stall on w.verify() unless they want it
# verification, to save a roundtrip? #try:
try: # verifier_bytes = yield w.when_verified() # might WrongPasswordError
yield w.when_version() #finally:
# this may raise WrongPasswordError # if not notify.called:
finally: # notify.cancel()
if not notify.called: yield w.when_verified()
notify.cancel()
if args.verify: if args.verify:
verifier = bytes_to_hexstr(verifier_bytes) verifier = bytes_to_hexstr(verifier_bytes)