我正在尝试创建自己的根 CA。
这是生成自签名根 key /证书的一种方法。
openssl req -x509 -nodes -newkey rsa:2048 -subj /CN=$1/countryName=UK/stateOrProvinceName=UK/organizationName=Me -keyout $1.key.pem -out $1.cert.pem
还有一个。
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 套接字连接失败并出现“未知”错误并且没有其他线索。我检查了客户端和服务器上是否使用了正确的证书。
我做错了什么?谢谢。
最佳答案
如果您使用 -days 36500
,则时间换回到 1975 年:
Validity
Not Before: Oct 18 11:57:31 2011 GMT
Not After : Aug 18 05:29:15 1975 GMT
使用较小的 -days 值。例如:
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
关于qt - 这两种OpenSSL生成方式的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7806621/