主题备用名称未复制到签名证书

Subject Alternative Name is not copied to signed certificate

我使用自签名 CA 证书来签署其他证书。对于某些证书,我需要指定主题备用名称。我可以在请求生成期间指定它们 (openssl req ...),并且我在 .csr 文件中看到它们。然后我使用

使用 CA 证书对其进行签名
openssl x509 -req -extensions x509v3_config -days 365 -in ${name}.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out ${name}.crt

以及 openssl.cnf 文件中的后续部分:

[ x509 ]
x509_extensions = x509v3_config

[ x509v3_config ]
copy_extensions = copy

但我在 .crt 文件中看不到 SAN。

我知道 solutionsopenssl ca ... 命令,但我没有有效的 [ca] 部分,我不想在不深入了解它的作用的情况下 copy/paste 它.所以我希望存在另一个使用 openssl x509 ... 命令的解决方案。

copy_extensions 指令只能被 openssl ca 命令理解。无法使用 openssl x509 命令将扩展名从 CSR 复制到证书。

相反,您应该指定 exact 作为 openssl x509 命令的一部分的扩展,使用与 openssl req 相同的指令。

抱歉,我还不能发表评论。

除了@frasertweedale:

我使用配置文件生成了我的服务器证书

openssl req -new -out certificate.csr -key certificate_private_key.pem -sha256 -days 1825 -config certificate.conf 

然后我做了

Instead, you should specify the exact extensions you want as part of the OpenSSL x509 command, using the same directives you used for OpenSSL req.

使用以下命令(我再次使用相同的 .conf 文件):

openssl x509 -req -in certificate.csr -CA ca-root-public-certificate.pem -CAkey ca-key.pem -CAcreateserial -out certificate_public.pem -sha256 -days 1825 -extfile certificate.conf -extensions v3_req

这里有一个很好的文档:Certificates

您需要在创建 x509 证书请求时编写一个 openssl conf 文件,如下所示:

创建 CSR

openssl req -new -key server.key -out server.csr -config csr.conf

签署 CERT

openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 10000 -extensions v3_ext -extfile csr.conf