无法通过stdin将证书和密钥提供给openssl

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

我跟着steps listed here创建了一个新的私钥和证书。现在我试图将它们组合成一个.pfx文件。

OpenSSL应该能够从单个文件中读取私钥和证书,并且根据人man文档,也应该能够从stdin读取。但是,这对我来说似乎不起作用。

在Mac OS X 10.14.3和openssl version上给出了“LibreSSL 2.6.5”。

我将证书和密钥合并到一个文件中(称为“combined.pem”)。我使用以下命令执行此操作:

$ openssl genrsa -out private.key 2048
$ openssl req -new -x509 -key private.key -out public.cer -days 365
$ cat public.cer >> combined.pem
$ cat private.key >> combined.pem

作为参考,combined.pem看起来像这样:

-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----

当我运行以下命令时,一切正常:

$ openssl pkcs12 -export -out x509.pfx -in combined.pem

当我运行此命令时,出现错误:

$ openssl pkcs12 -export -out x509.pfx < combined.pem
unable to load certificates

我也尝试过:

$ cat combined.pem | openssl pkcs12 -export -out x509.pfx
unable to load certificates

我错过了什么? OpenSSL真的无法从stdin读取这个吗?

另外,来自man文档:

     -in file
           The input file to read from, or standard input if not specified.  The order doesn't matter but one private key and its corresponding certificate should
           be present.  If additional certificates are present, they will also be included in the PKCS#12 file.

     -inkey file
           File to read a private key from.  If not present, a private key must be present in the input file.
openssl x509
1个回答
0
投票

从我收集的from this question OpenSSL确实不能与stdin开箱即用。你可以尝试的一件事是使用一些技巧:

openssl pkcs12 -export -out x509.pfx -in /dev/stdin < combined.pem

我没有测试过您的特定证书组合案例,但/dev/stdin重定向部分应该可以让您在OpenSSL中具有“stdin-like”功能


0
投票

使用标准输入时,有几个命令行实用程序需要破折号; openssl x509似乎遵循这个(在Ubuntu 18.04上测试,所以我合理地期望这是可移植的语法)。

cat combined.pem | openssl pkcs12 -export -out x509.pfx -in -
© www.soinside.com 2019 - 2024. All rights reserved.