change API to support upcoming --verify flag
This commit is contained in:
parent
af1e3c51ec
commit
ed1809d521
|
@ -138,7 +138,7 @@ class Common:
|
||||||
assert len(key) == SecretBox.KEY_SIZE
|
assert len(key) == SecretBox.KEY_SIZE
|
||||||
box = SecretBox(key)
|
box = SecretBox(key)
|
||||||
nonce = utils.random(SecretBox.NONCE_SIZE)
|
nonce = utils.random(SecretBox.NONCE_SIZE)
|
||||||
return box.encrypt(self.data, nonce)
|
return box.encrypt(data, nonce)
|
||||||
|
|
||||||
def _post_data(self, data):
|
def _post_data(self, data):
|
||||||
post_data = json.dumps({"message": hexlify(data).decode("ascii")})
|
post_data = json.dumps({"message": hexlify(data).decode("ascii")})
|
||||||
|
@ -167,9 +167,8 @@ class Common:
|
||||||
return HKDF(self.key, length, CTXinfo=purpose)
|
return HKDF(self.key, length, CTXinfo=purpose)
|
||||||
|
|
||||||
class Initiator(Common):
|
class Initiator(Common):
|
||||||
def __init__(self, appid, data, relay):
|
def __init__(self, appid, relay):
|
||||||
self.appid = appid
|
self.appid = appid
|
||||||
self.data = data
|
|
||||||
self.relay = relay
|
self.relay = relay
|
||||||
assert self.relay.endswith("/")
|
assert self.relay.endswith("/")
|
||||||
self.started = time.time()
|
self.started = time.time()
|
||||||
|
@ -186,12 +185,12 @@ class Initiator(Common):
|
||||||
self._post_pake()
|
self._post_pake()
|
||||||
return self.code
|
return self.code
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self, outbound_data):
|
||||||
key = self._get_pake([])
|
key = self._get_pake([])
|
||||||
self.key = key
|
self.key = key
|
||||||
try:
|
try:
|
||||||
outbound_key = self.derive_key(b"sender")
|
outbound_key = self.derive_key(b"sender")
|
||||||
outbound_encrypted = self._encrypt_data(outbound_key, self.data)
|
outbound_encrypted = self._encrypt_data(outbound_key, outbound_data)
|
||||||
other_msgs = self._post_data(outbound_encrypted)
|
other_msgs = self._post_data(outbound_encrypted)
|
||||||
|
|
||||||
inbound_encrypted = self._get_data(other_msgs)
|
inbound_encrypted = self._get_data(other_msgs)
|
||||||
|
@ -207,9 +206,8 @@ class Initiator(Common):
|
||||||
|
|
||||||
|
|
||||||
class Receiver(Common):
|
class Receiver(Common):
|
||||||
def __init__(self, appid, data, relay):
|
def __init__(self, appid, relay):
|
||||||
self.appid = appid
|
self.appid = appid
|
||||||
self.data = data
|
|
||||||
self.relay = relay
|
self.relay = relay
|
||||||
assert self.relay.endswith("/")
|
assert self.relay.endswith("/")
|
||||||
self.started = time.time()
|
self.started = time.time()
|
||||||
|
@ -239,7 +237,7 @@ class Receiver(Common):
|
||||||
idA=self.appid+":Initiator",
|
idA=self.appid+":Initiator",
|
||||||
idB=self.appid+":Receiver")
|
idB=self.appid+":Receiver")
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self, outbound_data):
|
||||||
assert self.code is not None
|
assert self.code is not None
|
||||||
assert self.channel_id is not None
|
assert self.channel_id is not None
|
||||||
other_msgs = self._post_pake()
|
other_msgs = self._post_pake()
|
||||||
|
@ -248,7 +246,7 @@ class Receiver(Common):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
outbound_key = self.derive_key(b"receiver")
|
outbound_key = self.derive_key(b"receiver")
|
||||||
outbound_encrypted = self._encrypt_data(outbound_key, self.data)
|
outbound_encrypted = self._encrypt_data(outbound_key, outbound_data)
|
||||||
other_msgs = self._post_data(outbound_encrypted)
|
other_msgs = self._post_data(outbound_encrypted)
|
||||||
|
|
||||||
inbound_encrypted = self._get_data(other_msgs)
|
inbound_encrypted = self._get_data(other_msgs)
|
||||||
|
|
|
@ -10,21 +10,21 @@ def receive_file(args):
|
||||||
# we're receiving
|
# we're receiving
|
||||||
transit_receiver = TransitReceiver(transit_relay=args.transit_helper)
|
transit_receiver = TransitReceiver(transit_relay=args.transit_helper)
|
||||||
|
|
||||||
mydata = json.dumps({
|
r = Receiver(APPID, args.relay_url)
|
||||||
"transit": {
|
|
||||||
"direct_connection_hints": transit_receiver.get_direct_hints(),
|
|
||||||
"relay_connection_hints": transit_receiver.get_relay_hints(),
|
|
||||||
},
|
|
||||||
}).encode("utf-8")
|
|
||||||
r = Receiver(APPID, mydata, args.relay_url)
|
|
||||||
code = args.code
|
code = args.code
|
||||||
if not code:
|
if not code:
|
||||||
code = r.input_code("Enter receive-file wormhole code: ",
|
code = r.input_code("Enter receive-file wormhole code: ",
|
||||||
args.code_length)
|
args.code_length)
|
||||||
r.set_code(code)
|
r.set_code(code)
|
||||||
|
|
||||||
|
mydata = json.dumps({
|
||||||
|
"transit": {
|
||||||
|
"direct_connection_hints": transit_receiver.get_direct_hints(),
|
||||||
|
"relay_connection_hints": transit_receiver.get_relay_hints(),
|
||||||
|
},
|
||||||
|
}).encode("utf-8")
|
||||||
try:
|
try:
|
||||||
data = json.loads(r.get_data().decode("utf-8"))
|
data = json.loads(r.get_data(mydata).decode("utf-8"))
|
||||||
except WrongPasswordError as e:
|
except WrongPasswordError as e:
|
||||||
print("ERROR: " + e.explain(), file=sys.stderr)
|
print("ERROR: " + e.explain(), file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -6,15 +6,15 @@ APPID = "lothar.com/wormhole/text-xfer"
|
||||||
|
|
||||||
def receive_text(args):
|
def receive_text(args):
|
||||||
# we're receiving
|
# we're receiving
|
||||||
data = json.dumps({"message": "ok"}).encode("utf-8")
|
r = Receiver(APPID, args.relay_url)
|
||||||
r = Receiver(APPID, data, args.relay_url)
|
|
||||||
code = args.code
|
code = args.code
|
||||||
if not code:
|
if not code:
|
||||||
code = r.input_code("Enter receive-text wormhole code: ",
|
code = r.input_code("Enter receive-text wormhole code: ",
|
||||||
args.code_length)
|
args.code_length)
|
||||||
r.set_code(code)
|
r.set_code(code)
|
||||||
|
data = json.dumps({"message": "ok"}).encode("utf-8")
|
||||||
try:
|
try:
|
||||||
them_bytes = r.get_data()
|
them_bytes = r.get_data(data)
|
||||||
except WrongPasswordError as e:
|
except WrongPasswordError as e:
|
||||||
print("ERROR: " + e.explain(), file=sys.stderr)
|
print("ERROR: " + e.explain(), file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -12,6 +12,12 @@ def send_file(args):
|
||||||
assert os.path.isfile(filename)
|
assert os.path.isfile(filename)
|
||||||
transit_sender = TransitSender(transit_relay=args.transit_helper)
|
transit_sender = TransitSender(transit_relay=args.transit_helper)
|
||||||
|
|
||||||
|
i = Initiator(APPID, args.relay_url)
|
||||||
|
code = i.get_code(args.code_length)
|
||||||
|
print("On the other computer, please run: wormhole receive-file")
|
||||||
|
print("Wormhole code is '%s'" % code)
|
||||||
|
print()
|
||||||
|
|
||||||
filesize = os.stat(filename).st_size
|
filesize = os.stat(filename).st_size
|
||||||
data = json.dumps({
|
data = json.dumps({
|
||||||
"file": {
|
"file": {
|
||||||
|
@ -24,13 +30,8 @@ def send_file(args):
|
||||||
},
|
},
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
|
|
||||||
i = Initiator(APPID, data, args.relay_url)
|
|
||||||
code = i.get_code(args.code_length)
|
|
||||||
print("On the other computer, please run: wormhole receive-file")
|
|
||||||
print("Wormhole code is '%s'" % code)
|
|
||||||
print()
|
|
||||||
try:
|
try:
|
||||||
them_bytes = i.get_data()
|
them_bytes = i.get_data(data)
|
||||||
except WrongPasswordError as e:
|
except WrongPasswordError as e:
|
||||||
print("ERROR: " + e.explain(), file=sys.stderr)
|
print("ERROR: " + e.explain(), file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -9,13 +9,13 @@ def send_text(args):
|
||||||
message = args.text
|
message = args.text
|
||||||
data = json.dumps({"message": message,
|
data = json.dumps({"message": message,
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
i = Initiator(APPID, data, args.relay_url)
|
i = Initiator(APPID, args.relay_url)
|
||||||
code = i.get_code(args.code_length)
|
code = i.get_code(args.code_length)
|
||||||
print("On the other computer, please run: wormhole receive-text")
|
print("On the other computer, please run: wormhole receive-text")
|
||||||
print("Wormhole code is: %s" % code)
|
print("Wormhole code is: %s" % code)
|
||||||
print("")
|
print("")
|
||||||
try:
|
try:
|
||||||
them_bytes = i.get_data()
|
them_bytes = i.get_data(data)
|
||||||
except WrongPasswordError as e:
|
except WrongPasswordError as e:
|
||||||
print("ERROR: " + e.explain(), file=sys.stderr)
|
print("ERROR: " + e.explain(), file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user