腳本中的命令失敗?

腳本中的命令失敗?

我正在嘗試編寫 OpenSSLec命令腳本。該腳本用於驗證另一個庫產生的密鑰集合。問題後的腳本如下所示。

從終端進行以下工作:

openssl ec -in ec-enc-priv-xxx.pem -passin pass:test -text -noout

從終端進行以下工作:

openssl ec -in ec-enc-priv-xxx.pem -passin pass:test -text -noout >/dev/null

但是,當我編寫最後一個腳本時,系統會提示我輸入密碼:

$ ./pem-verify.sh 
read RSA key
read RSA key
read RSA key
read DSA key
read DSA key
read DSA key
read EC key
read EC key
Enter PEM pass phrase:

相同的程式碼適用於腳本中的 RSA 和 DSA 金鑰。該問題僅與加密的 EC 私鑰有關。

有什麼想法可以解決這個問題嗎?


#! /bin/sh

# Script to verify the test keys written by pem-test.cpp

#################
# RSA keys

# The RSA command returns 0 on success

openssl rsa -in rsa-pub-xxx.pem -pubin -text -noout >/dev/null
RET=$?
if [ $RET -ne 0 ];then
  echo "Failed to read RSA public key"
fi

openssl rsa -in rsa-priv-xxx.pem -text -noout >/dev/null
RET=$?
if [ $RET -ne 0 ];then
  echo "Failed to read RSA private key"
fi

openssl rsa -in rsa-enc-priv-xxx.pem -passin pass:test -text -noout >/dev/null
RET=$?
if [ $RET -ne 0 ];then
  echo "Failed to read encrypted RSA private key"
fi

#################
# DSA keys

# The DSA command is broken. It returns 1 when using '-noout' option
#  instead of 0. A patch was submitted to RT.

openssl dsa -in dsa-pub-xxx.pem -pubin -text -noout >/dev/null

openssl dsa -in dsa-priv-xxx.pem -text -noout >/dev/null

openssl dsa -in dsa-enc-priv-xxx.pem -passin pass:test -text -noout >/dev/null

#################
# EC keys

# The EC command returns 0 on success

openssl ec -in ec-pub-xxx.pem -pubin -text -noout >/dev/null
RET=$?
if [ $RET -ne 0 ];then
  echo "Failed to read EC public key"
fi

openssl ec -in ec-priv-xxx.pem -text -noout >/dev/null
RET=$?
if [ $RET -ne 0 ];then
  echo "Failed to read EC private key"
fi

openssl ec -in ec-enc-priv-xxx.pem -passin pass:test -text -noout >/dev/null
RET=$?
if [ $RET -ne 0 ];then
  echo "Failed to read encrypted EC private key"
fi

答案1

我鄙視這類答案,但自從重新啟動 MacBook Pro 後我就無法重複這個問題了。所以這個例子中的答案似乎是重新啟動。嘆...

由於該問題不可重現,因此請結束該問題。

相關內容