web-dev-qa-db-ja.com

キーチェーンからエクスポートすることなく、aps_developer_identity.cerをp12に?

IPhone開発者ポータルからエクスポートされたshed loadの「aps_developer_identity.cer」証明書があります。これらはすべて、同じ証明書署名要求と(したがって)同じ秘密鍵を使用して作成されました。 Apple Key Chainから秘密鍵のみをエクスポートする場合、秘密鍵と「aps_developer_identity.cer」を取得し、opensslを使用して、マージされたp12/pkcs#12証明書を作成することができます。 (Windows)サーバーで使用できます。

明確にするために、秘密キーと証明書の両方を一緒にエクスポートして、キーチェーンからマージされたp12を取得する方法を知っていますが、可能な場合は、余分なマウスのクリックと入力をすべて削除したいと思います。

21
withakay

私はなんとかこれを解決することができました、それはシェルスクリプトでラップする必要があるだけです。 「Apple_developer_identity.cer」証明書をダウンロードして名前を変更したと仮定します。ここでは「test.cer」を使用しています。また、以下の「private_dev_key.p12」という名前の例では、キーチェーンから開発者キーもエクスポートしていると想定しています。

#convert *.cer (der format) to pem
openssl x509 -in test.cer -inform DER -out test.pem -outform PEM

#convert p12 private key to pem (requires the input of a minimum 4 char password)
openssl pkcs12 -nocerts -out private_dev_key.pem -in private_dev_key.p12

# if you want remove password from the private key
openssl rsa -out private_key_noenc.pem -in private_key.pem

#take the certificate and the key (with or without password) and create a PKCS#12 format file
openssl pkcs12 -export -in test.pem -inkey private_key_noenc.pem -certfile _CertificateSigningRequest.certSigningRequest  -name "test" -out test.p12

注:マウスを数回クリックしてファイル名を入力するだけでできることを実現するのに少し時間がかかると思われる場合は、通知を有効にするアプリが20個ある場合を考えてください。各アプリには開発証明書と製品証明書があり、それぞれ4か月と12か月で有効期限が切れます。それは非常に退屈でエラーが発生しやすい仕事です...

38
withakay

ここで素晴らしい仕事。本当に助けてくれてありがとう。他の人を助けるかもしれない以下のシェルスクリプトをドロップしました。対処するキーがいくつかあり、スクリプトも必要でした。このスクリプトは、出力ファイルの静的名を出力します(変更は簡単ですが)。

私はそれが誰かを助けることを望みます。

使用例(スクリプト名を想定):

$ . thisScript request_file.cer priv_key.p12 aps_dev.cer

スクリプト:

if [ $# -ne 3 ]
then
echo "Error in $0 - Invalid Argument Count"
echo "Syntax: $0 request_cer_file p12_file app_cer_file output_filename"
echo "  - request_cer_file      is the request file you sent to Apple"
echo "  - p12_file          is found in your keychain (it's the private key)"
echo "  - app_cer_file          is found on App ID screen from Apple"
else

reqFile=$1
p12File=$2
cerFile=$3

certPEM='apn_cert.pem'
pKeyPEM='apn_pkey.pem'
pKeyNoEncPEM='apn_pkey_noenc.pem'
p12FileOut='apn_cert_key.p12'

# remove old
rm $certPEM
rm $pKeyPEM
rm $pKeyNoEncPEM
rm $p12FileOut

#convert *.cer (der format) to pem
openssl x509 -in $cerFile -inform DER -out $certPEM -outform PEM

#convert p12 private key to pem (requires the input of a minimum 4 char password)
openssl pkcs12 -nocerts -out $pKeyPEM -in $p12File

# if you want remove password from the private key
openssl rsa -out $pKeyNoEncPEM -in $pKeyPEM

#take the certificate and the key (with or without password) and create a PKCS#12 format file
openssl pkcs12 -export -in $certPEM -inkey $pKeyNoEncPEM -certfile $reqFile  -name "apn_identity" -out $p12FileOut

#
#   
#   If all things worked then the following should work as a test
#   openssl s_client -connect gateway.sandbox.Push.Apple.com:2195 -cert apn_cert.pem -key apn_pkey_noenc.pem 
#
#
echo "Looks like everything was successful"
echo "Test command:"
echo "openssl s_client -connect gateway.sandbox.Push.Apple.com:2195 -cert apn_cert.pem -key apn_pkey_noenc.pem"
echo
fi
4
bladnman