當前位置: 首頁>>代碼示例>>Python>>正文


Python x509.Name方法代碼示例

本文整理匯總了Python中asn1crypto.x509.Name方法的典型用法代碼示例。如果您正苦於以下問題:Python x509.Name方法的具體用法?Python x509.Name怎麽用?Python x509.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在asn1crypto.x509的用法示例。


在下文中一共展示了x509.Name方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from asn1crypto import x509 [as 別名]
# 或者: from asn1crypto.x509 import Name [as 別名]
def __init__(self, subject, subject_public_key):
        """
        Unless changed, certificates will use SHA-256 for the signature,
        and will be valid from the moment created for one year. The serial
        number will be generated from the current time and a random number.

        :param subject:
            An asn1crypto.x509.Name object, or a dict - see the docstring
            for .subject for a list of valid options

        :param subject_public_key:
            An asn1crypto.keys.PublicKeyInfo object containing the public key
            the certificate is being issued for
        """

        self.subject = subject
        self.subject_public_key = subject_public_key
        self.ca = False

        self._hash_algo = 'sha256'
        self._other_extensions = {} 
開發者ID:wbond,項目名稱:certbuilder,代碼行數:23,代碼來源:__init__.py

示例2: test_build_name_printable

# 需要導入模塊: from asn1crypto import x509 [as 別名]
# 或者: from asn1crypto.x509 import Name [as 別名]
def test_build_name_printable(self):
        utf8_name = x509.Name.build(
            {
                'country_name': 'US',
                'state_or_province_name': 'Massachusetts',
                'common_name': 'Will Bond'
            }
        )
        self.assertIsInstance(utf8_name.chosen[2][0]['value'].chosen, core.UTF8String)
        self.assertEqual('common_name', utf8_name.chosen[2][0]['type'].native)
        printable_name = x509.Name.build(
            {
                'country_name': 'US',
                'state_or_province_name': 'Massachusetts',
                'common_name': 'Will Bond'
            },
            use_printable=True
        )
        self.assertIsInstance(printable_name.chosen[2][0]['value'].chosen, core.PrintableString)
        self.assertEqual('common_name', printable_name.chosen[2][0]['type'].native) 
開發者ID:wbond,項目名稱:asn1crypto,代碼行數:22,代碼來源:test_x509.py

示例3: test_v1_cert

# 需要導入模塊: from asn1crypto import x509 [as 別名]
# 或者: from asn1crypto.x509 import Name [as 別名]
def test_v1_cert(self):
        cert = self._load_cert('chromium/ndn.ca.crt')
        tbs_cert = cert['tbs_certificate']
        self.assertEqual('v1', tbs_cert['version'].native)
        self.assertEqual(15832340745319036834, tbs_cert['serial_number'].native)
        self.assertEqual(
            'Email Address: support@dreamhost.com; Common Name: New Dream Network Certificate Authority; '
            'Organizational Unit: Security; Organization: New Dream Network, LLC; Locality: Los Angeles; '
            'State/Province: California; Country: US',
            tbs_cert['issuer'].human_friendly
        )
        self.assertEqual(
            'Email Address: support@dreamhost.com; Common Name: New Dream Network Certificate Authority; '
            'Organizational Unit: Security; Organization: New Dream Network, LLC; Locality: Los Angeles; '
            'State/Province: California; Country: US',
            tbs_cert['subject'].human_friendly
        ) 
開發者ID:wbond,項目名稱:asn1crypto,代碼行數:19,代碼來源:test_x509.py

示例4: test_subject_alt_name_variations

# 需要導入模塊: from asn1crypto import x509 [as 別名]
# 或者: from asn1crypto.x509 import Name [as 別名]
def test_subject_alt_name_variations(self):
        cert = self._load_cert('chromium/subjectAltName_sanity_check.pem')
        alt_names = cert.subject_alt_name_value
        for general_name in alt_names:
            self.assertIsInstance(general_name, x509.GeneralName)
        self.assertIsInstance(alt_names[0].chosen, x509.IPAddress)
        self.assertEqual(alt_names[0].chosen.native, '127.0.0.2')
        self.assertIsInstance(alt_names[1].chosen, x509.IPAddress)
        self.assertEqual(alt_names[1].chosen.native, 'fe80::1')
        self.assertIsInstance(alt_names[2].chosen, x509.DNSName)
        self.assertEqual(alt_names[2].chosen.native, 'test.example')
        self.assertIsInstance(alt_names[3].chosen, x509.EmailAddress)
        self.assertEqual(alt_names[3].chosen.native, 'test@test.example')
        self.assertIsInstance(alt_names[4].chosen, x509.AnotherName)
        self.assertEqual(alt_names[4].chosen.native, util.OrderedDict([('type_id', '1.2.3.4'), ('value', 'ignore me')]))
        self.assertIsInstance(alt_names[5].chosen, x509.Name)
        self.assertEqual(alt_names[5].chosen.native, util.OrderedDict([('common_name', '127.0.0.3')])) 
開發者ID:wbond,項目名稱:asn1crypto,代碼行數:19,代碼來源:test_x509.py

示例5: cn_to_dn

# 需要導入模塊: from asn1crypto import x509 [as 別名]
# 或者: from asn1crypto.x509 import Name [as 別名]
def cn_to_dn(common_name, namespace, o=None, ou=None):
    from asn1crypto.x509 import Name, RelativeDistinguishedName, NameType, DirectoryString, RDNSequence, NameTypeAndValue, UTF8String, DNSName

    rdns = []

    for dc in reversed(namespace.split(".")):
        rdns.append(RelativeDistinguishedName([
            NameTypeAndValue({
                'type': NameType.map("domain_component"),
                'value': DNSName(value=dc)
            })
        ]))

    if o:
        rdns.append(RelativeDistinguishedName([
            NameTypeAndValue({
                'type': NameType.map("organization_name"),
                'value': DirectoryString(
                    name="utf8_string",
                    value=UTF8String(o))
            })
        ]))

    if ou:
        rdns.append(RelativeDistinguishedName([
            NameTypeAndValue({
                'type': NameType.map("organizational_unit_name"),
                'value': DirectoryString(
                    name="utf8_string",
                    value=UTF8String(ou))
            })
        ]))

    rdns.append(RelativeDistinguishedName([
        NameTypeAndValue({
            'type': NameType.map("common_name"),
            'value': DirectoryString(
                name="utf8_string",
                value=UTF8String(common_name))
        })
    ]))

    return Name(name='', value=RDNSequence(rdns)) 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:45,代碼來源:common.py

示例6: retrieve_by_name

# 需要導入模塊: from asn1crypto import x509 [as 別名]
# 或者: from asn1crypto.x509 import Name [as 別名]
def retrieve_by_name(self, name, first_certificate=None):
        """
        Retrieves a list certs via their subject name

        :param name:
            An asn1crypto.x509.Name object

        :param first_certificate:
            An asn1crypto.x509.Certificate object that if found, should be
            placed first in the result list

        :return:
            A list of asn1crypto.x509.Certificate objects
        """

        if not isinstance(name, x509.Name):
            raise TypeError(pretty_message(
                '''
                name must be an instance of asn1crypto.x509.Name, not %s
                ''',
                type_name(name)
            ))

        if first_certificate and not isinstance(first_certificate, x509.Certificate):
            raise TypeError(pretty_message(
                '''
                first_certificate must be an instance of
                asn1crypto.x509.Certificate, not %s
                ''',
                type_name(first_certificate)
            ))

        hashable = name.hashable

        if hashable not in self._subject_map:
            return []

        certs = self._subject_map[hashable]
        first = None
        output = []
        for cert in certs:
            if first_certificate and first_certificate.sha256 == cert.sha256:
                first = cert
            else:
                output.append(cert)
        if first:
            output.insert(0, first)
        return output 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:50,代碼來源:registry.py

示例7: subject

# 需要導入模塊: from asn1crypto import x509 [as 別名]
# 或者: from asn1crypto.x509 import Name [as 別名]
def subject(self, value):
        """
        An asn1crypto.x509.Name object, or a dict with a minimum of the
        following keys:

         - "country_name"
         - "state_or_province_name"
         - "locality_name"
         - "organization_name"
         - "common_name"

        Less common keys include:

         - "organizational_unit_name"
         - "email_address"
         - "street_address"
         - "postal_code"
         - "business_category"
         - "incorporation_locality"
         - "incorporation_state_or_province"
         - "incorporation_country"

        Uncommon keys include:

         - "surname"
         - "title"
         - "serial_number"
         - "name"
         - "given_name"
         - "initials"
         - "generation_qualifier"
         - "dn_qualifier"
         - "pseudonym"
         - "domain_component"

        All values should be unicode strings.
        """

        is_dict = isinstance(value, dict)
        if not isinstance(value, x509.Name) and not is_dict:
            raise TypeError(_pretty_message(
                '''
                subject must be an instance of asn1crypto.x509.Name or a dict,
                not %s
                ''',
                _type_name(value)
            ))

        if is_dict:
            value = x509.Name.build(value)

        self._subject = value 
開發者ID:wbond,項目名稱:certbuilder,代碼行數:54,代碼來源:__init__.py


注:本文中的asn1crypto.x509.Name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。