indent commands: no functional changes
This commit is contained in:
parent
cb5ad8ced1
commit
3daef13ac0
|
@ -12,85 +12,86 @@ def receive(args):
|
||||||
from .progress import start_progress, update_progress, finish_progress
|
from .progress import start_progress, update_progress, finish_progress
|
||||||
assert isinstance(args.relay_url, type(u""))
|
assert isinstance(args.relay_url, type(u""))
|
||||||
|
|
||||||
w = Wormhole(APPID, args.relay_url)
|
if True:
|
||||||
if args.zeromode:
|
w = Wormhole(APPID, args.relay_url)
|
||||||
assert not args.code
|
if args.zeromode:
|
||||||
args.code = u"0-"
|
assert not args.code
|
||||||
code = args.code
|
args.code = u"0-"
|
||||||
if not code:
|
code = args.code
|
||||||
code = w.input_code("Enter receive wormhole code: ", args.code_length)
|
if not code:
|
||||||
w.set_code(code)
|
code = w.input_code("Enter receive wormhole code: ", args.code_length)
|
||||||
|
w.set_code(code)
|
||||||
|
|
||||||
if args.verify:
|
if args.verify:
|
||||||
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
|
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
|
||||||
print("Verifier %s." % verifier)
|
print("Verifier %s." % verifier)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
them_bytes = w.get_data()
|
them_bytes = w.get_data()
|
||||||
except WrongPasswordError as e:
|
except WrongPasswordError as e:
|
||||||
print("ERROR: " + e.explain(), file=sys.stderr)
|
print("ERROR: " + e.explain(), file=sys.stderr)
|
||||||
w.close()
|
w.close()
|
||||||
return 1
|
return 1
|
||||||
them_d = json.loads(them_bytes.decode("utf-8"))
|
them_d = json.loads(them_bytes.decode("utf-8"))
|
||||||
if "error" in them_d:
|
if "error" in them_d:
|
||||||
print("ERROR: " + them_d["error"], file=sys.stderr)
|
print("ERROR: " + them_d["error"], file=sys.stderr)
|
||||||
w.close()
|
w.close()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if "message" in them_d:
|
if "message" in them_d:
|
||||||
# we're receiving a text message
|
# we're receiving a text message
|
||||||
print(them_d["message"])
|
print(them_d["message"])
|
||||||
data = json.dumps({"message_ack": "ok"}).encode("utf-8")
|
data = json.dumps({"message_ack": "ok"}).encode("utf-8")
|
||||||
|
w.send_data(data)
|
||||||
|
w.close()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if not "file" in them_d:
|
||||||
|
print("I don't know what they're offering\n")
|
||||||
|
print(them_d)
|
||||||
|
w.close()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if "error" in them_d:
|
||||||
|
print("ERROR: " + data["error"], file=sys.stderr)
|
||||||
|
w.close()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
file_data = them_d["file"]
|
||||||
|
# the basename() is intended to protect us against
|
||||||
|
# "~/.ssh/authorized_keys" and other attacks
|
||||||
|
filename = os.path.basename(file_data["filename"]) # unicode
|
||||||
|
filesize = file_data["filesize"]
|
||||||
|
|
||||||
|
# get confirmation from the user before writing to the local directory
|
||||||
|
if os.path.exists(filename):
|
||||||
|
print("Error: refusing to overwrite existing file %s" % (filename,))
|
||||||
|
data = json.dumps({"error": "file already exists"}).encode("utf-8")
|
||||||
|
w.send_data(data)
|
||||||
|
w.close()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
print("Receiving file (%d bytes) into: %s" % (filesize, filename))
|
||||||
|
while True and not args.accept_file:
|
||||||
|
ok = six.moves.input("ok? (y/n): ")
|
||||||
|
if ok.lower().startswith("y"):
|
||||||
|
break
|
||||||
|
print("transfer rejected", file=sys.stderr)
|
||||||
|
data = json.dumps({"error": "transfer rejected"}).encode("utf-8")
|
||||||
|
w.send_data(data)
|
||||||
|
w.close()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
transit_receiver = TransitReceiver(args.transit_helper)
|
||||||
|
data = json.dumps({
|
||||||
|
"file_ack": "ok",
|
||||||
|
"transit": {
|
||||||
|
"direct_connection_hints": transit_receiver.get_direct_hints(),
|
||||||
|
"relay_connection_hints": transit_receiver.get_relay_hints(),
|
||||||
|
},
|
||||||
|
}).encode("utf-8")
|
||||||
w.send_data(data)
|
w.send_data(data)
|
||||||
w.close()
|
w.close()
|
||||||
return 0
|
|
||||||
|
|
||||||
if not "file" in them_d:
|
|
||||||
print("I don't know what they're offering\n")
|
|
||||||
print(them_d)
|
|
||||||
w.close()
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if "error" in them_d:
|
|
||||||
print("ERROR: " + data["error"], file=sys.stderr)
|
|
||||||
w.close()
|
|
||||||
return 1
|
|
||||||
|
|
||||||
file_data = them_d["file"]
|
|
||||||
# the basename() is intended to protect us against
|
|
||||||
# "~/.ssh/authorized_keys" and other attacks
|
|
||||||
filename = os.path.basename(file_data["filename"]) # unicode
|
|
||||||
filesize = file_data["filesize"]
|
|
||||||
|
|
||||||
# get confirmation from the user before writing to the local directory
|
|
||||||
if os.path.exists(filename):
|
|
||||||
print("Error: refusing to overwrite existing file %s" % (filename,))
|
|
||||||
data = json.dumps({"error": "file already exists"}).encode("utf-8")
|
|
||||||
w.send_data(data)
|
|
||||||
w.close()
|
|
||||||
return 1
|
|
||||||
|
|
||||||
print("Receiving file (%d bytes) into: %s" % (filesize, filename))
|
|
||||||
while True and not args.accept_file:
|
|
||||||
ok = six.moves.input("ok? (y/n): ")
|
|
||||||
if ok.lower().startswith("y"):
|
|
||||||
break
|
|
||||||
print("transfer rejected", file=sys.stderr)
|
|
||||||
data = json.dumps({"error": "transfer rejected"}).encode("utf-8")
|
|
||||||
w.send_data(data)
|
|
||||||
w.close()
|
|
||||||
return 1
|
|
||||||
|
|
||||||
transit_receiver = TransitReceiver(args.transit_helper)
|
|
||||||
data = json.dumps({
|
|
||||||
"file_ack": "ok",
|
|
||||||
"transit": {
|
|
||||||
"direct_connection_hints": transit_receiver.get_direct_hints(),
|
|
||||||
"relay_connection_hints": transit_receiver.get_relay_hints(),
|
|
||||||
},
|
|
||||||
}).encode("utf-8")
|
|
||||||
w.send_data(data)
|
|
||||||
w.close()
|
|
||||||
|
|
||||||
# now receive the rest of the owl
|
# now receive the rest of the owl
|
||||||
tdata = them_d["transit"]
|
tdata = them_d["transit"]
|
||||||
|
|
|
@ -46,70 +46,71 @@ def send(args):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
w = Wormhole(APPID, args.relay_url)
|
if True:
|
||||||
if args.zeromode:
|
w = Wormhole(APPID, args.relay_url)
|
||||||
assert not args.code
|
if args.zeromode:
|
||||||
args.code = u"0-"
|
assert not args.code
|
||||||
if args.code:
|
args.code = u"0-"
|
||||||
w.set_code(args.code)
|
if args.code:
|
||||||
code = args.code
|
w.set_code(args.code)
|
||||||
else:
|
code = args.code
|
||||||
code = w.get_code(args.code_length)
|
else:
|
||||||
other_cmd = "wormhole receive"
|
code = w.get_code(args.code_length)
|
||||||
if args.verify:
|
other_cmd = "wormhole receive"
|
||||||
other_cmd = "wormhole --verify receive"
|
if args.verify:
|
||||||
if args.zeromode:
|
other_cmd = "wormhole --verify receive"
|
||||||
other_cmd += " -0"
|
if args.zeromode:
|
||||||
print("On the other computer, please run: %s" % other_cmd)
|
other_cmd += " -0"
|
||||||
if not args.zeromode:
|
print("On the other computer, please run: %s" % other_cmd)
|
||||||
print("Wormhole code is: %s" % code)
|
if not args.zeromode:
|
||||||
print("")
|
print("Wormhole code is: %s" % code)
|
||||||
|
print("")
|
||||||
|
|
||||||
if args.verify:
|
if args.verify:
|
||||||
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
|
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
|
||||||
while True:
|
while True:
|
||||||
ok = six.moves.input("Verifier %s. ok? (yes/no): " % verifier)
|
ok = six.moves.input("Verifier %s. ok? (yes/no): " % verifier)
|
||||||
if ok.lower() == "yes":
|
if ok.lower() == "yes":
|
||||||
break
|
break
|
||||||
if ok.lower() == "no":
|
if ok.lower() == "no":
|
||||||
print("verification rejected, abandoning transfer",
|
print("verification rejected, abandoning transfer",
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
reject_data = json.dumps({"error": "verification rejected",
|
reject_data = json.dumps({"error": "verification rejected",
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
w.send_data(reject_data)
|
w.send_data(reject_data)
|
||||||
w.close()
|
w.close()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
my_phase1_bytes = json.dumps(phase1).encode("utf-8")
|
my_phase1_bytes = json.dumps(phase1).encode("utf-8")
|
||||||
w.send_data(my_phase1_bytes)
|
w.send_data(my_phase1_bytes)
|
||||||
try:
|
try:
|
||||||
them_phase1_bytes = w.get_data()
|
them_phase1_bytes = w.get_data()
|
||||||
except WrongPasswordError as e:
|
except WrongPasswordError as e:
|
||||||
print("ERROR: " + e.explain(), file=sys.stderr)
|
print("ERROR: " + e.explain(), file=sys.stderr)
|
||||||
w.close()
|
|
||||||
return 1
|
|
||||||
them_phase1 = json.loads(them_phase1_bytes.decode("utf-8"))
|
|
||||||
|
|
||||||
if sending_message:
|
|
||||||
if them_phase1["message_ack"] == "ok":
|
|
||||||
print("text message sent")
|
|
||||||
w.close()
|
w.close()
|
||||||
return 0
|
return 1
|
||||||
print("error sending text: %r" % (them_phase1,))
|
them_phase1 = json.loads(them_phase1_bytes.decode("utf-8"))
|
||||||
w.close()
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if "error" in them_phase1:
|
if sending_message:
|
||||||
print("remote error: %s" % them_phase1["error"])
|
if them_phase1["message_ack"] == "ok":
|
||||||
print("transfer abandoned")
|
print("text message sent")
|
||||||
|
w.close()
|
||||||
|
return 0
|
||||||
|
print("error sending text: %r" % (them_phase1,))
|
||||||
|
w.close()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if "error" in them_phase1:
|
||||||
|
print("remote error: %s" % them_phase1["error"])
|
||||||
|
print("transfer abandoned")
|
||||||
|
w.close()
|
||||||
|
return 1
|
||||||
|
if them_phase1.get("file_ack") != "ok":
|
||||||
|
print("ambiguous response from remote: %s" % (them_phase1,))
|
||||||
|
print("transfer abandoned")
|
||||||
|
w.close()
|
||||||
|
return 1
|
||||||
w.close()
|
w.close()
|
||||||
return 1
|
|
||||||
if them_phase1.get("file_ack") != "ok":
|
|
||||||
print("ambiguous response from remote: %s" % (them_phase1,))
|
|
||||||
print("transfer abandoned")
|
|
||||||
w.close()
|
|
||||||
return 1
|
|
||||||
w.close()
|
|
||||||
|
|
||||||
tdata = them_phase1["transit"]
|
tdata = them_phase1["transit"]
|
||||||
transit_key = w.derive_key(APPID+"/transit-key")
|
transit_key = w.derive_key(APPID+"/transit-key")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user