非交互式创建 SSL 证书请求

非交互式创建 SSL 证书请求

有没有办法通过在初始命令上指定所有必需的参数来创建 SSL 证书请求?我正在编写一个基于 CLI 的 Web 服务器控制面板我想避免使用预计如果可能的话,执行时openssl

这是创建证书请求的典型方法:

$ openssl req -new -newkey rsa:2048 -nodes -sha256 -keyout foobar.com.key -out foobar.com.csr
Generating a 2048 bit RSA private key
.................................................+++
........................................+++
writing new private key to 'foobar.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New Sweden
Locality Name (eg, city) []:Stockholm
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Scandanavian Ventures, Inc.
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:foobar.com
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:FooBar

我希望看到这样的事情: (无效示例)

$ openssl req -new -newkey rsa:2048 -nodes -sha256 -keyout foobar.com.key -out foobar.com.csr \
-Country US \
-State "New Sweden" \
-Locality Stockholm \
-Organization "Scandanavian Ventures, Inc." \
-CommonName  foobar.com \
-EmailAddress [email protected] \
-Company FooBar

精美的手册页对此事只字未提,我也没有办法通过 Google 找到任何内容。SSL 证书请求生成必须是一个交互式过程吗,或者是否有某种方法可以在单个命令中指定所有参数?

这是在运行的 Debian 衍生 Linux 发行版上openssl 1.0.1

答案1

你缺少两部分:

主题行,可以称为

-subj "/C=US/ST=New Sweden/L=Stockholm /O=.../OU=.../CN=.../emailAddress=..."
  • 用值替换...,X=即 X509 代码(组织/組織nit/等等... )

密码值,可以称为

-passout pass:client11
-passin  pass:client11
  • 给出输出/输入密码

我要求新的钥匙看起来像

openssl genrsa -aes256 -out lib/client1.key -passout pass:client11 1024
openssl rsa -in lib/client1.key -passin pass:client11 -out lib/client1-nokey.key

openssl req -new -key lib/client1.key \
    -passin pass:client11 -out lib/client1.csr \
    -subj "/C=US/ST=New Sweden/L=Stockholm/O=.../OU=.../CN=.../emailAddress=..."

答案2

我附加到我的常规 openssl 命令:

openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout /etc/ssl/private/key.pem -out /etc/ssl/private/cert.pem

这一行:

-subj "/C=PE/ST=Lima/L=Lima/O=Acme Inc. /OU=IT Department/CN=acme.com"

描述:

  • 国家名称(2 个字母代码)[AU]:PE
  • 州或省名称(全名)[Some-State]:Lima
  • 地点名称(例如城市)[]:利马
  • 组织名称(例如公司)[Internet Widgits Pty Ltd]:Acme Inc.
  • 组织单位名称(例如部门)[]:IT 部门
  • 通用名称(例如服务器 FQDN 或您的名称)[]:acme.com

使用“/”之类的分隔符。

答案3

检查-batch选项,如中所述官方文档

相关内容