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 "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
但是,在这里只能将有效期更改为一天。有谁知道我是否可以添加一个参数来让我将开始日期和结束日期更改为秒或分钟的粒度。出于测试目的,我需要创建几个有效期仅几分钟变化的证书。我查看了其他答案,他们建议使用以下ca
命令:
openssl ca -config /path/to/myca.conf -in req.csr -out ourdomain.pem \
-startdate 0801010000Z -enddate 1001010000Z
但我不确定如何将两者结合起来,因为第二个命令似乎只是为域生成一个密钥。任何人都可以帮助组合这两个命令,或者以其他不涉及更改我的系统时间的方式更改证书时间。
解决方案
openssl 命令行不提供命令行选项来设置“x509 -req”选项的开始和结束日期。
如果你真的需要这样做,你可以修改 openssl 源代码来做你想做的事。
在 app\req.c 中,您需要修改“set_cert_times”调用:
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)
如果您提供 startdate 和 enddate,它将覆盖 days 参数,因此您可以这样做:
if (!set_cert_times(x509ss, "0801010000Z", "1001010000Z", days))
goto end;
这将对开始和结束日期进行硬编码,或者通过更多的工作,您可以在 x509 -req 处理中添加对 -startdate 和 -enddate 参数的支持。
推荐阅读
- sql - 如何使用在 postgres 中创建期间设置的默认值更新列?
- jupyter-notebook - 从 miniforge 安装后,某些模块无法在 jupyter notebook 上导入
- sql - 创建新列并填充条件格式数据
- kotlin - 如何使用 Android 两种方式绑定在 EditText 中设置正则表达式?
- python - 在 Selenium/chromedriver 上几次刷新后显示 reCAPTCHA
- javascript - 如何在 Laravel Mix 中使用全局 JS 变量?
- asp.net - PayPal 中的订阅
- nginx - 使用 NGINX 代理 http GSSAPI 保护端点
- typescript - 打字稿界面对象键
- azure-devops - 阻止用户在 azure devops 中创建超过 5 个工作项