Commit 0b0473f5 authored by Pascal Engélibert's avatar Pascal Engélibert

Support 43-characters pubkeys

parent 4ff1bff6
......@@ -92,7 +92,7 @@ def mix(amount, base, sender, path, host):
ot_salt, ot_password = genKeys()
ot_keys = SigningKey.from_credentials(ot_salt, ot_password)
onetime_keys.insert(0, ot_keys)
message = PublicKey(path[i]).encrypt_seal((path[i+1] + ot_keys.pubkey).encode() + message)
message = PublicKey(path[i]).encrypt_seal((normalize_pubkey(path[i+1]) + normalize_pubkey(ot_keys.pubkey)).encode() + message)
i -= 1
out_comment = secrets.token_urlsafe(48)
......@@ -103,14 +103,15 @@ def mix(amount, base, sender, path, host):
header, content = sdata(host, "POST", "/pubkey/mix/"+sender.pubkey+"/"+str(int(amount))+"/"+str(int(base))+"/client", message)
except ConnectionRefusedError:
print("Error: Connection refused; retrying...")
sleep(3)
time.sleep(3)
continue
try:
data = ubjson.loadb(content)
assert "mix_ok" in data and data["mix_ok"] == out_comment
except (ubjson.decoder.DecoderException, AssertionError):
print(content)
print("Error: bad response; retrying...")
sleep(3)
time.sleep(3)
continue
break
......
......@@ -294,8 +294,8 @@ class ServerThread(Thread):
sendResponse(client, "403 Forbidden", {"error": "bad_encryption"})
continue
receiver_pubkey = data[:44].decode() # receiver pubkey
onetime_pubkey = data[44:88].decode() # origin emitter one-time pubkey
receiver_pubkey = clean_pubkey(data[:44].decode()) # receiver pubkey
onetime_pubkey = clean_pubkey(data[44:88].decode()) # origin emitter one-time pubkey
try:
message = data[88:]
except ValueError:
......@@ -605,7 +605,9 @@ class ClientThread(Thread):
message = self.keys.sign(tx.out_comment.encode() + tx.message) # Sign
try:
sdata((peer.host, peer.port), "POST", "/mix/"+self.keys.pubkey+"/"+tx.out_amount+"/"+tx.out_base, message)
header, content = sdata((peer.host, peer.port), "POST", "/mix/"+self.keys.pubkey+"/"+tx.out_amount+"/"+tx.out_base, message)
data = ubjson.loadb(content)
assert data["mix_ok"] == tx.out_comment
tx.need_send = False
peer.up = True
logPrint("Sent "+tx.sender_pubkey[:8]+" -> "+tx.receiver_pubkey[:8]+" = "+str(tx.in_amount)+":"+str(tx.in_base)+" -> "+str(tx.out_amount)+":"+str(tx.out_base), LOG_TRACE)
......@@ -613,6 +615,8 @@ class ClientThread(Thread):
except ConnectionRefusedError:
peer.up = False
logPrint("Down "+str(peer), LOG_TRACE)
except (ubjson.decoder.DecoderException, KeyError, AssertionError):
logPrint("Error: bad response from "+str(peer), LOG_WARN)
else:
logPrint("Unknown peer: "+tx.receiver_pubkey, LOG_WARN)
......@@ -634,7 +638,7 @@ class ClientThread(Thread):
except ConnectionRefusedError:
peer.up = False
logPrint("Down "+str(peer), LOG_TRACE)
except (ubjson.decoder.DecoderException, IndexError, AssertionError):
except (ubjson.decoder.DecoderException, KeyError, AssertionError):
logPrint("Error: bad response from "+str(peer), LOG_WARN)
else:
......
......@@ -32,6 +32,14 @@ def bin_to_int(b):
def int_to_bin(n, b=4):
return bytes([(n>>(i*8))&255 for i in range(b)])
# Set fixed length 44
def normalize_pubkey(pubkey):
return pubkey + " "*(44-len(pubkey))
# Set original length (43 or 44)
def clean_pubkey(pubkey):
return pubkey.replace(" ", "")
#-------- NETWORK
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment