创建 EC CSR 时命名曲线或域参数

Named curves or domain parameters when creating an EC CSR

我正在使用 OpenSSL 为新证书创建 CSR。为了与现代兼容,我使用了 EC (secp521r1) 证书。在四处搜索时,我发现了两种不同的创建 CSR 的方法。

我可以显式创建私钥

openssl ecparam -name secp521r1 -genkey -param_enc explicit -out private.key
openssl req -new -sha256 -nodes -key private.key -out sslcert.csr -config san.cnf

或者我可以用请求

创建私钥
openssl ecparam -name secp521r1 > ec.file
openssl req -new -sha256 -nodes -newkey ec:ec.file -keyout private.key -out sslcert.csr -config san.cnf

这两种方法似乎都能创建有效的 CSR 文件(我已经对它们进行了测试 here)。

我的问题是上面的方法之一是better/safer吗?我注意到第一种方法生成的私钥文件比较大,CSR文件也比较大

例如,当我使用 openssl req -noout -text -in sslcert.csr 检查 CSR 时,第一种方法生成的 CSR 包含有关密钥的更多详细信息,其中包含 pub、[=15= 的部分]、ABGeneratorOrderCofactorSeed,但没有提到secp521r1

而第二种方法生成的CSR只有pub和一个ASN1 OID: secp521r1。如果我要创建用于 HTTPS 的证书,这些差异是否重要?

非常感谢!

For example, when I inspect the CSR using openssl req -noout -text -in sslcert.csr, the CSR generated by the first method contains much more detailed information about the key, with a section for pub, Prime, A, B, Generator, Order, Cofactor, Seed, but there is no mention of secp521r1.

这些被称为"domain parameters"。他们明确列出了模数、系数、生成器、public 点等

However, the CSR generated by the second method contains only pub and a ASN1 OID: secp521r1. Are these differences important if I'm creating certificates for HTTPS use?

ASN1 OID: secp521r1 这样的名字叫做 "named curve".

IETF 的 PKIX 和 TLS 工作组表示域参数和命名曲线 不是一回事。 PKIX 组负责互联网的 PKI 和证书。在 TLS 工作组邮件列表上对此进行了多次讨论。

如果您使用命名曲线,那么您的客户端和服务器将无法相互连接,即使域参数和命名曲线是等价的。您将收到类似于 "no shared cipher suites" 的错误,这将导致 TLS 警报。

如果您将域参数与命名曲线混合匹配,则在测试期间使用 s_clients_server 时会出现以下错误:

客户端 (s_client):

139925962778272:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:s3_pkt.c:1256:SSL alert number 40
139925962778272:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:s3_pkt.c:596:

服务器 (s_server):

140339533272744:error:1408A0C1:SSL routines:SSL3_GET_CLIENT_HELLO:no shared cipher:s3_srvr.c:1353:

为了互操作性,您应该始终 明确设置named_curve。另请参阅 OpenSSL wiki 上的 Elliptic Curve Cryptography | Named Curves


Both of these methods seem to create valid CSR files (I have tested them here).

他们有点做,但如果他们是mixed/matched,他们就不能很好地互操作。


For modern compatibility, I've gone with EC (secp521r1) certificates...

我最近没有调查过它,但 secp256r1 是(曾经是?)最受欢迎的。 这可能已经改变,但我不记得在任何地方读过它。也许扫描一下 Alexis 的前 100 万名就会给你一个想法或答案。

2016 年论文 TLS in the wild: An Internet-wide analysis of TLS-based protocols for electronic communication 说:

Looking at the elliptic curves that are used in ECDHE key exchanges reveals that 97.2% of connections use the secp256r1 curve, followed by 2% using secp384r1 and 0.78% using sect571r1.