當前位置: 首頁>>代碼示例>>Python>>正文


Python ssl.PROTOCOL_SSLv2方法代碼示例

本文整理匯總了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 
開發者ID:w-digital-scanner,項目名稱:w9scan,代碼行數:23,代碼來源:miniCurl.py

示例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 
開發者ID:DinoTools,項目名稱:pysslscan,代碼行數:22,代碼來源:int_ssl.py

示例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) 
開發者ID:omererdem,項目名稱:honeything,代碼行數:22,代碼來源:httpserver_test.py

示例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 
開發者ID:nanshihui,項目名稱:PocCollect,代碼行數:23,代碼來源:miniCurl.py

示例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) 
開發者ID:giampaolo,項目名稱:pyftpdlib,代碼行數:27,代碼來源:test_functional_ssl.py

示例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) 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:37,代碼來源:imaplib2.py

示例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) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:14,代碼來源:test_functional_ssl.py

示例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 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:8,代碼來源:test_functional_ssl.py

示例9: open_ssl_socket

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import PROTOCOL_SSLv2 [as 別名]
def open_ssl_socket(version=ssl.PROTOCOL_SSLv2):
    pass 
開發者ID:PyCQA,項目名稱:bandit,代碼行數:4,代碼來源:ssl-insecure-version.py

示例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 
開發者ID:giampaolo,項目名稱:pyftpdlib,代碼行數:15,代碼來源:test_functional_ssl.py


注:本文中的ssl.PROTOCOL_SSLv2方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。