生成证书
客户端和服务端搭建
https
simple-https-server.py
# run as follows: python simple-https-server.py
# then in your browser, visit:
# https://localhost
import ssl
import http.server
serverAddress = ('0.0.0.0', 443)
httpd = http.server.HTTPServer(
serverAddress, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(
httpd.socket, certfile='server.cer', server_side=True, keyfile="server.prikey", cert_reqs=ssl.CERT_REQUIRED, ca_certs="ca.cer") #
httpd.serve_forever()
# cert_reqs=ssl.CERT_REQUIRED 去掉即可浏览器访问
simple-https-client.py
import ssl
import http.client
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
context.load_verify_locations('ca.cer')
context.load_cert_chain(certfile="client.cer", keyfile="client.prikey")
context.verify_mode = ssl.CERT_REQUIRED
context.check_hostname = True
conn = http.client.HTTPSConnection("localhost", context=context)
conn.request("GET", "/")
print(conn.getresponse().read().decode())
sslsocket
验证
文章来源:https://www.toymoban.com/news/detail-546781.html
ssl文档文章来源地址https://www.toymoban.com/news/detail-546781.html
到了这里,关于搭建ssl双向验证python的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!