Apr-13-2025, 04:14 PM
client side:
server side:
import socket, ssl context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) context.verify_mode = ssl.CERT_REQUIRED context.load_cert_chain(certfile = 'ec_client.crt', keyfile = 'ec_client.key') context.load_verify_locations('ec_server_ca_chain.crt') # server and CA certificate combined. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('192.168.2.7', 8443)) ssl_sock = context.wrap_socket(s, server_side = False, server_hostname = 'somehostname')
Error:ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1000)
----------------------------------------------------------------------
server side:
import socket, ssl context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) context.verify_mode = ssl.CERT_REQUIRED context.load_cert_chain(certfile = 'ec_server.crt', keyfile = 'ec_server.key') context.load_verify_locations('ec_client_ca_chain.crt') # client and CA certificate combined. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('0.0.0.0', 8443)) s.listen(5) conn, addr = s.accept() ssl_conn = context.wrap_socket(conn, server_side = True)
Error:ssl.SSLError: [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1018)