3

私は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
])
4

2 に答える 2

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'),
        ),
    )
于 2016-05-30T21:32:11.117 に答える
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")

理解できるように、これは非常に「ハードコードされた」ソリューションであり、この方法でこのフィールドの内容を変更する簡単な方法はありません。

于 2015-08-05T10:56:49.313 に答える