sample clients: fill in more details
This commit is contained in:
parent
84852f26f5
commit
246e080c7c
|
@ -1,8 +1,6 @@
|
||||||
|
import os, sys, json
|
||||||
import sys, json
|
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
from nacl.secret import SecretBox
|
from nacl.secret import SecretBox
|
||||||
from nacl import utils
|
|
||||||
from . import api
|
from . import api
|
||||||
|
|
||||||
APPID = "lothar.com/wormhole/file-xfer"
|
APPID = "lothar.com/wormhole/file-xfer"
|
||||||
|
@ -16,8 +14,20 @@ them_bytes = r.finish()
|
||||||
them_d = json.loads(them_bytes.decode("utf-8"))
|
them_d = json.loads(them_bytes.decode("utf-8"))
|
||||||
print("them: %r" % (them_d,))
|
print("them: %r" % (them_d,))
|
||||||
xfer_key = unhexlify(them_d["xfer_key"].encode("ascii"))
|
xfer_key = unhexlify(them_d["xfer_key"].encode("ascii"))
|
||||||
filename = them_d["filename"] # unicode
|
filename = os.path.basename(them_d["filename"]) # unicode
|
||||||
filesize = them_d["filesize"]
|
filesize = them_d["filesize"]
|
||||||
relay = them_d["relay"].encode("ascii")
|
relay = them_d["relay"].encode("ascii")
|
||||||
|
|
||||||
# now receive the rest of the owl
|
# now receive the rest of the owl
|
||||||
|
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)
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
|
|
||||||
import sys, json
|
import sys, json
|
||||||
from . import api
|
from . import api
|
||||||
|
|
||||||
APPID = "lothar.com/wormhole/text-xfer"
|
APPID = "lothar.com/wormhole/text-xfer"
|
||||||
RELAY = "example.com"
|
|
||||||
|
|
||||||
# we're receiving
|
# we're receiving
|
||||||
code = sys.argv[1]
|
code = sys.argv[1]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import os, sys, json
|
import os, sys, json
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from nacl.secret import SecretBox
|
from nacl.secret import SecretBox
|
||||||
|
@ -28,4 +27,12 @@ them_bytes = i.finish()
|
||||||
them_d = json.loads(them_bytes.decode("utf-8"))
|
them_d = json.loads(them_bytes.decode("utf-8"))
|
||||||
print("them: %r" % (them_d,))
|
print("them: %r" % (them_d,))
|
||||||
|
|
||||||
|
box = SecretBox(xfer_key)
|
||||||
|
with open(filename, "rb") as f:
|
||||||
|
plaintext = f.read()
|
||||||
|
nonce = utils.random(SecretBox.NONCE_SIZE)
|
||||||
|
encrypted = box.encrypt(plaintext, nonce)
|
||||||
|
|
||||||
# now draw the rest of the owl
|
# now draw the rest of the owl
|
||||||
|
SEND(RELAY, encrypted)
|
||||||
|
print("file sent")
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
|
|
||||||
import sys, json
|
import sys, json
|
||||||
from nacl.secret import SecretBox
|
|
||||||
from nacl import utils
|
|
||||||
from . import api
|
from . import api
|
||||||
|
|
||||||
APPID = "lothar.com/wormhole/text-xfer"
|
APPID = "lothar.com/wormhole/text-xfer"
|
||||||
RELAY = "example.com"
|
|
||||||
|
|
||||||
# we're sending
|
# we're sending
|
||||||
message = sys.argv[1]
|
message = sys.argv[1]
|
||||||
xfer_key = utils.random(SecretBox.KEY_SIZE)
|
|
||||||
blob = json.dumps({"message": message,
|
blob = json.dumps({"message": message,
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
i = api.Initiator(APPID, blob)
|
i = api.Initiator(APPID, blob)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user