这是您可以生成 DER 的一种方式……它不包含 dirName 的代码,但我希望它可以让您了解如何构建 DER
from pyasn1.codec.der import encoder as der_encoder
from pyasn1.type import tag
from pyasn1_modules import rfc2459
class GeneralNames(rfc2459.GeneralNames):
"""
rfc2459 has wrong tagset.
"""
tagSet = tag.TagSet(
(),
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0),
)
class DistributionPointName(rfc2459.DistributionPointName):
"""
rfc2459 has wrong tagset.
"""
tagSet = tag.TagSet(
(),
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0),
)
cdps = [('uri', 'http://something'), ('dns', 'some.domain.com')]
cdp = rfc2459.CRLDistPointsSyntax()
values = []
position = 0
for cdp_type, cdp_value in cdps:
cdp_entry = rfc2459.DistributionPoint()
general_name = rfc2459.GeneralName()
if cdp_type == 'uri':
general_name.setComponentByName(
'uniformResourceIdentifier',
cdp_value,
)
elif cdp_type == 'dns':
general_name.setComponentByName(
'dNSName',
cdp_value,
)
general_names = GeneralNames()
general_names.setComponentByPosition(0, general_name)
name = DistributionPointName()
name.setComponentByName('fullName', general_names)
cdp_entry.setComponentByName('distributionPoint', name)
cdp.setComponentByPosition(position, cdp_entry)
position += 1
cdp_der = der_encoder.encode(cdp)
extensions.append(
crypto.X509Extension(
b'crlDistributionPoints',
False,
'DER:' + cdp_der.encode('hex'),
),
)