OpenSSL - 使用 CA 签名时添加主题备用名称 (SAN)

mec*_*hgt 6 openssl ssl-certificate csr certificate-authority subject-alternative-names

如何在使用 OpenSSL 签署证书请求时添加主题备用名称(如果重要,在 Windows 中)?

我已经从 IIS 界面生成了一个基本的证书签名请求 (CSR)。现在,我想添加几个主题备用名称,使用现有的根证书对其进行签名,然后返回证书以完成签名请求。

我能找到的每个教程都涉及生成一个新的私钥和一个全新的 CSR,但是我的印象是私钥驻留在发出请求的计算机上(我不一定有权访问)。我只想在添加备用名称的同时签署请求。我对 OpenSSL 和 CA 主题比较陌生,所以这可能是我的误解。

Law*_*w29 10

就我个人而言,我在 CSR 生成时添加了替代名称,所以我知道这是可行的(在生成和签名的默认 conf 文件中都有一些旁白)。

对于事后更改,据我所知,替代名称是扩展名,似乎您可以在签名时覆盖或添加所需的扩展名。我会无耻的复制:

From: Patrick Patterson @carillonis.com
Newsgroups: mailing.openssl.users
Subject: Re: Sign CSR after modifying data in CSR possible?
Date: Tue, 5 Jan 2010 15:14:05 -0500
Message-ID: <mailpost.1262722567.7762451.82829.mailing.openssl.users@FreeBSD.cs.nctu.edu.tw>
Run Code Online (Sandbox Code Playgroud)

当您使用 openssl CA(奇怪的是:openssl ca)命令时,您可以为其提供许多选项,包括使用哪个 Subject 值(-subj参数)以及使用哪些扩展(通过-extfile-extensions参数)。

因此您可以通过以下命令设置您想要的扩展名和您想要的主题(导致 CSR 中的两个值都被完全忽略):

openssl ca -config /etc/myca/openssl.cnf                       \
    -extfile /etc/myca/openssl-exts.cnf                        \
    -extension sig-medium                                      \
    -subj "/C=CA/O=Example Company/OU=Engineering/CN=John Doe" \
    -in req.csr                                                \
    -out john-doe.pem
Run Code Online (Sandbox Code Playgroud)

在哪里:

/etc/myca/openssl-exts.cnf 包含:

[ sig-medium ]
basicConstraints                = CA:FALSE
keyUsage                        = critical, digitalSignature
extendedKeyUsage                = emailProtection, anyExtendedKeyUsage
nsComment                       = "Do Not trust - PURE TEST purposes only"
subjectKeyIdentifier            = hash
authorityKeyIdentifier          = keyid,issuer
subjectAltName                  = @testsan
authorityInfoAccess             = @aia_points
crlDistributionPoints           = @crl_dist_points

[ testsan ]
email = test...@example.com
DNS = www.example.com
dirName = test_dir
URI = http://www.example.com/
IP = 172.16.0.1
otherName.0 = 1.3.6.1.4.1.311.20.2.3;UTF8:test@kerberose-domain.internal
otherName.1 = 1.3.6.1.5.5.7.8.7;IA5STRING:_mail.example.com
otherName.2 = 1.3.6.1.5.5.7.8.5;UTF8:testuser@im.example.com

[aia_points]
caIssuers;URI.0=http://www.example.com/caops/Signing-CA.p7c
caIssuers;URI.1=ldap://dir.example.com/<DN of Signing 
CA>?cACertificate;binary?base?objectclass=pkiCA

[crl_dist_points]
URI.0=http://www.example.com/caops/test-signca1-crl.crl
URI.1=ldap://dir.example.com/<DN of Signing 
CA>?certificateRevocationList;binary?base?objectclass=pkiCA
Run Code Online (Sandbox Code Playgroud)