【发布时间】:2015-06-17 16:08:13
【问题描述】:
我在 Python 2.7.10 中使用 ssl.SSLContext 正确设置 SNI 标志时遇到问题,每次握手都失败,我不知道为什么。
这是我尝试的方法:
import ssl
import socket
if ssl.HAS_SNI:
print "SNI is available"
print(ssl.OPENSSL_VERSION)
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.load_cert_chain('cacrt.pem', 'cakey.pem', 'password')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock = context.wrap_socket(sock, server_hostname='virtServer')
sock.connect(('ip.to.the.server', 443))
http_client = tornado.httpclient.HTTPClient()
http_client.fetch('https://ip.to.the.server/some_url', method='GET', ssl_options=context)
这是我得到的输出:
SNI is available
OpenSSL 0.9.8zd 8 Jan 2015
Traceback (most recent call last):
File "test/steps/test.py", line 37, in <module>
sock.connect(('10.59.71.242', 443))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 844, in connect
self._real_connect(addr, False)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 835, in _real_connect
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 808, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)
我做错了什么导致此错误?如何更改我的代码来解决这个问题?
对此的任何想法/帮助将不胜感激。
谢谢, 问候, 亚罗
【问题讨论】:
标签: python python-2.7 ssl tornado sni