Пример #1
0
    def connect(self):
        "Connect to a host on a given (SSL) port"
        results = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC,
                                     socket.SOCK_STREAM)

        for r in results:
            af, socktype, proto, canonname, sa = r
            try:
                sock = socket.socket(af, socktype, proto)
                sock.connect((self.host, self.port))
                sock.settimeout(self.timeout)
            except socket.error:
                e = sys.exc_info()[1]
                if e.errno != errno.EINTR:
                    sock.close()
                    sock = None
                continue
            break

        if sock is None:
            raise socket.error(
                "Unable to connect to the host and port specified")

        self.sock = SSL.SSLSocket(sock, self.trusted_certs)
        self.sock.init_ssl()
Пример #2
0
 def connect(self):
     # Set the connection with the proxy
     HTTPProxyConnection.connect(self)
     # Use the stock HTTPConnection putrequest
     host = "%s:%s" % (self._host, self._port)
     HTTPConnection.putrequest(self, "CONNECT", host)
     # Add proxy-specific stuff
     self._add_proxy_headers()
     # And send the request
     HTTPConnection.endheaders(self)
     # Save the response class
     response_class = self.response_class
     # And replace the response class with our own one, which does not
     # close the connection after
     self.response_class = HTTPSProxyResponse
     response = HTTPConnection.getresponse(self)
     # Restore the response class
     self.response_class = response_class
     # Close the response object manually
     response.close()
     if response.status != 200:
         # Close the connection manually
         self.close()
         raise xmlrpclib.ProtocolError(host, response.status,
                                       response.reason, response.msg)
     self.sock = SSL.SSLSocket(self.sock, self.trusted_certs)
     self.sock.init_ssl()
Пример #3
0
def run_test(server_name, server_port, ca_cert):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((server_name, server_port))

    sslsock = SSL.SSLSocket(sock, [ca_cert])
    sslsock.init_ssl()

    sslsock.close()