是否可以让 openssl 跳过国家/通用名称提示?

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

有没有办法让openssl跳过诸如

之类的提示
Country Name (2 letter code) [US]:
Organization Name (eg, company) [My Company Name LTD.]:
Common Name (eg, YOUR name) [something]:

使用

创建证书时
openssl req -config openssl.cnf -new -x509 ...

鉴于这些参数在

openssl.cnf
文件中提供

例如

countryName         = Country Name (2 letter code)
countryName_default     = US
countryName_min     = 2
countryName_max     = 2
0.organizationName      = Organization Name (eg, company)
0.organizationName_default  = My Company Name LTD.
commonName          = Common Name (eg, YOUR name)
commonName_max      = 64
commonName_default      = ${ENV::CN}
openssl
5个回答
159
投票

感谢@indiv

根据这个指南

-subj
是要走的路,例如

-subj '/CN=www.mydom.com/O=My Company Name LTD./C=US'

47
投票

另一个解决方案包括在配置文件中使用

prompt = no
指令。
请参阅OpenSSL:配置文件格式

prompt

如果设置为值

no
,则会禁用证书字段的提示,并直接从配置文件中获取值。它还更改了
distinguished_name
attributes
部分的预期格式。

distinguished name
attribute
部分有两种不同的格式。

如果提示选项设置为

no
,那么这些部分仅包含字段名称和值:例如,

CN = My Name
OU = My Organization
emailAddress = [email protected]

这允许外部程序(例如基于 GUI)生成包含所有字段名称和值的模板文件,并将其传递给

req

或者,如果提示选项不存在或未设置为“否”,则文件包含字段提示信息。它由以下形式的行组成:

fieldName="prompt"
fieldName_default="default field value"
fieldName_min= 2
fieldName_max= 4

20
投票

生成一个配置文件,在 [req] 部分你可以输入prompt = no。

例如:

[req]
prompt = no
distinguished_name = req_distinguished_name
req_extensions = v3_req

[req_distinguished_name]
C = US
ST = California
L = Los Angeles
O = Our Company Llc
#OU = Org Unit Name
CN = Our Company Llc
#emailAddress = [email protected]

[v3_req]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = example.com
DNS.2 = www.example.com

然后执行例如

openssl req -new -sha256 -config THATFILE.conf -key example.com.key -out example.com.csr

10
投票

不支持混合方法

可能直观地认为混合方法是可能的,您可能会考虑在 openssl.cnf 中放置一些静态字段并通过

-subj
选项指定一些(CN)。然而,这不起作用。

我测试了一个场景,其中我

  • 将 C、ST、L、O 和 OU 放入 openssl.cnf 部分
    req_distinguished_name
  • openssl req
    -subj=/CN=www.mydom.com

openssl 抱怨缺少强制性国家/地区名称字段,并且生成的证书在主题行中只有 CN。似乎

-subj
选项完全覆盖主题行并且不允许更新单个字段。

这使得以下三种提供主题字段的方法彼此互斥:

  • 提示
  • 配置文件
  • -subj
    选项

6
投票

-batch
可选参数导致
openssl req
命令不提示输入任何信息字段。我以这种方式使用它,无需显式配置文件来实现自签名证书的自动化。

帮助中列出了:

openssl help req
...
...
-batch              Do not ask anything during request generation
© www.soinside.com 2019 - 2024. All rights reserved.