【问题标题】:Invalid certificate warning when running the python HTTPServer运行 python HTTPServer 时出现无效证书警告
【发布时间】:2020-09-30 13:05:42
【问题描述】:

我正在尝试使用自签名证书运行 python3 HTTPServer。我创建了自签名证书:

openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 
 -keyout key.localhost.pem -out cert.localhost.pem

那我用的是pythonSimpleHTTPRequestHandler

#!/usr/bin/env python3 
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
import socketserver

import sys
port = int(sys.argv[1])
# httpd = HTTPServer(('localhost', port), BaseHTTPRequestHandler)
httpd = socketserver.TCPServer(('localhost', port), SimpleHTTPRequestHandler)

keyfile="/Users/steve/key.localhost.pem" ;certfile='/Users/steve/cert.localhost.pem'
httpd.socket = ssl.wrap_socket (httpd.socket, 
       keyfile="/Users/steve/localhost.key", certfile='/Users/steve/localhost.crt', server_side=True)

httpd.serve_forever()

让我们尝试从https://localhost:9443/tests 的网络服务器加载一些东西。

请注意,我们收到了 Not secure ..

点击红色Not Secure我们会得到更多信息:

让我们看看“证书无效”的详细信息:

我做错了哪些步骤?

【问题讨论】:

  • 当我在 Google 中搜索信息时,我看到 self signed certificates 不可信。您必须在网络浏览器中接受异常才能使用它。要创建受信任的证书,您必须生成 RootCA - 并使用它签署您的证书。但即使在这里,您也必须将 RootCA 作为受信任的证书添加到系统中。所有这一切都是出于安全原因 - 如果您可以如此轻松地创建 tursted 证书,那么黑客就会使用它。 freecodecamp.org/news/…
  • @furas 不错的链接:似乎有几个小的附加步骤可以正确执行此操作。随意回答

标签: python https openssl


【解决方案1】:

当我在 Google 中搜索此内容时,我发现 self signed certificates 不可信。
您必须在网络浏览器中接受例外才能使用它。

要创建受信任的证书,您必须生成一个 RootCA 并使用它来签署您的证书。但即使在这里,您也必须将RootCA 作为受信任的证书添加到系统中。

所有这些都是出于安全原因。如果您可以如此轻松地创建受信任的证书,那么黑客就会使用它。


顺便说一句:我在 Google 上找到的链接之一:

How to get HTTPS working on your local development environment in 5 minutes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 2022-11-11
    相关资源
    最近更新 更多