Chinaunix首页 | 论坛 | 博客
  • 博客访问: 275935
  • 博文数量: 83
  • 博客积分: 2393
  • 博客等级: 大尉
  • 技术积分: 640
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-24 15:14
文章分类

全部博文(83)

文章存档

2019年(21)

2011年(5)

2010年(2)

2009年(1)

2008年(9)

2007年(33)

2006年(12)

我的朋友

分类: IT业界

2011-02-19 11:18:43

   由于客户的需要,项目中需要使用AS2协议与客户进行系统连接,因此对AS2的协议进行研究和学习。AS2的协议是支持B2B的贸易伙伴间进行EDI数据交换的协议。以下是学习的笔记。
  •   术语(涉及的名词)
  •   MIME简介 
  • AS2消息 
  • AS2消息传送 (HTTP)
  • AS2-MDN消息 
  • 项目简介 与应用实例
  1.    术语

    1)AS2    :Applicability Statement 2

    2)MIME  : 多用途的网际邮件扩充协议(Multipurpose Internet Mail Extension protocol)

    3)B2B : Business to Business

    4)EDI :Electronic Data Interchange

    5)EC:  Business-to-Business Electronic Commerce

    6)Receipt: 收据 ,是一个功能性的消息,是接受者发送给发送者的一个信息交换的确认收据;这个收据可以是异步发送也可以是同步发送

    7)Signed Receipt:经过签名的收据

    8)Synchronous Receipt: 同步收据,收据返回和发送者发送的信息在同一个httpsession中发生。

    9)Asynchronous Receipt:异步收据,收据返回和发送者发送的信息不在同一个http session中发送

    10)Message Disposition Notification (MDN): 用来传送收据的一种消息格式,一个mdn是一个收据

    11)Non-repudiation of receipt (NRR): 收据的认可性(或者说收据的作用),当经过签名edi/ec交换信息的原始发送者验证了接收者返回的签名收据时就标志一个法律事件的发生。

    12)S/MIME: 是对Internet MIME messages进行数字签名或者加密的格式和协议;

    13)Cryptographic Message Syntax (CMS): 对任意消息进行加密、字数签名、鉴别的一种封装方法;

    14)SHA-1:  一种安全的、用来进行数字签名的hash算法,在AS2中被推荐使用的算法

    15)MD5:    一种安全的数字签名hash算法,在AS2中允许使用的算法

    16)MIC:   The message integrity check (MIC), 消息完成行校验,也称为消息的摘要,是hash算法摘要的输出。

   17)User Agent (UA):  AS2请求的操作和处理应用。

  2 MIME介绍

  • MIME协议用于定义复杂邮件体的格式,它可以表达多段平行的文本内容和非文本的邮件内容,例如,在邮件体中内嵌的图像数据和邮件附件等。另外,MIME协议的数据格式也可以避免邮件内容在传输过程中发生信息丢失。MIME协议不是对RFC822邮件格式的升级和替代,而是基于RFC822邮件格式的扩展应用。
  • MIME HEADER:一个采用了 MIME协议的电子邮件就叫做MIME邮件,MIME邮件在RFC822文档中定义的邮件头字段的基础上,扩充了一些自己专用的邮件头字段,如使用:Content-Type头字段指定邮件体的MIME类型。
    Content-Type:multipart/mixed; boundary="----=_Part_13_15604459.1297646186406".其中,“multipart/mixed”部分说明邮件体中包含有多段数据,每段数据之间使用boundary属性中指定的字符文本作为分隔标识符。
  • Content-Transfer-Encoding HEADER:
    Content-Transfer-Encoding头字段用于指定MIME消息体中的内容所采用的邮件编码方式:
    7bit:指消息体内容全部是没有经过编码的ASCII字符。
    8bit:指消息体内容是没有经过编码的原始数据,且其中包含有非ASCII字符的数据。现在的邮件服务器基本上都支持8Bit编码。
    BASE64:Base64是将二进制数据转换成可打印的ASCII字符的一种最常见的编码方式,它的基本原理是将一组连续的字节数据按6个bit位进行分组,然后对每组数据用一个ASCII字符来表示。
    BINARY:使用文件源内容(HTTP支持)
  • Content-Disposition:Content- Disposition头字段用于指定邮件阅读程序处理数据内容的方式,有inline和attachment两种标准方式,inline表示直接处理,而attachment表示当做附件处理。

 3 S/MIME

  •     S/MIME是一套标准,它描述客户端如何创建,操作,接受和读被数字签名、信息加密的邮件。
    S/MIME增加了新的MIME数据类型,用于提供数据保密、完整性保护、认证和鉴定服务等功能,这些数据类型包括“应用 /pkcs7-MIME”(application/pkcs7-MIME)、“复合/已签名”(multipart/signed)和“应用 /pkcs7-签名”(application/pkcs7-signature)等。
  • S/MIME只保护邮件的邮件主体,对头部信息则不进行加密,以便让邮件成功地在发送者和接收者的网关之间传递。
    MIME 消息可以包含文本、图象、声音、视频及其它应用程序的特定数据。
  • S/MIME 并不仅限于邮件的使用,它也能应用于任何可以传送 MIME 数据的传输机制,例如 HTTP 。

4 AS2

   AS2协议是用来让贸易伙伴的双方交换EDI数据的协议,AS2协议中的报文分为两种,一种是发送方发送EDI数据的报文,另一种是接收方对收到数据后发送给发送方的消息;首先来看一下发送方发送给贸易伙伴的接收方的消息格式。

    AS2协议可以选择签名、加密,或者不选择加密、不选择签名,都可以使用HTTP协议进行传输。

  •    不签名不加密时,如下图:

    

     实际报文样式:

       

  1. POST / HTTP/1.1
  2. as2-version: 1.2
  3. ediint-features: multiple-attachments, CEM
  4. mime-version: 1.0
  5. recipient-address: http://localhost:10080
  6. message-id: <mendelson_opensource_AS2-1297645774218-2@mycompanyAS2_mendelsontestAS2>
  7. as2-from: mycompanyAS2
  8. as2-to: mendelsontestAS2
  9. subject: AS2 message
  10. from: as2@company.com
  11. Connection: close, TE
  12. date: Mon, 14 Feb 2011 09:09:34 CST
  13. content-type: application/EDI-Consent
  14. disposition-notification-to: http://localhost:8080/as2/HttpReceiver
  15. disposition-notification-options: signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha1, md5
  16. content-disposition: attachment; filename="AS2Message8994276009463294233.as2"
  17. host: localhost:10080
  18. Content-Length: 1075
  19. User-Agent: mendelson opensource AS2 1.1 build 33 - www.mendelson-e-c.com
  20. Expect: 100-Continue

  21. ISA*00*ASCENTIAL *01*92511930 *zz*myPartner *zz*myCompany *940401*0942*U*00201*000000002*0*T*>
  22. GS*PO*006250740*3122721850*940401*0942*1*X*002003
  23. ST*850*1
  24. BEG**BY*ab100**931028
  25. NTE**This is a header message
  •    签名不加密

      

  

     

  1. POST / HTTP/1.1
  2. as2-version: 1.2
  3. ediint-features: multiple-attachments, CEM
  4. mime-version: 1.0
  5. recipient-address: http://localhost:10080
  6. message-id: <mendelson_opensource_AS2-1297646186359-5@mycompanyAS2_mendelsontestAS2>
  7. as2-from: mycompanyAS2
  8. as2-to: mendelsontestAS2
  9. subject: AS2 message
  10. from: as2@company.com
  11. connection: close, TE
  12. date: Mon, 14 Feb 2011 09:16:26 CST
  13. content-type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary="----=_Part_13_15604459.1297646186406"
  14. disposition-notification-to: http://localhost:8080/as2/HttpReceiver
  15. disposition-notification-options: signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha1, md5
  16. content-disposition: attachment; filename="smime.p7m"
  17. host: localhost:10080
  18. Content-Length: 3344
  19. User-Agent: mendelson opensource AS2 1.1 build 33 - www.mendelson-e-c.com
  20. Expect: 100-Continue

  21. ------=_Part_13_15604459.1297646186406
  22. Content-Type: application/EDI-Consent
  23. Content-Transfer-Encoding: binary
  24. Content-Disposition: attachment; filename=AS2Message8994276009463294233.as2

  25. ISA*00*ASCENTIAL *01*92511930 *zz*myPartner *zz*myCompany *
  26. ------=_Part_13_15604459.1297646186406
  27. Content-Type: application/pkcs7-signature; name=smime.p7s; smime-type=signed-data
  28. Content-Transfer-Encoding: base64
  29. Content-Disposition: attachment; filename="smime.p7s"
  30. Content-Description: S/MIME Cryptographic Signature

  31. MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIAwggLQMIIC
  32. ------=_Part_13_15604459.1297646186406--
  • 加密不签名

    

    实际报文样式

 

POST / HTTP/1.1
as2-version: 1.2
ediint-features: multiple-attachments, CEM
mime-version: 1.0
recipient-address:
message-id: <>
as2-from: mycompanyAS2
as2-to: mendelsontestAS2
subject: AS2 message
from:
connection: close, TE
date: Sat, 19 Feb 2011 12:28:51 CST
content-type: application/pkcs7-mime; smime-type=enveloped-data; name=smime.p7m
receipt-delivery-option:
disposition-notification-to:
disposition-notification-options: signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha1, md5
content-disposition: attachment; filename="inbound.EDIX12"
host: 192.168.1.101:10080
Content-Length: 1496
User-Agent: mendelson opensource AS2 1.1 build 33 -
Expect: 100-Continue

0

阅读(5427) | 评论(0) | 转发(0) |
0

上一篇:db2安装后的问题

下一篇:对AS2的学习(续1)

给主人留下些什么吧!~~