运行python HTTPServer时,出现无效证书警告。

问题描述 投票:0回答:1

我正在尝试运行python3 HTTPServer 与自签证书。 我创建的自签名证书。

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

然后我使用python的 SimpleHTTPRequestHandler:

#!/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 ..

enter image description here

点击红色 Not Secure 我们得到更多的信息。

enter image description here

让我们来看看 "证书无效 "的细节。

enter image description here

enter image description here

我哪一步做错了?

python https openssl
1个回答
1
投票

当我在Google中搜索这个时,我发现 self signed certificates 不可信。你必须在网络浏览器中接受一个异常才能使用它。

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

所有这些都是出于安全考虑。如果你能如此轻易地创建一个可信的证书,那么黑客就会使用它。


另外:我在Gooogle上找到的一个链接。

如何在5分钟内让HTTPS在你的本地开发环境中工作。

© www.soinside.com 2019 - 2024. All rights reserved.