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


Python PrivateCertificate.load方法代码示例

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


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

示例1: setUp

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import load [as 别名]
    def setUp(self):
        """
        Create a L{PantheonHTTPChecker} pointed at a mock authentication service
        with some simple site and user information.
        """
        self.site = 'example.com'
        self.cwd = '/some/path'
        self.uid = 1542
        self.username = 'alice'
        self.password = 'correct password'
        keyString = FilePath(__file__).sibling('id_rsa').getContent()
        self.privateKey = Key.fromString(keyString)

        caKeyString = FilePath(__file__).sibling('cakey.pem').getContent()
        self.caKey = KeyPair.load(caKeyString, FILETYPE_PEM)
        caCertString = FilePath(__file__).sibling('cacert.pem').getContent()
        self.caCert = PrivateCertificate.load(
            caCertString, self.caKey, FILETYPE_PEM)

        self.resource = MockPantheonAuthResource(
            sites={self.site: [self.username]},
            authorizations={self.site: dict(cwd=self.cwd, uid=self.uid)},
            passwords={self.username: self.password},
            keys={self.username: self.privateKey},
            )
        self.server = MockPantheonAuthServer(
            reactor, self.resource, self.caCert)
        self.server.startService()
        self.addCleanup(self.server.stopService)
开发者ID:exarkun,项目名称:Pantheon-SSH,代码行数:31,代码来源:fakebackend.py

示例2: getServerContext

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import load [as 别名]
    def getServerContext(self):
        """
        Generate a new L{OpenSSL.SSL.Context} object configured to use a
        certificate signed by C{self.ca} and only accept connections from peers
        which are also using a certificate signed by C{self.ca}.
        """
        # Generate a new key for the server and have the CA sign a certificate
        # for it.
        key = KeyPair.generate(size=512)
        req = key.certificateRequest(DN(commonName='localhost'))
        certData = self.ca.signCertificateRequest(req, lambda dn: True, 1)
        cert = PrivateCertificate.load(certData, key)

        # Use the new key/certificate
        context = Context(TLSv1_METHOD)
        context.use_privatekey(key.original)
        context.use_certificate(cert.original)
        context.check_privatekey()

        # Allow peer certificates signed by the CA
        store = context.get_cert_store()
        store.add_cert(self.ca.original)

        # Verify the peer certificate and require that they have one.
        def verify(conn, cert, errno, depth, preverify_ok):
            return preverify_ok
        context.set_verify(VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT, verify)
        return context
开发者ID:exarkun,项目名称:Pantheon-SSH,代码行数:30,代码来源:fakebackend.py

示例3: getServerContext

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import load [as 别名]
 def getServerContext(self):
     """
     Return a new SSL context suitable for use in a test server.
     """
     pem = self._pem.getContent()
     cert = PrivateCertificate.load(
         pem, KeyPair.load(pem, FILETYPE_PEM), FILETYPE_PEM)
     return cert.options()
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:10,代码来源:test_tls.py

示例4: getServerContext

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import load [as 别名]
 def getServerContext(self):
     """
     Return a new SSL context suitable for use in a test server.
     """
     cert = PrivateCertificate.load(
         self._certificateText,
         KeyPair.load(self._privateKeyText, FILETYPE_PEM),
         FILETYPE_PEM)
     return cert.options()
开发者ID:Almad,项目名称:twisted,代码行数:11,代码来源:test_tls.py

示例5: import

# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import load [as 别名]
"""

from twisted.internet.protocol import ServerFactory
from twisted.internet.endpoints import SSL4ClientEndpoint
from twisted.internet.ssl import (
    DN, KeyPair, PrivateCertificate, CertificateOptions)
from twisted.protocols.wire import Echo

from tcp_throughput import Client, driver

# Generate a new self-signed certificate
key = KeyPair.generate(size=2048)
req = key.certificateRequest(DN(commonName='localhost'), digestAlgorithm='sha1')
cert = PrivateCertificate.load(
    key.signCertificateRequest(
        DN(commonName='localhost'), req,
        lambda dn: True, 1, digestAlgorithm='sha1'),
    key)


def main(reactor, duration):
    chunkSize = 16384

    server = ServerFactory()
    server.protocol = Echo
    port = reactor.listenSSL(0, server, cert.options())
    client = Client(
        reactor,
        SSL4ClientEndpoint(
            reactor, '127.0.0.1', port.getHost().port,
            CertificateOptions(
开发者ID:AlekSi,项目名称:twisted-benchmarks,代码行数:33,代码来源:ssl_throughput.py


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