curl-and-python

Making https requests, using x509 certificate

From: Максим Lacrima <lacrima.maxim_at_gmail.com>
Date: Mon, 6 Jul 2009 10:45:50 +0300

Hello!
I am trying to use urllib to fetch some internet resources, using my
client x509 certificate.
I have divided my .p12 file into mykey.key and mycert.cer files.
Then I use following approach:

import pycurl
import StringIO
b = StringIO.StringIO()
c = pycurl.Curl()
url = 'https://example.com/'
c.setopt(pycurl.URL, url)
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.CAINFO, 'cert.crt')
c.setopt(pycurl.SSLKEY, 'mykey.key')
c.setopt(pycurl.SSLCERT, 'mycert.cer')
c.setopt(pycurl.SSLKEYPASSWD , 'pass phrase')
c.perform()

This code raise an error:
pycurl.error: (35, 'error reading X.509 key or certificate file')

Instead, if I use urllib, it works ok:
import urllib
opener = urllib.URLopener(key_file = 'mykey.key', cert_file = 'mycert.cer')
url = 'https://example.com/'
f = opener.open(url)

This code works ok, but I am asked to enter PEM pass phrase every time,
because urllib doesn't allow me to specify pass phrase.

So what's wrong with my code above? Why it raises 35 error?

With regards, Max
(sorry if my English isn't very proper)

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2009-07-06