iOS

iOS 如何实现移动设备管理(MDM)

2019-07-18  本文已影响0人  西西里铿锵

概述

移动设备管理(MDM)即Mobile Device Managment,是为了方便企业能够远程管理iPad、iPhone等移动设备。

工作原理

MDM工作流程如下:


mdm工作原理.jpg

设备需要安装一个config文件,描述文件中定义了server可以对设备有哪些管控权限。服务端通过APNS推送MDM命令来实现对设备的管理。

MDM提供哪些功能?

1、配置

2、查询

3、管理

可以看到MDM提供的功能是很多的,并且权限很高,能几乎管控一个设备的使用。

准备工作

0、开通MDM服务功能

初试企业证书并不具备MDM功能,需要申请开通成为Vendor。

1、MDM证书制作

1.1生成vendor相关证书

openssl pkcs12 -in vendor.p12 -nocerts -out vendor.key

1.2生成customer相关文件

openssl genrsa -des3 -out customerPrivateKey.pem 2048
openssl req -new -key customerPrivateKey.pem -out 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 

完整的证书列表如下:

mdm证书.jpg

1.3验证证书有效性并格式化。

openssl s_client -connect gateway.push.apple.com:2195 -cert MDM_Certificate.pem -key customerPrivateKey.pem -debug -showcerts -status

1.4安装pem证书

1.5导出APNs推送证书

openssl pkcs12 -export -in MDM_Certificate.pem -out MDM_Certificate.p12 -inkey customerPrivateKey.pem

2描述文件

2.1使用iPhone配置使用工具生成配置文件

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>配置访问限制</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>

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描述文件放在服务器上提供用户下载,服务器需https。

3描述文件安装与登记

4移动设备管理

流程如下:

4.1设备的一些状态值:

Status Description
Acknowledge 正常,等待响应指令
Error 错误
CommandFormatError 指令格式错误
Idle 空闲
NotNow 设备当前无法执行,空闲后会再次请求服务器

大多情况下只辉出现Acknowledge和Idle两种状态

4.2服务端命令格式

命令必须包含Command和CommandUUID,例如如下:

<?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参考文档

上一篇下一篇

猜你喜欢

热点阅读