From 1ad001bbc3693d202cc966215c913a9cc4e0d9ba Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 16 Nov 2015 18:25:28 -0800 Subject: [PATCH] WIP: test that we tolerate missing key-confirmation messages --- src/wormhole/blocking/transcribe.py | 3 +++ src/wormhole/test/test_blocking.py | 18 ++++++++++++++++++ src/wormhole/test/test_twisted.py | 18 ++++++++++++++++++ src/wormhole/twisted/transcribe.py | 3 +++ 4 files changed, 42 insertions(+) diff --git a/src/wormhole/blocking/transcribe.py b/src/wormhole/blocking/transcribe.py index 01fed57..b51d898 100644 --- a/src/wormhole/blocking/transcribe.py +++ b/src/wormhole/blocking/transcribe.py @@ -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) diff --git a/src/wormhole/test/test_blocking.py b/src/wormhole/test/test_blocking.py index 8556df5..44c5a0e 100644 --- a/src/wormhole/test/test_blocking.py +++ b/src/wormhole/test/test_blocking.py @@ -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) diff --git a/src/wormhole/test/test_twisted.py b/src/wormhole/test/test_twisted.py index f522b06..341a44a 100644 --- a/src/wormhole/test/test_twisted.py +++ b/src/wormhole/test/test_twisted.py @@ -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) diff --git a/src/wormhole/twisted/transcribe.py b/src/wormhole/twisted/transcribe.py index d92123b..9081ba1 100644 --- a/src/wormhole/twisted/transcribe.py +++ b/src/wormhole/twisted/transcribe.py @@ -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)