Creating a custom SSL client/server
So far, we have been dealing more with the SSL or TLS client. Now, let us have a look at the server side briefly. As you are already familiar with the TCP/UDP socket server creation process, let's skip that part and just concentrate on the SSL wrapping part. The following code snippet shows an example of a simple SSL server:
import socket import ssl SSL_SERVER_PORT = 8000 if __name__ == '__main__': server_socket = socket.socket() server_socket.bind(('', SSL_SERVER_PORT)) server_socket.listen(5) print("Waiting for ssl client on port %s" %SSL_SERVER_PORT) newsocket, fromaddr = server_socket.accept() # Generate your server's public certificate and private key pairs. ssl_conn = ssl.wrap_socket(newsocket, server_side=True, ...
Get Learning Python Network Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.