allow pre-generated (human-offline-created) codes

Just make up a code like NUMBER-STUFF, and add --code= to the
send-text/send-file command. Also don't use tab-completion on the
codewords part of the receiving side, unless you stuck to the even/odd
PGP wordlist. (tab still works for the channel-id).
This commit is contained in:
Brian Warner 2015-04-09 22:50:07 -05:00
parent 3aa7e22708
commit 5e593509b4
4 changed files with 25 additions and 7 deletions

View File

@ -1,5 +1,5 @@
from __future__ import print_function
import sys, time, requests, json, textwrap
import sys, time, re, requests, json, textwrap
from binascii import hexlify, unhexlify
from spake2 import SPAKE2_A, SPAKE2_B
from nacl.secret import SecretBox
@ -214,14 +214,22 @@ class Initiator(Common):
self.key = None
self.verifier = None
def get_code(self, code_length=2):
self.channel_id = self._allocate() # allocate channel
self.code = codes.make_code(self.channel_id, code_length)
def set_code(self, code): # used for human-made pre-generated codes
mo = re.search(r'^(\d+)-', code)
if not mo:
raise ValueError("code (%s) must start with NN-" % code)
self.channel_id = int(mo.group(1))
self.code = code
self.sp = SPAKE2_A(self.code.encode("ascii"),
idA=self.appid+":Initiator",
idB=self.appid+":Receiver")
self._post_pake()
return self.code
def get_code(self, code_length=2):
channel_id = self._allocate() # allocate channel
code = codes.make_code(channel_id, code_length)
self.set_code(code)
return code
def _wait_for_key(self):
if not self.key:

View File

@ -16,7 +16,11 @@ def send_file(args):
transit_sender = TransitSender(args.transit_helper)
i = Initiator(APPID, args.relay_url)
code = i.get_code(args.code_length)
if args.code:
i.set_code(args.code)
code = args.code
else:
code = i.get_code(args.code_length)
print("On the other computer, please run: wormhole receive-file")
print("Wormhole code is '%s'" % code)
print()

View File

@ -10,7 +10,11 @@ def send_text(args):
from ..blocking.transcribe import Initiator, WrongPasswordError
i = Initiator(APPID, args.relay_url)
code = i.get_code(args.code_length)
if args.code:
i.set_code(args.code)
code = args.code
else:
code = i.get_code(args.code_length)
print("On the other computer, please run: wormhole receive-text")
print("Wormhole code is: %s" % code)
print("")

View File

@ -56,6 +56,7 @@ sp_restart.set_defaults(func=cmd_server.restart_server)
# CLI: send-text
p = subparsers.add_parser("send-text", description="Send a text mesasge",
usage="wormhole send-text TEXT")
p.add_argument("--code", metavar="CODE", help="human-generated code phrase")
p.add_argument("text", metavar="TEXT", help="the message to send (a string)")
p.set_defaults(func=cmd_send_text.send_text)
@ -72,6 +73,7 @@ p.set_defaults(func=cmd_receive_text.receive_text)
# CLI: send-file
p = subparsers.add_parser("send-file", description="Send a file",
usage="wormhole send-file FILENAME")
p.add_argument("--code", metavar="CODE", help="human-generated code phrase")
p.add_argument("filename", metavar="FILENAME", help="The file to be sent")
p.set_defaults(func=cmd_send_file.send_file)