I have got an encrypted client certificate and an encrypted key as PEM files and want to authenticate at a web site and to acquire a page (via GET) using a python script. I already managed to do so using curl in the shell. So I tried to call curl from the python script but I cannot use subprocess.Popen to send the password via stdin as the password is not read via stdin by curl (similar to ssh). I would be even happier if there is a way to use the python standard libs to decode an encrypted certificate and use it to access the web site.
I found several proposals for solving similar problems but non of them met all of my requirements:
I managed to find a solution using pycurl:
import pycurl
from StringIO import StringIO
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, MYURL)
c.setopt(c.WRITEFUNCTION, buffer.write)
c.setopt(c.SSLCERT, 'clientcert.pem')
c.setopt(c.SSLCERTPASSWD, passphrase)
c.setopt(c.SSLKEY, 'clientkey.pem')
c.perform()
c.close()
print buffer.getvalue()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.