diff --git a/.clients_keys b/.clients_keys
index 5010206..ac4d505 100644
--- a/.clients_keys
+++ b/.clients_keys
@@ -3,3 +3,12 @@ b544fb5d-f779-4cc1-92d5-b7d9b6d1e739 PutsEcWM9C16j3jXgxHRMsc4IYbN9fIwmiLd-koc0_Y
4529ae1f-8ffc-42eb-b9b6-d1d4225b1607 EjrlAzFKCE1QeLrLBjtr3nhgpk7YCEmE7KRlUoilxsg= 0
26c9f89a-f8e1-4b22-83bd-417c5047e527 3Po3ppCKsxBbCxsfueFxnSu_IzuXR17mC4Mw8ybfGtE= 0
73e129a2-461b-40ef-a97c-a059a664a08e DHXNwpBPUp6CQ4ePvKm04z5a4EE2hSCpz6Nd7oyNe18= 0
+af31fde9-6168-4125-893d-dc91f84cadff -KH4ff18t4m-eHvZ2q1GShW-HQNOK1dr3_T07eXFY-U= 0
+7aa18f27-6b71-4290-ab20-aeb66059e6ee d14i6fyR_cBsWZecFzgWkHgdvhC2eOF7sNzI9zKa9Yo= 0
+a0ee1a26-c2ba-4270-b731-30fcbee18dd3 aBwZ-PaWMKTyuiK5pjZvU47MaAymX8k_ujGiH5lm-8Y= 0
+dc65ab06-0959-4885-b881-c9c9da1a6adc Iay5UfQgmSJZKcGGI03Q1rhhp-pjrQIvw_MBbFuhid4= 0
+e4fc52d4-d485-4546-b0fd-e2c7f2a010da AdCkxszIsUCvEcMTB-Zi0ACdeYViXYkGeldEb4o8R6Q= 0
+fd05a547-8032-450c-a0f1-6a204aa1288e -n2gtRIBrlDpRisHeno-1pxYLXn5muuct7CHuJXCsbI= 0
+20a03a39-d9f0-495b-ae38-016e3350ede3 78J-gIZ710ozVxg4Iu4S9r3olhZCMtcKYRC3_H4hCxU= 0
+9c5b6d7c-6317-4db1-a14a-d4be911ef45f u4SdDIORALLuPoKtJ076rZzpJk1ZiUCRWERZwQdNsxY= 0
+f6325f18-2909-4665-b681-a0f764fa6c68 _d0ywQ34kEgiRopLnr8R8RDjjDLbH7JTZJp1_FkwgWw= 0
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..15a15b2
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..65531ca
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..d95276c
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/pj_crypto_1_v2.iml b/.idea/pj_crypto_1_v2.iml
new file mode 100644
index 0000000..6711606
--- /dev/null
+++ b/.idea/pj_crypto_1_v2.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..a534146
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,151 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1573564637760
+
+
+ 1573564637760
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/client_test_3.py b/client_test_3.py
index bcc1efc..6abcd39 100644
--- a/client_test_3.py
+++ b/client_test_3.py
@@ -38,7 +38,7 @@ while MESSAGE != 'exit':
print("Server public key received")
print("Sending current client public key [ ... ] ")
tcpClientA.send(public_key_pem)
- print("Sending current client public key [ OK ] ")
+ print("Sending current client public key [ OK ] ")
else:
print(" Client2 received data:", data)
diff --git a/server_test_3.py b/server_test_3.py
index 12968fa..8d8884a 100644
--- a/server_test_3.py
+++ b/server_test_3.py
@@ -2,7 +2,8 @@ import socket
from threading import Thread
from socketserver import ThreadingMixIn
from utils.keys_manager_1 import *
-from utils.symmetric_keys_manager_1 import *
+from utils.symmetric_keys_manager_1 import *
+from utils.rsa_tenamortech_utils import *
# --- Init keys ---
()
@@ -11,8 +12,6 @@ def de_serialize_pub_key(public_key_pem):
# Multithreaded Python server : TCP Server Socket Thread Pool
class ClientThread(Thread):
- got_pub_key_client = False
- able_to_retrieve_session_id = False
def __init__(self,ip,port, private_key, public_key):
Thread.__init__(self)
self.ip = ip
@@ -23,24 +22,26 @@ class ClientThread(Thread):
conn.send(public_key_pem)
def run(self):
+ got_pub_key_client = False
+ able_to_retrieve_session_id = False
while True :
data = conn.recv(2048)
if not got_pub_key_client: # we might receive a pub_key in clear, or an encrtpted session_id
- print("[DEBUG] Waiting for HandShake [ ... ]"
+ print("[DEBUG] Waiting for HandShake [ ... ]")
# --- Text was clear and client sent pub_key
- if "-----BEGIN PUBLIC KEY-----" in data:
+ if ("-----BEGIN PUBLIC KEY-----").encode('utf-8') in data:
print("[DEBUG] Received Public Key from Client [ OK ]")
public_key_client = de_serialize_pub_key(data)
got_pub_key_client = True
# --- Decrypt data and try to load session_id etc
- else:
+ else:
print("[DEBUG] No HandShake, got SessionID from Client")
print("[DEBUG] Waiting for SessionID validation [ ... ]")
- msg = decrypt_msg(data, private_key)
+ msg = decrypt_msg(data, private_key)
if(len(msg) == 36): # SessionID length should be 36 char.
print("[DEBUG] SessionID format looks correct [ ~ ]")
session_id = msg
- (symmetric_key,client_pub_key) = reload_session_sym_key(session_id)
+ (symmetric_key,public_key_client) = reload_session_sym_key(session_id)
# --- Unable to retrieve sessionID and public Key was not sent
# --- Abort connection now
@@ -81,7 +82,7 @@ threads = []
# --- Init keys ---
(private_key, public_key) = check_for_existing_keys()
-print(public_key_serializer(public_key))
+#print(public_key_serializer(public_key))
while True:
tcpServer.listen(4)
diff --git a/utils/__pycache__/rsa_tenamortech_utils.cpython-36.pyc b/utils/__pycache__/rsa_tenamortech_utils.cpython-36.pyc
index 1c998da..44e7053 100644
Binary files a/utils/__pycache__/rsa_tenamortech_utils.cpython-36.pyc and b/utils/__pycache__/rsa_tenamortech_utils.cpython-36.pyc differ
diff --git a/utils/__pycache__/symmetric_keys_manager_1.cpython-36.pyc b/utils/__pycache__/symmetric_keys_manager_1.cpython-36.pyc
new file mode 100644
index 0000000..7742166
Binary files /dev/null and b/utils/__pycache__/symmetric_keys_manager_1.cpython-36.pyc differ
diff --git a/utils/rsa_tenamortech_utils.py b/utils/rsa_tenamortech_utils.py
index 020b5ff..c58d519 100644
--- a/utils/rsa_tenamortech_utils.py
+++ b/utils/rsa_tenamortech_utils.py
@@ -105,6 +105,7 @@ def encrypt_msg(msg,public_key):
)
return enc_msg
+
def decrypt_msg(enc_msg,private_key):
msg = private_key.decrypt(
enc_msg,
diff --git a/utils/symmetric_keys_manager_1.py b/utils/symmetric_keys_manager_1.py
index 49988aa..c526fe7 100644
--- a/utils/symmetric_keys_manager_1.py
+++ b/utils/symmetric_keys_manager_1.py
@@ -4,11 +4,16 @@ from cryptography.fernet import Fernet
#UniqueID
import uuid
+# To get user home directory
+from pathlib import Path
+
+# Home made RSA Keys lib
+from utils.rsa_tenamortech_utils import *
def gen_rand_session_id():
return str(uuid.uuid4())
-def gen_sym_key_and_save(client_pub_key):
+def gen_sym_key_and_save(public_key_client):
key = Fernet.generate_key()
root_file_path = '.auth_server_test/'
@@ -25,15 +30,15 @@ def gen_sym_key_and_save(client_pub_key):
# --- Store the client public Key for next time.
# --- Public keys are stored in '.auth_server_test/server/clients_pub_keys/session_id.pub'
- keys_dir_path = Path.home() / path_client_pub_keys
+ keys_dir_path = Path.home() / path_clients_pub_keys
# Path exists ? If not we will create it
keys_dir_path.mkdir(exist_ok=True)
- key_pem = public_key_serializer(key)
- key_path = keys_dir_path / str(session_id) + '.pub'
+ public_key_client_pem = public_key_serializer(public_key_client)
+ key_path = keys_dir_path / (str(session_id) + '.pub')
with open(str(key_path), 'wb') as f:
- f.write(client_pub_key)
+ f.write(public_key_client_pem)
return key
@@ -60,12 +65,12 @@ def reload_session_sym_key(sessionid):
# --- We found the given sessionID, so we will now load the corresponding client public key we previously stored.
if session_id_found == True:
with open(str(path_clients_pub_keys + cur_client_infos[0] + '.pub'), "rb") as key_file:
- client_pub_key_pem = serialization.load_pem_public_key(
+ public_key_client = serialization.load_pem_public_key(
key_file.read(),
backend=default_backend()
)
# --- Return the Symmetric Key used with this client and the PEM formated client public Key
- return (cur_client_infos[1],client_pub_key_pem)
+ return (cur_client_infos[1],public_key_client_pem)
else:
# Return Error tuple
return (-1,'')
@@ -82,4 +87,4 @@ def encrypt_msg_symmetric(msg, key):
#print(decrypted)
#gen_sym_key_and_save()
-print(reload_session_sym_key("26c9f89a-f8e1-4b22-83bd-417c5047e527"))
+#print(reload_session_sym_key("26c9f89a-f8e1-4b22-83bd-417c5047e527"))