2009-09-21 48 views
16

我有一個從iPhone Developer門戶導出的'aps_developer_identity.cer'證書的卸載負載。它們都是使用相同的證書籤名請求和(因此)相同的私鑰創建的。如果我只從Apple Key Chain導出私鑰,則可以使用私鑰和「aps_developer_identity.cer」並使用openssl創建可在我的(Windows)服務器上使用的合併的p12/pkcs#12證書。aps_developer_identity.cer至p12,無需從鑰匙鏈導出?

要清楚的是,我知道如何通過將私鑰和證書導出到一起來從Key Chain獲取合併的p12,但是我想要刪除所有額外的鼠標單擊和打字,如果可以的話。

+0

「它們都是使用相同的證書籤名請求創建的」 - 爲什麼?在這種情況下,他們都將被命名爲相同的共同名稱,這是什麼目的? – NoBugs 2015-02-02 19:06:39

回答

35

我設法解決這個問題,它只是需要封裝在一個shell腳本中,它是很好的去。 我假設您已經下載並重命名了您的'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個月內過期。這是一個非常無聊和容易出錯的工作...

+0

「_CertificateSigningRequest.certSigningRequest」來自哪裏?我記得創建一個開發證書時曾經有一次這個文件O_o – 2011-01-06 18:55:55

+0

有關於如何在這裏創建CSR的詳細說明:http://jainmarket.blogspot.com/2009/11/generate-apple-push-notification .html 我在下面加了下劃線,因爲我和所有其他證書保持在同一個文件夾中,這樣它就是列表中的第一個... – withakay 2011-01-28 02:30:36

+1

_CertificateSigningRequest.certSigningRequest問題是絕對不清楚的,需要解釋。該鏈接沒有詳細說明這一點。我知道如何使用鑰匙串來製作一個,但是當我在上面的腳本中使用它時,我總是收到錯誤「沒有證書匹配私鑰」。爲什麼?到底什麼是certSigningRequest在上面提到? – Zigglzworth 2012-07-23 10:34:51

4

真棒工作在這裏。感謝真正的幫助人。我已經放在我的shell腳本下面,可以幫助其他人。我有幾個要處理的密鑰,並且需要一個腳本。這個腳本將輸出輸出文件的靜態名稱(儘管這很容易改變)。

我希望它可以幫助別人。

用法示例(假設腳本名稱):

$ . 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 
+0

謝謝。這非常有幫助。 – 2012-09-14 01:18:31

-2

可以使P12/PKCS#12證書直接在鑰匙串。 不需要執行任何命令。

1.雙擊一下就從蘋果開發網站下載你的開發/生產證書文件。(它會在鑰匙串添加)

2.我假設你有.p12文件,你從導出私鑰了

3.go添加到鑰匙串下的我的證書選項卡。

只需點擊爲APN.it你的開發/生產證書應該表現出與它

相關私鑰4.Right點擊和導出證書的.p12格式

這就是最終的.p12文件!

+0

我不認爲你在發佈這個答案之前閱讀這個問題。 OP明確指出他們不想使用鑰匙串。 – Jonathan 2014-10-29 04:34:03