SSL 证书请求的非交互式创建

dot*_*hen 24 linux command-line-interface openssl apache-2.2

有没有办法通过在初始命令上指定所有必需的参数来创建 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 []:gustav@foobar.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:FooBar
Run Code Online (Sandbox Code Playgroud)

我希望看到这样的事情 :(不工作的例子)

$ 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 gustav@foobar.com \
-Company FooBar
Run Code Online (Sandbox Code Playgroud)

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

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

Arc*_*mar 23

你缺少两部分:

主题行,可以称为

-subj "/C=US/ST=New Sweden/L=Stockholm /O=.../OU=.../CN=.../emailAddress=..."
Run Code Online (Sandbox Code Playgroud)
  • 替换...与值,X=作为X509代码(ø rganisation / ö rganisation ü尼特/等...)

密码值,可以称为

-passout pass:client11
-passin  pass:client11
Run Code Online (Sandbox Code Playgroud)
  • 给出输出/输入密码

我对新钥匙的要求看起来像

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 -subj req -new \
    -passin pass:client11 -out lib/client1.csr \
    -subj "/C=US/ST=New Sweden/L=Stockholm/O=.../OU=.../CN=.../emailAddress=..."
Run Code Online (Sandbox Code Playgroud)

(现在我看到了,有两个-new......)


小智 7

我附加到我的常规 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"
Run Code Online (Sandbox Code Playgroud)

描述:

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

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

  • 赞成,因为这个答案更好地解释了要放入“-subj”行的数据 (3认同)