WIP: test that we tolerate missing key-confirmation messages

This commit is contained in:
Brian Warner 2015-11-16 18:25:28 -08:00
parent 6b57d7d05d
commit 1ad001bbc3
4 changed files with 42 additions and 0 deletions

View File

@ -194,6 +194,7 @@ def close_on_error(f): # method decorator
class Wormhole:
motd_displayed = False
version_warning_displayed = False
_send_confirm = True
def __init__(self, appid, relay_url, wait=0.5*SECOND, timeout=3*MINUTE):
if not isinstance(appid, type(u"")): raise TypeError(type(appid))
@ -315,6 +316,8 @@ class Wormhole:
pake_msg = self._channel.get(u"pake")
self.key = self.sp.finish(pake_msg)
self.verifier = self.derive_key(u"wormhole:verifier")
if not self._send_confirm:
return
conf = self.derive_key(u"wormhole:confirmation")
self._channel.send(u"_confirm", conf)

View File

@ -276,6 +276,24 @@ class Blocking(ServerBase, unittest.TestCase):
d.addCallback(_done)
return d
def test_no_confirm(self):
# newer versions (which check confirmations) should will work with
# older versions (that don't send confirmations)
w1 = Wormhole(APPID, self.relayurl)
w1._send_confirm = False
w2 = Wormhole(APPID, self.relayurl)
d = deferToThread(w1.get_code)
d.addCallback(lambda code: w2.set_code(code))
d.addCallback(lambda _: self.doBoth([w1.send_data, b"data1"],
[w2.get_data]))
d.addCallback(lambda dl: self.assertEqual(dl[1], b"data1"))
d.addCallback(lambda _: self.doBoth([w1.get_data],
[w2.send_data, b"data2"]))
d.addCallback(lambda dl: self.assertEqual(dl[0], b"data2"))
d.addCallback(lambda _: self.doBoth([w1.close], [w2.close]))
return d
def test_verifier(self):
w1 = Wormhole(APPID, self.relayurl)
w2 = Wormhole(APPID, self.relayurl)

View File

@ -256,6 +256,24 @@ class Basic(ServerBase, unittest.TestCase):
d.addCallback(_done)
return d
def test_no_confirm(self):
# newer versions (which check confirmations) should will work with
# older versions (that don't send confirmations)
w1 = Wormhole(APPID, self.relayurl)
w1._send_confirm = False
w2 = Wormhole(APPID, self.relayurl)
d = w1.get_code()
d.addCallback(lambda code: w2.set_code(code))
d.addCallback(lambda _: self.doBoth(w1.send_data(b"data1"),
w2.get_data()))
d.addCallback(lambda dl: self.assertEqual(dl[1], b"data1"))
d.addCallback(lambda _: self.doBoth(w1.get_data(),
w2.send_data(b"data2")))
d.addCallback(lambda dl: self.assertEqual(dl[0], b"data2"))
d.addCallback(lambda _: self.doBoth(w1.close(), w2.close()))
return d
def test_verifier(self):
w1 = Wormhole(APPID, self.relayurl)
w2 = Wormhole(APPID, self.relayurl)

View File

@ -192,6 +192,7 @@ class ChannelManager:
class Wormhole:
motd_displayed = False
version_warning_displayed = False
_send_confirm = True
def __init__(self, appid, relay_url):
if not isinstance(appid, type(u"")): raise TypeError(type(appid))
@ -333,6 +334,8 @@ class Wormhole:
key = self.sp.finish(pake_msg)
self.key = key
self.verifier = self.derive_key(u"wormhole:verifier")
if not self._send_confirm:
return key
conf = self.derive_key(u"wormhole:confirmation")
d1 = self._channel.send(u"_confirm", conf)
d1.addCallback(lambda _: key)