I have been given the following code that should perform an ssl handshake and certificate authentication:
1 s = socket.socket()
2 print "connecting..."
3 logging.debug("Connecting")
4 # Connect with SSL mutual authentication
5 # We only trust our server's CA, and it only trusts user certificates signed by it
6 c = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED,
7 ssl_version=ssl.PROTOCOL_SSLv3, ca_certs='ca.crt',
8 certfile='user.crt', keyfile='user.key')
9 c.connect((constants.server_addr, constants.port))
I have 2 questions about this:
- where do we specify the server/port to which we are connecting? are these arguments to
socket.socket()? - I have a .p12 from which I extracted a cert and a key in pem format(see this question), and I assume that these correspond to
user.crtanduser.key(line 8), respectively. However, while I assume thatca.crt(line 7) is retrived from the certificate authority, how to I retrieve it?
If any part of the above code or my assumptions about it are incorrect, please let me know. Thanks!
.p12file) can, and typically do, contain the relevant CA certificate as well.man pkcs12-- particularly-cacertsin conjunction with-out. That said, Bruno's warning applies -- the client and server certificates may or may not be signed by the same CA.