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


Python ssl.DefaultOpenSSLContextFactory方法代碼示例

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


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

示例1: get_ssl_context

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def get_ssl_context():
    """Construct an SSL context factory from the user's privatekey/cert.
    TODO: document set up for server operators.
    """
    pkcdata = {}
    for x, y in zip(["ssl_private_key_location", "ssl_certificate_location"],
                    ["key.pem", "cert.pem"]):
        if cs_single().config.get("SERVER", x) == "0":
            sslpath = os.path.join(cs_single().homedir, "ssl")
            if not os.path.exists(sslpath):
                print("No ssl configuration in home directory, please read "
                      "installation instructions and try again.")
                sys.exit(0)
            pkcdata[x] = os.path.join(sslpath, y)
        else:
            pkcdata[x] = cs_single().config.get("SERVER", x)
    return ssl.DefaultOpenSSLContextFactory(pkcdata["ssl_private_key_location"],
                                            pkcdata["ssl_certificate_location"]) 
開發者ID:AdamISZ,項目名稱:CoinSwapCS,代碼行數:20,代碼來源:coinswap_run.py

示例2: setUp

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def setUp(self):
        plainRoot = Data(b'not me', 'text/plain')
        tlsRoot = Data(b'me neither', 'text/plain')

        plainSite = server.Site(plainRoot, timeout=None)
        tlsSite = server.Site(tlsRoot, timeout=None)

        self.tlsPort = reactor.listenSSL(
            0, tlsSite,
            contextFactory=ssl.DefaultOpenSSLContextFactory(
                serverPEMPath, serverPEMPath),
            interface="127.0.0.1")
        self.plainPort = reactor.listenTCP(0, plainSite, interface="127.0.0.1")

        self.plainPortno = self.plainPort.getHost().port
        self.tlsPortno = self.tlsPort.getHost().port

        plainRoot.putChild(b'one', Redirect(self.getHTTPS('two')))
        tlsRoot.putChild(b'two', Redirect(self.getHTTP('three')))
        plainRoot.putChild(b'three', Redirect(self.getHTTPS('four')))
        tlsRoot.putChild(b'four', Data(b'FOUND IT!', 'text/plain')) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:23,代碼來源:test_webclient.py

示例3: test_openSSLBuffering

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def test_openSSLBuffering(self):
        serverProto = self.serverProto = SingleLineServerProtocol()
        clientProto = self.clientProto = RecordingClientProtocol()

        server = protocol.ServerFactory()
        client = self.client = protocol.ClientFactory()

        server.protocol = lambda: serverProto
        client.protocol = lambda: clientProto

        sCTX = ssl.DefaultOpenSSLContextFactory(certPath, certPath)
        cCTX = ssl.ClientContextFactory()

        port = reactor.listenSSL(0, server, sCTX, interface='127.0.0.1')
        self.addCleanup(port.stopListening)

        clientConnector = reactor.connectSSL('127.0.0.1', port.getHost().port,
                                             client, cCTX)
        self.addCleanup(clientConnector.disconnect)

        return clientProto.deferred.addCallback(
            self.assertEqual, b"+OK <some crap>\r\n") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:24,代碼來源:test_ssl.py

示例4: setUp

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def setUp(self):
        plainRoot = static.Data('not me', 'text/plain')
        tlsRoot = static.Data('me neither', 'text/plain')

        plainSite = server.Site(plainRoot, timeout=None)
        tlsSite = server.Site(tlsRoot, timeout=None)

        from twisted import test
        self.tlsPort = reactor.listenSSL(0, tlsSite,
                                         contextFactory=ssl.DefaultOpenSSLContextFactory(
            FilePath(test.__file__).sibling('server.pem').path,
            FilePath(test.__file__).sibling('server.pem').path,
            ),
                                         interface="127.0.0.1")
        self.plainPort = reactor.listenTCP(0, plainSite, interface="127.0.0.1")

        self.plainPortno = self.plainPort.getHost().port
        self.tlsPortno = self.tlsPort.getHost().port

        plainRoot.putChild('one', util.Redirect(self.getHTTPS('two')))
        tlsRoot.putChild('two', util.Redirect(self.getHTTP('three')))
        plainRoot.putChild('three', util.Redirect(self.getHTTPS('four')))
        tlsRoot.putChild('four', static.Data('FOUND IT!', 'text/plain')) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:25,代碼來源:test_webclient.py

示例5: test_openSSLBuffering

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def test_openSSLBuffering(self):
        serverProto = self.serverProto = SingleLineServerProtocol()
        clientProto = self.clientProto = RecordingClientProtocol()

        server = protocol.ServerFactory()
        client = self.client = protocol.ClientFactory()

        server.protocol = lambda: serverProto
        client.protocol = lambda: clientProto

        sCTX = ssl.DefaultOpenSSLContextFactory(certPath, certPath)
        cCTX = ssl.ClientContextFactory()

        port = reactor.listenSSL(0, server, sCTX, interface='127.0.0.1')
        self.addCleanup(port.stopListening)

        reactor.connectSSL('127.0.0.1', port.getHost().port, client, cCTX)

        return clientProto.deferred.addCallback(
            self.assertEquals, "+OK <some crap>\r\n") 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:22,代碼來源:test_ssl.py

示例6: callRemote

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def callRemote(self, method, *args):
        factory = AuthQueryFactory(self.path, self.host, method,
                                   self.user, self.password, *args)
        #factory = xmlrpc.QueryFactory(self.path, self.host, method,
        #                           self.user, self.password, *args)
        if self.secure:
            from twisted.internet import ssl
            #print "Connecting using ssl to host", self.host, "port", (self.port or 443)
            reactor.connectSSL(self.host, self.port or 443, factory, 
                               AuthContextFactory(self.certificate_file_name,
                                                  self.private_key_file_name))
            #reactor.connectSSL(self.host, self.port or 443, factory, 
            #    ssl.DefaultOpenSSLContextFactory("", self.certificate_file_name))

        else:
            reactor.connectTCP(self.host, self.port or 80, factory)
        return factory.deferred 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:19,代碼來源:auth_xmlrpc.py

示例7: setUp

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def setUp(self):
        plainRoot = static.Data('not me', 'text/plain')
        tlsRoot = static.Data('me neither', 'text/plain')

        plainSite = server.Site(plainRoot, timeout=None)
        tlsSite = server.Site(tlsRoot, timeout=None)

        from twisted import test
        self.tlsPort = reactor.listenSSL(0, tlsSite,
                                         contextFactory=ssl.DefaultOpenSSLContextFactory(
            sibpath(test.__file__, 'server.pem'),
            sibpath(test.__file__, 'server.pem'),
            ),
                                         interface="127.0.0.1")
        self.plainPort = reactor.listenTCP(0, plainSite, interface="127.0.0.1")

        self.plainPortno = self.plainPort.getHost().port
        self.tlsPortno = self.tlsPort.getHost().port

        plainRoot.putChild('one', util.Redirect(self.getHTTPS('two')))
        tlsRoot.putChild('two', util.Redirect(self.getHTTP('three')))
        plainRoot.putChild('three', util.Redirect(self.getHTTPS('four')))
        tlsRoot.putChild('four', static.Data('FOUND IT!', 'text/plain')) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:25,代碼來源:test_webclient.py

示例8: setUp

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def setUp(self):
        test_tcp.PortCleanerUpper.setUp(self)
        self.serverConns = []
        f = protocol.ServerFactory()
        f.protocol = protocol.Protocol
        self.listener = reactor.listenSSL(
            0, f, ssl.DefaultOpenSSLContextFactory(certPath, certPath), interface="127.0.0.1",
        )
        self.ports.append(self.listener)
        f = protocol.ClientFactory()
        f.protocol = test_tcp.ConnectionLosingProtocol

        f.protocol.master = self

        L = []
        def connector():
            p = self.listener.getHost().port
            ctx = ssl.ClientContextFactory()
            return reactor.connectSSL('127.0.0.1', p, f, ctx)
        self.connector = connector

        self.totalConnections = 0 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:24,代碼來源:test_ssl.py

示例9: testOpenSSLBuffering

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def testOpenSSLBuffering(self):
        serverProto = self.serverProto = SingleLineServerProtocol()
        clientProto = self.clientProto = RecordingClientProtocol()

        server = protocol.ServerFactory()
        client = self.client = protocol.ClientFactory()

        server.protocol = lambda: serverProto
        client.protocol = lambda: clientProto
        client.buffer = []

        sCTX = ssl.DefaultOpenSSLContextFactory(certPath, certPath)
        cCTX = ssl.ClientContextFactory()

        port = self.port = reactor.listenSSL(0, server, sCTX, interface='127.0.0.1')
        reactor.connectSSL('127.0.0.1', port.getHost().port, client, cCTX)

        i = 0
        while i < 5000 and not client.buffer:
            i += 1
            reactor.iterate()

        self.assertEquals(client.buffer, ["+OK <some crap>\r\n"]) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:25,代碼來源:test_ssl.py

示例10: run_proxy

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def run_proxy():
    proxy = DynamicProxy()
    site = Site(proxy)
    reactor.listenTCP(args.LPORT, site, interface=args.LHOST)

    if not args.SSL_KEY or not args.SSL_CERT:
        args.SSL_CERT, args.SSL_KEY = get_self_signed_cert(args.URI_HOST)
    with open(args.SSL_CERT, "br") as f:
        cert = f.read()
    cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert)
    global FINGERPRINT
    FINGERPRINT = cert.digest("sha1").decode()
    reactor.listenSSL(args.SSL_PORT,
                      site,
                      ssl.DefaultOpenSSLContextFactory(
                          args.SSL_KEY.encode(),
                          args.SSL_CERT.encode(),
                      ),
                      interface=args.LHOST,
                      )
    reactor.run() 
開發者ID:AdrianVollmer,項目名稱:PowerHub,代碼行數:23,代碼來源:reverseproxy.py

示例11: _listen

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def _listen(self, site):
        return reactor.listenSSL(
            0, site,
            contextFactory=ssl.DefaultOpenSSLContextFactory(
                serverPEMPath, serverPEMPath),
            interface="127.0.0.1") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:8,代碼來源:test_webclient.py

示例12: makeContextFactory

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def makeContextFactory(self, org, orgUnit, *args, **kwArgs):
        base = self.mktemp()
        generateCertificateFiles(base, org, orgUnit)
        serverCtxFactory = ssl.DefaultOpenSSLContextFactory(
            os.extsep.join((base, 'key')),
            os.extsep.join((base, 'cert')),
            *args, **kwArgs)

        return base, serverCtxFactory 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:test_ssl.py

示例13: __init__

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def __init__(self, *args, **kw):
            kw['sslmethod'] = SSL.TLSv1_METHOD
            ssl.DefaultOpenSSLContextFactory.__init__(self, *args, **kw) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:5,代碼來源:test_ssl.py

示例14: test_method

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def test_method(self):
        """
        L{ssl.DefaultOpenSSLContextFactory.getContext} returns an SSL context
        which can use SSLv3 or TLSv1 but not SSLv2.
        """
        # SSLv23_METHOD allows SSLv2, SSLv3, or TLSv1
        self.assertEqual(self.context._method, SSL.SSLv23_METHOD)

        # And OP_NO_SSLv2 disables the SSLv2 support.
        self.assertTrue(self.context._options & SSL.OP_NO_SSLv2)

        # Make sure SSLv3 and TLSv1 aren't disabled though.
        self.assertFalse(self.context._options & SSL.OP_NO_SSLv3)
        self.assertFalse(self.context._options & SSL.OP_NO_TLSv1) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:test_ssl.py

示例15: test_missingCertificateFile

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import DefaultOpenSSLContextFactory [as 別名]
def test_missingCertificateFile(self):
        """
        Instantiating L{ssl.DefaultOpenSSLContextFactory} with a certificate
        filename which does not identify an existing file results in the
        initializer raising L{OpenSSL.SSL.Error}.
        """
        self.assertRaises(
            SSL.Error,
            ssl.DefaultOpenSSLContextFactory, certPath, self.mktemp()) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:test_ssl.py


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