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

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

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

 $ 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 (eg 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 

我希望看到这样的事情: (unworking例子)

 $ 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 

这个好人的页面没有什么可说的,我也没能通过Googlefind任何东西。 必须生成SSL证书请求是一个交互过程,还是有一些方法可以在一个命令中指定所有参数?

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

你缺less两部分:

主题行,可以被称为

 -subj "/C=US/ST=New Sweden/L=Stockholm /O=.../OU=.../CN=.../emailAddress=..." 
  • 用值replace…, X= X509代码(组织/组织…)

密码值,可以被称为

 -passout pass:client11 -passin pass:client11 
  • 它提供输出/input密码

我要求新的密钥看起来像

 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=..." 

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

按官方文档中所述检查-batch选项。