1. 程式人生 > IOS開發 >iOS MDM詳解(3)— 生成mobileconfig配置檔案及簽名

iOS MDM詳解(3)— 生成mobileconfig配置檔案及簽名

簡介

配置描述檔案是一個用於安裝到裝置的XML格式的檔案,包含了相關的配置資訊。

比如:

  • 裝置安全性策略和訪問限制
  • VPN 配置資訊
  • Wi-Fi 設定
  • 密碼策略設定
  • 移動裝置管理
  • 郵件和日曆帳戶等

製作一個配置檔案可以iPhone配置使用工具手寫XML檔案兩種方式。為了方便操作我用了前者(網上說這個已被蘋果拋棄,好像不影響檔案生成)。

###用iPhone配置使用工具生成配置檔案 開啟檔案——新建配置檔案,主要涉及使用到的配置如下:

Snip20170502_3.png

  • 通用:設定配置檔案的基本資訊,其中標示符和APP ID類似,安全性表示是否可移除該描述檔案預設總是允許刪除、可選擇永不:表示禁止刪除,使用授權:表示需要密碼驗證

  • 限制:設定裝置訪問許可權,比如是否允許安裝應用、是否允許相機、iCloud等,按預設設定即可。

  • 憑證:用於和MDM Server 認證的一個p12格式的證書檔案(注意:這個p12 和蘋果開發者中心的證書沒有關係、真的沒有關係,他們只是P12格式而已。這個是有Server提供的用於HTTPS通訊相關的用於之間認證的一個檔案(Server 生成的CA證書的祕鑰檔案),是https通訊所需要的)。

  • 移動裝置管理:這一步配置尤為關鍵,設定如下。

Snip20170502_4.png

  • 伺服器URL:設備註冊後以後每次連線的URL地址。
  • 登記URL:首次設備註冊的地址,包括認證和更新token操作。
  • 主題:在上一篇證書製作中提到的 使用者ID : com.apple.mgmt.External.*。
  • 身份:在憑證中新增的證書。
  • 移除時檢查:當為TRUE,當用戶刪除裝置上的配置檔案時裝置會向登記URL傳送個訊息表示配置檔案要刪除了,MDM Serve可以依此來檢測裝置是否還在監控中。
  • 訪問許可權:按預設即可。
  • Apple 推送通知服務:選中表示使用的開發環境APNs,這裡不要選中。

至此配置設定基本完成,儲存、匯出會提示給配置檔案簽名,選擇無即可。

生成的完整的XML檔案

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
> <plist version="1.0"> <dict> <key>PayloadContent</key> <array> <dict> <key>PayloadDescription</key> <string>配置訪問限制</string> <key>PayloadDisplayName</key> <string>訪問限制</string> <key>PayloadIdentifier</key> <string>com.apple.applicationaccess.C6130962-2621-47FD-8E9C-8832BCE3C5B0</string> <key>PayloadType</key> <string>com.apple.applicationaccess</string> <key>PayloadUUID</key> <string>C6130962-2621-47FD-8E9C-8832BCE3C5B0</string> <key>PayloadVersion</key> <integer>1</integer> <key>allowActivityContinuation</key> <true/> <key>allowAddingGameCenterFriends</key> <true/> <key>allowAppCellularDataModification</key> <true/> <key>allowAppInstallation</key> <true/> <key>allowAppRemoval</key> <true/> <key>allowAssistant</key> <true/> <key>allowAssistantWhileLocked</key> <true/> <key>allowAutoCorrection</key> <true/> <key>allowAutomaticAppDownloads</key> <true/> <key>allowBluetoothModification</key> <true/> <key>allowBookstore</key> <true/> <key>allowBookstoreErotica</key> <true/> <key>allowCamera</key> <true/> <key>allowChat</key> <true/> <key>allowCloudBackup</key> <true/> <key>allowCloudDocumentSync</key> <true/> <key>allowCloudPhotoLibrary</key> <true/> <key>allowDefinitionLookup</key> <true/> <key>allowDeviceNameModification</key> <true/> <key>allowEnablingRestrictions</key> <true/> <key>allowEnterpriseAppTrust</key> <true/> <key>allowEnterpriseBookBackup</key> <true/> <key>allowEnterpriseBookMetadataSync</key> <true/> <key>allowEraseContentAndSettings</key> <true/> <key>allowExplicitContent</key> <true/> <key>allowFingerprintForUnlock</key> <true/> <key>allowFingerprintModification</key> <true/> <key>allowGameCenter</key> <true/> <key>allowGlobalBackgroundFetchWhenRoaming</key> <true/> <key>allowInAppPurchases</key> <true/> <key>allowKeyboardShortcuts</key> <true/> <key>allowManagedAppsCloudSync</key> <true/> <key>allowMultiplayerGaming</key> <true/> <key>allowMusicService</key> <true/> <key>allowNews</key> <true/> <key>allowNotificationsModification</key> <true/> <key>allowOpenFromManagedToUnmanaged</key> <true/> <key>allowOpenFromUnmanagedToManaged</key> <true/> <key>allowPairedWatch</key> <true/> <key>allowPassbookWhileLocked</key> <true/> <key>allowPasscodeModification</key> <true/> <key>allowPhotoStream</key> <true/> <key>allowPredictiveKeyboard</key> <true/> <key>allowRadioService</key> <true/> <key>allowRemoteScreenObservation</key> <true/> <key>allowSafari</key> <true/> <key>allowScreenShot</key> <true/> <key>allowSharedStream</key> <true/> <key>allowSpellCheck</key> <true/> <key>allowSpotlightInternetResults</key> <true/> <key>allowUIAppInstallation</key> <true/> <key>allowUIConfigurationProfileInstallation</key> <true/> <key>allowUntrustedTLSPrompt</key> <true/> <key>allowVideoConferencing</key> <true/> <key>allowVoiceDialing</key> <true/> <key>allowWallpaperModification</key> <true/> <key>allowiTunes</key> <true/> <key>forceAirDropUnmanaged</key> <false/> <key>forceAssistantProfanityFilter</key> <false/> <key>forceEncryptedBackup</key> <false/> <key>forceITunesStorePasswordEntry</key> <false/> <key>forceWatchWristDetection</key> <false/> <key>ratingApps</key> <integer>1000</integer> <key>ratingMovies</key> <integer>1000</integer> <key>ratingRegion</key> <string>us</string> <key>ratingTVShows</key> <integer>1000</integer> <key>safariAcceptCookies</key> <integer>2</integer> <key>safariAllowAutoFill</key> <true/> <key>safariAllowJavaScript</key> <true/> <key>safariAllowPopups</key> <true/> <key>safariForceFraudWarning</key> <false/> </dict> <dict> <key>PayloadDescription</key> <string>配置密碼設定</string> <key>PayloadDisplayName</key> <string>密碼</string> <key>PayloadIdentifier</key> <string>com.apple.mobiledevice.passwordpolicy.B52AEECB-63DD-4B05-AFB2-6B547038F8D7</string> <key>PayloadType</key> <string>com.apple.mobiledevice.passwordpolicy</string> <key>PayloadUUID</key> <string>B52AEECB-63DD-4B05-AFB2-6B547038F8D7</string> <key>PayloadVersion</key> <integer>1</integer> <key>allowSimple</key> <true/> <key>forcePIN</key> <true/> <key>requireAlphanumeric</key> <false/> </dict> <dict> <key>Password</key> <string>123456</string> <key>PayloadCertificateFileName</key> <string>out.p12</string> <key>PayloadContent</key> <data> //證書內容base64編碼的字串 </data> <key>PayloadDescription</key> <string>提供裝置鑑定(證書或身份)。</string> <key>PayloadDisplayName</key> <string>out.p12</string> <key>PayloadIdentifier</key> <string>com.apple.security.pkcs12.ACACFDA4-64B4-46D5-A8BD-DB241775A394</string> <key>PayloadOrganization</key> <string>Gener-Tech</string> <key>PayloadType</key> <string>com.apple.security.pkcs12</string> <key>PayloadUUID</key> <string>ACACFDA4-64B4-46D5-A8BD-DB241775A394</string> <key>PayloadVersion</key> <integer>1</integer> </dict> <dict> <key>AccessRights</key> <integer>8191</integer> <key>CheckInURL</key> <string>https://www..../checkin.do?deviceId=fc97f6b4524346a18f14d1a425986abb</string> <key>CheckOutWhenRemoved</key> <true/> <key>IdentityCertificateUUID</key> <string>ACACFDA4-64B4-46D5-A8BD-DB241775A394</string> <key>PayloadDescription</key> <string>配置“移動裝置管理”</string> <key>PayloadDisplayName</key> <string>移動裝置管理</string> <key>PayloadIdentifier</key> <string>com.apple.mdm.02D2C93A-3F6D-4E54-B15D-EECC1B7BD583</string> <key>PayloadOrganization</key> <string>Gener-Tech</string> <key>PayloadType</key> <string>com.apple.mdm</string> <key>PayloadUUID</key> <string>02D2C93A-3F6D-4E54-B15D-EECC1B7BD583</string> <key>PayloadVersion</key> <integer>1</integer> <key>ServerURL</key> <string>https://www..../mdm/server.do?deviceId=fc97f6b4524346a18f14d1a425986abb</string> <key>SignMessage</key> <true/> <key>Topic</key> <string>com.apple.mgmt.External.*</string> <key>UseDevelopmentAPNS</key> <true/> </dict> </array> <key>PayloadDescription</key> <string>Lock&Reset All Settings&Erase</string> <key>PayloadDisplayName</key> <string>Gener MDM Sever</string> <key>PayloadIdentifier</key> <string>net.myfleet.mdm</string> <key>PayloadOrganization</key> <string>Gener-Tech</string> <key>PayloadRemovalDisallowed</key> <false/> <key>PayloadType</key> <string>Configuration</string> <key>PayloadUUID</key> <string>984CE2FF-6BE1-49AE-A3EF-43B0B0EC9A11</string> <key>PayloadVersion</key> <integer>1</integer> </dict> </plist> 複製程式碼

我們可以直接修改此XML檔案,據此Configuration Profile Reference 可新增其他所需的欄位。你也可以在此基礎上修改適合為自己的(估計很容易遺漏或出錯),我還是喜歡在iPhone配置使用工具中操作比較方便。

給生成的配置檔案簽名

以上生成的配置檔案其實可以直接安裝到裝置上,如果安裝成功後會有一個紅色的提示‘未簽名’如下。

Snip20170508_1.png

簽名要經歷兩個操作,一、MDM Sever端簽名。二、用蘋果頒發的證書籤名。

MDM Sever簽名

需要以下證書檔案:

  • unsigned.mobileconfig 原始的未簽過名的配置檔案
  • server.crt 伺服器端用於簽名的證書
  • server.key 伺服器端用於簽名的證書的祕鑰
  • cert-chain.crt 其他機構為伺服器頒發的CA證書
  • signed.mobileconfig will be your signed configuration profile

可以再終端中執行:openssl smime -sign -in unsigned.mobileconfig -out signed.mobileconfig -signer server.crt -inkey server.key -certfile cert-chain.crt -outform der -nodetach

(以上是Java後臺簽名的操作過程,我沒有驗證,在此作為一個操作步驟總結放在這裡)。

我猜測MDM Sever的簽名只是為了和客戶端進行下認證和對描述檔案的加密過程,只是讓這兩個之間相互認知對方,和iOS系統是否承認無關。所以以上操作之後還會提示‘未簽名’。(實際測試中這個操作可以省略)。

#####蘋果證書相關的簽名 以下操作引自 天狐部落格,文章地址www.skyfox.org/ios-mobilec…

這個操作有幾種方法可供選擇,這裡我使用了指令碼簽名。

藉助於強大的github,找到了一個python指令碼進行簽名

地址:github.com/nmcspadden/…

1.簽名一個mobileconfig

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

./profile_signer.py -n "3rd Party Mac Developer Application" sign AcrobatPro.mobileconfig AcrobatProSigned.mobileconfig 2.加密一個mobileconfig

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

./profile_signer.py -n "3rd Party Mac Developer Application" both AcrobatPro.mobileconfig AcrobatProBoth.mobileconfig "3rd Party Mac Developer Application"為你的證書在鑰匙串中的全名,選擇證書=>顯示簡介=>複製常用名稱加上引號即可,比如

"iPhone Developer: jakey.shao [email protected]"

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

66911171-EE9C-4DB7-BFCE-6564CC1B4E1A如果能正確讀取到證書,會提示允許訪問鑰匙串,點選允許即可!

最終安裝提示已驗證啦。

Snip20170508_2.png

至此得到mobileconfig配置檔案,交由MDM Sever供裝置下載。