Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Error using httlib's HTTPSConnection with PKCS#12 certificate

Thread Tools

Error using httlib's HTTPSConnection with PKCS#12 certificate

Posts: n/a
I'm trying to use httplib's HTTPSConnection for client validation,
using a PKCS #12 certificate. I know the certificate is good, as I
can connect to the server using it in MSIE and Firefox.

Here's my connect function (the certificate includes the private key).
I've pared it down to just the basics:

def connect(self, cert_file, host, usrname, passwd):
self.cert_file = cert_file = host

self.conn = httplib.HTTPSConnection(, port=self.port,
key_file=cert_file, cert_file=cert_file)

self.conn.putrequest('GET', 'pathnet/,DanaInfo=')
retCreateCon = self.conn.getresponse()

if is_verbose:
print "Create HTTPS connection, " +

# ...

(Note: the request path is correct, as I connect to it in MSIE and
Firefox. I changed the IP address for the post.)

When I try to run this using a PKCS#12 certificate (a .pfx file), I
get back what appears to be an openSSL error. Here is the entire error

File "", line 175, in <module>
t.connect(cert_file=opts["-keys"], host=host_name, usrname=opts["-
username"], passwd=opts["-password"])
File "", line 40, in connect
File "c:\python26\lib\", line 904, in endheaders
File "c:\python26\lib\", line 776, in _send_output
File "c:\python26\lib\", line 735, in send
File "c:\python26\lib\", line 1112, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File "c:\python26\lib\", line 350, in wrap_socket
File "c:\python26\lib\", line 113, in __init__
cert_reqs, ssl_version, ca_certs) ssl.SSLError: [Errno 336265225]
_ssl.c:337: error:140B0009:SSL
routines:SSL_CTX_use_PrivateKey_fileEM lib

Notice, the openSSL error notes "PEM lib", which I found odd, since
I'm not trying to use a PEM certificate.

For kicks, I converted the PKCS#12 cert to a PEM cert, and ran the
same code using *that*. In that case, I received no error, I was
prompted to enter the PEM pass phrase, and the code did attempt to
reach the server. (I received the response "The service is not
available. Please try again later.", but I believe that would be
because the server does not accept the PEM cert. I can't connect in
Firefox to the server using the PEM cert either.)

Is httplib's HTTPSConnection supposed to support PCKS#12
certificates? (That is, pfx files.) If so, why does it look like
openSSL is trying to load it inside the PEM lib? Am I doing this all

Any advice is welcome.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Certificate validation with HTTPSConnection Ned Deily Python 5 10-27-2010 10:43 PM
HTTPSConnection: client certificate auth Mailing List SVR Python 0 01-31-2009 08:45 AM
Using HTTPSConnection and verifying server's CRT =?iso-8859-1?Q?Marc_Poulhi=E8s?= Python 4 02-01-2005 10:04 PM
httplib.HTTPSConnection problem Terry Kerr Python 0 07-16-2004 08:06 AM
HTTPSConnection Problems John Glista Python 2 02-07-2004 12:58 AM