我有一个Python(3.6)Tornado(4.5.2)服务器的简单示例,我正在尝试添加ssl证书以进行测试。我已经确定它正在找到密钥和csr文件。以下是我的代码在详细说明错误后使用堆栈跟踪的样子。有没有人碰到这个或解决了它?
import tornado.httpserver
import tornado.ioloop
import tornado.web
class indexHandler(tornado.web.RequestHandler):
def get(self):
self.write("hello")
application = tornado.web.Application([
(r'/', indexHandler),
])
if __name__ == '__main__':
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
"certfile": "cert/ig.csr",
"keyfile": "cert/ig.key",
})
http_server.listen(443)
tornado.ioloop.IOLoop.instance().start()
在Python 3.6.4上运行并且服务器运行但是当页面作为https://localhost访问时,它会抛出以下异常。我错过了什么?
ERROR:asyncio:Exception in callback BaseAsyncIOLoop._handle_events(5, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(5, 1)>
Traceback (most recent call last):
File "/<python path>/asyncio/events.py", line 145, in _run
self._callback(*self._args)
File "/<python path>/site-packages/tornado/platform/asyncio.py", line 102, in _handle_events
handler_func(fileobj, events)
File "/<python path>/site-packages/tornado/stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "/<python path>/site-packages/tornado/netutil.py", line 252, in accept_handler
callback(connection, address)
File "/<python path>/site-packages/tornado/tcpserver.py", line 264, in _handle_connection
do_handshake_on_connect=False)
File "/<python path>/site-packages/tornado/netutil.py", line 551, in ssl_wrap_socket
context = ssl_options_to_context(ssl_options)
File "/<python path>/site-packages/tornado/netutil.py", line 526, in ssl_options_to_context
context.load_cert_chain(ssl_options['certfile'], ssl_options.get('keyfile', None))
ssl.SSLError: [SSL] PEM lib (_ssl.c:3337)
在上面的错误消息中,/<python path>/
等于:
"/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/"
答案 0 :(得分:1)
这是因为您的证书签名和密钥不匹配。
答案 1 :(得分:0)
课程:首先验证密钥和证书!