当前位置: 首页>>代码示例>>Python>>正文


Python PrivateCertificate.loadPEM方法代码示例

本文整理汇总了Python中twisted.internet.ssl.PrivateCertificate.loadPEM方法的典型用法代码示例。如果您正苦于以下问题:Python PrivateCertificate.loadPEM方法的具体用法?Python PrivateCertificate.loadPEM怎么用?Python PrivateCertificate.loadPEM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.ssl.PrivateCertificate的用法示例。


在下文中一共展示了PrivateCertificate.loadPEM方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: connect

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
    def connect(self, host=None, port=None, cert=None, key=None):
        '''
        Connect to another portal somewhere. If retry is set, will attempt to reconnect
        with the target continuously. As of the time of this writing, you cannot stop a 
        polling connection without taking down the portal.

        :param retry: continuously attempt to connect on drops or rejections
        :type retry: bool.
        '''

        host = host if host else self.host
        port = port if port else self.port
        cert = cert if cert else self.certCa
        key = key if key else self.keyPrivate  # ???

        # the first term is the name the server is using in the cert (for now)
        ctx = optionsForClientTLS(u"pds.production", Certificate.loadPEM(cert), PrivateCertificate.loadPEM(key))

        factory = RiffleClientFactory()
        SSL4ClientEndpoint(reactor, host, port, ctx,).connect(factory)

        print 'Connecting to ' + host + ':' + str(port)
        avatar = yield factory.login(self)

        defer.returnValue(Levy(avatar))
开发者ID:SejalChauhan,项目名称:Paradrop,代码行数:27,代码来源:riffle.py

示例2: getFactory

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
    def getFactory(self):
        if self.factory is None:
            if self.certificateFile is not None:
                cert = PrivateCertificate.loadPEM(
                    file(self.certificateFile).read())
                certOpts = CertificateOptions(
                    cert.privateKey.original,
                    cert.original,
                    requireCertificate=False,
                    method=SSL.SSLv23_METHOD)
            else:
                certOpts = None

            self.portal = portal.Portal(
                self.userbase, [self.userbase, checkers.AllowAnonymousAccess()])
            self.factory = ESMTPFactory(
                self.portal,
                self.domain,
                {'CRAM-MD5': credentials.CramMD5Credentials,
                 'LOGIN': imap4.LOGINCredentials,
                 },
                certOpts)
            if self.debug:
                self.factory = policies.TrafficLoggingFactory(self.factory, 'smtp')
        return self.factory
开发者ID:pombredanne,项目名称:quotient,代码行数:27,代码来源:mail.py

示例3: addSubprocesses

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
 def addSubprocesses(self, fds, name, factory):
     super(HendrixDeploySSL, self).addSubprocesses(fds, name, factory)
     if name == 'main_web_ssl':
         privateCert = PrivateCertificate.loadPEM(
             open(self.options['cert']).read() + open(self.options['key']).read()
         )
         factory = TLSMemoryBIOFactory(
             privateCert.options(), False, factory
         )
开发者ID:SlashRoot,项目名称:hendrix,代码行数:11,代码来源:ssl.py

示例4: main

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
def main(reactor):
    pemBytes = FilePath(b"ca-private-cert.pem").getContent()
    certificateAuthority = Certificate.loadPEM(pemBytes)
    myCertificate = PrivateCertificate.loadPEM(pemBytes)
    serverEndpoint = SSL4ServerEndpoint(
        reactor, 4321, myCertificate.options(certificateAuthority)
    )
    serverEndpoint.listen(Factory.forProtocol(ReportWhichClient))
    return Deferred()
开发者ID:damouse,项目名称:pdservertemp,代码行数:11,代码来源:whichclient.py

示例5: createCertOptions

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
def createCertOptions(server):
	pk = None
	cert = None
	if server.cert:
		pc = PrivateCertificate.loadPEM(open(server.cert,"rb").read())
		pk = pc.privateKey.original
		cert = pc.original
	tr = platformTrust() if server.verify else None
	return CertificateOptions(privateKey=pk, certificate=cert, trustRoot=tr)
开发者ID:Clam-,项目名称:pyBurlyBot,代码行数:11,代码来源:settings.py

示例6: getCAPrivateCert

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
def getCAPrivateCert():
    privatePath = FilePath(b"ca-private-cert.pem")
    if privatePath.exists():
        return PrivateCertificate.loadPEM(privatePath.getContent())
    else:
        caKey = KeyPair.generate(size=4096)
        caCert = caKey.selfSignedCert(1, CN="the-authority")
        privatePath.setContent(caCert.dumpPEM())
        return caCert
开发者ID:damouse,项目名称:pdservertemp,代码行数:11,代码来源:newcert.py

示例7: open

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
    def open(self, port=None, cert=None):
        '''
        Listen for connections on the given port. 
        '''
        port = port if port else self.port
        cert = cert if cert else self.certCa

        ca = Certificate.loadPEM(cert)
        myCertificate = PrivateCertificate.loadPEM(cert)

        SSL4ServerEndpoint(reactor, port, myCertificate.options(ca)).listen(RiffleServerFactory(self))
开发者ID:SejalChauhan,项目名称:Paradrop,代码行数:13,代码来源:riffle.py

示例8: getContextFactory

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
 def getContextFactory(self):
     if SSL is None:
         raise RuntimeError("No SSL support: you need to install OpenSSL.")
     cert = PrivateCertificate.loadPEM(
         self.certificatePath.open().read())
     certOpts = CertificateOptions(
         cert.privateKey.original,
         cert.original,
         requireCertificate=False,
         method=SSL.SSLv23_METHOD)
     return certOpts
开发者ID:rcarmo,项目名称:divmod.org,代码行数:13,代码来源:port.py

示例9: start_ssl_cmd_server

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
def start_ssl_cmd_server():
    with open(settings["Agent_Cert"], 'r') as certfile:
        certdata = certfile.read()
    if settings["Agent_Priv_Key"] != settings["Agent_Cert"]:
        with open(settings.get("Agent_Priv_Key"), 'r') as keyfile:
            certdata += keyfile.read()
    with open(settings.get("Broker_Cert"), 'r') as f:
        authdata = f.read()
    certificate = PrivateCertificate.loadPEM(certdata)
    authority = Certificate.loadPEM(authdata)
    factory = Factory.forProtocol(CommandHandler)
    reactor.listenSSL(int(settings.get("Command_Port")), factory, certificate.options(authority))
开发者ID:caedm,项目名称:cabs,代码行数:14,代码来源:cabsagent.py

示例10: start

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
    def start(self, fd=None):
        pids = [str(os.getpid())]  # script pid

        if fd is None:
            # anything in this block is only run once

            # TODO add global services here, possibly add a services kwarg on
            # __init__
            self.addGlobalServices()

            self.hendrix.startService()
            if self.options['workers']:
                # Create a new listening port and several other processes to help out.
                childFDs = {0: 0, 1: 1, 2: 2}
                self.fds = {}
                for name in self.servers:
                    port = self.hendrix.get_port(name)
                    fd = port.fileno()
                    childFDs[fd] = fd
                    self.fds[name] = fd

                args = self.getSpawnArgs()
                transports = []
                for i in range(self.options['workers']):
                    transport = reactor.spawnProcess(
                        None, executable, args, childFDs=childFDs, env=environ
                    )
                    transports.append(transport)
                    pids.append(str(transport.pid))
            with open(self.pid, 'w') as pid_file:
                pid_file.write('\n'.join(pids))
        else:
            # Another process created the port, drop the tcp service and
            # just start listening on it.
            fds = pickle.loads(fd)
            factories = {}
            for name in self.servers:
                factory = self.disownService(name)
                factories[name] = factory
            self.hendrix.startService()
            for name, factory in factories.iteritems():
                if name == 'main_web_ssl':
                    privateCert = PrivateCertificate.loadPEM(
                        open(self.options['cert']).read() + open(self.options['key']).read()
                    )
                    factory = TLSMemoryBIOFactory(
                        privateCert.options(), False, factory
                    )
                port = reactor.adoptStreamPort(fds[name], AF_INET, factory)

        reactor.run()
开发者ID:zenweasel,项目名称:hendrix,代码行数:53,代码来源:deploy.py

示例11: create_agent

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
def create_agent(ca_cert, client_cert, client_key):
    ca_certificate = Certificate.loadPEM(FilePath(ca_cert).getContent())
    client_certificate = PrivateCertificate.loadPEM(
        FilePath(client_cert).getContent() + b"\n" +
        FilePath(client_key).getContent())

    customPolicy = BrowserLikePolicyForHTTPSWithClientCertificate(
        trustRoot=ca_certificate,
        clientCertificate=client_certificate)

    pool = HTTPConnectionPool(reactor, persistent=True)
    agent = Agent(reactor, customPolicy, pool=pool)

    return agent
开发者ID:Seekscale,项目名称:smbproxy,代码行数:16,代码来源:ssl_agent.py

示例12: __init__

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
 def __init__(self, uri, verify, timeout=600, reactor=reactor, clientCert=None):
     Resource.__init__(self)
     self._uri = URLPath.fromString(uri)
     self._verify = verify
     self._timeout = timeout
     self._reactor = reactor
     pool = HTTPConnectionPool(reactor)
     if clientCert is not None:
         clientCert = PrivateCertificate.loadPEM(
             FilePath(clientCert).getContent())
     self._agent = Agent(
         reactor,
         StupidPolicyForHTTPS(InsecureTLSOptions(clientCert)),
         pool=pool)
开发者ID:fusionapp,项目名称:soapproxy,代码行数:16,代码来源:proxy.py

示例13: test_authenticateSucceed

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
    def test_authenticateSucceed(self):
        """
        L{authenticateRequest} returns C{True} if the provided client
        certificate has a matching hostname.
        """
        privateCert = PrivateCertificate.loadPEM(
            FilePath(__file__).sibling(b'data').child(b'test.cert').getContent())
        self.assertEqual(
            privateCert.original.get_subject().commonName, b'localhost')

        options = CertificateOptions(
            privateKey=privateCert.privateKey.original,
            certificate=privateCert.original)
        request = self.createRequest(options)
        self.assertEqual(True, authenticateRequest(request, u'localhost'))
开发者ID:fusionapp,项目名称:fusion-index,代码行数:17,代码来源:test_resource.py

示例14: test_handshakeFailure

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
    def test_handshakeFailure(self):
        """
        L{TLSMemoryBIOProtocol} reports errors in the handshake process to the
        application-level protocol object using its C{connectionLost} method
        and disconnects the underlying transport.
        """
        clientConnectionLost = Deferred()
        clientFactory = ClientFactory()
        clientFactory.protocol = (
            lambda: ConnectionLostNotifyingProtocol(
                clientConnectionLost))

        clientContextFactory = HandshakeCallbackContextFactory()
        wrapperFactory = TLSMemoryBIOFactory(
            clientContextFactory, True, clientFactory)
        sslClientProtocol = wrapperFactory.buildProtocol(None)

        serverConnectionLost = Deferred()
        serverFactory = ServerFactory()
        serverFactory.protocol = (
            lambda: ConnectionLostNotifyingProtocol(
                serverConnectionLost))

        # This context factory rejects any clients which do not present a
        # certificate.
        certificateData = FilePath(certPath).getContent()
        certificate = PrivateCertificate.loadPEM(certificateData)
        serverContextFactory = certificate.options(certificate)
        wrapperFactory = TLSMemoryBIOFactory(
            serverContextFactory, False, serverFactory)
        sslServerProtocol = wrapperFactory.buildProtocol(None)

        connectionDeferred = loopbackAsync(sslServerProtocol, sslClientProtocol)

        def cbConnectionLost(protocol):
            # The connection should close on its own in response to the error
            # induced by the client not supplying the required certificate.
            # After that, check to make sure the protocol's connectionLost was
            # called with the right thing.
            protocol.lostConnectionReason.trap(Error)
        clientConnectionLost.addCallback(cbConnectionLost)
        serverConnectionLost.addCallback(cbConnectionLost)

        # Additionally, the underlying transport should have been told to
        # go away.
        return gatherResults([
                clientConnectionLost, serverConnectionLost,
                connectionDeferred])
开发者ID:Almad,项目名称:twisted,代码行数:50,代码来源:test_tls.py

示例15: _serviceDescription

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import loadPEM [as 别名]
 def _serviceDescription(self):
     """
     Produce a description of the service we should start.
     """
     ca = Certificate.loadPEM(
         FilePath(self.caPath.encode('utf-8')).getContent())
     certBytes = FilePath(self.certPath.encode('utf-8')).getContent()
     cert = PrivateCertificate.loadPEM(certBytes)
     # Can't use PrivateCertificate.options until Twisted #6361 is fixed
     options = CertificateOptions(
         privateKey=cert.privateKey.original,
         certificate=cert.original,
         trustRoot=ca,
         extraCertChain=chainCerts(certBytes))
     router = IndexRouter(store=self.store)
     return _ServiceDescription(
         reactor=reactor, port=self.port, interface=self.interface,
         options=options, router=router)
开发者ID:fusionapp,项目名称:fusion-index,代码行数:20,代码来源:service.py


注:本文中的twisted.internet.ssl.PrivateCertificate.loadPEM方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。