我是pyOpenSSL的新用户,我想用以下代码制作证书
from OpenSSL import crypto as c
cert = c.X509()
cert.add_extensions([
c.X509Extension('crlDistributionPoints', False, 'dirName:/C=US/O=TEST'),
])
此代码无法正常工作,任何人都可以帮助我吗?pyOpenSSL似乎不支持dirName
cert.add_extensions([
c.X509Extension('crlDistributionPoints', False, 'URI:http://somesite') can work
])
答案 0 :(得分:0)
我有完全相同的问题,但是,我也找不到真正的解决方案,我设法通过Python完成了一些工作。 在此页面中,格式化解释为http://openssl.org/docs/apps/x509v3_config.html#CRL-distribution-points,并且还提供了使用原始DER字节的选项。 (章节:仲裁延期)
首先'收集'来自已具有正确URI和dirName的证书的DER字节。替代方案使用带有正确crlDistributionPoint的openssl创建证书,此示例中的tmpcert是此证书。还要弄清楚使用了哪个扩展索引。 get_short_name将提供'键'的扩展名,所以搜索crlDistributionPoint。 使用以下方法收集它:
from binascii import hexlify
print tmpcert.get_extension(5).get_short_name()
print hexlify(tmpcert.get_extension(5).get_data())
然后格式化此输出并在X509Extension()
的初始化中使用它crypto.X509Extension('crlDistributionPoints', False,
"DER:30:6a:xx:xx:xx:..........:xx:xx")
正如人们所理解的那样,这是一个“硬编码”的问题。解决方案,没有直接的方式来改变这个领域的内容。
答案 1 :(得分:0)
这是一种可以生成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'),
),
)