Package web :: Package clientjob :: Module secure_connection
[hide private]
[frames] | no frames]

Source Code for Module web.clientjob.secure_connection

 1  from httplib import HTTPSConnection 
 2  from socket import socket, AF_INET, SOCK_STREAM 
 3  import config 
 4  from ssl import wrap_socket, CERT_REQUIRED 
 5   
6 -class SecureConnection(HTTPSConnection):
7 ''' 8 This is an https connection that verifies that the server certificate is signed by 9 a trusted ca_cert. 10 11 NOTE that it does NOT validate that the hostname matches the one in the certificate, 12 because multiple clients (with different hostnames) will use the same certificate. 13 Thus, for us it's enough to know that a given client has the private key whose public 14 key is trusted. 15 '''
16 - def connect(self):
17 # overrides the version in httplib so that we do certificate verification 18 sock = socket(AF_INET, SOCK_STREAM) 19 sock.connect((self.host, self.port)) 20 21 if not self.cert_file: 22 self.cert_file = config.cert_file 23 if not self.key_file: 24 self.key_file = config.key_file 25 self.ca_certs = (config.ca_cert) 26 27 self.sock = wrap_socket(sock, self.key_file, self.cert_file, 28 cert_reqs=CERT_REQUIRED, ca_certs=self.ca_certs)
29