do_convert_from_pkcs8:/dev/fd/63不是可识别的公钥格式



我正试图使用以下脚本检索我的PIV密钥:

getPIVkey.sh

NAME=`security find-certificate | grep PIV | sed 's;keychain:";;g' | sed 's;";;g'`
echo $NAME
ssh-keygen -i -m pkcs8 -f <(security find-certificate -p "$NAME" | openssl x509 -noout -pubkey)

在Mac OS High Sierra 10.13.4上。我得到:

./getPIVPub.sh

keychain: PIV-Bill K Brown (piv)
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
unable to load certificate
140735828857800:error:0906D06C:PEM routines:PEM_read_bio:no start line:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.50.2/libressl/crypto/pem/pem_lib.c:704:Expecting: TRUSTED CERTIFICATE
do_convert_from_pkcs8: /dev/fd/63 is not a recognised public key format

在第一个sed命令中,keychain:和引号之间似乎缺少一个空格。因此,设置NAME变量的命令应该是

NAME=`security find-certificate | grep PIV | sed 's;keychain: ";;g' | sed 's;";;g'`

使用改进的sed命令,NAME的(打印(值不应再以keychain:开头,而应仅包含名称。

由于NAME中的错误值,第二个security find-certificate命令失败,因此输出The specified output could not be found in the keychain.。之后执行的命令也会失败。

仅供参考,引用/dev/fd/63的原因在对以下问题的回答中有解释:为什么进程替换会导致一个名为/dev/fd/63的文件,它是一个管道?

最新更新