Python3: ssl cert information - python

I have been trying to get information regarding expired ssl certificates using python 3 but it would be nice to be able to get as verbose a workup as possible. any takers?
So far i have been trying to use urllib.request to get this info (to no avail), does this strike anyone as foolish?
I have seen some examples of similar work using older versions of python, but nothing using v3.
http://objectmix.com/python/737581-re-urllib-getting-ssl-certificate-info.html
http://www.mail-archive.com/python-list#python.org/msg208150.html

The 3.1.1 documentation for SSL has an example.

Related

Workarounds to get Google sign-in functioning with Python 2.6 and pyOpenSSL 0.10-2

I'm trying to get Google sign-in working using their Python API but the server I'm on (4UHosting) has Python 2.6 and pyOpenSSL 0.10-2 (5-years old).
This means that the API's call to OpenSSL.crypto.verify() fails as it doesn't exist in this version.
I can't install these myself, even --self as they require compiler use which I don't have. The admins are reluctant to install any updates that are not vetted. They won't install pyOpenSSL or Python 2.7 locally just for me. I can't find documentation from pyOpenSSL 0.10-2 that would have an equivalent function to verify().
I'm looking for some suggestions as where to head from here.
Any suggestions would be greatly appreciated,
Cyrille
A few ideas:
You could directly make your API calls to the Google API Endpoints instead of using the Python client library, for example, the token info endpoint can be used to verify tokens
You could do sign-in operations client-side and transfer data to your server once a session is attached
You could use another language (e.g. Ruby) for the sign-in operations

Sending http post request in buildbot

I am using buildbot version 0.8.5 and need to send an HTTP post request from it as a step. After searching for it on internet, I found that the latest version 0.8.8 has a step called HTTPStep for doing so. Is there any similar step in the older version?
I know it can be done using batch file or python program using urllib2. but is there any other way to do it?
You should be able to use the HTTPStep from 0.8.8 (provided you install the necessary dependency (https://pypi.python.org/pypi/txrequests and http://python-requests.org/)). Just copy the http.py file from 0.8.8 next to your master.cfg, and have your master.cfg import the HTTPStep derived class POST from module http instead of buildbot.steps.http.
Some small adjustments might be needed to make it work with the API of 0.8.5 though.
Just my thoughts..As far as I know it is better to use a python script from a build step. Simple and easy to control. The logic being:
the entire buildbot is inside one http connection/session and sending another http request somewhere might have issues with the connection/session.
from the buildbot httpstep description, you need to install additional python packages which might be not be so convenient to do on multiple slaves/masters.

python requests not working with google app engine

I'm trying to fetch a page using python requests with this code in views.py:
s = requests.Session()
r = s.get("https://www.23andme.com/")
I get the error Exceeded 30 redirects. My app is a Google App Engine Django app. I've gotten this code to work in the python console and a django server on pythonanywhere.com, but for some reason it isn't working on google app engine. What could be causing this? Thanks
Edit: It seems like there is another issue with the Requests module in my app. I have this code to add an email to a mailchimp list:
m = mailchimp.Mailchimp(MAILCHIMP_API_KEY)
list_response = m.lists.list()
but if fails with the error HTTPS/SSL is required
Try installing urllib3 (and other stuff, see below).
See, historically there were tons of issues for requests with google app engine (and see issue #498). Those were mostly resolved with urllib3 support for GAE that came with v1.3. It came out a long time ago (the current release is 1.7), so its probably not the issue, however when you initially install requests, it includes urllib3 in a folder called packages and maybe it doesn't include the entirey of it.
I also tried searching the source code for requests and found this interesting:
# Attempt to enable urllib3's SNI support, if possible
try:
from requests.packages.urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()
except ImportError:
pass
Going deeper, the contrib package includes a pyopenssl.py script which requires:
SSL with SNI-support for Python 2.
This needs the following packages installed:
pyOpenSSL (tested with 0.13)
ndg-httpsclient (tested with 0.3.2)
pyasn1 (tested with 0.1.6)
So, to sum up:
Install urllib3 and other SSL packages mentioned above, then try running that request you're doing again and see if anything has changed. My guess is that this will (at the very least) help with the mailchimp as it's also complaining about SSL/HTTPS issues.
If that doesn't work, try using urllib3 api instead of requests to do the same task and see if that's working. If so, the problem is specifically with the packaged urllib3 that requests is using, which might need some patching.
import urllib3
http = urllib3.PoolManager()
r = http.request('GET', 'https://www.23andme.com/')
Sorry this isn't a definite solution, hopefully one of my suggestions will help. Update me as to the progress I'll try and help out as much as I can
According to this discussion, the issue is with netrc on Google App Engine. I was able to work around the problem by using an older version of Requests (1.2.3 in my case, but others may work too.)
Edit: According to this answer, Requests 2.1.0 should work as well.

Adding server certificate validation to httplib.HTTPSConnection

I've found that httplib.HTTPSConnection doesn't perform an automatic server certificate check. As far as I've understood the problem, I need to add that functionality manually, e.g. by subclassing this class as described here.
As I'm using Python2.4.5 and an upgrade is not possible under the given circumstances, I cannot use the workaround given in this blog post, because the ssl module has not been introduced until Py2.6.
I've been trying to avoid the usage of the ssl module by using M2Crypto. A promising approach for doing so is contained in this blog post (in the "Clients" section). But I haven't yet managed to override httplib.HTTPSConnection.connect appropriately by using that approach.
Any ideas or hints?
Try this site maybe: http://www.cs.technion.ac.il/~danken/xmlrpc-ssl.html
It requires SSL but doesn't require the Python SSL module. It only requires Open SSL library.

Is there a Python library for connecting to a PostgreSQL 8.4 server using certificate authentication?

We are in the process of upgrading from PostgreSQL 8.3 to PostgreSQL 8.4, in a large part so that we can start using certificate-based authentication.
We have some Python 2.x code that accesses the database that uses PyGreSQL. Is there a way to get it or any other Python library to use a cert to access PostgreSQL?
Looking through the PyGreSQL source, I didn't see a way to supply a certificate.
psycopg2 is based on libpq, so it should work there. I don't think there's a specific interface for it, so you'll have to use the environment variables (see the libpq documentation) to control it, but it should work. (disclaimer: I haven't actually tried it, but anything on top of libpq should work)

Categories