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


Python ssl.optionsForClientTLS方法代碼示例

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


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

示例1: integrationTest

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def integrationTest(self, hostName, expectedAddress, addressType):
        """
        Wrap L{AgentTestsMixin.integrationTest} with TLS.
        """
        authority, server = certificatesForAuthorityAndServer(hostName
                                                              .decode('ascii'))
        def tlsify(serverFactory):
            return TLSMemoryBIOFactory(server.options(), False, serverFactory)
        def tlsagent(reactor):
            from twisted.web.iweb import IPolicyForHTTPS
            from zope.interface import implementer
            @implementer(IPolicyForHTTPS)
            class Policy(object):
                def creatorForNetloc(self, hostname, port):
                    return optionsForClientTLS(hostname.decode("ascii"),
                                               trustRoot=authority)
            return client.Agent(reactor, contextFactory=Policy())
        (super(AgentHTTPSTests, self)
         .integrationTest(hostName, expectedAddress, addressType,
                          serverWrapper=tlsify,
                          createAgent=tlsagent,
                          scheme=b'https')) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:24,代碼來源:test_agent.py

示例2: integrationTest

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def integrationTest(self, hostName, expectedAddress, addressType):
        """
        Wrap L{AgentTestsMixin.integrationTest} with TLS.
        """
        certHostName = hostName.strip(b'[]')
        authority, server = certificatesForAuthorityAndServer(certHostName
                                                              .decode('ascii'))
        def tlsify(serverFactory):
            return TLSMemoryBIOFactory(server.options(), False, serverFactory)
        def tlsagent(reactor):
            from twisted.web.iweb import IPolicyForHTTPS
            from zope.interface import implementer
            @implementer(IPolicyForHTTPS)
            class Policy(object):
                def creatorForNetloc(self, hostname, port):
                    return optionsForClientTLS(hostname.decode("ascii"),
                                               trustRoot=authority)
            return client.Agent(reactor, contextFactory=Policy())
        (super(AgentHTTPSTests, self)
         .integrationTest(hostName, expectedAddress, addressType,
                          serverWrapper=tlsify,
                          createAgent=tlsagent,
                          scheme=b'https')) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:25,代碼來源:test_agent.py

示例3: test_extraKeywords

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_extraKeywords(self):
        """
        When passed a keyword parameter other than C{extraCertificateOptions},
        L{sslverify.optionsForClientTLS} raises an exception just like a
        normal Python function would.
        """
        error = self.assertRaises(
            TypeError,
            sslverify.optionsForClientTLS,
            hostname=u'alpha', someRandomThing=u'beta',
        )
        self.assertEqual(
            str(error),
            "optionsForClientTLS() got an unexpected keyword argument "
            "'someRandomThing'"
        ) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:18,代碼來源:test_sslverify.py

示例4: test_butIfTheyDidItWouldWork

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_butIfTheyDidItWouldWork(self):
        """
        L{ssl.optionsForClientTLS} should be using L{ssl.platformTrust} by
        default, so if we fake that out then it should trust ourselves again.
        """
        cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup(
            u"valid.example.com",
            u"valid.example.com",
            useDefaultTrust=True,
            fakePlatformTrust=True,
        )
        self.assertEqual(cWrapped.data,
                         b'greetings!')

        cErr = cWrapped.lostReason
        sErr = sWrapped.lostReason
        self.assertIsNone(cErr)
        self.assertIsNone(sErr) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:20,代碼來源:test_sslverify.py

示例5: test_clientPresentsCertificate

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_clientPresentsCertificate(self):
        """
        When the server verifies and the client presents a valid certificate
        for that verification by passing it to
        L{sslverify.optionsForClientTLS}, communication proceeds.
        """
        cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup(
            u"valid.example.com",
            u"valid.example.com",
            validCertificate=True,
            serverVerifies=True,
            clientPresentsCertificate=True,
        )

        self.assertEqual(cWrapped.data,
                         b'greetings!')

        cErr = cWrapped.lostReason
        sErr = sWrapped.lostReason
        self.assertIsNone(cErr)
        self.assertIsNone(sErr) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:23,代碼來源:test_sslverify.py

示例6: test_clientPresentsBadCertificate

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_clientPresentsBadCertificate(self):
        """
        When the server verifies and the client presents an invalid certificate
        for that verification by passing it to
        L{sslverify.optionsForClientTLS}, the connection cannot be established
        with an SSL error.
        """
        cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup(
            u"valid.example.com",
            u"valid.example.com",
            validCertificate=True,
            serverVerifies=True,
            validClientCertificate=False,
            clientPresentsCertificate=True,
        )

        self.assertEqual(cWrapped.data,
                         b'')

        cErr = cWrapped.lostReason.value
        sErr = sWrapped.lostReason.value

        self.assertIsInstance(cErr, SSL.Error)
        self.assertIsInstance(sErr, SSL.Error) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:26,代碼來源:test_sslverify.py

示例7: test_trustRootSelfSignedServerCertificate

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_trustRootSelfSignedServerCertificate(self):
        """
        L{trustRootFromCertificates} called with a single self-signed
        certificate will cause L{optionsForClientTLS} to accept client
        connections to a server with that certificate.
        """
        key, cert = makeCertificate(O=b"Server Test Certificate", CN=b"server")
        selfSigned = sslverify.PrivateCertificate.fromCertificateAndKeyPair(
            sslverify.Certificate(cert),
            sslverify.KeyPair(key),
        )

        trust = sslverify.trustRootFromCertificates([selfSigned])

        # Since we trust this exact certificate, connections to this server
        # should succeed.
        sProto, cProto, sWrap, cWrap, pump = loopbackTLSConnectionInMemory(
            trustRoot=trust,
            privateKey=selfSigned.privateKey.original,
            serverCertificate=selfSigned.original,
        )
        self.assertEqual(cWrap.data, b'greetings!')
        self.assertIsNone(cWrap.lostReason) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:25,代碼來源:test_sslverify.py

示例8: test_trustRootCertificateAuthorityTrustsConnection

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_trustRootCertificateAuthorityTrustsConnection(self):
        """
        L{trustRootFromCertificates} called with certificate A will cause
        L{optionsForClientTLS} to accept client connections to a server with
        certificate B where B is signed by A.
        """
        caCert, serverCert = certificatesForAuthorityAndServer()

        trust = sslverify.trustRootFromCertificates([caCert])

        # Since we've listed the CA's certificate as a trusted cert, a
        # connection to the server certificate it signed should succeed.
        sProto, cProto, sWrap, cWrap, pump = loopbackTLSConnectionInMemory(
            trustRoot=trust,
            privateKey=serverCert.privateKey.original,
            serverCertificate=serverCert.original,
        )
        self.assertEqual(cWrap.data, b'greetings!')
        self.assertIsNone(cWrap.lostReason) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:21,代碼來源:test_sslverify.py

示例9: add_connection

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def add_connection(self, id_, url):
        """
        Convenience function to connect and store the resulting
        connector.
        """
        if not url.startswith("wss://"):
            raise ValueError("expected wss:// URL prefix")

        hostname = url[6:]

        factory = self.factories[id_]
        options = ssl.optionsForClientTLS(hostname=hostname) # for TLS SNI
        self._conns[id_] = connectWS(factory, options) 
開發者ID:krakenfx,項目名稱:kraken-wsclient-py,代碼行數:15,代碼來源:kraken_wsclient_py.py

示例10: creatorForNetloc

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def creatorForNetloc(self, hostname, port):
        return optionsForClientTLS(
            u"control-service",
            trustRoot=self.ca_certificate,
            clientCertificate=self.client_credential.private_certificate()) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:7,代碼來源:_validation.py

示例11: __init__

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def __init__(self, xs, required=True, configurationForTLS=None):
        """
        @param configurationForTLS: An object which creates appropriately
            configured TLS connections. This is passed to C{startTLS} on the
            transport and is preferably created using
            L{twisted.internet.ssl.optionsForClientTLS}.  If C{None}, the
            default is to verify the server certificate against the trust roots
            as provided by the platform. See
            L{twisted.internet._sslverify.platformTrust}.
        @type configurationForTLS: L{IOpenSSLClientConnectionCreator} or
            C{None}
        """
        super(TLSInitiatingInitializer, self).__init__(
                xs, required=required)
        self._configurationForTLS = configurationForTLS 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:17,代碼來源:xmlstream.py

示例12: onProceed

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def onProceed(self, obj):
        """
        Proceed with TLS negotiation and reset the XML stream.
        """

        self.xmlstream.removeObserver('/failure', self.onFailure)
        if self._configurationForTLS:
            ctx = self._configurationForTLS
        else:
            ctx = ssl.optionsForClientTLS(self.xmlstream.otherEntity.host)
        self.xmlstream.transport.startTLS(ctx)
        self.xmlstream.reset()
        self.xmlstream.sendHeader()
        self._deferred.callback(Reset) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:16,代碼來源:xmlstream.py

示例13: test_bytesFailFast

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_bytesFailFast(self):
        """
        If you pass L{bytes} as the hostname to
        L{sslverify.optionsForClientTLS} it immediately raises a L{TypeError}.
        """
        error = self.assertRaises(
            TypeError,
            sslverify.optionsForClientTLS, b'not-actually-a-hostname.com'
        )
        expectedText = (
            "optionsForClientTLS requires text for host names, not " +
            bytes.__name__
        )
        self.assertEqual(str(error), expectedText) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:16,代碼來源:test_sslverify.py

示例14: test_IPv4AddressHostname

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_IPv4AddressHostname(self):
        """
        If you pass an IPv4 address to L{sslverify.optionsForClientTLS}
        L{_hostnameIsDnsName} will be False
        """
        options = sslverify.optionsForClientTLS(u'127.0.0.1')
        self.assertFalse(options._hostnameIsDnsName) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:9,代碼來源:test_sslverify.py

示例15: test_IPv6AddressHostname

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import optionsForClientTLS [as 別名]
def test_IPv6AddressHostname(self):
        """
        If you pass an IPv6 address to L{sslverify.optionsForClientTLS}
        L{_hostnameIsDnsName} will be False
        """
        options = sslverify.optionsForClientTLS(u'::1')
        self.assertFalse(options._hostnameIsDnsName) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:9,代碼來源:test_sslverify.py


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