2015-02-11 09:18:31 +00:00
|
|
|
from __future__ import print_function
|
2015-02-11 01:04:28 +00:00
|
|
|
import os, sys, json
|
2015-02-11 00:50:32 +00:00
|
|
|
from binascii import unhexlify
|
|
|
|
from nacl.secret import SecretBox
|
2015-02-11 02:34:13 +00:00
|
|
|
from .transcribe import Receiver
|
2015-02-11 00:50:32 +00:00
|
|
|
|
|
|
|
APPID = "lothar.com/wormhole/file-xfer"
|
|
|
|
RELAY = "example.com"
|
|
|
|
|
|
|
|
# we're receiving
|
|
|
|
code = sys.argv[1]
|
|
|
|
blob = b""
|
2015-02-11 02:34:13 +00:00
|
|
|
r = Receiver(APPID, blob, code)
|
|
|
|
them_bytes = r.get_data()
|
2015-02-11 00:50:32 +00:00
|
|
|
them_d = json.loads(them_bytes.decode("utf-8"))
|
|
|
|
print("them: %r" % (them_d,))
|
|
|
|
xfer_key = unhexlify(them_d["xfer_key"].encode("ascii"))
|
2015-02-11 01:04:28 +00:00
|
|
|
filename = os.path.basename(them_d["filename"]) # unicode
|
2015-02-11 00:50:32 +00:00
|
|
|
filesize = them_d["filesize"]
|
|
|
|
relay = them_d["relay"].encode("ascii")
|
|
|
|
|
|
|
|
# now receive the rest of the owl
|
2015-02-11 01:04:28 +00:00
|
|
|
encrypted = RECEIVE(relay)
|
|
|
|
|
|
|
|
decrypted = SecretBox(xfer_key).decrypt(encrypted)
|
|
|
|
|
|
|
|
# only write to the current directory, and never overwrite anything
|
|
|
|
here = os.path.abspath(os.getcwd())
|
|
|
|
target = os.path.abspath(os.path.join(here, filename))
|
|
|
|
assert os.path.dirname(target) == here
|
|
|
|
assert not os.path.exists(target)
|
|
|
|
with open(target, "wb") as f:
|
|
|
|
f.write(decrypted)
|
|
|
|
print("%s written" % filename)
|