如何在Python中创建一个双认证HTTPS客户端,而不(L)GPL库? [英] How to create a dual-authentication HTTPS client in Python without (L)GPL libs?

查看:164
本文介绍了如何在Python中创建一个双认证HTTPS客户端,而不(L)GPL库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端和服务器是内部的,每个具有由内部CA和CA证书签署的证书。我需要在客户端与服务器的反对它有CA证书验证证书。还应其证书发送到服务器进行身份验证。

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.

的urllib2 的说明书说,不进行服务器身份验证。的 PycURL 的是一种自然的选择,但其许可证尚未获批。我也$不必从源头code编译库,而是改用RPM p $ PFER。

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.

我走过去喜欢的请求一堆库的httplib2 的并没有看到我需要什么。此外还有的 SSL 的模块,但我不觉得自己实现HTTP自己,如果我不绝对必须。

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.

在RHEL 5.7的Python 2.6

Python 2.6 on RHEL 5.7

推荐答案

很好,获胜者(几乎)是的 httplib2的 V0.7。从这个版本开始支持SSL证书认证。这里的样本code

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。可惜这种简单的方案不为我工作,我忘了提额外要求 - 具有RHEL 5.7和放大器RPM安装; Python 2.6中。

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.

这篇关于如何在Python中创建一个双认证HTTPS客户端,而不(L)GPL库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆