【发布时间】:2014-03-13 18:26:07
【问题描述】:
我正在尝试使用 Python 来测试 Web 服务器。我几乎没有使用 Python 的经验,但鼓励使用它,因为它易于学习且易于使用(其他人的意见,目前不是我的意见)。我使用的脚本是:
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2 = ssl.wrap_socket(s1,
ca_certs="./pki/signing-dss-cert.pem",
cert_reqs=ssl.CERT_REQUIRED,
ssl_version=ssl.PROTOCOL_TLSv1,
server_hostname="localhost")
s2.connect( ("localhost", 8443) )
s2.send("GET / ")
time.sleep(1)
s2.send("HTTP/1.1")
错误是:
Traceback (most recent call last):
File "./fetch.sh", line 10, in <module>
server_hostname="localhost")
TypeError: wrap_socket() got an unexpected keyword argument 'server_hostname'
我也尝试过使用servername、name、hostname 和sni,但没有任何乐趣。
Python 文档没有提到 SNI(TLS/SSL wrapper for socket objects 和 SSL wiki page)。但我知道 SNI 和 server_hostname 的补丁是 4 年前在 2010 年合并的(Add a *server_hostname* argument to SSLContext.wrap_socket,changeset 65593:846c0e1342d0)。
我需要访问的等效 OpenSSL 调用是 SSL_set_tlsext_host_name。
如何指定 SNI 主机名? (最终,我需要将其设置为任意名称,因为我正在测试代理)。
【问题讨论】:
-
尝试将我的代码与您的代码合并,并在创建连接时尝试使用服务器名而不是
"localhost"。 -
您使用的是哪个版本的 Python?
-
sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)。 Debian 7.3 (x64),完全修补。