indent commands: no functional changes

This commit is contained in:
Brian Warner 2015-11-11 18:10:18 -08:00
parent cb5ad8ced1
commit 3daef13ac0
2 changed files with 135 additions and 133 deletions

View File

@ -12,85 +12,86 @@ def receive(args):
from .progress import start_progress, update_progress, finish_progress
assert isinstance(args.relay_url, type(u""))
w = Wormhole(APPID, args.relay_url)
if args.zeromode:
assert not args.code
args.code = u"0-"
code = args.code
if not code:
code = w.input_code("Enter receive wormhole code: ", args.code_length)
w.set_code(code)
if True:
w = Wormhole(APPID, args.relay_url)
if args.zeromode:
assert not args.code
args.code = u"0-"
code = args.code
if not code:
code = w.input_code("Enter receive wormhole code: ", args.code_length)
w.set_code(code)
if args.verify:
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
print("Verifier %s." % verifier)
if args.verify:
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
print("Verifier %s." % verifier)
try:
them_bytes = w.get_data()
except WrongPasswordError as e:
print("ERROR: " + e.explain(), file=sys.stderr)
w.close()
return 1
them_d = json.loads(them_bytes.decode("utf-8"))
if "error" in them_d:
print("ERROR: " + them_d["error"], file=sys.stderr)
w.close()
return 1
try:
them_bytes = w.get_data()
except WrongPasswordError as e:
print("ERROR: " + e.explain(), file=sys.stderr)
w.close()
return 1
them_d = json.loads(them_bytes.decode("utf-8"))
if "error" in them_d:
print("ERROR: " + them_d["error"], file=sys.stderr)
w.close()
return 1
if "message" in them_d:
# we're receiving a text message
print(them_d["message"])
data = json.dumps({"message_ack": "ok"}).encode("utf-8")
if "message" in them_d:
# we're receiving a text message
print(them_d["message"])
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.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
tdata = them_d["transit"]

View File

@ -46,70 +46,71 @@ def send(args):
},
}
w = Wormhole(APPID, args.relay_url)
if args.zeromode:
assert not args.code
args.code = u"0-"
if args.code:
w.set_code(args.code)
code = args.code
else:
code = w.get_code(args.code_length)
other_cmd = "wormhole receive"
if args.verify:
other_cmd = "wormhole --verify receive"
if args.zeromode:
other_cmd += " -0"
print("On the other computer, please run: %s" % other_cmd)
if not args.zeromode:
print("Wormhole code is: %s" % code)
print("")
if True:
w = Wormhole(APPID, args.relay_url)
if args.zeromode:
assert not args.code
args.code = u"0-"
if args.code:
w.set_code(args.code)
code = args.code
else:
code = w.get_code(args.code_length)
other_cmd = "wormhole receive"
if args.verify:
other_cmd = "wormhole --verify receive"
if args.zeromode:
other_cmd += " -0"
print("On the other computer, please run: %s" % other_cmd)
if not args.zeromode:
print("Wormhole code is: %s" % code)
print("")
if args.verify:
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
while True:
ok = six.moves.input("Verifier %s. ok? (yes/no): " % verifier)
if ok.lower() == "yes":
break
if ok.lower() == "no":
print("verification rejected, abandoning transfer",
file=sys.stderr)
reject_data = json.dumps({"error": "verification rejected",
}).encode("utf-8")
w.send_data(reject_data)
w.close()
return 1
if args.verify:
verifier = binascii.hexlify(w.get_verifier()).decode("ascii")
while True:
ok = six.moves.input("Verifier %s. ok? (yes/no): " % verifier)
if ok.lower() == "yes":
break
if ok.lower() == "no":
print("verification rejected, abandoning transfer",
file=sys.stderr)
reject_data = json.dumps({"error": "verification rejected",
}).encode("utf-8")
w.send_data(reject_data)
w.close()
return 1
my_phase1_bytes = json.dumps(phase1).encode("utf-8")
w.send_data(my_phase1_bytes)
try:
them_phase1_bytes = w.get_data()
except WrongPasswordError as e:
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")
my_phase1_bytes = json.dumps(phase1).encode("utf-8")
w.send_data(my_phase1_bytes)
try:
them_phase1_bytes = w.get_data()
except WrongPasswordError as e:
print("ERROR: " + e.explain(), file=sys.stderr)
w.close()
return 0
print("error sending text: %r" % (them_phase1,))
w.close()
return 1
return 1
them_phase1 = json.loads(them_phase1_bytes.decode("utf-8"))
if "error" in them_phase1:
print("remote error: %s" % them_phase1["error"])
print("transfer abandoned")
if sending_message:
if them_phase1["message_ack"] == "ok":
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()
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"]
transit_key = w.derive_key(APPID+"/transit-key")