为什么在Python中解码的SSL证书中包含元组?

2024-05-14 22:31:59 发布

您现在位置:Python中文网/ 问答频道 /正文

这是ssl.SSLSocket.getpeercert的示例输出,取自文档。你知道吗

{'issuer': ((('countryName', 'IL'),),
            (('organizationName', 'StartCom Ltd.'),),
            (('organizationalUnitName',
              'Secure Digital Certificate Signing'),),
            (('commonName',
              'StartCom Class 2 Primary Intermediate Server CA'),)),
 'notAfter': 'Nov 22 08:15:19 2013 GMT',
 'notBefore': 'Nov 21 03:09:52 2011 GMT',
 'serialNumber': '95F0',
 'subject': ((('description', '571208-SLe257oHY9fVQ07Z'),),
             (('countryName', 'US'),),
             (('stateOrProvinceName', 'California'),),
             (('localityName', 'San Francisco'),),
             (('organizationName', 'Electronic Frontier Foundation, Inc.'),),
             (('commonName', '*.eff.org'),),
             (('emailAddress', 'hostmaster@eff.org'),)),
 'subjectAltName': (('DNS', '*.eff.org'), ('DNS', 'eff.org')),
 'version': 3}

我想知道issuersubject中的单元素元组的用途是什么。一个主题可以在同一行中有几个属性吗?你知道吗


Tags: orgssl示例dnsnovsubjectissuergmt
1条回答
网友
1楼 · 发布于 2024-05-14 22:31:59

嵌套结构可能直接来自RFC 5280,第4.1.2.4节:

RelativeDistinguishedName ::=
    SET SIZE (1..MAX) OF AttributeTypeAndValue

AttributeTypeAndValue ::= SEQUENCE {
    type     AttributeType,
    value    AttributeValue }

嗯,也许不是。你知道吗

我想可能会遇到一种属性类型的多个实例(locality,例如),但可能性不大。根据不同的用例,我会忽略相同类型的后续值,并记录一个警告以帮助调试。你知道吗

如果您认为它值得您花时间,您可以阅读X.500标准中的所有内容,但对于它的价值,下面是它的实际表现:

默认的openssl.cnf包含以下内容:

[ req_distinguished_name ]
0.organizationName      = Organization Name (eg, company)
0.organizationName_default  = Internet Widgits Pty Ltd

# we can do this but it is not needed normally :-)
#1.organizationName      = Second Organization Name (eg, company)
#1.organizationName_default  = World Wide Web Pty Ltd

如果激活第二个o,则在Python中的结果如下:

{'notAfter': 'Apr 27 20:03:12 2014 GMT',
 'subject': ((('countryName', u'AU'),),
             (('stateOrProvinceName', u'Some-State'),),
             (('organizationName', u'Internet Widgits Pty Ltd'),),
             (('organizationName', u'World Wide Web Pty Ltd'),),
             (('commonName', u'www.example.com'),),
             (('emailAddress', u'foo@example.com'),))}

相关问题 更多 >

    热门问题