[TP06] Fix e QOL
This commit is contained in:
parent
eacfa5363f
commit
287ae0e466
3 changed files with 29 additions and 47 deletions
|
@ -1,37 +0,0 @@
|
|||
from socket import socket, AF_INET, SOCK_STREAM
|
||||
from ssl import SSLContext, PROTOCOL_TLS_SERVER, CERT_REQUIRED
|
||||
import ssl
|
||||
|
||||
|
||||
ip = "127.0.0.1"
|
||||
port = 8443
|
||||
|
||||
client_cert = "client.crt"
|
||||
server_cert = "server.crt"
|
||||
server_key = "server.key"
|
||||
|
||||
context = SSLContext(PROTOCOL_TLS_SERVER)
|
||||
context.set_ciphers("TLS_CHACHA20_POLY1305_SHA256")
|
||||
print("Using Cipher: ", context.get_ciphers())
|
||||
context.minimum_version = ssl.TLSVersion.TLSv1_3
|
||||
print("Minimum TLS Version: ", context.minimum_version)
|
||||
context.load_cert_chain("server_cert.pem", "server_key.pem")
|
||||
context.verify_mode = CERT_REQUIRED
|
||||
|
||||
with socket(AF_INET, SOCK_STREAM) as server:
|
||||
server.bind((ip, port))
|
||||
server.listen(1)
|
||||
with context.wrap_socket(server, server_side=True) as tls:
|
||||
connection, address = tls.accept()
|
||||
print(f"Connected by {address}\n")
|
||||
data = connection.recv(1024)
|
||||
print(f"Client Says: {data.decode()}")
|
||||
|
||||
while True:
|
||||
message = input("Server: ")
|
||||
connection.sendall(message.encode())
|
||||
if message.lower() == "exit":
|
||||
break
|
||||
|
||||
data = connection.recv(1024)
|
||||
print(f"Client says: {data.decode()}")
|
Loading…
Add table
Add a link
Reference in a new issue