OpenSSL创建证书和密钥

7

[OpenSSL v1.1.0f]

我使用以下命令创建自签名证书,仅供测试目的:

$ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 10000 -nodes

然而,我收到的信息如下:
Can't open /usr/local/ssl/openssl.cnf for reading, No such file or directory
140480609138432:error:02001002:system library:fopen:No such file or directory:crypto/bio/bss_file.c:74:fopen('/usr/local/ssl/openssl.cnf','r')
140480609138432:error:2006D080:BIO routines:BIO_new_file:no such file:crypto/bio/bss_file.c:81:
Generating a 4096 bit RSA private key
..................................++
.................................................................................................................................................................................................................++
writing new private key to 'key.pem'
-----
unable to find 'distinguished_name' in config
problems making Certificate Request
140480609138432:error:0E06D06A:configuration file routines:NCONF_get_string:no conf or environment variable:crypto/conf/conf_lib.c:272:

我该怎么做来解决这个问题?


你是用什么方式安装了openssl?使用sudo apt-get install libssl-dev命令吗? - Stepan Novikov
1个回答

7

通常openssl会使用默认配置,但似乎您没有将其放置在正确的位置。您还可以将配置文件作为命令行参数传递。请注意-config选项。

openssl req -x509 -config openssl.cnf -newkey rsa:4096 -keyout key.pem -out cert.pem -days 10000 -nodes

2
谢谢。openssl.cnf文件至少应包含什么内容? - Mark X
2
最佳的信息来源应该在openssl文档中找到。你也可以直接从github下载openssl.cnf,这可能是最简单的方法,因为你只需要一个用于测试的东西。 - Marek Klein
该命令和使用openssl.cnf对我没用。在Windows上出现错误20636:error:0E06D06A:configuration file routines:NCONF_get_string:no conf or environment variable:crypto\conf\conf_lib.c:270: - tryingHard

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