Exchange ActiveSync

ActiveSync[1]是由Microsoft开发,用于移动设备(mobile)数据同步的技术和协议。

Exchange ActiveSync简称EAS, 是移动设备与Exchange Server之间同步e-mail/calendar/contacts/tasks的协议。

EAS协议基于HTTP和XML,虽然HTTP和XML都是开放的标准协议,但EAS是一个私有协议,目前只开放license给几家知名的手机厂商(如Apple, Nokia)。

1. 通讯方式

EAS使用HTTP 1.1, 在移动客户端和Exchange服务器之间的所有通信都是基于HTTP的请求与响应[13]。请求由mobile client通过HTTP POST method发起,Exchange server响应这个请求。

每一个请求都包含一个start-lines, headers, 可能的body。

HTTP body则是一种WBXML (WAP Binary XML)格式的数据。

2. 基本交互流程

总的来说,移动终端在使用ActiveSync同步大概过程如下:

注意 HTTP content body的乱码是经过WBXML编码的数据

2.1. Http Options(客户端配置初始化)

OPTIONS /Microsoft-Server-ActiveSync HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: keep-alive
Content-Length: 0
Host: 172.27.236.207
User-Agent: Apple-iPhone4C1/1002.329
X-MS-PolicyKey: 0


HTTP/1.1 200 OK
Allow: OPTIONS,POST
Cache-Control: private
Content-Length: 0
Date: Thu, 26 Sep 2013 03:11:34 GMT
MS-ASProtocolCommands: Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,Provision,ResolveRecipients,ValidateCert
MS-ASProtocolVersions: 2.0,2.1,2.5,12.0,12.1,14.0,14.1
MS-Server-ActiveSync: 14.1
Public: OPTIONS,POST
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET

2.2. FolderSync(PolicyKey:0)

POST /Microsoft-Server-ActiveSync?User=suchao&DeviceId=ApplC8PL55GXDTD2&DeviceType=iPhone&Cmd=FolderSync HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: keep-alive
Content-Length: 13
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 14.1
User-Agent: Apple-iPhone4C1/1002.329
X-MS-PolicyKey: 0
jVR0


HTTP/1.1 200 OK
Content-Length: 15
Content-Type: application/vnd.ms-sync.wbxml
Date: Thu, 26 Sep 2013 03:16:00 GMT
MS-ASProtocolCommands: Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,Provision,ResolveRecipients,ValidateCert
MS-ASProtocolVersions: 2.0,2.1,2.5,12.0,12.1,14.0,14.1
X-MS-RP: 2.0,2.1,2.5,12.0,12.1,14.0,14.1
jVL142

2.3. Provision

POST /Microsoft-Server-ActiveSync?User=suchao&DeviceId=ApplC8PL55GXDTD2&DeviceType=iPhone&Cmd=Provision HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: keep-alive
Content-Length: 151
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 14.1
User-Agent: Apple-iPhone4C1/1002.329
jEVHWiPhone4C1`iOS/6.1.3 (10B329) dataaccessd/1.0ZiOS 6.1.3 10B329[zh-HansY??ɫ iPhone 4SFGHMS-EAS-Provisioning-WBXML

11:15:58,260 WARN : com.li3huo.netty.service.proxy.HttpOutboundClientHandler - UNKNOWN SERVER CERTIFICATE: CN=mail.nqsky.hissagetest.net, OU=oma, O=hesine, L=??????, ST=??????, C=CN
11:15:58,667 INFO : com.li3huo.netty.service.proxy.ChannelBufferUtils - 
HTTP/1.1 200 OK
Content-Length: 264
Content-Type: application/vnd.ms-sync.wbxml
Date: Thu, 26 Sep 2013 03:16:02 GMT
jEVF1K1FGHMS-EAS-Provisioning-WBXMLK1I1216564242JMN0O0Q0P0S1X1Z0[1\1]0^1_1`1a1b1c1d2e1f0g1h0i1j0k-1l-1m0n0o0p0q2r1s1t1u1v179

第二次

POST /Microsoft-Server-ActiveSync?User=suchao&DeviceId=ApplC8PL55GXDTD2&DeviceType=iPhone&Cmd=Provision HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: keep-alive
Content-Length: 60
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 14.1
User-Agent: Apple-iPhone4C1/1002.329
jEFGHMS-EAS-Provisioning-WBXMLI1216564242K1


HTTP/1.1 200 OK
Content-Length: 65
Content-Type: application/vnd.ms-sync.wbxml
Date: Thu, 26 Sep 2013 03:16:05 GMT
jEK1FGHMS-EAS-Provisioning-WBXMLK1I2828078187

2.4. FolderSync(PolicyKey: 2828078187)

POST /Microsoft-Server-ActiveSync?User=suchao&DeviceId=ApplC8PL55GXDTD2&DeviceType=iPhone&Cmd=FolderSync HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: keep-alive
Content-Length: 13
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 14.1
User-Agent: Apple-iPhone4C1/1002.329
X-MS-PolicyKey: 2828078187
jVR0

11:16:03,396 WARN : com.li3huo.netty.service.proxy.HttpOutboundClientHandler - UNKNOWN SERVER CERTIFICATE: CN=mail.nqsky.hissagetest.net, OU=oma, O=hesine, L=??????, ST=??????, C=CN
11:16:03,895 INFO : com.li3huo.netty.service.proxy.ChannelBufferUtils - 
HTTP/1.1 200 OK
Content-Length: 397
Content-Type: application/vnd.ms-sync.wbxml
Date: Thu, 26 Sep 2013 03:16:08 GMT
MS-ASProtocolCommands: Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,Provision,ResolveRecipients,ValidateCert
MS-ASProtocolVersions: 2.0,2.1,2.5,12.0,12.1,14.0,14.1
X-MS-RP: 2.0,2.1,2.5,12.0,12.1,14.0,14.1
jVL1R1NW12OH1I0G???J10OH2I0G?ݸ?J3OH3I0G??????J6OH4I0G?????ʼ?J12OH5I0G??ϵ??J9OH6I0G????J7OH7I0G????J8OH8I0G??־J11OH9I0G?ռ???J2OH10I0G?ѷ????ʼ?J5OH11I0G??ɾ???ʼ?J4OHRII0GRecipientInfoJ19

HTTP/1.1 200 OK
Content-Length: 66
Content-Type: application/vnd.ms-sync.wbxml
Date: Thu, 26 Sep 2013 03:16:09 GMT
jEF1]F1Gde^csuchao@exchange.hissage.orgVF1

2.5. Settings

POST /Microsoft-Server-ActiveSync?User=suchao&DeviceId=ApplC8PL55GXDTD2&DeviceType=iPhone&Cmd=Settings HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: keep-alive
Content-Length: 117
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 14.1
User-Agent: Apple-iPhone4C1/1002.329
X-MS-PolicyKey: 2828078187
jE]VHWiPhone4C1`iOS/6.1.3 (10B329) dataaccessd/1.0ZiOS 6.1.3 10B329[zh-HansY??ɫ iPhone 4S

2.6. Sync

POST /Microsoft-Server-ActiveSync?User=suchao&DeviceId=ApplC8PL55GXDTD2&DeviceType=iPhone&Cmd=Sync HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: keep-alive
Content-Length: 45
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 14.1
User-Agent: Apple-iPhone4C1/1002.329
X-MS-PolicyKey: 2828078187
jE\OK0R7WX5EF1G32768

2.7. Sync(获取邮件)

POST /Microsoft-Server-ActiveSync?User=suchao&DeviceId=ApplC8PL55GXDTD2&DeviceType=iPhone&Cmd=Sync HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: keep-alive
Content-Length: 61
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 14.1
User-Agent: Apple-iPhone4C1/1002.329
X-MS-PolicyKey: 2828078187
jE\OK2053323650R7U25WX5EF1G32768

11:16:08,010 WARN : com.li3huo.netty.service.proxy.HttpOutboundClientHandler - UNKNOWN SERVER CERTIFICATE: CN=mail.nqsky.hissagetest.net, OU=oma, O=hesine, L=??????, ST=??????, C=CN
11:16:08,137 INFO : com.li3huo.netty.service.proxy.ChannelBufferUtils - 
HTTP/1.1 200 OK
Content-Length: 2205
Content-Type: application/vnd.ms-sync.wbxml
Date: Thu, 26 Sep 2013 03:16:11 GMT
jE\OK334718389R9N1VGM9:1]V"luyu" <luyu@exchange.hissage.org>, "suchao" <suchao@exchange.hissage.org>X"suchao" <suchao@exchange.hissage.org>TtestO2013-09-25T03:21:53.266ZQluyu; suchaoutestR1U1JF1L13K

?????? HTC
SIPM.Notey65001:|urn:content-classes:messageV2I???9tO?F??"?wq+J????a(K1L2013-09-25T03:29:44.173ZM9:2]V"suchao" <suchao@exchange.hissage.org>, "luyu" <luyu@exchange.hissage.org>X"suchao" <suchao@exchange.hissage.org>T?ظ?: testO2013-09-25T03:29:44.777ZQsuchao; luyuutestR1U1JF1L227Kap

?????? HTC

----- Reply message -----
?????ˣ? "suchao" <suchao@exchange.hissage.org>
???ڣ? ????, 9 ?? 25 ??, 2013 ?? 11:21
???⣺ test
?ռ??ˣ? "luyu" <luyu@exchange.hissage.org>, "suchao" <suchao@exchange.hissage.org>



?????? HTC
SIPM.Notey936:|urn:content-classes:messageV2I???9tO?F??"?wq+J?
???a(F@rK1L2013-09-25T09:17:41.013ZM9:3]V"suchao" <suchao@exchange.hissage.org>X"suchao" <suchao@exchange.hissage.org>TxxxO2013-09-25T11:10:46.006ZQsuchaouxxxR1U1JF1L5Kabc
?*I?2??-???J?????M9:4]V"suchao" <suchao@exchange.hissage.org>, "luyu" <luyu@exchange.hissage.org>X"suchao" <suchao@exchange.hissage.org>T?ظ?: testO2013-09-25T09:17:42.256ZQsuchao; luyuutestR1U1JF1L443K

?????? HTC

----- Reply message -----
?????ˣ? "suchao" <suchao@exchange.hissage.org>
???ڣ? ????, 9 ?? 25 ??, 2013 ?? 11:29
???⣺ ?ظ?: test
?ռ??ˣ? "suchao" <suchao@exchange.hissage.org>, "luyu" <luyu@exchange.hissage.org>

ap

?????? HTC

----- Reply message -----
?????ˣ? "suchao" <suchao@exchange.hissage.org>
???ڣ? ????, 9 ?? 25 ??, 2013 ?? 11:21
???⣺ test
?ռ??ˣ? "luyu" <luyu@exchange.hissage.org>, "suchao" <suchao@exchange.hissage.org>



?????? HTC
SIPM.Notey936:|urn:content-classes:messageV2I???9tO?F??"?wq+J????a(F@r
                                                                      &??

2.8. 在Android客户端上抓到的

2.8.1. GetItemEstimate

POST /Microsoft-Server-ActiveSync?Cmd=GetItemEstimate&User=suchao&DeviceId=HTCAnd88e6fc3e&DeviceType=htcbravo HTTP/1.1
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: Keep-Alive
Content-Length: 38
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 12.1
User-Agent: Android-EAS/0.1
X-MS-PolicyKey: 222651377
jEGHJ9X2K2092021431


HTTP/1.1 200 OK
Content-Length: 27
Content-Type: application/vnd.ms-sync.wbxml
Date: Wed, 25 Sep 2013 08:48:01 GMT
jEMN1HJ9L0

2.8.2. Sync

POST /Microsoft-Server-ActiveSync?Cmd=Sync&User=suchao&DeviceId=HTCAnd88e6fc3e&DeviceType=htcbravo HTTP/1.1
Accept-Encoding: compress, gzip
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: Keep-Alive
Content-Length: 77
Content-Type: application/vnd.ms-sync.wbxml
Host: 172.27.236.207
MS-ASProtocolVersion: 12.1
User-Agent: Android-EAS/0.1
X-MS-PolicyKey: 222651377
jE\OK2092021431R9^1U50WX2EF2G5120H0[1


HTTP/1.1 200 OK
Content-Length: 0
Date: Wed, 25 Sep 2013 08:48:02 GMT

2.8.3. SaveInSent

POST /Microsoft-Server-ActiveSync?Cmd=SmartReply&SaveInSent=T&User=suchao&ItemId=9:2&CollectionId=9&DeviceId=HTCAnd88e6fc3e&DeviceType=htcbravo HTTP/1.1
Authorization: Basic c3VjaGFvOmxpbmZlbmdmZWl5ZS0xMjM=
Connection: Keep-Alive
Content-Length: 1568
Content-Type: message/rfc822
Host: 172.27.236.207
MS-ASProtocolVersion: 12.1
User-Agent: Android-EAS/0.1
X-MS-PolicyKey: 222651377
Message-ID: <3AEC4153-7137-4BB0-9459-FEC8A4575640@exchange.hissage.org>
From:  
To: suchao@exchange.hissage.org,luyu@exchange.hissage.org
Subject: ?ظ?: test
Importance: Normal
MIME-Version: 1.0
Content-Type: multipart/alternative;
        boundary="----=_Part_1_1380100616602"

------=_Part_1_1380100616602
Content-Type: text/plain;
        charset= utf-8
Content-Transfer-Encoding: base64
Content-Disposition: inline

DQoKCuWPkemAgeiHqiBIVEMKCi0tLS0tIFJlcGx5IG1lc3NhZ2UgLS0tLS0K5Y+R5Lu25Lq677yaICJzdWNoYW8iIDxzdWNoYW9AZXhjaGFuZ2UuaGlzc2FnZS5vcmc+CuaXpeacn++8miDlkajkuIksIDkg5pyIIDI1IOaXpSwgMjAxMyDlubQgMTE6MjkK5Li76aKY77yaIOWbnuWkjTogdGVzdArmlLbku7bkurrvvJogInN1Y2hhbyIgPHN1Y2hhb0BleGNoYW5nZS5oaXNzYWdlLm9yZz4sICJsdXl1IiA8bHV5dUBleGNoYW5nZS5oaXNzYWdlLm9yZz4KDQo=
------=_Part_1_1380100616602
Content-Type: text/html;
        charset= utf-8
Content-Transfer-Encoding: base64
Content-Disposition: inline

DQo8aHRtbD4NPGhlYWQ+DTxtZXRhIGh0dHAtZXF1aXY9IkNvbnRlbnQtVHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PXV0Zi04Ij4NPC9oZWFkPg08Ym9keT48YnI+PGJyPuWPkemAgeiHqiBIVEM8YnI+PGJyPjxkaXYgaWQ9Imh0Y19oZWFkZXIiIHN0eWxlPSIiPi0tLS0tIFJlcGx5IG1lc3NhZ2UgLS0tLS08YnI+5Y+R5Lu25Lq677yaICZxdW90O3N1Y2hhbyZxdW90OyAmbHQ7c3VjaGFvQGV4Y2hhbmdlLmhpc3NhZ2Uub3JnJmd0Ozxicj7ml6XmnJ/vvJog5ZGo5LiJLCA5IOaciCAyNSDml6UsIDIwMTMg5bm0IDExOjI5PGJyPuS4u+mimO+8miDlm57lpI06IHRlc3Q8YnI+5pS25Lu25Lq677yaICZxdW90O3N1Y2hhbyZxdW90OyAmbHQ7c3VjaGFvQGV4Y2hhbmdlLmhpc3NhZ2Uub3JnJmd0OywgJnF1b3Q7bHV5dSZxdW90OyAmbHQ7bHV5dUBleGNoYW5nZS5oaXNzYWdlLm9yZyZndDs8YnI+PGJyPjwvZGl2Pg0K
------=_Part_1_1380100616602--


HTTP/1.1 200 OK
Content-Length: 0
Date: Wed, 25 Sep 2013 09:17:41 GMT

2.8.4.


3. ActiveSync Clients

3.1. Workable Client on Windows 7

EAS – MD: v1.71 40k

4. Reference


CategoryDev

MainWiki: ActiveSync (last edited 2013-09-26 14:08:17 by twotwo)