web-dev-qa-db-ja.com

OpenSSLで証明書テンプレート情報を含むCSRを生成する

次の構成ファイルを使用して、OpenSSLでCSRを生成しています。

_[ req ]
default_bits           = 2048
default_keyfile        = usercert.key
distinguished_name     = req_distinguished_name
attributes             = req_attributes
Prompt                 = no

[ req_distinguished_name ]
C            = FR
L            = Paris
OU           = IT
CN           = FirstName LastName

[ req_attributes ]
1.3.6.1.4.1.311.13.2.1 = CertificateTemplate=CustomUserOffline
_

ここでの目標は、Windows CAで処理できるように、CSRにテンプレート名を含めることです。

次のコマンドラインを使用してCSRを生成します。

_openssl req -new -key usercert.key -out usercert.csr -config usercert.cnf
_

実行してもエラーは発生せず、次のコマンドでCSRを確認できます。

_openssl req -text -noout -verify -in usercert.csr
_
_verify OK
Certificate Request:
    Data:
        Version: 1 (0x0)
        Subject: C = FR, L = Paris, OU = IT, CN = FirstName LastName
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                RSA Public-Key: (2048 bit)
                Modulus:
                    00:af:85:28:40:84:d8:8a:58:35:86:b8:f5:25:b2:
                    ...
                    05:8d:57:cc:a0:4c:8f:da:f3:f4:a7:57:76:51:e2:
                    56:25
                Exponent: 65537 (0x10001)
        Attributes:
            1.3.6.1.4.1.311.13.2.1   :CertificateTemplate=CustomUserOffline
    Signature Algorithm: sha256WithRSAEncryption
         1e:4e:9b:6d:24:75:81:5f:be:52:58:ba:79:a1:ac:c8:d6:c9:
         ...
         40:2d:b6:fc
_

しかし、Windowsで_certutil usercert.csr_を使用してCSRを検証しようとすると、次のエラーが発生します。

_PKCS10 Certificate Request:
Version: 1
Subject:
    CN=FirstName LastName
    OU=IT
    L=Paris
    C=FR
  Name Hash(sha1): ab6adbd772e0ca2a0fce4a32abfdd1645686c0b9
  Name Hash(md5): 21d7edb09130201e880133c245617304

Public Key Algorithm:
    Algorithm ObjectId: 1.2.840.113549.1.1.1 RSA (RSA_SIGN)
    Algorithm Parameters:
    05 00
Public Key Length: 2048 bits
Public Key: UnusedBits = 0
    0000  30 82 01 0a 02 82 01 01  00 af 85 28 40 84 d8 8a
    ...
    0100  f3 f4 a7 57 76 51 e2 56  25 02 03 01 00 01
Request Attributes: 1
  1 attributes:

  Attribute[0]: 1.3.6.1.4.1.311.13.2.1 (Enrollment Name Value Pair)
    Value[0][0], Length = 27
Cannot decode object: The data is invalid. 0x8007000d (WIN32: 13 ERROR_INVALID_DATA)
CertUtil: -dump command FAILED: 0x8007000d (WIN32: 13 ERROR_INVALID_DATA)
CertUtil: The data is invalid.
_

カスタム属性は1.3.6.1.4.1.311.13.2.1 (Enrollment Name Value Pair)が表示されていると認識されているようですが、名前と値のペア_CertificateTemplate=CustomUserOffline_が適切な形式ではないようです。
どうすれば修正できますか?

いくつかのメモ:

  • 私はOpenSSLを使用してCSRを生成しています。これは、最終的にはLinuxクライアントがCSRを生成するためです。

  • _certreq -attrib "CertificateTemplate:CustomUserOffline" -submit usercert.csr_コマンドを知っていますが、リクエストはcertenroll APIを使用してC#コードを通じて送信されるため、証明書テンプレート情報を直接CSRに含めたいのです。

2
Chris

openssl.confの上部に次のように入力します。

[ OIDs ]

certificateTemplateName = 1.3.6.1.4.1.311.20.2

[req_attributes]内:

certificateTemplateName = ASN1:PRINTABLESTRING:CustomUserOffline

もちろん、質問で行ったように、OIDの定義をスキップして、OIDを直接使用することもできます。


次のopenssl構成ファイルを使用します。

oid_section = OIDs

[ OIDs ]

# This uses the short name of the template:
certificateTemplateName = 1.3.6.1.4.1.311.20.2

# Use this instead if you need to refer to the template by OID:
# certificateTemplateOID = 1.3.6.1.4.1.311.21.7  

  [ req ]

Prompt             = no
string_mask        = default

# The size of the keys in bits:
default_bits       = 2048
distinguished_name = req_dn
req_extensions     = req_ext

[ req_dn ]

# Note that the following are in 'reverse order' to what you'd expect to see in
# Windows and the numbering is irrelevant as long as each line's number differs.

# Domain Components style:
# Server name:
# 2.DC = com
# 1.DC = example
# commonName = Acme Web Server

# Locality style:
# countryName = GB
# stateOrProvinceName = London
# localityName = Letsby Avenue
# organizationName = Acme
# organizationalUnitName = IT Dept
# organizationalUnitName = Web Services
# commonName = Acme Web Server

# Or traditional org style:
countryName = GB
organizationName = Acme
organizationalUnitName = IT Dept
2.organizationalUnitName = Web Services
commonName = Acme Web Server

[ req_ext ]

#basicConstraints=critical,CA:TRUE

# This requests a certificate using the 'CustomUserOffline' template.  Check with the CA for the correct name to use,
# or alternatively comment it out and let the CA apply it:
certificateTemplateName = ASN1:PRINTABLESTRING:CustomUserOffline

subjectAltName = @alt_names

[alt_names]
# To copy the CN (in the case of a DNS name in the CN) use:
# DNS = ${req_dn::commonName}
DNS.1 = www.example.com
DNS.2 = example.com

これにより、openssl req -in usercert.csr -noout -textを使用して表示すると次のようになります。

    Attributes:
    Requested Extensions:
        1.3.6.1.4.1.311.20.2:
            ..CustomUserOffline

certutil usercert.csrで表示した場合の次の抜粋:

  Attribute[0]: 1.2.840.113549.1.9.14 (Certificate Extensions)
    Value[0][0], Length = 4d
Certificate Extensions: 2
    1.3.6.1.4.1.311.20.2: Flags = 0, Length = 13
    Certificate Template Name (Certificate Type)
        CustomUserOffline
2
garethTheRed