如何在没有 (L)GPL 库的情况下在 Python 中创建双重身份验证 HTTPS 客户端?
客户端和服务器都是内部的,各自都有一个由内部CA签名的证书和CA证书。我需要客户端根据服务器拥有的 CA 证书来验证服务器的证书。它还应该将其证书发送到服务器进行身份验证。
urllib2手册说不执行服务器身份验证。 PycURL 是一个自然的替代方案,但其许可证尚未获得批准。我还希望不必从源代码编译库,而是使用 RPM。
我浏览了很多库,例如 requests、httplib2,但没有看到我需要什么。还有 ssl 模块,但如果不是绝对必须的话,我不想自己实现 http。
RHEL 5.7 上的 Python 2.6
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,获胜者(几乎)是 httplib2 v0.7。从该版本开始支持SSL证书认证。这是示例代码,
请注意
domain=''
参数,否则它对我不起作用。附言。不幸的是,这个简单的解决方案对我不起作用,因为我忘记提及额外的要求 - 为 RHEL 5.7 和 RPM 安装 RPM。 Python 2.6。
well, the winner (almost) is httplib2 v0.7. Starting from this version it supports SSL certificate authentication. Here's the sample code
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.
Twisted Python 是一个可以满足您需要的库,尽管我不确定 MIT 许可证是否适合您想。 GPL 是一个非常具体的许可证,希望您不是指“所有开源许可证”。
有关 SSL 示例,请参阅 http://twistedmatrix.com/documents/current/core/ howto/ssl.html。根据您的描述,该页面上的最后几个示例特别相关。 Twisted 使用 PyOpenSSL (docs),它已获得 Apache 许可证的许可。您也可以考虑直接使用 PyOpenSSL。
Twisted Python is a library that may do what you need although I'm not sure if the MIT license fits what you want. GPL is a pretty specific license and hopefully you didn't mean "all open source licenses."
For SSL examples, see http://twistedmatrix.com/documents/current/core/howto/ssl.html. The last couple examples on that page are particularly relevant based on your description. Twisted uses PyOpenSSL (docs) which is licensed with the Apache license. You might consider using PyOpenSSL directly as well.
更新:如果 requests 之前不支持客户端证书,现在支持,前提是本地证书的私钥(如果有)是未加密:
Update: If requests didn't support client-side certificates before, it supports it now, provided the local cert's private key (if any) is unencrypted: