Commit 56c64b98 authored by Pascal Engélibert's avatar Pascal Engélibert

Tx comments gen with seeds

parent 45094689
......@@ -39,17 +39,19 @@ class Confirmation():
self.raw = raw
data = libnacl.sign.Verifier(PublicKey(node_pubkey).hex_pk()).verify(raw)
print(data)
data = ubjson.loadb(data)
print(data)
assert data["document"] == "gmixer-mixconfirm1"
self.sender_pubkey = data["sender_pubkey"]
self.in_seeds = data["in_seeds"]
self.in_comment = data["in_comment"]
self.in_amount = int(data["in_amount"])
self.in_base = int(data["in_base"])
self.in_amount = data["in_amount"]
self.in_base = data["in_base"]
self.receiver_pubkey = data["receiver_pubkey"]
self.out_seeds = data["out_seeds"]
self.out_comment = data["out_comment"]
self.out_amount = int(data["out_amount"])
self.out_base = int(data["out_base"])
self.out_amount = data["out_amount"]
self.out_base = data["out_base"]
def to_dict(self):
return {
......@@ -108,17 +110,27 @@ def mix(db_txs, amount, base, sender, path, host, proxy=None, proxy_onion_only=F
start_time = time.time()
onetime_keys = []
comment_seeds = [[secrets.token_bytes(32), None, secrets.token_bytes(32)]] # [client, sender, receiver]
message = b""
i = len(path)-2
while i >= 0:
ot_salt, ot_password = genKeys()
ot_salt, ot_password = gen_keys()
ot_keys = SigningKey.from_credentials(ot_salt, ot_password)
onetime_keys.insert(0, ot_keys)
message = PublicKey(path[i]).encrypt_seal((normalize_pubkey(path[i+1]) + normalize_pubkey(ot_keys.pubkey)).encode() + message)
out_seeds = comment_seeds[0]
in_seeds = [secrets.token_bytes(32), None, None]
comment_seeds.insert(0, in_seeds)
message = PublicKey(path[i]).encrypt_seal(ubjson.dumpb({
"receiver": path[i+1],
"onetime": ot_keys.pubkey,
"in_seeds": in_seeds,
"out_seeds": out_seeds,
"message": message
}))
i -= 1
out_comment = secrets.token_urlsafe(48)
message = sender.sign(out_comment.encode() + message)
comment_seeds[0][1] = secrets.token_bytes(32)
message = sender.sign(comment_seeds[0][1] + message)
while True:
try:
......@@ -129,7 +141,7 @@ def mix(db_txs, amount, base, sender, path, host, proxy=None, proxy_onion_only=F
continue
try:
data = ubjson.loadb(content)
assert "mix_ok" in data and data["mix_ok"] == out_comment
assert "mix_ok" in data and data["mix_ok"] == comment_seeds[0][1]
except (ubjson.decoder.DecoderException, AssertionError):
print(content)
print("Error: bad response; retrying...")
......@@ -143,7 +155,7 @@ def mix(db_txs, amount, base, sender, path, host, proxy=None, proxy_onion_only=F
time.sleep(5)
print("Asking input node for confirmation...")
try:
header, content = sdata(host, "GET", "/getconfirm/"+sender.pubkey+"/"+out_comment, proxy=proxy, proxy_onion_only=proxy_onion_only)
header, content = sdata(host, "GET", "/getconfirm/"+sender.pubkey+"/"+comment_seeds[0][1].hex(), proxy=proxy, proxy_onion_only=proxy_onion_only)
except ConnectionRefusedError:
continue
......@@ -170,8 +182,8 @@ def mix(db_txs, amount, base, sender, path, host, proxy=None, proxy_onion_only=F
print("Bad encryption")
continue
if out_comment != data[:64].decode():
print("Bad comment #1")
if comment_seeds[0][1] != data[:32]:
print("Bad seed0_1")
continue
raw_confirms = []
......@@ -205,12 +217,25 @@ def mix(db_txs, amount, base, sender, path, host, proxy=None, proxy_onion_only=F
if confirm.receiver_pubkey != path[i+1]:
print("Bad receiver_pubkey #"+str(i))
return
if not re.match("^[a-zA-Z0-9_-]{64}$", confirm.in_comment):
print("Bad in_comment #"+str(i))
return
if not re.match("^[a-zA-Z0-9_-]{64}$", confirm.out_comment):
print("Bad out_comment #"+str(i))
return
for k in range(3):
if comment_seeds[i][k] != None:
if comment_seeds[i][k] != confirm.in_seeds[k]:
print("Bad in_seeds #"+str(i)+"_"+str(k))
return
elif type(confirm.in_seeds[k]) == bytes and len(confirm.in_seeds[k]) == 32:
comment_seeds[i][k] = confirm.in_seeds[k]
else:
print("Bad in_seeds #"+str(i)+"_"+str(k))
for k in range(3):
if comment_seeds[i+1][k] != None:
if comment_seeds[i+1][k] != confirm.out_seeds[k]:
print("Bad out_seeds #"+str(i)+"_"+str(k))
return
elif type(confirm.out_seeds[k]) == bytes and len(confirm.out_seeds[k]) == 32:
comment_seeds[i+1][k] = confirm.out_seeds[k]
else:
print("Bad out_seeds #"+str(i)+"_"+str(k))
confirms.append(confirm)
i += 1
......@@ -220,7 +245,7 @@ def mix(db_txs, amount, base, sender, path, host, proxy=None, proxy_onion_only=F
print("Remind: no-tx mode")
if input("OK? [yn]: ").lower() == "y":
db_txs.put(out_comment.encode(), PublicKey(sender.pubkey).encrypt_seal(ubjson.dumpb({
db_txs.put(comment_seeds[0][1], PublicKey(sender.pubkey).encrypt_seal(ubjson.dumpb({
"sender": sender.pubkey,
"path": path,
"amount": amount,
......@@ -229,7 +254,7 @@ def mix(db_txs, amount, base, sender, path, host, proxy=None, proxy_onion_only=F
})))
if send_tx:
sendTransaction(sender, path[0], amount, out_comment)
sendTransaction(sender, path[0], amount, gen_comment(comment_seeds[0]))
return
async def test1(db_txs, host, receiver, amount=1000, layers=3, proxy=None, proxy_onion_only=False, send_tx=True):
......
This diff is collapsed.
......@@ -16,7 +16,7 @@
along with ĞMixer-py. If not, see <https://www.gnu.org/licenses/>.
"""
import sys, os, re, socket, time, secrets
import sys, os, re, socket, time, secrets, hashlib
import socks
from duniterpy.key import SigningKey, PublicKey
_argv = sys.argv # silkaj reads sys.argv!
......@@ -44,9 +44,11 @@ def normalize_pubkey(pubkey):
def clean_pubkey(pubkey):
return pubkey.replace(" ", "")
def genKeys():
def gen_keys():
return secrets.token_urlsafe(), secrets.token_urlsafe()
def gen_comment(seeds):
return socks.b64encode(hashlib.sha512(b"".join(seeds)).digest()).decode()
#-------- 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