ssl - Persistent loading of a PEM key/certificate pair for HTTPS connections in Python 2.x (6, 7) -


I am trying to get some resource ( GET ) from SSL-secured web service To certify in the service, I have a PEM pair of key-certificate file. I am using a slightly extended version (see below) to join the service.

My point is: after processing the content of the request, I will issue more requests on the same socket / connection. The code structure is like this:

  conn = HTTPSClientAuthConnection ("a host name", 443, key_file = a_key_file, cert_file = a_cert_file, ca_file = none) full_page, response = conn.do_request (The_main_url)) Further_requests = process_page (full_page) for the referees in further_requests: new_data, feedback = conn.do_request (ref) print process_data (new_data)  

This annoyance is that do_request , a passphrase is requested for the certificate / key pair. How can I make that consistently? I am trying to apply this client only to Python with Stadtib, because the machine I will run is not easily modified. But if this is not possible, then a good library suggestion is also welcome ...

I have passphrase & gt; & Lt; First request stdout & gt; There is no output but enter the PEM pass phrase: & lt; I passphrase & gt; & Lt; Output of this step & gt; Enter the PEM pass phrase: & lt; I passphrase & gt; & Lt; Output of this step & gt; Enter the PEM pass phrase: & lt; I passphrase & gt; & Lt; Output of this step & gt; ...

SSL client code:

  import socket import SSL import hippopation class HTTPSClientAuthConnection (httplib.HTTPSConnection): "" "to create an HTTPS Def __init __ (auto, host, port, key_file, cert_file, ca_file, timeout = none) with support for class connection, full client-based SSL authentication: httplib.HTTPSConnection .__ init __ (self, host, Key_file = key_file, cert_file = Cert_file) self.key_file = key_file self.cert_file = cert_file self.ca_file = ca_file self.timeout = timeout def connect (manually): "" "connect to a host on a host (SSL) port Please. If ca_file is pointing somewhere, use it to check the server certificate. Redefined / Copied and expanded from httplib.py/105 (Python 2.6.x). It is necessary to pass ssl.wrap_socket () as the cert_recus = ssl.CERT_REQUIRED parameter, which prevents SSL against the server certificate against our client certificate. "" "Sock = socket.create_connection (self.host, self.port), self.timeout) If self._tunnel_host: self.sock = sock self._tunnel () # If there is no CA file, then the server certificate Do not check the self.ca_file: self.sock = ssl.wrap_socket (sock, self.key_file, self.cert_file, ca_certs = self.ca_file, cert_reqs = ssl.CERT_REQUIRED) Other: self.sock = ssl.wrap_socket (sock , "Auto_key", " Alive "(method, url, header = header) response = self.getresponse () data = response. Read () returns data, counter Or  


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -