在python中将服务器证书添加到CA_BUNDLE [英] Adding server certificates to CA_BUNDLE in python

查看:1075
本文介绍了在python中将服务器证书添加到CA_BUNDLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用请求通过https与远程服务器通信。目前我还没有验证SSL证书,我想解决这个问题。

I'm using requests to communicate with remote server over https. At the moment I'm not verifying SSL certificate and I'd like to fix that.

在请求文档中,我发现:

Within requests documentation, I've found that:


您可以通过证书
可信CA来验证路径到CA_BUNDLE文件。此可信CA的列表也可以通过
指定REQUESTS_CA_BUNDLE环境变量。

You can pass verify the path to a CA_BUNDLE file with certificates of trusted CAs. This list of trusted CAs can also be specified through the REQUESTS_CA_BUNDLE environment variable.

我不想使用系统的证书,但要生成我自己的商店。

I don't want to use system's certs, but to generate my own store.

到目前为止,我正在使用ssl.get_server_certificate(addr)获取服务器证书,但我不知道如何创建我的自己的商店并将其添加到那里。

So far I'm grabbing server certificate with ssl.get_server_certificate(addr), but I don't know how to create my own store and add it there.

推荐答案

这实际上是微不足道的...... CA_BUNDLE可以是您附加证书的任何文件,所以你只需将ssl.get_server_certificate()的输出附加到该文件即可。

This is actually trivial... CA_BUNDLE can be any file that you append certificates to, so you can simply append the output of ssl.get_server_certificate() to that file and it works.

这篇关于在python中将服务器证书添加到CA_BUNDLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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