Patched errors

This commit is contained in:
Votre Nom 2019-11-12 15:24:37 +01:00
parent a66014a22b
commit 7a980574d0
13 changed files with 218 additions and 18 deletions

View File

@ -3,3 +3,12 @@ b544fb5d-f779-4cc1-92d5-b7d9b6d1e739 PutsEcWM9C16j3jXgxHRMsc4IYbN9fIwmiLd-koc0_Y
4529ae1f-8ffc-42eb-b9b6-d1d4225b1607 EjrlAzFKCE1QeLrLBjtr3nhgpk7YCEmE7KRlUoilxsg= 0 4529ae1f-8ffc-42eb-b9b6-d1d4225b1607 EjrlAzFKCE1QeLrLBjtr3nhgpk7YCEmE7KRlUoilxsg= 0
26c9f89a-f8e1-4b22-83bd-417c5047e527 3Po3ppCKsxBbCxsfueFxnSu_IzuXR17mC4Mw8ybfGtE= 0 26c9f89a-f8e1-4b22-83bd-417c5047e527 3Po3ppCKsxBbCxsfueFxnSu_IzuXR17mC4Mw8ybfGtE= 0
73e129a2-461b-40ef-a97c-a059a664a08e DHXNwpBPUp6CQ4ePvKm04z5a4EE2hSCpz6Nd7oyNe18= 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

4
.idea/encodings.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pj_crypto_1_v2.iml" filepath="$PROJECT_DIR$/.idea/pj_crypto_1_v2.iml" />
</modules>
</component>
</project>

11
.idea/pj_crypto_1_v2.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

151
.idea/workspace.xml Normal file
View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="8b6808a0-dab7-485f-abd0-e90e162bb69e" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.clients_keys" beforeDir="false" afterPath="$PROJECT_DIR$/.clients_keys" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server_test_3.py" beforeDir="false" afterPath="$PROJECT_DIR$/server_test_3.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/utils/rsa_tenamortech_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/utils/rsa_tenamortech_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/utils/symmetric_keys_manager_1.py" beforeDir="false" afterPath="$PROJECT_DIR$/utils/symmetric_keys_manager_1.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/server_test_3.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="5" column="41" selection-start-line="5" selection-start-column="41" selection-end-line="5" selection-end-column="41" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/utils/rsa_tenamortech_utils.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="466">
<caret line="108" column="15" lean-forward="true" selection-start-line="108" selection-start-column="15" selection-end-line="108" selection-end-column="15" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/utils/rsa_tenamortech_utils.py" />
<option value="$PROJECT_DIR$/server_test_3.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="100" />
<option name="y" value="52" />
<option name="width" value="1400" />
<option name="height" value="828" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="pj_crypto_1_v2" type="b2602c69:ProjectViewProjectNode" />
<item name="pj_crypto_1_v2" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="pj_crypto_1_v2" type="b2602c69:ProjectViewProjectNode" />
<item name="pj_crypto_1_v2" type="462c0819:PsiDirectoryNode" />
<item name="utils" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="8b6808a0-dab7-485f-abd0-e90e162bb69e" name="Default Changelist" comment="" />
<created>1573564637760</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1573564637760</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="0" y="32" width="1600" height="868" extended-state="6" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24984147" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Python Console" />
<window_info active="true" anchor="bottom" id="Terminal" visible="true" weight="0.3293011" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/utils/rsa_tenamortech_utils.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="466">
<caret line="108" column="15" lean-forward="true" selection-start-line="108" selection-start-column="15" selection-end-line="108" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/server_test_3.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="5" column="41" selection-start-line="5" selection-start-column="41" selection-end-line="5" selection-end-column="41" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>

View File

@ -3,6 +3,7 @@ from threading import Thread
from socketserver import ThreadingMixIn from socketserver import ThreadingMixIn
from utils.keys_manager_1 import * 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 --- # --- Init keys ---
() ()
@ -11,8 +12,6 @@ def de_serialize_pub_key(public_key_pem):
# Multithreaded Python server : TCP Server Socket Thread Pool # Multithreaded Python server : TCP Server Socket Thread Pool
class ClientThread(Thread): class ClientThread(Thread):
got_pub_key_client = False
able_to_retrieve_session_id = False
def __init__(self,ip,port, private_key, public_key): def __init__(self,ip,port, private_key, public_key):
Thread.__init__(self) Thread.__init__(self)
self.ip = ip self.ip = ip
@ -23,12 +22,14 @@ class ClientThread(Thread):
conn.send(public_key_pem) conn.send(public_key_pem)
def run(self): def run(self):
got_pub_key_client = False
able_to_retrieve_session_id = False
while True : while True :
data = conn.recv(2048) data = conn.recv(2048)
if not got_pub_key_client: # we might receive a pub_key in clear, or an encrtpted session_id 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 # --- 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 ]") print("[DEBUG] Received Public Key from Client [ OK ]")
public_key_client = de_serialize_pub_key(data) public_key_client = de_serialize_pub_key(data)
got_pub_key_client = True got_pub_key_client = True
@ -40,7 +41,7 @@ class ClientThread(Thread):
if(len(msg) == 36): # SessionID length should be 36 char. if(len(msg) == 36): # SessionID length should be 36 char.
print("[DEBUG] SessionID format looks correct [ ~ ]") print("[DEBUG] SessionID format looks correct [ ~ ]")
session_id = msg 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 # --- Unable to retrieve sessionID and public Key was not sent
# --- Abort connection now # --- Abort connection now
@ -81,7 +82,7 @@ threads = []
# --- Init keys --- # --- Init keys ---
(private_key, public_key) = check_for_existing_keys() (private_key, public_key) = check_for_existing_keys()
print(public_key_serializer(public_key)) #print(public_key_serializer(public_key))
while True: while True:
tcpServer.listen(4) tcpServer.listen(4)

View File

@ -105,6 +105,7 @@ def encrypt_msg(msg,public_key):
) )
return enc_msg return enc_msg
def decrypt_msg(enc_msg,private_key): def decrypt_msg(enc_msg,private_key):
msg = private_key.decrypt( msg = private_key.decrypt(
enc_msg, enc_msg,

View File

@ -4,11 +4,16 @@ from cryptography.fernet import Fernet
#UniqueID #UniqueID
import uuid 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(): def gen_rand_session_id():
return str(uuid.uuid4()) 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() key = Fernet.generate_key()
root_file_path = '.auth_server_test/' 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. # --- Store the client public Key for next time.
# --- Public keys are stored in '.auth_server_test/server/clients_pub_keys/session_id.pub' # --- 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 # Path exists ? If not we will create it
keys_dir_path.mkdir(exist_ok=True) keys_dir_path.mkdir(exist_ok=True)
key_pem = public_key_serializer(key) public_key_client_pem = public_key_serializer(public_key_client)
key_path = keys_dir_path / str(session_id) + '.pub' key_path = keys_dir_path / (str(session_id) + '.pub')
with open(str(key_path), 'wb') as f: with open(str(key_path), 'wb') as f:
f.write(client_pub_key) f.write(public_key_client_pem)
return key 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. # --- We found the given sessionID, so we will now load the corresponding client public key we previously stored.
if session_id_found == True: if session_id_found == True:
with open(str(path_clients_pub_keys + cur_client_infos[0] + '.pub'), "rb") as key_file: 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(), key_file.read(),
backend=default_backend() backend=default_backend()
) )
# --- Return the Symmetric Key used with this client and the PEM formated client public Key # --- 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: else:
# Return Error tuple # Return Error tuple
return (-1,'') return (-1,'')
@ -82,4 +87,4 @@ def encrypt_msg_symmetric(msg, key):
#print(decrypted) #print(decrypted)
#gen_sym_key_and_save() #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"))