本文整理汇总了Python中cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME属性的典型用法代码示例。如果您正苦于以下问题:Python ExtensionOID.SUBJECT_ALTERNATIVE_NAME属性的具体用法?Python ExtensionOID.SUBJECT_ALTERNATIVE_NAME怎么用?Python ExtensionOID.SUBJECT_ALTERNATIVE_NAME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cryptography.x509.oid.ExtensionOID
的用法示例。
在下文中一共展示了ExtensionOID.SUBJECT_ALTERNATIVE_NAME属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match
# 需要导入模块: from cryptography.x509.oid import ExtensionOID [as 别名]
# 或者: from cryptography.x509.oid.ExtensionOID import SUBJECT_ALTERNATIVE_NAME [as 别名]
def match(self, value):
# This is somewhat terrible. Probably can be better after
# pyca/service_identity#14 is resolved.
target_ids = [
DNSPattern(target_name.encode('utf-8'))
for target_name
in (
value.extensions
.get_extension_for_oid(
ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
.value
.get_values_for_type(x509.DNSName)
)]
ids = [DNS_ID(self.name)]
try:
verify_service_identity(
cert_patterns=target_ids, obligatory_ids=ids, optional_ids=[])
except VerificationError:
return Mismatch(
'{!r} is not valid for {!r}'.format(value, self.name))
示例2: request_issuance
# 需要导入模块: from cryptography.x509.oid import ExtensionOID [as 别名]
# 或者: from cryptography.x509.oid.ExtensionOID import SUBJECT_ALTERNATIVE_NAME [as 别名]
def request_issuance(self, csr):
csr = csr.csr
# TODO: Only in Cryptography 1.3
# assert csr.is_signature_valid
cert = (
x509.CertificateBuilder()
.subject_name(csr.subject)
.issuer_name(self._ca_name)
.not_valid_before(self._now() - timedelta(seconds=3600))
.not_valid_after(self._now() + timedelta(days=90))
.serial_number(int(uuid4()))
.public_key(csr.public_key())
.add_extension(
csr.extensions.get_extension_for_oid(
ExtensionOID.SUBJECT_ALTERNATIVE_NAME).value,
critical=False)
.add_extension(
x509.SubjectKeyIdentifier.from_public_key(csr.public_key()),
critical=False)
.add_extension(self._ca_aki, critical=False)
.sign(
private_key=self._ca_key,
algorithm=hashes.SHA256(),
backend=default_backend()))
cert_res = messages.CertificateResource(
body=cert.public_bytes(encoding=serialization.Encoding.DER))
return self._controller.issue().addCallback(lambda _: cert_res)
示例3: subject_alternative_name
# 需要导入模块: from cryptography.x509.oid import ExtensionOID [as 别名]
# 或者: from cryptography.x509.oid.ExtensionOID import SUBJECT_ALTERNATIVE_NAME [as 别名]
def subject_alternative_name(self):
ext = self.get_x509_extension(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
if ext is not None:
return SubjectAlternativeName(ext)
示例4: subject_alt_name
# 需要导入模块: from cryptography.x509.oid import ExtensionOID [as 别名]
# 或者: from cryptography.x509.oid.ExtensionOID import SUBJECT_ALTERNATIVE_NAME [as 别名]
def subject_alt_name(self):
"""
Extract certificate's alt names
:return: unicode
"""
try:
alt_names = self.x509.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME).value
alt_name_strings = [alt_name.value for alt_name in alt_names]
return ",".join(alt_name_strings)
except x509.ExtensionNotFound:
return "(no subject alt name)"