I am using the following code to perform and ssl handshake and certificate validation with an ssl server.
import ssl
import socket
s = socket.socket()
print "connecting..."
#logging.debug("Connecting")
# Connect with SSL mutual authentication
# We only trust our server's CA, and it only trusts user certificates signed by it
c = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED,
ssl_version=ssl.PROTOCOL_SSLv3, ca_certs='ca.crt',
certfile='user.crt', keyfile='user.key')
c.connect((constants.server_addr, constants.port))
I am able to get a connection to the server and the certificate is validated correctly, however, I am not sure what to do from here. I need to perform https actions over the socket, including posting XML to a REST API. How do I go about this?
You can use your
wrap_socketcode to extendhttplib.HTTPConnection, as described in this answer.(I’d still consider using something like PycURL, as I’ve already answered in your previous question.)