上一节 亲测:windows使用OpenSSL生成证书(使用者备用名称(DNS))已经使用OpenSSL生成了证书,现在就开始使用这些证书了。
使用分为两步:服务端使用和客户端使用
1、服务端使用
由于tornado支持使用SSL证书,所有直接使用一下代码测试就可以啦!
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os.path
from tornado import httpserver
from tornado import ioloop
from tornado import web
class TestHandler(web.RequestHandler):
def get(self):
self.write("Hello, World!")
def main():
settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static"),
}
application = web.Application([
(r"/", TestHandler),
], **settings)
server = httpserver.HTTPServer(application, ssl_options={
"certfile": os.path.join(os.path.abspath("."), "server.crt"),
"keyfile": os.path.join(os.path.abspath("."), "server.key"),
})
server.listen(8000)
ioloop.IOLoop.instance().start()
if __name_