`

ActiveSync Primer continued – The PROVISION command

 
阅读更多

ActiveSync Primer continued – The PROVISION command

February 3rd, 2011 § 1

The PROVISION command and response is used by Exchange servers to communicate security policy settings to client devices.  If a security policy has been setup for an Exchange server, Exchange will not process any requests received from a client, until the policy settings are requested and acknowledged by the client. Please see the ActiveSync Provisioning Protocol Specification for more information about this command.

Depending upon the version of the Exchange server one of the following error messages are returned when a client issues a request before accepting the security policies.

  • HTTP/1.1 449 : Retry after sending a PROVISION command
  • HTTP/1.1 200 with a global status code in the body of the response of 142 (see example here).

A lot of this is repeated from the ActiveSync provisioning protocol documentation. However there are a few gotchas here, so I think it might be better to step through it.

Step 1: Client requests security policy from the server

Header

// Send a POST request to the mail server. Append
// the string “Microsoft-Server-ActiveSync” to the URL, and add the
// the following query strings as parameters to the URL as shown below
// username - Username used to log into the server.
// deviceId: DeviceId for the device (not validated by server)
// deviceType: Type of device (not validated by server)
// cmd: The actual command being sent across (Provision in this case)

POST https://mail.example.com/Microsoft-Server-ActiveSync?User=username&DeviceId=123412341234&DeviceType=Android&Cmd=Provision HTTP/1.1

// Set the user-agent
User-Agent: Android

// Authorization: This is the text Basic followed by a
// base64 encode of the string DOMAIN\USERNAME:PASSWORD.
// Replace with appropriate values.
Authorization: Basic RE9NQUlOXFVTRVJOQU1FOlBBU1NXT1JE

// Set the content-length to the length of the WBXML being sent (more on this in a bit)
Content-Length: FIXME

// Indicate to the Exchange server that we are sending
// WBXML encoded content.
Content-Type: application/vnd.ms-sync.wbxml

// Identifies the protocol version the client (we) support
// NOTE: This cannot be higher than the highest ActiveSync protocol
// version supported by the server. See my Options primer
// for details.
// Also I would recommend setting this to 12.1, because some Exchange
// 2010 requires servers (v14.1) require 14.1 clients to send several
// optional fields (yep you read that right). Setting this to 12.1
// makes your life a wee bit easier.

MS-ASProtocolVersion: 12.1

// English language
Accept-Language: en-US

// Hostname the request is being sent to
Host: mail.example.com

// Set the PolicyKey to zero indicating to the server
// That you do not currently have a policy key
X-MS-PolicyKey: 0

Body

// Send the following XML string to the server.
// Note that the XML below has to be encoded
// into WBXML before sending it across to the
// Exchange server. More on this in a bit.
// The policyType should be set to
// MS-EAS-Provisioning-WBXML if the activeSync version greater
/ than or equal to 12.0, MS-WAP-Provisioning-XML otherwise

<?xml version="1.0" encoding="utf-8"?>
<Provision xmlns="Provision:">
  <Policies>
    <Policy>
      <!-- If ActiveSync Version >= 12.0 -->
      <PolicyType>MS-EAS-Provisioning-WBXML</PolicyType>
      <!-- If ActiveSync Version < 12.0 -->
      <PolicyType>MS-WAP-Provisioning-XML</PolicyType>
    </Policy>
  </Policies>
</Provision>

Now the XML in the body above has to be encoded into WBXML, before it can be sent across to the server. This is true for all ActiveSync commands that have a body. I wrote a Java implementation of a WBXML encoder and decoder for my app, and you can find the source code here. The source code is based on a WBXML parser I found in the k9mail. I modified the source to add support for International languages.

Step 2: Server responds to client request with security policy and temporary policyKey

Once the request above is sent to the server, you should get a response that looks somewhat like this. Again the XML returned from the server is encoded in WBXML. It is the client’s responsibility to decode this WBXML and make sense of it.

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 1069
Content-Type: application/vnd.ms-sync.wbxml
Server: Microsoft-IIS/7.5
MS-Server-ActiveSync: 8.3
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Cache-Control: private
Date: Mon, 01 Feb 2011 21:14:17 GMT

<?xml version="1.0" encoding="utf-8"?>
<Provision xmlns="Provision">
<Status>1</Status>
<Policies>
<Policy>
<PolicyType>MS-EAS-Provisioning-WBXML</PolicyType>
<Status>1</Status>
<PolicyKey>2152355410</PolicyKey>
<Data>
  <EASProvisionDoc>
    <DevicePasswordEnabled>0</DevicePasswordEnabled>
    <AlphanumericDevicePasswordRequired>0</AlphanumericDevicePasswordRequired>
    <PasswordRecoveryEnabled>0</PasswordRecoveryEnabled>
    <DeviceEncryptionEnabled>0</DeviceEncryptionEnabled>
    <AttachmentsEnabled>1</AttachmentsEnabled>
    <MinDevicePasswordLength/>
    <MaxInactivityTimeDeviceLock/>
    <MaxDevicePasswordFailedAttempts/>
    <MaxAttachmentSize/>
    <AllowSimpleDevicePassword>0</AllowSimpleDevicePassword>
    <DevicePasswordExpiration/>
    <DevicePasswordHistory>0</DevicePasswordHistory>
    <AllowStorageCard>1</AllowStorageCard>
    <AllowCamera>1</AllowCamera>
    <RequireDeviceEncryption>0</RequireDeviceEncryption>
    <AllowUnsignedApplications>1</AllowUnsignedApplications>
    <AllowUnsignedInstallationPackages>1</AllowUnsignedInstallationPackages>
    <MinDevicePasswordComplexCharacters>3</MinDevicePasswordComplexCharacters>
    <AllowWiFi>1</AllowWiFi>
    <AllowTextMessaging>1</AllowTextMessaging>
    <AllowPOPIMAPEmail>1</AllowPOPIMAPEmail>
    <AllowBluetooth>2</AllowBluetooth>
    <AllowIrDA>1</AllowIrDA>
    <RequireManualSyncWhenRoaming>1</RequireManualSyncWhenRoaming>
    <AllowDesktopSync>1</AllowDesktopSync>
    <MaxCalendarAgeFilter>0</MaxCalendarAgeFilter>
    <AllowHTMLEmail>1</AllowHTMLEmail>
    <MaxEmailAgeFilter>0</MaxEmailAgeFilter>
    <MaxEmailBodyTruncationSize>-1</MaxEmailBodyTruncationSize>
    <MaxEmailHTMLBodyTruncationSize>-1</MaxEmailHTMLBodyTruncationSize>
    <RequireSignedSMIMEMessages>0</RequireSignedSMIMEMessages>
    <RequireEncryptedSMIMEMessages>0</RequireEncryptedSMIMEMessages>
    <RequireSignedSMIMEAlgorithm>0</RequireSignedSMIMEAlgorithm>
    <RequireEncryptionSMIMEAlgorithm>0</RequireEncryptionSMIMEAlgorithm>
    <AllowSMIMEEncryptionAlgorithmNegotiation>2</AllowSMIMEEncryptionAlgorithmNegotiation>
    <AllowSMIMESoftCerts>1</AllowSMIMESoftCerts>
    <AllowBrowser>1</AllowBrowser>
    <AllowConsumerEmail>1</AllowConsumerEmail>
    <AllowRemoteDesktop>1</AllowRemoteDesktop>
    <AllowInternetSharing>1</AllowInternetSharing>
    <UnapprovedInROMApplicationList/>
    <ApprovedApplicationList/>
  </EASProvisionDoc>
</Data>
</Policy>
</Policies>
</Provision>

The 200 response code indicates a success. The XML returned from the server contains the security policy that the server would like the client to implement. Once the client receives this security policy, it needs to implement the security policy indicated in the XML, and then acknowledge receipt of the security policy. Note that the policyKey (2152355410) returned by the server in the response is temporary and needs to be sent to the server in Step 3 (acknowledgement).

Step 3: Client acknowledges receipt and application of security policy

The client should now acknowledge the security policy and its application by using the temporary policyKey obtained in Step 2.

POST https://mail.example.com/Microsoft-Server-ActiveSync?User=username&DeviceId=123412341234&DeviceType=Android&Cmd=Provision HTTP/1.1
User-Agent: Android
Authorization: Basic RE9NQUlOXFVTRVJOQU1FOlBBU1NXT1JE
Content-Length: FIXME
Content-Type: application/vnd.ms-sync.wbxml
MS-ASProtocolVersion: 12.1
Accept-Language: en-US
Host: mail.example.com
X-MS-PolicyKey: 2152355410

<?xml version="1.0" encoding="utf-8"?>
<Provision xmlns="Provision:">
  <Policies>
    <Policy>
      <PolicyType>MS-EAS-Provisioning-WBXML</PolicyType>
      <PolicyKey>2152355410</PolicyKey>
      <Status>1</Status>
    </Policy>
  </Policies>
</Provision>

Step 4: Server responds with final policyKey

At this point the server will respond with the ”final” policyKey which the client then uses in the X-MS-PolicyKey header of all successive command requests to the server.

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 1069
Content-Type: application/vnd.ms-sync.wbxml
Server: Microsoft-IIS/7.5
MS-Server-ActiveSync: 8.3
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Cache-Control: private
Date: Mon, 01 Feb 2011 21:15:17 GMT

<?xml version="1.0" encoding="utf-8"?>
<Provision xmlns="Provision:">
  <Status>1</Status>
    <Policies>
       <Policy>
           <PolicyType>MS-EAS-Provisioning-WBXML</PolicyType>
           <Status>1</Status>
           <PolicyKey>12432432244</PolicyKey>
       </Policy>
     </Policies>
</Provision>

A word of caution here. I have seen cases where a server processes a few client requests that contain the final policyKey obtained using the method above, and then start sending down a 449 or a 142 error code. This implies that the client needs to acknowledge the policy settings again. So make sure you always check for 142 and 449 error codes even if you have accepted the policy settings once and received a final policyKey.

分享到:
评论

相关推荐

    ActiveSync

    **ActiveSync:移动设备同步与管理的里程碑** ActiveSync是由微软公司开发的一种数据同步协议,主要用于将Windows Mobile设备(如早期的Pocket PC、Windows Phone)与个人电脑或企业服务器进行同步。这个工具允许...

    ActiveSync win64位专用

    **ActiveSync:Windows 64位版本的同步神器** ActiveSync是微软开发的一款强大的设备管理与数据同步软件,尤其在Windows Mobile设备流行的时代,它扮演了至关重要的角色。这款工具使得用户可以无缝地将个人电脑(PC...

    activesync 6.1(64)

    Microsoft ActiveSync (ActiveSync)是Microsoft Windows CE系统设备的电脑同步软件,activesync可以在Win 98/Win ME/Win NT/Win 2000/Win XP系统上运行;实现设备端与电脑的连接与通讯。

    ActiveSync4.2的安装包

    ActiveSync 4.2 是微软推出的一款用于连接个人电脑(主机)与移动设备,特别是Windows Mobile设备(如掌上电脑或智能手机)的同步和管理工具。这个安装包提供了开发者和普通用户一个方便的桥梁,使得数据传输、应用...

    ActiveSync同步问题解决

    ActiveSync同步问题解决 ActiveSync是Microsoft开发的一种同步技术,用于同步Windows Mobile设备和计算机之间的数据。然而,在使用ActiveSync 4.5同步Windows Mobile 6.1手机时,可能会出现问题,即在同步设置向导...

    MicrosoftActiveSync_setup_cn_4.5.0.rar

    【Microsoft ActiveSync:连接Windows CE设备的桥梁】 Microsoft ActiveSync是一款由微软开发的同步软件,主要用于将Windows CE或Pocket PC设备(如掌上电脑、智能手机)与运行Windows操作系统的个人计算机进行数据...

    ActiveSync4.5.msi

    【ActiveSync 4.5.msi】是一款微软推出的用于连接Windows CE设备与Windows桌面操作系统的同步软件。在本文中,我们将深入探讨ActiveSync 4.5及其在驱动开发和LabVIEW应用中的重要性。 首先,ActiveSync是微软为...

    Activesync6.1(包括64位和32位)

    ActiveSync 6.1 是微软开发的一个用于同步Windows Mobile设备(如智能手机和平板电脑)与Windows PC的重要工具。这个版本的软件支持64位和32位操作系统,确保了广泛的兼容性,无论用户使用的是哪种架构的计算机都能...

    ActiveSync4.5 英文原版

    ActiveSync 4.5 是微软开发的一款用于连接和同步Windows Mobile设备(如多普达手机)与个人电脑的软件。这款软件在当时是许多企业用户和智能手机爱好者的主要选择,因为它提供了高效的数据同步功能,使用户能够方便...

    ActiveSync4.5_OfficialRelease

    《ActiveSync 4.5官方发布:连接与同步的基石》 ActiveSync 4.5是微软推出的一款针对Windows XP操作系统的重要同步软件,它在个人电脑与移动设备,特别是Windows Mobile设备之间架起了数据同步的桥梁。这款软件的...

    同步软件Activesync For XP

    **同步软件Activesync For XP** Activesync是一款在Windows XP时代广泛使用的数据同步软件,主要功能是将个人计算机(尤其是运行Windows XP的系统)与移动设备,如早期的Windows Mobile设备,进行无缝的数据同步。...

    win7用到的ActiveSync

    标题中的“win7用到的ActiveSync”指的是Windows Mobile Device Center(WMDC),它是在Windows 7系统中用于与移动设备同步数据的工具,特别是针对早期的Windows CE或Windows Mobile操作系统的PDA(个人数字助手)。...

    ActiveSync自动同步补丁

    ActiveSync是一款由微软开发的设备同步软件,主要用于将Windows Mobile设备(如早期的智能手机和Pocket PC)与Windows桌面操作系统进行数据同步。这个“ActiveSync自动同步补丁”显然是为了解决在使用ActiveSync过程...

    PC通过Activesync远程控制Wince平台

    标题中的“PC通过Activesync远程控制Wince平台”指的是使用Microsoft ActiveSync软件,让个人计算机(PC)能够与运行Windows CE(Wince)操作系统的设备进行远程连接和交互。Windows CE是一种轻量级的嵌入式操作系统...

    ActiveSync4.1简体中文版

    ActiveSync 4.1是微软推出的一款用于移动设备与个人电脑间同步数据的重要工具,尤其在Windows Mobile设备的用户中非常常见。这个简体中文版的发布,为中文用户提供了更加便捷的操作体验,无需进行注册步骤,使得手机...

    ActiveSync.zip

    ActiveSync是一款由微软开发的同步软件,主要用于将Windows CE设备(如Palm-size PC、Pocket PC、Windows Mobile设备等)与个人电脑进行数据同步。这个压缩包“ActiveSync.zip”包含了适用于不同操作系统的版本,...

    微软同步工具(ActiveSync_win7_x64_6.0.5824)

    《微软同步工具ActiveSync在Win7_x64系统上的应用详解》 ActiveSync,作为微软推出的一款重要同步工具,主要用于连接Windows CE(Windows Embedded Compact)设备与个人电脑,实现数据同步和设备管理。本文将围绕...

    Activesync driver

    Microsoft ActiveSync是一款由微软开发的同步软件,主要用于将Windows Mobile设备(如早期的智能手机和Pocket PC)与运行Windows操作系统的个人电脑进行数据同步。这款驱动程序是连接移动设备与PC的关键组件,允许...

    activesync 4.5

    **ActiveSync 4.5详解** ActiveSync是微软推出的一款同步软件,主要用于Windows Mobile设备(如Pocket PC、Smartphone)与个人电脑之间的数据同步。在本文中,我们将深入探讨ActiveSync 4.5版本,了解其功能、改进...

Global site tag (gtag.js) - Google Analytics