|
@@ -7,14 +7,13 @@ import time
|
|
|
import json
|
|
import json
|
|
|
from create_keys import make_keys, get_private_key, get_plain_key
|
|
from create_keys import make_keys, get_private_key, get_plain_key
|
|
|
import os
|
|
import os
|
|
|
-from cryptography.hazmat.primitives import hashes
|
|
|
|
|
-from cryptography.hazmat.primitives.asymmetric import padding
|
|
|
|
|
-from cryptography.fernet import Fernet
|
|
|
|
|
-import rsa
|
|
|
|
|
|
|
+from gui.encyption import decrypt_data
|
|
|
|
|
|
|
|
|
|
+# from gui.encyption import decrypt
|
|
|
def new_contract():
|
|
def new_contract():
|
|
|
def add():
|
|
def add():
|
|
|
name = str(title.get())
|
|
name = str(title.get())
|
|
|
|
|
+
|
|
|
if not os.path.isdir('contract_keys\\' + name):
|
|
if not os.path.isdir('contract_keys\\' + name):
|
|
|
make_keys(name)
|
|
make_keys(name)
|
|
|
pubkey = get_plain_key(name)
|
|
pubkey = get_plain_key(name)
|
|
@@ -35,11 +34,10 @@ def new_contract():
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
|
|
|
-
|
|
|
|
|
t = Transaction()
|
|
t = Transaction()
|
|
|
t.set_contract(contract)
|
|
t.set_contract(contract)
|
|
|
t.hash(contract=name)
|
|
t.hash(contract=name)
|
|
|
|
|
+ conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
|
conn.root.push_transaction(t.serialize(out_json=True))
|
|
conn.root.push_transaction(t.serialize(out_json=True))
|
|
|
|
|
|
|
|
conn.close()
|
|
conn.close()
|
|
@@ -48,10 +46,6 @@ def new_contract():
|
|
|
print('Contract name already exists, choose another')
|
|
print('Contract name already exists, choose another')
|
|
|
newWindow.destroy()
|
|
newWindow.destroy()
|
|
|
new_contract()
|
|
new_contract()
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newWindow = Tk()
|
|
newWindow = Tk()
|
|
@@ -95,7 +89,7 @@ def find_transaction():
|
|
|
def find():
|
|
def find():
|
|
|
conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
|
iden = get_plain_key(str(key.get()))
|
|
iden = get_plain_key(str(key.get()))
|
|
|
- transactions = [x.data for x in conn.root.find_transactions(iden)]
|
|
|
|
|
|
|
+ transactions = conn.root.find_transactions(iden)
|
|
|
transactions = decrypt_transactions(transactions, str(key.get()))
|
|
transactions = decrypt_transactions(transactions, str(key.get()))
|
|
|
print(current_contract_state(transactions, iden=iden))
|
|
print(current_contract_state(transactions, iden=iden))
|
|
|
|
|
|
|
@@ -108,7 +102,7 @@ def find_transaction():
|
|
|
Label(newWindow, text='Contract key: ').grid(row=0, column=0)
|
|
Label(newWindow, text='Contract key: ').grid(row=0, column=0)
|
|
|
key = Entry(newWindow, width=35, borderwidth=5)
|
|
key = Entry(newWindow, width=35, borderwidth=5)
|
|
|
key.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
|
|
key.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
|
|
|
- key.insert(0, '1')
|
|
|
|
|
|
|
+ key.insert(0, 'test')
|
|
|
|
|
|
|
|
Button(newWindow, text='find contracts', command=find).grid(row=1, column=1)
|
|
Button(newWindow, text='find contracts', command=find).grid(row=1, column=1)
|
|
|
|
|
|
|
@@ -300,13 +294,7 @@ def get_updates(transactions, iden=None, attr=None, accepted=None):
|
|
|
return updates
|
|
return updates
|
|
|
|
|
|
|
|
def decrypt_transactions(transactions, name):
|
|
def decrypt_transactions(transactions, name):
|
|
|
- private_key = get_private_key(name)
|
|
|
|
|
- decrypted = []
|
|
|
|
|
-
|
|
|
|
|
- for encrypted in transactions:
|
|
|
|
|
- decrypted_key = rsa.decrypt(encrypted['encrypted key'],private_key)
|
|
|
|
|
- cipher = Fernet(decrypted_key)
|
|
|
|
|
- decrypted.append(cipher.decrypt(encrypted['data']))
|
|
|
|
|
|
|
+ decrypted_data = [decrypt_data(name, x) for x in transactions]
|
|
|
|
|
|
|
|
|
|
|
|
|
# old code
|
|
# old code
|
|
@@ -321,4 +309,4 @@ def decrypt_transactions(transactions, name):
|
|
|
# )
|
|
# )
|
|
|
# decrypted.append(decrypting_message)
|
|
# decrypted.append(decrypting_message)
|
|
|
|
|
|
|
|
- return decrypted
|
|
|
|
|
|
|
+ return decrypted_data
|