使用keytool生成“过期”SSL证书

问题描述 投票:5回答:3

我使用以下命令创建我的密钥库:

keytool -genkey -keystore myStore.keystore -keyalg RSA -keysize 1024 -alias myAlias

我怎么能生成一个过期的过期日期(使用它?我想用过期的证书测试我的应用程序的行为)。

keystore keytool
3个回答
3
投票

使用java keytool,密钥库证书的最低有效期可以是1天。

编辑:看起来像@ shyam0191已经回答了-startdate的选项。

因此,您不能(更正:您实际上)可以生成具有过去日期的证书。我建议使用以下命令,该命令将生成一个有效期为1天的证书,第二天您将能够使用它进行测试:

keytool -selfcert -alias Test -genkey -keystore myStore.keystore -keyalg RSA -validity 1

或使用@ shyam0191的答案,最终会有相同的最终结果(但更快)。


9
投票

您可以使用以下参数使用keytool命令生成过期证书。

-开始日期

-validity

虽然有效性参数只需要输入天数,但是有效性开始时可以使用startdate参数。输入到startdate参数的格式[yyyy / mm / dd] [HH:MM:SS]

有关详细信息,请参阅此链接http://docs.oracle.com/javase/7/docs/technotes/tools/windows/keytool.html


0
投票

您可以使用以下openssl命令生成过期证书,这些证书模仿签署证书的官方流程。

注意:仅在Linux上测试过。

Assume yourself as a CA

#Create CA key, which means you are now the CA using root.key and root.cer to sign certificates
openssl genrsa 4096 > root.key
#Create CA certificate expired ten years later
openssl req -new -x509 -key root.key -out root.cer -days 3650

Now, you are the one applying a signed certificate from CA

#Generates your own private key 
openssl genrsa 4096 > server.key
#Build a Certificate Signing Request
openssl req -new -key server.key -out server.csr

Now you are the CA again

#sign the certificate and make the certificate expired 1 day ago. Pay attention to the negative -days argument( not working on MacOS )
openssl x509 -req -in server.csr -CA root.cer -CAkey root.key -CAcreateserial -out server.cer -days -1

Then you can check the dates

openssl x509 -noout -text -in server.cer

Validity Not Before: Mar 7 09:11:13 2019 GMT Not After : Mar 6 09:11:13 2019 GMT

© www.soinside.com 2019 - 2024. All rights reserved.