本文整理汇总了Python中twisted.internet.ssl.PrivateCertificate.fromCertificateAndKeyPair方法的典型用法代码示例。如果您正苦于以下问题:Python PrivateCertificate.fromCertificateAndKeyPair方法的具体用法?Python PrivateCertificate.fromCertificateAndKeyPair怎么用?Python PrivateCertificate.fromCertificateAndKeyPair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.ssl.PrivateCertificate
的用法示例。
在下文中一共展示了PrivateCertificate.fromCertificateAndKeyPair方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clientCertFor
# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import fromCertificateAndKeyPair [as 别名]
def clientCertFor(name):
signingCert = getCAPrivateCert()
clientKey = KeyPair.generate(size=4096)
csr = clientKey.requestObject(DN(CN=name), "sha1")
clientCert = signingCert.signRequestObject(
csr, serialNumber=1, digestAlgorithm="sha1")
return PrivateCertificate.fromCertificateAndKeyPair(clientCert, clientKey)
示例2: clientCertFor
# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import fromCertificateAndKeyPair [as 别名]
def clientCertFor(p_name):
l_signingCert = getCAPrivateCert()
l_clientKey = KeyPair.generate(size = 4096)
l_csr = l_clientKey.requestObject(DN(CN = p_name), "sha1")
l_clientCert = l_signingCert.signRequestObject(
l_csr, serialNumber = 1, digestAlgorithm = "sha1")
return PrivateCertificate.fromCertificateAndKeyPair(l_clientCert, l_clientKey)
示例3: private_certificate
# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import fromCertificateAndKeyPair [as 别名]
def private_certificate(self):
"""
Combine private key and certificate into a ``PrivateCertificate``.
:return: ``PrivateCertificate`` instance.
"""
return PrivateCertificate.fromCertificateAndKeyPair(
self.certificate, self.keypair.keypair)
示例4: _create_tls_client_context
# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import fromCertificateAndKeyPair [as 别名]
def _create_tls_client_context(config, cbdir, log):
"""
Create a CertificateOptions object for use with TLS listening endpoints.
"""
# server hostname: The expected name of the remote host.
hostname = config['hostname']
# explicit trust (certificate) root
ca_certs = None
if 'ca_certificates' in config:
log.info("TLS client using explicit trust ({cnt_certs} certificates)", cnt_certs=len(config['ca_certificates']))
ca_certs = []
for cert_fname in [os.path.abspath(os.path.join(cbdir, x)) for x in (config['ca_certificates'])]:
cert = crypto.load_certificate(
crypto.FILETYPE_PEM,
six.u(open(cert_fname, 'r').read())
)
log.info("TLS client trust root CA certificate loaded from '{fname}'", fname=cert_fname)
ca_certs.append(cert)
ca_certs = OpenSSLCertificateAuthorities(ca_certs)
else:
log.info("TLS client using platform trust")
# client key/cert to use
client_cert = None
if 'key' in config:
if 'certificate' not in config:
raise Exception('TLS client key present, but certificate missing')
key_fname = os.path.abspath(os.path.join(cbdir, config['key']))
with open(key_fname, 'r') as f:
private_key = KeyPair.load(f.read(), format=crypto.FILETYPE_PEM)
log.info("Loaded client TLS key from '{key_fname}'", key_fname=key_fname)
cert_fname = os.path.abspath(os.path.join(cbdir, config['certificate']))
with open(cert_fname, 'r') as f:
cert = Certificate.loadPEM(f.read(),)
log.info("Loaded client TLS certificate from '{cert_fname}' (cn='{cert_cn}', sha256={cert_sha256}..)",
cert_fname=cert_fname,
cert_cn=cert.getSubject().CN,
cert_sha256=cert.digest('sha256')[:12])
client_cert = PrivateCertificate.fromCertificateAndKeyPair(cert, private_key)
else:
if 'certificate' in config:
log.warn('TLS client certificate present, but key is missing')
# create TLS client context
ctx = optionsForClientTLS(hostname, trustRoot=ca_certs, clientCertificate=client_cert)
return ctx
示例5: actualTest
# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import fromCertificateAndKeyPair [as 别名]
def actualTest(result):
ponged = defer.Deferred()
signer = self.serverService2.certificateStorage.getPrivateCertificate(
self.fromDomain).privateKey
req = signer.requestObject(DistinguishedName(commonName=self.toDomain))
sreq = signer.signRequestObject(
DistinguishedName(commonName=self.fromDomain), req, 12345)
selfSignedLie = PrivateCertificate.fromCertificateAndKeyPair(
sreq, signer)
self.serverService2.connectQ2Q(self.fromAddress,
self.toAddress,
'pony',
OneTrickPonyClientFactory(ponged),
selfSignedLie,
fakeFromDomain=self.toDomain).addErrback(
lambda e: e.trap(q2q.VerifyError))
return self.assertFailure(ponged, q2q.VerifyError)
示例6: __init__
# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import fromCertificateAndKeyPair [as 别名]
def __init__(self, publicPath, privatePath, csrPath, key, cert, issuer):
self.publicPath = publicPath
self.privatePath = privatePath
self.csrPath = csrPath
self.cert = PrivateCertificate.fromCertificateAndKeyPair(cert, key)
self.issuer = issuer
示例7: pems
# 需要导入模块: from twisted.internet.ssl import PrivateCertificate [as 别名]
# 或者: from twisted.internet.ssl.PrivateCertificate import fromCertificateAndKeyPair [as 别名]
def pems():
for i in count():
key = KeyPair.generate()
cert = key.selfSignedCert(i, commonName=u"lae_automation testing")
pem = PrivateCertificate.fromCertificateAndKeyPair(cert, key).dumpPEM()
yield pem.decode("ascii")