How to create a dual-authentication HTTPS client in Python without (L)GPL libs?

2024/10/16 3:21:57

Both the client and the server are internal, each has a certificate signed by the internal CA and the CA certificate. I need the client to authenticate the server's certificate against the CA certificate it has. It also should send its certificate to the server for authentication.

The urllib2 manual says that server authentication is not performed. PycURL is a natural alternative but its license is not approved yet. I would also prefer not having to compile the library from the source code but to use RPM instead.

I went over a bunch of libraries like requests, httplib2 and don't see what I need. There is also the ssl module but I don't feel like implementing http myself if I don't absolutely must.

Python 2.6 on RHEL 5.7

Answer

well, the winner (almost) is httplib2 v0.7. Starting from this version it supports SSL certificate authentication. Here's the sample code

import httplib2
client = httplib2.Http(ca_certs='ca.crt')
client.add_certificate(key='client_private_key.pem', cert='cert_client.pem', domain='')
headers, resp = client.request(query)

Note the domain='' parameter, it didn't work for me otherwise.

PS. unfortunately this simple solution does not work for me as I forgot to mention additional requirement - having RPM installation for RHEL 5.7 & Python 2.6.

https://en.xdnf.cn/q/69206.html

Related Q&A

Generate a certificate for .exe created by pyinstaller

I wrote a script for my company that randomly selects employees for random drug tests. It works wonderfully, except when I gave it to the person who would use the program. She clicked on it and a messa…

Some doubts modelling some features for the libsvm/scikit-learn library in python

I have scraped a lot of ebay titles like this one:Apple iPhone 5 White 16GB Dual-Coreand I have manually tagged all of them in this wayB M C S NAwhere B=Brand (Apple) M=Model (iPhone 5) C=Color (White)…

Python ReportLab use of splitfirst/splitlast

Im trying to use Python with ReportLab 2.2 to create a PDF report. According to the user guide,Special TableStyle Indeces [sic]In any style command the first row index may be set to one of the special …

Extract specific section from LaTeX file with python

I have a set of LaTeX files. I would like to extract the "abstract" section for each one: \begin{abstract}.....\end{abstract}I have tried the suggestion here: How to Parse LaTex fileAnd tried…

Installing LXML, facing a legacy-install-failure error

Trying to install lxml on Python 311. Faced with this error. PS C:\Users\chharlie\Desktop\code> pip install lxml Collecting lxmlUsing cached lxml-4.9.1.tar.gz (3.4 MB)Preparing metadata (setup.py) .…

PyInstaller wont install, Python 3.6.0a4 and x64 Windows

I have said Python version (from https://www.python.org/downloads/windows/), and x64 Windows 10. Every time I try to execute "pip install pyinstaller" it crashes with an error:C:\WINDOWS\syst…

matplotlib figures disappearing between show() and savefig()

Ive kept a set of references to figures in a dictionary so that I could save them later if desired. I am troubled that the saved figures are blank if invoke a show() command and look at them first. S…

Regular expression that never finishes running

I wrote a small, naive regular expression that was supposed to find text inside parentheses:re.search(r\((.|\s)*\), name)I know this is not the best way to do it for a few reasons, but it was working j…

fatal error: Python.h: No such file or directory, python-Levenshtein install

Firstly, Im working on an Amazon EC2 instance, Amazon linux version 2 AMI using Python 3.7.Im trying to install the python-Levenshtein package using the command:pip3 install python-Levenshtein --useran…

How to install data_files to absolute path?

I use pip with setuptools to install a package. I want pip to copy some resource files to, say, /etc/my_package. My setup.py looks like this: setup(...data_files=[(/etc/my_package, [config.yml])] )Whe…