Created
April 10, 2015 17:01
-
-
Save Averroes/c0dcd21e94077390248a to your computer and use it in GitHub Desktop.
adding ssl to network servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # echoclient.py | |
| # | |
| # An example of a client that connects to an SSL server | |
| # and verifies its certificate | |
| from socket import socket, AF_INET, SOCK_STREAM | |
| import ssl | |
| s = socket(AF_INET, SOCK_STREAM) | |
| # Wrap with an SSL layer and require the server to present its certificate | |
| ssl_s = ssl.wrap_socket(s, | |
| cert_reqs=ssl.CERT_REQUIRED, | |
| ca_certs='server_cert.pem', | |
| ) | |
| ssl_s.connect(('localhost', 20000)) | |
| # Communicate with the server | |
| ssl_s.send(b'Hello World!') | |
| resp = ssl_s.recv(8192) | |
| print('Got:', resp) | |
| # Done | |
| ssl_s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment