Add --appid to override the APPID, for subprocess-based wrappers.

Tools which use `wormhole send` under the hood should use a distinct
--appid= (setting the same URL-shaped value on both sides, starting with a
domain name related to the tool and/or its author), so wormhole codes used by
those tools won't compete for short channelids with other tools, or the
default text/file/directory-sending tool.

Closes #113
This commit is contained in:
Brian Warner 2016-12-22 15:44:13 -05:00
parent d81f2dae95
commit f2e011bc9c
6 changed files with 54 additions and 6 deletions

View File

@ -54,6 +54,8 @@ class AliasedGroup(click.Group):
# top-level command ("wormhole ...")
@click.group(cls=AliasedGroup)
@click.option(
"--appid", default=None, metavar="APPID", help="appid to use")
@click.option(
"--relay-url", default=public_relay.RENDEZVOUS_RELAY,
metavar="URL",
@ -75,7 +77,7 @@ class AliasedGroup(click.Group):
version=__version__,
)
@click.pass_context
def wormhole(context, dump_timing, transit_helper, relay_url):
def wormhole(context, dump_timing, transit_helper, relay_url, appid):
"""
Create a Magic Wormhole and communicate through it.
@ -84,6 +86,7 @@ def wormhole(context, dump_timing, transit_helper, relay_url):
anyone who doesn't use the same code.
"""
context.obj = cfg = Config()
cfg.appid = appid
cfg.relay_url = relay_url
cfg.transit_helper = transit_helper
cfg.dump_timing = dump_timing

View File

@ -57,8 +57,8 @@ class TwistedReceiver:
# with the user handing off the wormhole code
yield self._tor_manager.start()
w = wormhole(APPID, self.args.relay_url, self._reactor,
self._tor_manager, timing=self.args.timing)
w = wormhole(self.args.appid or APPID, self.args.relay_url,
self._reactor, self._tor_manager, timing=self.args.timing)
# I wanted to do this instead:
#
# try:

View File

@ -47,7 +47,7 @@ class Sender:
# with the user handing off the wormhole code
yield self._tor_manager.start()
w = wormhole(APPID, self._args.relay_url,
w = wormhole(self._args.appid or APPID, self._args.relay_url,
self._reactor, self._tor_manager,
timing=self._timing)
d = self._go(w)

View File

@ -63,7 +63,7 @@ def find_public_key(hint=None):
def accept(cfg, reactor=reactor):
yield xfer_util.send(
reactor,
u"lothar.com/wormhole/ssh-add",
cfg.appid or u"lothar.com/wormhole/ssh-add",
cfg.relay_url,
data=cfg.public_key[2],
code=cfg.code,
@ -104,7 +104,7 @@ def invite(cfg, reactor=reactor):
pubkey = yield xfer_util.receive(
reactor,
u"lothar.com/wormhole/ssh-add",
cfg.appid or u"lothar.com/wormhole/ssh-add",
cfg.relay_url,
None, # allocate a code for us
use_tor=cfg.tor,

View File

@ -14,6 +14,7 @@ class Send(unittest.TestCase):
self.assertEqual(cfg.dump_timing, None)
self.assertEqual(cfg.hide_progress, False)
self.assertEqual(cfg.listen, True)
self.assertEqual(cfg.appid, None)
self.assertEqual(cfg.relay_url, RENDEZVOUS_RELAY)
self.assertEqual(cfg.transit_helper, TRANSIT_RELAY)
self.assertEqual(cfg.text, "hi")
@ -21,6 +22,12 @@ class Send(unittest.TestCase):
self.assertEqual(cfg.verify, False)
self.assertEqual(cfg.zeromode, False)
def test_appid(self):
cfg = config("--appid", "xyz", "send", "--text", "hi")
self.assertEqual(cfg.appid, "xyz")
cfg = config("--appid=xyz", "send", "--text", "hi")
self.assertEqual(cfg.appid, "xyz")
def test_file(self):
cfg = config("send", "fn")
#pprint(cfg.__dict__)
@ -76,12 +83,19 @@ class Receive(unittest.TestCase):
self.assertEqual(cfg.listen, True)
self.assertEqual(cfg.only_text, False)
self.assertEqual(cfg.output_file, None)
self.assertEqual(cfg.appid, None)
self.assertEqual(cfg.relay_url, RENDEZVOUS_RELAY)
self.assertEqual(cfg.transit_helper, TRANSIT_RELAY)
self.assertEqual(cfg.tor, False)
self.assertEqual(cfg.verify, False)
self.assertEqual(cfg.zeromode, False)
def test_appid(self):
cfg = config("--appid", "xyz", "receive")
self.assertEqual(cfg.appid, "xyz")
cfg = config("--appid=xyz", "receive")
self.assertEqual(cfg.appid, "xyz")
def test_nolisten(self):
cfg = config("receive", "--no-listen")
self.assertEqual(cfg.listen, False)

View File

@ -740,3 +740,34 @@ class ExtractFile(unittest.TestCase):
zi.filename = "/etc/passwd"
e = self.assertRaises(ValueError, ef, zf, zi, extract_dir)
self.assertIn("malicious zipfile", str(e))
class AppID(ServerBase, unittest.TestCase):
def setUp(self):
d = super(AppID, self).setUp()
self.cfg = cfg = config("send")
# common options for all tests in this suite
cfg.hide_progress = True
cfg.relay_url = self.relayurl
cfg.transit_helper = ""
cfg.stdout = io.StringIO()
cfg.stderr = io.StringIO()
return d
@inlineCallbacks
def test_override(self):
# make sure we use the overridden appid, not the default
self.cfg.text = "hello"
self.cfg.appid = "appid2"
self.cfg.code = "1-abc"
send_d = cmd_send.send(self.cfg)
receive_d = cmd_receive.receive(self.cfg)
yield send_d
yield receive_d
used = self._rendezvous._db.execute("SELECT DISTINCT `app_id`"
" FROM `nameplate_usage`"
).fetchall()
self.assertEqual(len(used), 1, used)
self.assertEqual(used[0]["app_id"], u"appid2")