0

我正在尝试将 P12 文件转换为 PEM 文件。当我执行命令时,终端会询问我三件事:

P12 密码(我输入,回车)
PEM 密码(输入,回车)
PEM 密码确认(输入,回车)

我知道我可以使用以下命令一次性执行 sudo 命令:

echo sudopassword | sudo rm -rf /file.p12;

如何一次添加所有三个值?谢谢

4

4 回答 4

1

你能解释一下这些 P12 文件是什么吗?我发现这个链接处理使用 .PEM 将 pkcs12 证书/密钥文件转换为 .PEM 格式openssl。(http://gridsite.org)

答案的关键是:

用于无人-passin file:...值守-passout file:...处理

我猜你必须为这种情况指定-passin file:P12passphraseand-passout file PEMpassphrase选项。

这个小测试确认了如何通过file:<...>参数指定输入密码。这有助于隐藏此类短语免受任何过肩攻击。不要忘记限制对此类文件的访问。尽管它是大多数 openssl 命令的共同特征,但并未明确提及,它是原始问题的关键。完整的选项列表如下。

$ openssl pkcs12 -passin file:P12phrase
Can't open file P12phrase
Error getting passwords

(我把它留给 OP 来构建完整的命令。)

以下是pkcs12子命令的所有支持选项:

$ openssl pkcs12 help 
Usage: pkcs12 [options]
where options are
-export       output PKCS12 file
-chain        add certificate chain
-inkey file   private key if not infile
-certfile f   add all certs in f
-CApath arg   - PEM format directory of CA's
-CAfile arg   - PEM format file of CA's
-name "name"  use name as friendly name
-caname "nm"  use nm as CA friendly name (can be used more than once).
-in  infile   input filename
-out outfile  output filename
-noout        don't output anything, just verify.
-nomacver     don't verify MAC.
-nocerts      don't output certificates.
-clcerts      only output client certificates.
-cacerts      only output CA certificates.
-nokeys       don't output private keys.
-info         give info about PKCS#12 structure.
-des          encrypt private keys with DES
-des3         encrypt private keys with triple DES (default)
-aes128, -aes192, -aes256
              encrypt PEM output with cbc aes
-nodes        don't encrypt private keys
-noiter       don't use encryption iteration
-maciter      use MAC iteration
-twopass      separate MAC, encryption passwords
-descert      encrypt PKCS#12 certificates with triple DES (default RC2-40)
-certpbe alg  specify certificate PBE algorithm (default RC2-40)
-keypbe alg   specify private key PBE algorithm (default 3DES)
-keyex        set MS key exchange type
-keysig       set MS key signature type
-password p   set import/export password source
-passin p     input file pass phrase source
-passout p    output file pass phrase source
-engine e     use engine e, possibly a hardware device.
-rand file:file:...
              load the file (or the files in the directory) into
              the random number generator
-CSP name     Microsoft CSP name
-LMK          Add local machine keyset attribute to private key
于 2012-08-11T23:41:25.623 回答
0

这些命令不太可能从标准输入读取。他们更有可能直接从终端读取。这允许他们设置不将密码回显到屏幕的模式。尝试将您的输入回显到/dev/tty.

除此之外,您还需要使用诸如expect / pexect 之类的东西来控制这些。这些项目是专门为此目的而构建的。


Openssl 有一个 -stdin optoin 从标准输入读取其输入。这有效:

tmp=`mktemp`
cat > $tmp <<EOF                                                                                       







$1                                                                                      

EOF                                                                                     
cat $tmp | openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key 

我使用 cat 和 here-document 来避免将密码放在命令行上。

于 2012-08-11T23:44:00.940 回答
0

我用过openssl pkcs12 -in Certificates.p12 -out sampleCore.pem -nodes,它对我有用。

于 2020-04-26T12:44:21.893 回答
-1

您是否尝试过仅回显三行?它可能会工作

echo $'P12 passphrase\nPEM passphrase\nPEM passphrase confirm' | cmd

虽然我觉得我必须指出像这样的回显密码是非常不安全的。密码不仅最终出现在您的 bash 历史文件中,而且系统上运行ps.

于 2012-08-11T04:11:47.887 回答