本文整理汇总了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
示例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')])
示例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)
示例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