OpenSSL 在配置文件中找不到 Distinguished_name

Emm*_*e19 7 windows openssl

当尝试在 Windows 上通过 openssl 生成 csr 时,我收到错误消息“无法在配置中找到‘distinguished_name’”。我以前已经这样做过,没有任何问题,但似乎无法弄清楚为什么它现在不这样做。

我的配置文件(request.txt):

[req]
default_bits           = 2048
prompt                 = no
default_md             = sha384
req_extensions         = req_ext
distinguished_name     = req_distinguished_name

[req_distinguished_name]
countryName            = US
stateOrProvinceName    = Nevada
organizationName       = OrgName
organizationalUnitName = DepName
commonName             = <snip-fqdn>
emailAddress           = <snip-email>

[req_ext]
subjectAltName         = @alt_names

[alt_names]
DNS.1                  = <snip-fqdn1>
DNS.2                  = <snip-fqdn2>
IP.1                   = <snip-ip>
Run Code Online (Sandbox Code Playgroud)

我用来生成 csr 的命令(OpenSSL 是 openssl.exe 的 PowerShell 别名):

OpenSSL req -newkey rsa:2048 -keyout key.pem -nodes -out request.csr -config request.txt
Run Code Online (Sandbox Code Playgroud)

这会导致错误,指出在配置中找不到 Distinguished_name:

req: Error on line 1 of config file "H:\path\to\request.txt"
Generating a RSA private key
................+++++
..........+++++
writing new private key to 'H:\path\to\key.pem'
-----
unable to find 'distinguished_name' in config
problems making Certificate Request
3252:error:0E06D06A:configuration file routines:NCONF_get_string:no conf or environment variable:crypto\conf\conf_lib.c:270:
Run Code Online (Sandbox Code Playgroud)

区别名是在配置中定义的,所以我不确定 openssl 在这里是什么。我真的对这个不知所措。有任何想法吗?

小智 2

看来这是你真正的错误:

req: Error on line 1 of config file "H:\path\to\request.txt"
Run Code Online (Sandbox Code Playgroud)

这可能是由于文件第一行中的奇怪字符或空格引起的requests.txt