本文整理汇总了Python中cryptography.hazmat.backends.openssl.backend.backend方法的典型用法代码示例。如果您正苦于以下问题:Python backend.backend方法的具体用法?Python backend.backend怎么用?Python backend.backend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.hazmat.backends.openssl.backend
的用法示例。
在下文中一共展示了backend.backend方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _backend_import_fallback
# 需要导入模块: from cryptography.hazmat.backends.openssl import backend [as 别名]
# 或者: from cryptography.hazmat.backends.openssl.backend import backend [as 别名]
def _backend_import_fallback(backends):
# If backends already exist just return them. This branch is here
# to get full line coverage from our tests.
if backends:
return backends
# if iter_entry_points fails to find any backends then manually try to
# import our current backends as a workaround for issues with application
# bundlers like pyinstaller, cx_freeze, etc
# OpenSSL is guaranteed to be present until we unbundle the backends.
from cryptography.hazmat.backends.openssl.backend import backend as be_ossl
backends = [be_ossl]
try:
from cryptography.hazmat.backends.commoncrypto.backend import (
backend as be_cc
)
except ImportError:
pass
else:
backends.append(be_cc)
return backends
示例2: test_export_der
# 需要导入模块: from cryptography.hazmat.backends.openssl import backend [as 别名]
# 或者: from cryptography.hazmat.backends.openssl.backend import backend [as 别名]
def test_export_der(self):
"""
If passed ``FILETYPE_ASN1`` for the format, ``CRL.export`` returns a
"DER" format string representing a serial number, a revoked reason, and
certificate issuer information.
"""
crl = self._get_crl()
# DER format
dumped_crl = self._get_crl().export(
self.cert, self.pkey, FILETYPE_ASN1, digest=b"md5"
)
crl = x509.load_der_x509_crl(dumped_crl, backend)
revoked = crl.get_revoked_certificate_by_serial_number(0x03AB)
assert revoked is not None
assert crl.issuer == x509.Name([
x509.NameAttribute(x509.NameOID.COUNTRY_NAME, u"US"),
x509.NameAttribute(x509.NameOID.STATE_OR_PROVINCE_NAME, u"IL"),
x509.NameAttribute(x509.NameOID.LOCALITY_NAME, u"Chicago"),
x509.NameAttribute(x509.NameOID.ORGANIZATION_NAME, u"Testing"),
x509.NameAttribute(x509.NameOID.COMMON_NAME, u"Testing Root CA"),
])
# Flaky because we compare the output of running commands which sometimes
# varies by 1 second
示例3: _load_keys
# 需要导入模块: from cryptography.hazmat.backends.openssl import backend [as 别名]
# 或者: from cryptography.hazmat.backends.openssl.backend import backend [as 别名]
def _load_keys(self, certificates):
new_keys = []
for cert in certificates:
logger.debug("Loading public key from certificate: %s", cert)
cert_obj = load_der_x509_certificate(base64.b64decode(cert), backend)
new_keys.append(cert_obj.public_key())
self.signing_keys = new_keys
示例4: test_convert_from_cryptography_private_key
# 需要导入模块: from cryptography.hazmat.backends.openssl import backend [as 别名]
# 或者: from cryptography.hazmat.backends.openssl.backend import backend [as 别名]
def test_convert_from_cryptography_private_key(self):
"""
PKey.from_cryptography_key creates a proper private PKey.
"""
key = serialization.load_pem_private_key(
intermediate_key_pem, None, backend
)
pkey = PKey.from_cryptography_key(key)
assert isinstance(pkey, PKey)
assert pkey.bits() == key.key_size
assert pkey._only_public is False
assert pkey._initialized is True
示例5: test_convert_from_cryptography_public_key
# 需要导入模块: from cryptography.hazmat.backends.openssl import backend [as 别名]
# 或者: from cryptography.hazmat.backends.openssl.backend import backend [as 别名]
def test_convert_from_cryptography_public_key(self):
"""
PKey.from_cryptography_key creates a proper public PKey.
"""
key = serialization.load_pem_public_key(cleartextPublicKeyPEM, backend)
pkey = PKey.from_cryptography_key(key)
assert isinstance(pkey, PKey)
assert pkey.bits() == key.key_size
assert pkey._only_public is True
assert pkey._initialized is True
示例6: test_convert_from_cryptography_unsupported_type
# 需要导入模块: from cryptography.hazmat.backends.openssl import backend [as 别名]
# 或者: from cryptography.hazmat.backends.openssl.backend import backend [as 别名]
def test_convert_from_cryptography_unsupported_type(self):
"""
PKey.from_cryptography_key raises TypeError with an unsupported type.
"""
key = serialization.load_pem_private_key(
ec_private_key_pem, None, backend
)
with pytest.raises(TypeError):
PKey.from_cryptography_key(key)
示例7: test_convert_from_cryptography
# 需要导入模块: from cryptography.hazmat.backends.openssl import backend [as 别名]
# 或者: from cryptography.hazmat.backends.openssl.backend import backend [as 别名]
def test_convert_from_cryptography(self):
crypto_req = x509.load_pem_x509_csr(
cleartextCertificateRequestPEM, backend
)
req = X509Req.from_cryptography(crypto_req)
assert isinstance(req, X509Req)