这两种 OpenSSL 生成方法的区别

3

我想创建自己的根证书颁发机构。

这里有一种生成自签名根密钥/证书的方法。

openssl req -x509 -nodes -newkey rsa:2048 -subj /CN=$1/countryName=UK/stateOrProvinceName=UK/organizationName=Me -keyout $1.key.pem -out $1.cert.pem

And here's another.

openssl genrsa -des3 -out $1.key.pem 2048
openssl req -new -subj /CN=$1/countryName=UK/stateOrProvinceName=UK/organizationName=Me -key $1.key.pem -out $1.csr
openssl x509 -req -days 36500 -in $1.csr -signkey $1.key.pem -out $1.crt.pem

如果我使用第一个证书创建客户端和服务器连接(使用QSslSocket),那么连接就会成功。问题是证书上的日期为1975年,我无法用它来签署其他证书。
我构建了第二种方法来生成一个有效日期的根证书,但SSL套接字连接失败,并显示“未知”错误,没有其他线索。我检查了客户端和服务器上正在使用正确的证书。
我做错了什么?谢谢。
1个回答

2
如果您使用-days 36500,则时间会回溯到1975年。
    Validity
        Not Before: Oct 18 11:57:31 2011 GMT
        Not After : Aug 18 05:29:15 1975 GMT

使用较小的“天数”值。例如:
openssl req -x509 -days 3000 -nodes -newkey rsa:2048 -subj /CN=xx/countryName=UK/stateOrProvinceName=UK/organizationName=Me -keyout xx.key.pem -text -out xx.cert.pem

然后您应该获取有效的日期:

    Validity
        Not Before: Oct 18 12:01:17 2011 GMT
        Not After : Jan  4 12:01:17 2020 GMT

啊,http://www.wolframalpha.com/input/?i=days+between+now+and+2038?我现在无法测试,但看起来就是它 :-) - spraff

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接