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


Python NameOID.ORGANIZATIONAL_UNIT_NAME属性代码示例

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


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

示例1: build_name_attributes_update_dict_from_name

# 需要导入模块: from cryptography.x509.oid import NameOID [as 别名]
# 或者: from cryptography.x509.oid.NameOID import ORGANIZATIONAL_UNIT_NAME [as 别名]
def build_name_attributes_update_dict_from_name(name):
    update_dict = {}
    for oid, ztl_attr, is_list in ((NameOID.COMMON_NAME, "common_name", False),
                                   (NameOID.ORGANIZATION_NAME, "organization", False),
                                   (NameOID.ORGANIZATIONAL_UNIT_NAME, "organizational_unit", False),
                                   (NameOID.DOMAIN_COMPONENT, "domain", True)):
        name_attributes = name.get_attributes_for_oid(oid)
        if name_attributes:
            if is_list:
                value = ".".join(na.value for na in name_attributes[::-1])
            else:
                value = name_attributes[-1].value
            update_dict[ztl_attr] = value
    return update_dict 
开发者ID:zentralopensource,项目名称:zentral,代码行数:16,代码来源:utils.py

示例2: test_fields

# 需要导入模块: from cryptography.x509.oid import NameOID [as 别名]
# 或者: from cryptography.x509.oid.NameOID import ORGANIZATIONAL_UNIT_NAME [as 别名]
def test_fields(self):
        s = Subject('')
        self.assertEqual(list(s.fields), [])

        s = Subject('/C=AT')
        self.assertEqual(list(s.fields), [(NameOID.COUNTRY_NAME, 'AT')])

        s = Subject('/C=AT/CN=example.com')
        self.assertEqual(list(s.fields), [(NameOID.COUNTRY_NAME, 'AT'), (NameOID.COMMON_NAME, 'example.com')])

        s = Subject('/C=AT/OU=foo/CN=example.com')
        self.assertEqual(list(s.fields), [(NameOID.COUNTRY_NAME, 'AT'),
                                          (NameOID.ORGANIZATIONAL_UNIT_NAME, 'foo'),
                                          (NameOID.COMMON_NAME, 'example.com')])
        s = Subject('/C=AT/OU=foo/OU=bar/CN=example.com')
        self.assertEqual(list(s.fields), [(NameOID.COUNTRY_NAME, 'AT'),
                                          (NameOID.ORGANIZATIONAL_UNIT_NAME, 'foo'),
                                          (NameOID.ORGANIZATIONAL_UNIT_NAME, 'bar'),
                                          (NameOID.COMMON_NAME, 'example.com')])

        # Also test order
        s = Subject('/CN=example.com/C=AT/OU=foo/OU=bar')
        self.assertEqual(list(s.fields), [(NameOID.COUNTRY_NAME, 'AT'),
                                          (NameOID.ORGANIZATIONAL_UNIT_NAME, 'foo'),
                                          (NameOID.ORGANIZATIONAL_UNIT_NAME, 'bar'),
                                          (NameOID.COMMON_NAME, 'example.com')]) 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:28,代码来源:tests_subject.py

示例3: subject_name

# 需要导入模块: from cryptography.x509.oid import NameOID [as 别名]
# 或者: from cryptography.x509.oid.NameOID import ORGANIZATIONAL_UNIT_NAME [as 别名]
def subject_name(self):
        attribute_list = []
        if self.common_name:
            attribute_list.append(
                x509.NameAttribute(
                    NameOID.COMMON_NAME, text_type(self.common_name)
                )
            )
        if self.organization:
            attribute_list.append(
                x509.NameAttribute(
                    NameOID.ORGANIZATION_NAME, text_type(self.organization)
                )
            )
        if self.organizational_unit:
            attribute_list.append(
                x509.NameAttribute(
                    NameOID.ORGANIZATIONAL_UNIT_NAME,
                    text_type(self.organizational_unit),
                )
            )
        if self.country:
            attribute_list.append(
                x509.NameAttribute(
                    NameOID.COUNTRY_NAME, text_type(self.country)
                )
            )
        if self.state:
            attribute_list.append(
                x509.NameAttribute(
                    NameOID.STATE_OR_PROVINCE_NAME, text_type(self.state)
                )
            )
        if self.city:
            attribute_list.append(
                x509.NameAttribute(NameOID.LOCALITY_NAME, text_type(self.city))
            )
        if self.email_id:
            attribute_list.append(
                x509.NameAttribute(
                    NameOID.EMAIL_ADDRESS, text_type(self.email_id)
                )
            )
        return x509.Name(attribute_list) 
开发者ID:nokia,项目名称:SROS-grpc-services,代码行数:46,代码来源:cert_manager.py

示例4: ensure_ca_cert

# 需要导入模块: from cryptography.x509.oid import NameOID [as 别名]
# 或者: from cryptography.x509.oid.NameOID import ORGANIZATIONAL_UNIT_NAME [as 别名]
def ensure_ca_cert(output_dir, ca_private_key):
    ca_cert_filename = os.path.join(output_dir, CA_FILENAME + '.' + CERT_EXT)
    ca_public_key = ca_private_key.public_key()
    if os.path.exists(ca_cert_filename):
        with open(ca_cert_filename, "rb") as ca_cert_file:
            ca_cert = x509.load_pem_x509_certificate(
                ca_cert_file.read(),
                backend=default_backend())
    else:
        iname = x509.Name([
            x509.NameAttribute(NameOID.COMMON_NAME, 'Test CA'),
            x509.NameAttribute(NameOID.ORGANIZATION_NAME,
                'postfix-mta-sts-resolver dev'),
            x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME,
                'postfix-mta-sts-resolver testsuite'),
        ])
        ca_cert = x509.CertificateBuilder().\
            subject_name(iname).\
            issuer_name(iname).\
            not_valid_before(datetime.datetime.today() - DAY).\
            not_valid_after(datetime.datetime.today() + 3650 * DAY).\
            serial_number(x509.random_serial_number()).\
            public_key(ca_public_key).\
            add_extension(
                x509.BasicConstraints(ca=True, path_length=None),
                critical=True).\
            add_extension(
                x509.KeyUsage(digital_signature=False,
                              content_commitment=False,
                              key_encipherment=False,
                              data_encipherment=False,
                              key_agreement=False,
                              key_cert_sign=True,
                              crl_sign=True,
                              encipher_only=False,
                              decipher_only=False),
                critical=True).\
            add_extension(
                x509.SubjectKeyIdentifier.from_public_key(ca_public_key),
                critical=False).\
            sign(
                private_key=ca_private_key,
                algorithm=hashes.SHA256(),
                backend=default_backend()
            )
        with open(ca_cert_filename, "wb") as ca_cert_file:
            ca_cert_file.write(
                ca_cert.public_bytes(encoding=serialization.Encoding.PEM))
    assert isinstance(ca_cert, x509.Certificate)
    return ca_cert 
开发者ID:Snawoot,项目名称:postfix-mta-sts-resolver,代码行数:52,代码来源:mkcerts.py


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