Python is an interpreted language that has become popular with many programmers and server administrators. It is known for its relative ease-of-use and its sizeable library of tools to handle common computing tasks, ranging from graphics animation to networking. An example of this is the SSL library, which provides all the tools a developer needs to create a Secure Sockets Layer (SSL) for clients and servers.
- Skill level:
- Moderately Easy
Things you need
- SSL library
- SSL certificate and key (Optional)
Open a text-editor, preferably a programming editor with Python syntax highlighting.
Paste the following code into your editor, taken directly from the Python SSL library documentation:
import socket, ssl, pprint
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
require a certificate from the server
ssl_sock = ssl.wrap_socket(s,
note that closing the SSLSocket will also close the underlying socket
This simple SSL client program will connect to a server (in this case, verisign.com), request a copy of its SSL certificate, and print the information about it, before closing the connection. Save your work as "SSLclient.py."
Open a new text editor and paste the following SSL server code into it. Again, this code is taken directly from the SSL documentation:
import socket, ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
bindsocket = socket.socket()
newsocket, fromaddr = bindsocket.accept()
connstream = context.wrap_socket(newsocket, server_side=True)
This code is slightly more complex, and it requires that you purchase an SSL certificate. These certificates cannot be program-generated. They must be created by a "trusted" certificate provider, such as Verisign. Certificates generally cost between £259 and £974 per year, though they can sometimes be purchased more cheaply in combination with web-hosting service contracts. If you have a certificate and its key, replace the "mycertfile" with the file name for your certificate and the "mykeyfile" with the file name for its key.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for