更改openssl自签名证书的开始和结束日期

更改openssl自签名证书的开始和结束日期,openssl,Openssl,我用这三条语句生成一个自签名证书,其中包含我拥有的根证书 openssl genrsa -out domain.org.key openssl req -newkey rsa:2048 -nodes -keyout domain.org.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=*.domain.org" -out domain.org.csr openssl x509 -req -extfile <(printf "subjectAltNam

我用这三条语句生成一个自签名证书,其中包含我拥有的根证书

openssl genrsa -out domain.org.key
openssl req -newkey rsa:2048 -nodes -keyout domain.org.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=*.domain.org" -out domain.org.csr
openssl x509 -req -extfile <(printf "subjectAltName=DNS:domain.org,DNS:www.domain.org") -days 1 -in domain.org.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out domain.org.crt

但我不知道如何将两者结合起来,因为第二个命令似乎只是在为域生成一个密钥。有谁能帮我把这两个命令结合起来,或者用其他方式改变证书时间,而不需要改变我的系统时间

openssl命令行不提供命令行选项来设置“x509-req”选项的开始和结束日期

如果您真的需要这样做,您可以修改openssl源代码来做您想做的事情

在app\req.c中,您需要修改“设置证书时间”调用:

如果您提供startdate和enddate,它将覆盖days参数,因此您可以执行以下操作:

if (!set_cert_times(x509ss, "0801010000Z", "1001010000Z", days))
    goto end;

这将对开始日期和结束日期进行硬编码,或者您可以在x509-req处理中添加对-startdate和-enddate参数的支持。

谢谢您的回答!我是否必须更改代码,然后重新编译openssl以再次使用它?还有,有没有一种方法可以这样做,我可以给出开始和结束时间作为参数?是的,是的。如果查看req.c文件,您可以看到-req选项的参数处理,您应该能够很容易地添加对这些参数的支持。我假设你懂C语言。我可以阅读并理解C,但不是很擅长。我猜想,如果我在
req\u options
OPTION\u choice
(链接如下)中添加一个新参数,然后在第249行开始的开关案例中提取该值,然后对
设置证书时间
进行更改,它应该可以工作了?应该可以。您可以从apps\ca.cpp复制startdate/enddate选项处理行,这会让您更轻松。哦,很好,谢谢您指出这一点!我会看看进展如何,我会把它贴在这里。
    if (days == 0) {
        /* set default days if it's not specified */
        days = 30;
    }
    if (!set_cert_times(x509ss, NULL, NULL, days))
        goto end;

int set_cert_times(X509 *x, const char *startdate, const char *enddate,
                   int days)
if (!set_cert_times(x509ss, "0801010000Z", "1001010000Z", days))
    goto end;