finalizando trabalho 4

This commit is contained in:
2023-10-31 18:31:12 -03:00
parent 7b1b7860b6
commit 583aca1960
5 changed files with 112 additions and 36 deletions
+12 -5
View File
@@ -1,10 +1,10 @@
import socket
from common import *
import socket
from AES import AESCipher
import os
from random import randint
import socket
import os
import base64
import time
HOST = "127.0.0.1"
PORT = SERVICE_PORT
@@ -34,6 +34,11 @@ def process_message(message):
T_c_s = T_c_s.split("<>")
ID_C = T_c_s[0]
T_A = T_c_s[1]
if int(T_A) < int(time.time()):
print("Invalid ticket [expired]")
return "Invalid ticket [expired]"
K_c_s = eval(T_c_s[2])
M5_inner_AES = AESCipher(K_c_s)
@@ -43,10 +48,13 @@ def process_message(message):
N3 = M5_inner[3]
# generate M6
M6_inner = f"{randint(0, 100)}<>{N3}"
message = "OPEN"
M6_inner = f"{message}<>{N3}"
M6_inner_AES = AESCipher(K_c_s)
M6_inner = M6_inner_AES.encrypt(M6_inner)
print("Sending M6", f"[{message}<>{N3}]")
M6 = f"{M6_inner}"
return M6
@@ -57,7 +65,6 @@ def main():
while True:
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
all_data = ""
data = conn.recv(4096)
all_data += data.decode()