Skip to content

Instantly share code, notes, and snippets.

@Averroes
Created April 10, 2015 17:01
Show Gist options
  • Select an option

  • Save Averroes/c0dcd21e94077390248a to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/c0dcd21e94077390248a to your computer and use it in GitHub Desktop.
adding ssl to network servers
# 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