概述
移動(dòng)設(shè)備管理(MDM)即Mobile Device Managment,是為了方便企業(yè)能夠遠(yuǎn)程管理iPad罕扎、iPhone等移動(dòng)設(shè)備。
工作原理
MDM工作流程如下:
設(shè)備需要安裝一個(gè)config文件,描述文件中定義了server可以對(duì)設(shè)備有哪些管控權(quán)限昙篙。服務(wù)端通過(guò)APNS推送MDM命令來(lái)實(shí)現(xiàn)對(duì)設(shè)備的管理。
MDM提供哪些功能诱咏?
1苔可、配置
- 賬戶配置(wifi、vpn袋狞、email)
- 密碼策略
- 安全與隱私(獲取設(shè)備定位等)
- 設(shè)備功能限制(是否允許攝像頭焚辅、siri等)
- 應(yīng)用限制(是否允許使用xxx app)
- 云
- 內(nèi)容分級(jí)
2映屋、查詢
- 設(shè)備基本信息(UUID、設(shè)備名同蜻,IMEI等)
- 網(wǎng)絡(luò)信息(MAC地址棚点、手機(jī)號(hào)等)
- 合規(guī)性和安全性
- 應(yīng)用(設(shè)備上的應(yīng)用ID,名稱等)
3埃仪、管理
- 管理配置(描述文件)
- 管理APP(安裝刪除)
- 管理設(shè)備(鎖屏乙濒、還原、重啟卵蛉、清除密碼等)
可以看到MDM提供的功能是很多的颁股,并且權(quán)限很高,能幾乎管控一個(gè)設(shè)備的使用傻丝。
準(zhǔn)備工作
0甘有、開(kāi)通MDM服務(wù)功能
初試企業(yè)證書(shū)并不具備MDM功能,需要申請(qǐng)開(kāi)通成為Vendor葡缰。
1亏掀、MDM證書(shū)制作
1.1生成vendor相關(guān)證書(shū)
- 首先通過(guò)本地鑰匙串生成certSigningRequest,與普通證書(shū)制作并無(wú)二致泛释。即鑰匙串-證書(shū)管理-從證書(shū)頒發(fā)機(jī)構(gòu)請(qǐng)求證書(shū)滤愕,存儲(chǔ)到磁盤生成文件。
- 導(dǎo)出p12文件也與普通證書(shū)一致怜校,直接到鑰匙串中導(dǎo)出即可间影,
- 使用openssl將p12密鑰轉(zhuǎn)為pem格式,命令如下:
openssl pkcs12 -in vendor.p12 -nocerts -out vendor.key
-
登錄apple開(kāi)發(fā)者中心茄茁,生成MDM CSR文件魂贬。
1.2生成customer相關(guān)文件
- 使用命令生成customer.csr
openssl genrsa -des3 -out customerPrivateKey.pem 2048
openssl req -new -key customerPrivateKey.pem -out customer.csr
- 對(duì)customer.csr簽名
openssl pkcs12 -in mdm_vendor.p12 -nocerts -out mdm_vendor.key
python mdm_vendor_sign.py
--key mdm_vendor.key
--csr customer.csr
--mdm mdm.cer
--root AppleIncRootCertificate.cer
--WWDR AppleWWDRCA.cer
完整的證書(shū)列表如下:
1.3驗(yàn)證證書(shū)有效性并格式化。
- 使用以下命令對(duì)pen文件進(jìn)行驗(yàn)證
openssl s_client -connect gateway.push.apple.com:2195 -cert MDM_Certificate.pem -key customerPrivateKey.pem -debug -showcerts -status
1.4安裝pem證書(shū)
- 雙擊安裝裙顽,記錄用戶ID:com.apple.mgmt.External.*
1.5導(dǎo)出APNs推送證書(shū)
- 將pem證書(shū)轉(zhuǎn)為服務(wù)端需要的p12
openssl pkcs12 -export -in MDM_Certificate.pem -out MDM_Certificate.p12 -inkey customerPrivateKey.pem
2描述文件
2.1使用iPhone配置使用工具生成配置文件
- 通用:配置文件的基本信息付燥,標(biāo)識(shí)符、該描述文件是否允許刪除等愈犹。
- 限制:設(shè)備功能限制键科,包括安裝應(yīng)用,相機(jī)使用甘萧,iCloud等萝嘁。
- 憑證:MDM Server認(rèn)證使用的p12
- 移動(dòng)設(shè)備管理:這一步比較關(guān)鍵。需要注意配置服務(wù)器URL扬卷、登記URL牙言、主題(com.apple.mgmt.External.*)、身份怪得、訪問(wèn)權(quán)限咱枉、Apple推送通知卑硫。
2.2完整的描述文件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>配置訪問(wèn)限制</string>
<key>PayloadDisplayName</key>
<string>訪問(wèn)限制</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>配置密碼設(shè)置</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>
//證書(shū)內(nèi)容base64編碼的字符串
</data>
<key>PayloadDescription</key>
<string>提供設(shè)備鑒定(證書(shū)或身份)。</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>配置“移動(dòng)設(shè)備管理”</string>
<key>PayloadDisplayName</key>
<string>移動(dòng)設(shè)備管理</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>
2.3給描述文件簽名
openssl smime -sign -in unsigned.mobileconfig -out signed.mobileconfig -signer server.crt -inkey server.key -certfile cert-chain.crt -outform der -nodetach
2.4描述文件放在服務(wù)器上提供用戶下載蚕断,服務(wù)器需https欢伏。
3描述文件安裝與登記
- 直接以u(píng)rl形式,系統(tǒng)會(huì)自動(dòng)跳轉(zhuǎn)到設(shè)置進(jìn)行描述文件安裝亿乳。
- 安裝描述文件設(shè)備會(huì)發(fā)送一個(gè)登記請(qǐng)求硝拧,包括消息類型、主題葛假、UDID
- 服務(wù)端收到請(qǐng)求后障陶,記錄設(shè)備信息(后面就可以根據(jù)設(shè)備信息進(jìn)行設(shè)備管理了),響應(yīng)200即登記成功聊训。
4移動(dòng)設(shè)備管理
流程如下:
- Server與APNs建立鏈接抱究,發(fā)送一個(gè)詢問(wèn)請(qǐng)求,詢問(wèn)設(shè)備是否空閑
- 設(shè)備Server狀態(tài)是空閑的
- 當(dāng)Server收到設(shè)備回應(yīng)的空閑消息后带斑,才可以發(fā)送管理命令鼓寺,例如權(quán)限管理,鎖屏等等勋磕。
- 設(shè)備收到管理命令后妈候,響應(yīng)服務(wù)端。
- Server收到響應(yīng)挂滓,更新后臺(tái)設(shè)備狀態(tài)州丹。
4.1設(shè)備的一些狀態(tài)值:
Status | Description |
---|---|
Acknowledge | 正常,等待響應(yīng)指令 |
Error | 錯(cuò)誤 |
CommandFormatError | 指令格式錯(cuò)誤 |
Idle | 空閑 |
NotNow | 設(shè)備當(dāng)前無(wú)法執(zhí)行杂彭,空閑后會(huì)再次請(qǐng)求服務(wù)器 |
大多情況下只輝出現(xiàn)Acknowledge和Idle兩種狀態(tài)
4.2服務(wù)端命令格式
命令必須包含Command和CommandUUID,例如如下:
- 獲取設(shè)備已安裝應(yīng)用
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Command</key>
<dict>
<key>RequestType</key>
<string>InstalledApplicationList</string>
</dict>
<key>CommandUUID</key>
<string>149e4fd2-0267-4da2-9b58-bf94282dcdb4</string>
</dict>
</plist>
5參考文檔
- MDM協(xié)議官方文檔:https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/MobileDeviceManagementProtocolRef/3-MDM_Protocol/MDM_Protocol.html#//apple_ref/doc/uid/TP40017387-CH3-SW2
- 配置描述文件參考:https://developer.apple.com/library/content/featuredarticles/iPhoneConfigurationProfileRef/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010206-CH1-SW1
- iOSMDM詳解http://www.reibang.com/p/6112050ea31a