SSL not working with Python 3.7 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: SSL not working with Python 3.7 (/thread-15567.html) |
SSL not working with Python 3.7 - Kyuu - Jan-22-2019 I started to learn python and sockets those days and I made a simple client-server app just to make some tests and it works fine with Python 3.6, but gives me error in the newest version. I make the code while studying the Python's docs. I'm using Python 3.7.2 in Windows 10 64 bits. Server.py import socket, ssl context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) context.verify_mode = ssl.CERT_REQUIRED context.load_cert_chain(certfile="SSL/server.crt", keyfile="SSL/server.key") context.load_verify_locations("SSL/client.crt") bindsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) bindsocket.bind(("127.0.0.1", 65405)) bindsocket.listen(5) while True: newsocket, fromaddr = bindsocket.accept() print(newsocket) #it prints successfully connstream = context.wrap_socket(newsocket, server_side=True) #this line gives me the error try: print(connstream.getpeercert()) finally: connstream.shutdown(socket.SHUT_RDWR) connstream.close()Client.py import ssl, socket context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) context.load_cert_chain(certfile="SSL/clientKaori.crt", keyfile="SSL/clientKaori.key") context.verify_mode = ssl.CERT_REQUIRED context.check_hostname = True context.load_verify_locations("SSL/serverKaori.crt") conn = context.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), server_hostname="127.0.0.1") try: conn.connect(("127.0.0.1", 65405)) conn.sendall(b"aff") print(conn.getpeercert()) except: print("não") finally: conn.shutdown(socket.SHUT_RDWR) conn.close()The error is: Thanks for all!
RE: SSL not working with Python 3.7 - Kyuu - Jan-22-2019 When I use the command "s_client -connect 127.0.0.1:65405 -cert client.pem -key client.pem -CAfile server.crt" in the OpenSSL it works fine |