Skip to content
Snippets Groups Projects
Commit d7aec65c authored by Dominik Fuhrmann's avatar Dominik Fuhrmann
Browse files

new server

parent aeb4c331
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,7 @@ def main():
configure_logging()
# server information
host = '192.168.178.51'
host = '192.168.178.63'
port = 12345
# Load RSA public key (for encrypting the key)
......
......@@ -21,7 +21,7 @@ def load_private_key():
def decrypt_key_with_rsa(private_key, encrypted_key):
cipher = PKCS1_OAEP.new(private_key)
key = cipher.decrypt(encrypted_key)
logging.info(f"Decrypted key: {key.hex()}")
logging.info(f"Decrypted RSA key: {key.hex()}")
return key
# Decrypt received message using the key, depending on algorithm
......@@ -75,15 +75,14 @@ def handle_client(conn, addr, private_key):
encrypted_key = base64.b64decode(data['encrypted_key'])
encrypted_message = data['encrypted_message']
logging.info(f"Algorithm: {algorithm}, Key Length: {key_length}")
user_input(f"Received data from client {addr}: Algorithm: {algorithm}, Key Length: {key_length}, Encrypted message: {encrypted_message}")
except json.JSONDecodeError as e:
logging.error(f"Error decoding data: {e}")
conn.close()
return
# Decrypt the key using RSA
logging.info(f"Decrypted RSA key from client {addr}.")
key = decrypt_key_with_rsa(private_key, encrypted_key)
logging.info(f"Decrypted key from client {addr}.")
# Decrypt the message using the key
decrypted_message = decrypt_message(algorithm, key, encrypted_message)
......@@ -103,7 +102,7 @@ def main():
configure_logging()
# server information
host = '192.168.178.51'
host = '192.168.178.63'
port = 12345
# Load RSA private key (for decrypting the key)
......@@ -125,6 +124,7 @@ def main():
while True:
try:
conn, addr = s.accept()
logging.info("\n")
logging.info(f"Connection from {addr}")
handle_client(conn, addr, private_key)
conn.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment