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


Python ssl.HAS_SNI屬性代碼示例

本文整理匯總了Python中ssl.HAS_SNI屬性的典型用法代碼示例。如果您正苦於以下問題:Python ssl.HAS_SNI屬性的具體用法?Python ssl.HAS_SNI怎麽用?Python ssl.HAS_SNI使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在ssl的用法示例。


在下文中一共展示了ssl.HAS_SNI屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: connect

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def connect(self):
            "Connect to a host on a given (SSL) port."

            sock = socket_create_connection((self.host, self.port),
                                            self.timeout, self.source_address)

            if self._tunnel_host:
                self.sock = sock
                self._tunnel()

            server_hostname = self.host if ssl.HAS_SNI else None
            self.sock = self._context.wrap_socket(sock,
                                                  server_hostname=server_hostname)
            try:
                if self._check_hostname:
                    ssl.match_hostname(self.sock.getpeercert(), self.host)
            except Exception:
                self.sock.shutdown(socket.SHUT_RDWR)
                self.sock.close()
                raise 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:22,代碼來源:client.py

示例2: ssl_wrap_socket

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def ssl_wrap_socket(
    socket: socket.socket,
    ssl_options: Union[Dict[str, Any], ssl.SSLContext],
    server_hostname: str = None,
    **kwargs: Any
) -> ssl.SSLSocket:
    """Returns an ``ssl.SSLSocket`` wrapping the given socket.

    ``ssl_options`` may be either an `ssl.SSLContext` object or a
    dictionary (as accepted by `ssl_options_to_context`).  Additional
    keyword arguments are passed to ``wrap_socket`` (either the
    `~ssl.SSLContext` method or the `ssl` module function as
    appropriate).
    """
    context = ssl_options_to_context(ssl_options)
    if ssl.HAS_SNI:
        # In python 3.4, wrap_socket only accepts the server_hostname
        # argument if HAS_SNI is true.
        # TODO: add a unittest (python added server-side SNI support in 3.4)
        # In the meantime it can be manually tested with
        # python3 -m tornado.httpclient https://sni.velox.ch
        return context.wrap_socket(socket, server_hostname=server_hostname, **kwargs)
    else:
        return context.wrap_socket(socket, **kwargs) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:26,代碼來源:netutil.py

示例3: ssl_wrap_socket

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def ssl_wrap_socket(socket, ssl_options, server_hostname=None, **kwargs):
    """Returns an ``ssl.SSLSocket`` wrapping the given socket.

    ``ssl_options`` may be either an `ssl.SSLContext` object or a
    dictionary (as accepted by `ssl_options_to_context`).  Additional
    keyword arguments are passed to ``wrap_socket`` (either the
    `~ssl.SSLContext` method or the `ssl` module function as
    appropriate).
    """
    context = ssl_options_to_context(ssl_options)
    if ssl.HAS_SNI:
        # In python 3.4, wrap_socket only accepts the server_hostname
        # argument if HAS_SNI is true.
        # TODO: add a unittest (python added server-side SNI support in 3.4)
        # In the meantime it can be manually tested with
        # python3 -m tornado.httpclient https://sni.velox.ch
        return context.wrap_socket(socket, server_hostname=server_hostname,
                                   **kwargs)
    else:
        return context.wrap_socket(socket, **kwargs) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:22,代碼來源:netutil.py

示例4: connect

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def connect(self):
            "Connect to a host on a given (SSL) port."

            sock = socket.create_connection((self.host, self.port),
                                            self.timeout, self.source_address)

            if self._tunnel_host:
                self.sock = sock
                self._tunnel()

            server_hostname = self.host if ssl.HAS_SNI else None
            self.sock = self._context.wrap_socket(sock,
                                                  server_hostname=server_hostname)
            try:
                if self._check_hostname:
                    ssl.match_hostname(self.sock.getpeercert(), self.host)
            except Exception:
                self.sock.shutdown(socket.SHUT_RDWR)
                self.sock.close()
                raise 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:22,代碼來源:client.py

示例5: starttls

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def starttls(self):
        #TODO: check how to read the local computer name
        yield self.ehlo_or_helo_if_needed() 
        if not self.has_extn('starttls'): 
            raise smtplib.SMTPException('STARTTLS extension not supported ')

        code, msg = yield self.docmd(b'STARTTLS')
        if code == 220: 
            if not _have_ssl: 
                raise RuntimeError("No SSL support included in this Python ")

            server_hostname = self.host if ssl.HAS_SNI else None
            self.stream = yield self.stream.start_tls(False, server_hostname = server_hostname)
            self.helo_resp = None 
            self.ehlo_resp = None 
            self.esmtp_features = {}
            self.does_esmtp = 0 
        return (code, msg) 
開發者ID:vuamitom,項目名稱:tornado-smtpclient,代碼行數:20,代碼來源:client.py

示例6: connect

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def connect(self, url, **options):
        """
        Connect to url. url is websocket url scheme. ie. ws://host:port/resource
        You can customize using 'options'.
        If you set "header" dict object, you can set your own custom header.

        >>> ws = WebSocket()
        >>> ws.connect("ws://echo.websocket.org/",
                ...     header={"User-Agent: MyProgram",
                ...             "x-custom: header"})

        timeout: socket timeout time. This value is integer.
                 if you set None for this value,
                 it means "use default_timeout value"

        options: current support option is only "header".
                 if you set header as dict value,
                 the custom HTTP headers are added.

        """
        hostname, port, resource, is_secure = _parse_url(url)
        # TODO: we need to support proxy
        self.sock.connect((hostname, port))
        if is_secure:
            if HAVE_SSL:
                if self.sslopt is None:
                    sslopt = {}
                else:
                    sslopt = self.sslopt
                if ssl.HAS_SNI:
                    self.sock = _wrap_sni_socket(self.sock, sslopt, hostname)
                else:
                    self.sock = ssl.wrap_socket(self.sock, **sslopt)
            else:
                raise WebSocketException("SSL not available.")

        self._handshake(hostname, port, resource, **options) 
開發者ID:MediaBrowser,項目名稱:plugin.video.emby,代碼行數:39,代碼來源:websocket.py

示例7: test_https_sni

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def test_https_sni(self):
        if ssl is None:
            self.skipTest("ssl module required")
        if not ssl.HAS_SNI:
            self.skipTest("SNI support required in OpenSSL")
        sni_name = [None]
        def cb_sni(ssl_sock, server_name, initial_context):
            sni_name[0] = server_name
        context = ssl.SSLContext(ssl.PROTOCOL_TLS)
        context.set_servername_callback(cb_sni)
        handler = self.start_https_server(context=context, certfile=CERT_localhost)
        context = ssl.create_default_context(cafile=CERT_localhost)
        self.urlopen("https://localhost:%s" % handler.port, context=context)
        self.assertEqual(sni_name[0], "localhost") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_urllib2_localnet.py

示例8: test_https_sni

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def test_https_sni(self):
        if ssl is None:
            self.skipTest("ssl module required")
        if not ssl.HAS_SNI:
            self.skipTest("SNI support required in OpenSSL")
        sni_name = [None]
        def cb_sni(ssl_sock, server_name, initial_context):
            sni_name[0] = server_name
        context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        context.set_servername_callback(cb_sni)
        handler = self.start_https_server(context=context, certfile=CERT_localhost)
        context = ssl.create_default_context(cafile=CERT_localhost)
        self.urlopen("https://localhost:%s" % handler.port, context=context)
        self.assertEqual(sni_name[0], "localhost") 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:16,代碼來源:test_urllib2_localnet.py

示例9: test_https_sni

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def test_https_sni(self):
        if ssl is None:
            self.skipTest("ssl module required")
        if not ssl.HAS_SNI:
            self.skipTest("SNI support required in OpenSSL")
        sni_name = None
        def cb_sni(ssl_sock, server_name, initial_context):
            nonlocal sni_name
            sni_name = server_name
        context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        context.set_servername_callback(cb_sni)
        handler = self.start_https_server(context=context, certfile=CERT_localhost)
        context = ssl.create_default_context(cafile=CERT_localhost)
        self.urlopen("https://localhost:%s" % handler.port, context=context)
        self.assertEqual(sni_name, "localhost") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:17,代碼來源:test_urllib2_localnet.py

示例10: ssl_wrap_socket

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def ssl_wrap_socket(sock, keyfile=None, certfile=None,cert_reqs=None, ca_certs=None, server_hostname=None,ssl_version=None):
	context = SSLContext(ssl_version)
	context.verify_mode = cert_reqs
	if ca_certs:
		try:
			context.load_verify_locations(ca_certs)
		except Exception as e:
			raise SSLError(e)
	if certfile:
		context.load_cert_chain(certfile, keyfile)
	if HAS_SNI: # OpenSSL enabled SNI
		return context.wrap_socket(sock,server_hostname=server_hostname)
	
	return context.wrap_socket(sock) 
開發者ID:PacktPublishing,項目名稱:Learning-Python-Networking-Second-Edition,代碼行數:16,代碼來源:ssl_client.py

示例11: _create_socket

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def _create_socket(self):
        sock = super()._create_socket()
        server_hostname = self.host if ssl.HAS_SNI else None
        return self.ssl_context.wrap_socket(sock, server_hostname=server_hostname) 
開發者ID:ikvk,項目名稱:imap_tools,代碼行數:6,代碼來源:pysocks_proxy.py

示例12: context

# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import HAS_SNI [as 別名]
def context(self, context):
        """Set the ssl ``context`` to use."""
        self._context = context
        # Python 3.7+
        # if a context is provided via `cherrypy.config.update` then
        # `self.context` will be set after `__init__`
        # use a property to intercept it to add an SNI callback
        # but don't override the user's callback
        # TODO: chain callbacks
        with suppress(AttributeError):
            if ssl.HAS_SNI and context.sni_callback is None:
                context.sni_callback = _sni_callback 
開發者ID:cherrypy,項目名稱:cheroot,代碼行數:14,代碼來源:builtin.py


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