為iOS的mobileconfig文件進行簽名


本文主要講,使用蘋果開發者證書進行簽名達到目的,本文兩種方法,一種是刀耕火種的一步步操作,一種使用腳本簽名

一.導出蘋果證書進行簽名

1.從鑰匙串(keychain)中導出證書

實用工具->鑰匙串訪問->選擇要導出的證書,導出生成p12文件 InnovCertificates.p12

然后轉換成 InnovCertificates.pem 文件

2. p12換成pem格式方法

p12在線轉換pem   https://www.sslshopper.com/ssl-converter.html

(證書)cer.p12文件 轉cer.pem文件

openssl pkcs12 -clcerts -nokeys -out cer.pem -in cer.p12

(私鑰)key.p12文件轉key.pem文件

openssl pkcs12 -nocerts -out key.pem -inkey.p12

3.下載 Apple Root Certificate 和 Apple Intermediate Certificate

(對於本篇文章 .mobileconfig文件的驗證我使用了蘋果的以下兩個證書.

Apple Root Certificate(蘋果根證書)

Apple Application Integration Certificate (蘋果應用集成證書 )

你也可以使用這些證書或者蘋果提供的其他證書 地址: http://www.apple.com/certificateauthority/

下載的文件中包括證書(cer)和私鑰(key)

(在命令行中讀取證書,參考鏈接 info.ssl.com/article.aspx?id=12149)

根據這個文件我們可以解壓出來證書.

2. p12換成pem格式方法

p12在線轉換pem   https://www.sslshopper.com/ssl-converter.html

(證書)cer.p12文件 轉cer.pem文件

openssl pkcs12 -clcerts -nokeys -out cer.pem -in cer.p12

(私鑰)key.p12文件轉key.pem文件

openssl pkcs12 -nocerts -out key.pem -inkey.p12

3.下載 Apple Root Certificate 和 Apple Intermediate Certificate

(對於本篇文章 .mobileconfig文件的驗證我使用了蘋果的以下兩個證書.

Apple Root Certificate(蘋果根證書)

Apple Application Integration Certificate (蘋果應用集成證書 )

你也可以使用這些證書或者蘋果提供的其他證書 地址: http://www.apple.com/certificateauthority/

下載的文件中包括證書(cer)和私鑰(key)

(在命令行中讀取證書,參考鏈接 info.ssl.com/article.aspx?id=12149)

根據這個文件我們可以解壓出來證書.

解壓 Apple Root Certificate證書. 然后解壓Apple Intermediate Certificate
openssl x509 -inform DER -outform PEM -in AppleIncRootCertificate.cer -out root.crt.pem
openssl x509 -inform DER -outform PEM -in AppleAAICA.cer -out Intermediate.crt.pem
 
在文本編輯器中打開兩個解壓出來的文件
復制並且粘貼 Intermediate.crt.pem root.crt.pem的開始位置,保存,然后你的root.crt.pem文件就是兩個證書合並的結果
 
4.簽名和驗證.mobileconfig文件

上邊所有文件准備號后,運行命令行工具,運行以下命令

1
openssl smime -sign -in Example.mobileconfig -out SignedVerifyExample.mobileconfig -signer InnovCertificates.pem -certfile root.crt.pem -outform der -nodetach
 
結果就是簽名並且驗證后的 .mobileconfig文件
 

二.腳本簽名

借助於強大的github,找到了一個python腳本進行簽名

地址:https://github.com/nmcspadden/ProfileSigner

1.簽名一個mobileconfig

profile_signer.py與 mobileconfig 放在同一目錄,終端進入目錄執行

1
./profile_signer.py -n "3rd Party Mac Developer Application" sign AcrobatPro.mobileconfig AcrobatProSigned.mobileconfig
2.加密一個mobileconfig
1
./profile_signer.py -n "3rd Party Mac Developer Application" encrypt AcrobatPro.mobileconfig AcrobatProEnc.mobileconfig
 
3.簽名並且加密一個mobileconfig
1
./profile_signer.py -n "3rd Party Mac Developer Application" both AcrobatPro.mobileconfig AcrobatProBoth.mobileconfig

"3rd Party Mac Developer Application"為你的證書在鑰匙串中的全名,選擇證書=>顯示簡介=>復制常用名稱加上引號即可,比如

"iPhone Developer: jakey.shao xxxx@xxx.com"

"iPhone Distribution: Skyfox Network Technology Co., Ltd."

66911171-EE9C-4DB7-BFCE-6564CC1B4E1A

如果能正確讀取到證書,會提示如上圖所示,點擊允許即可!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM