本文整理汇总了Python中ssl.PROTOCOL_SSLv2方法的典型用法代码示例。如果您正苦于以下问题:Python ssl.PROTOCOL_SSLv2方法的具体用法?Python ssl.PROTOCOL_SSLv2怎么用?Python ssl.PROTOCOL_SSLv2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ssl
的用法示例。
在下文中一共展示了ssl.PROTOCOL_SSLv2方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _connect
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def _connect(self, host, port, timeout, isssl=False):
conn = None
try:
if isssl and not _SUPPORT_SSL:
raise 'Not SUPPORT SSL'
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect((host, port))
if isssl:
try:
conn = ssl.wrap_socket(conn, ssl_version=ssl.PROTOCOL_SSLv23)
except ssl.SSLError as _:
conn.close()
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect((host, port))
conn = ssl.wrap_socket(conn, ssl_version=ssl.PROTOCOL_SSLv2)
conn.settimeout(timeout)
except Exception as e:
raise CurlError(Curl.CURLE_COULDNT_CONNECT)
return conn
示例2: convert_version2method
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def convert_version2method(protocol_version):
"""
Convert internal protocol version ID to Python SSL method.
:param Integer protocol_version: Version ID
:return: OpenSSL method or None if not found
:rtype: OpenSSL method or None
"""
if protocol_version == flextls.registry.version.SSLv2:
return ssl.PROTOCOL_SSLv2
if protocol_version == flextls.registry.version.SSLv3:
return ssl.PROTOCOL_SSLv3
if protocol_version == flextls.registry.version.TLSv10:
return ssl.PROTOCOL_TLSv1
if protocol_version == flextls.registry.version.TLSv11:
return ssl.PROTOCOL_TLSv1_1
if protocol_version == flextls.registry.version.TLSv12:
return ssl.PROTOCOL_TLSv1_2
return None
示例3: test_sslv2_fail
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def test_sslv2_fail(self):
# This is really more of a client test, but run it here since
# we've got all the other ssl version tests here.
# Clients should have SSLv2 disabled by default.
try:
# The server simply closes the connection when it gets
# an SSLv2 ClientHello packet.
# request_timeout is needed here because on some platforms
# (cygwin, but not native windows python), the close is not
# detected promptly.
response = self.fetch('/', request_timeout=1)
except ssl.SSLError:
# In some python/ssl builds the PROTOCOL_SSLv2 constant
# exists but SSLv2 support is still compiled out, which
# would result in an SSLError here (details vary depending
# on python version). The important thing is that
# SSLv2 request's don't succeed, so we can just ignore
# the errors here.
return
self.assertEqual(response.code, 599)
示例4: _connect
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def _connect(self, host, port, timeout, isssl = False):
conn = None
try:
if isssl and not _SUPPORT_SSL:
raise 'Not SUPPORT SSL'
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect((host, port))
if isssl:
try:
conn = ssl.wrap_socket(conn, ssl_version=ssl.PROTOCOL_SSLv23)
except ssl.SSLError as _:
conn.close()
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect((host, port))
conn = ssl.wrap_socket(conn, ssl_version=ssl.PROTOCOL_SSLv2)
conn.settimeout(timeout)
except Exception as e:
raise CurlError(Curl.CURLE_COULDNT_CONNECT)
return conn
示例5: try_protocol_combo
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def try_protocol_combo(self, server_protocol, client_protocol):
self._setup(ssl_protocol=server_protocol)
self.client.ssl_version = client_protocol
close_client(self.client)
self.client.connect(self.server.host, self.server.port)
try:
self.client.login()
except (ssl.SSLError, socket.error):
self.client.close()
else:
self.client.quit()
# def test_ssl_version(self):
# protos = [ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23,
# ssl.PROTOCOL_TLSv1]
# if hasattr(ssl, "PROTOCOL_SSLv2"):
# protos.append(ssl.PROTOCOL_SSLv2)
# for proto in protos:
# self.try_protocol_combo(ssl.PROTOCOL_SSLv2, proto)
# for proto in protos:
# self.try_protocol_combo(ssl.PROTOCOL_SSLv3, proto)
# for proto in protos:
# self.try_protocol_combo(ssl.PROTOCOL_SSLv23, proto)
# for proto in protos:
# self.try_protocol_combo(ssl.PROTOCOL_TLSv1, proto)
示例6: ssl_wrap_socket
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def ssl_wrap_socket(self):
# Allow sending of keep-alive messages - seems to prevent some servers
# from closing SSL, leading to deadlocks.
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
try:
import ssl
if self.ca_certs is not None:
cert_reqs = ssl.CERT_REQUIRED
else:
cert_reqs = ssl.CERT_NONE
if self.ssl_version == "tls1":
ssl_version = ssl.PROTOCOL_TLSv1
elif self.ssl_version == "ssl2":
ssl_version = ssl.PROTOCOL_SSLv2
elif self.ssl_version == "ssl3":
ssl_version = ssl.PROTOCOL_SSLv3
elif self.ssl_version == "ssl23" or self.ssl_version is None:
ssl_version = ssl.PROTOCOL_SSLv23
else:
raise socket.sslerror("Invalid SSL version requested: %s", self.ssl_version)
self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ca_certs=self.ca_certs, cert_reqs=cert_reqs, ssl_version=ssl_version)
ssl_exc = ssl.SSLError
self.read_fd = self.sock.fileno()
except ImportError:
# No ssl module, and socket.ssl has no fileno(), and does not allow certificate verification
raise socket.sslerror("imaplib2 SSL mode does not work without ssl module")
if self.cert_verify_cb is not None:
cert_err = self.cert_verify_cb(self.sock.getpeercert(), self.host)
if cert_err:
raise ssl_exc(cert_err)
示例7: test_ssl_version
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def test_ssl_version(self):
protos = [ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1]
if hasattr(ssl, "PROTOCOL_SSLv2"):
protos.append(ssl.PROTOCOL_SSLv2)
for proto in protos:
self.try_protocol_combo(ssl.PROTOCOL_SSLv2, proto)
for proto in protos:
self.try_protocol_combo(ssl.PROTOCOL_SSLv3, proto)
for proto in protos:
self.try_protocol_combo(ssl.PROTOCOL_SSLv23, proto)
for proto in protos:
self.try_protocol_combo(ssl.PROTOCOL_TLSv1, proto)
示例8: test_sslv2
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def test_sslv2(self):
self.client.ssl_version = ssl.PROTOCOL_SSLv2
self.client.close()
self.client.connect(self.server.host, self.server.port)
self.assertRaises(socket.error, self.client.login)
self.client.ssl_version = ssl.PROTOCOL_SSLv2
示例9: open_ssl_socket
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def open_ssl_socket(version=ssl.PROTOCOL_SSLv2):
pass
示例10: test_sslv2
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 别名]
def test_sslv2(self):
self.client.ssl_version = ssl.PROTOCOL_SSLv2
close_client(self.client)
if not OSX:
with self.server.lock:
self.client.connect(self.server.host, self.server.port)
self.assertRaises(socket.error, self.client.login)
else:
with self.server.lock:
with self.assertRaises(socket.error):
self.client.connect(self.server.host, self.server.port,
timeout=0.1)
self.client.ssl_version = ssl.PROTOCOL_SSLv2