如何使用Python使用Windows证书管理器中存储的证书

时间:2020-03-03 16:52:19

标签: python python-3.x windows ssl

  1. 我的python应用程序在http://0.0.0.0:80/上本地运行
  2. 后来,为了建立SSL连接,我生成了MyCert.crt和Mycert.key文件。
  3. 稍后,提供证书和密钥文件的位置。我的应用程序运行完美,并按预期开始通过https连接运行。

    代码段: 从OpenSSL导入SSL

    context =(“ C:/myCert.crt”,“ C:/Mycert.key”) app.run(host =“ 0.0.0.0”,port ='80',ssl_context = context)

  4. 现在,我将同一证书导入到:Windows证书管理器->受信任的根证书颁发机构。它显示证书名称为 localhost

  5. 现在,我的目标是访问同一python应用程序的证书,并从Windows证书管理器开始使用它。 我提到了几个库(请求,wincertstore),但是由于我是这个领域的新手,所以我无法理解它们。

如何修改我的python代码以访问此证书。

1 个答案:

答案 0 :(得分:0)

您首先需要更改端口,443会很棒(据我们所知,https超过443) 并用这一行替换您的行:

app.run(host='0.0.0.0', port=443, debug=True, ssl_context=('/home/ubuntu/cert/myCert.pem', '/home/ubuntu/cert/myCert2.pem'))

阅读本文,它将对您有所帮助: https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https