diff --git a/lab12/https_server.py b/lab12/https_server.py index 3b5649d469d8a73eec0342440a05268d0bc5d2a4..86d25159c040a08f439403bd025f4050f4de7318 100644 --- a/lab12/https_server.py +++ b/lab12/https_server.py @@ -8,7 +8,7 @@ SERVER_CERT = './server.crt' SERVER_PRIVATE = './server.key' context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) -#context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) # Ubuntu 16.04 +# context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) # Ubuntu 16.04 context.load_cert_chain(SERVER_CERT, SERVER_PRIVATE) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) @@ -18,7 +18,7 @@ sock.listen(5) while True: newsock, fromaddr = sock.accept() ssock = context.wrap_socket(newsock, server_side=True) - data = ssock.recv(1024) # Read data over TLS - ssock.sendall(html.encode('utf-8')) # Send data over TLS - ssock.shutdown(socket.SHUT_RDWR) # Close the TLS connection + data = ssock.recv(1024) # Read data over TLS + ssock.sendall(html.encode('utf-8')) # Send data over TLS + ssock.shutdown(socket.SHUT_RDWR) # Close the TLS connection ssock.close() diff --git a/lab12/ssl_client.py b/lab12/ssl_client.py index 10bb560a3d525d5dea6ed78b1df41243f40afda3..a0f434553771fc16fde071a989fae847b0117f9d 100644 --- a/lab12/ssl_client.py +++ b/lab12/ssl_client.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 import socket, ssl, sys, pprint + # Primim ca argument hostname-ul serverului, de exemplu google.com hostname = sys.argv[1] @@ -16,15 +17,15 @@ cadir = '/etc/ssl/certs' # Set up the TLS context context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) -#context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) # For Ubuntu 16.04 +# context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) # For Ubuntu 16.04 context.load_verify_locations(capath=cadir) context.verify_mode = ssl.CERT_REQUIRED context.check_hostname = True # Add the TLS ssock = context.wrap_socket(sock, server_hostname=hostname, -do_handshake_on_connect=False) -ssock.do_handshake() # Start the handshake + do_handshake_on_connect=False) +ssock.do_handshake() # Start the handshake pprint.pprint(ssock.getpeercert()) input("After handshake. Press any key to continue ...")