茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1670354 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00193.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

一網情深 : [轉貼]淺談EDI AS2 傳輸/連接

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]淺談EDI AS2 傳輸/連接

淺談EDI AS2 傳輸/連接

版權聲明:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/bluesky19910220/article/details/85115872

近期有很多公司被要求與國外客戶建立AS2連接,之前只知道類似於FTP或者SFTP連接協議,從未聽說過這個協議呀,可以具體講講嗎?

AS2傳輸定義?

AS2,是Applicability Statement 2的縮寫,是一種貿易雙方點對點的電子數據交換規範,旨在確保數據在互聯網能夠安全可靠地傳輸。

與FTP或者SFTP等傳統文件傳輸協議不同的是, AS2連接並不存在客戶端(Server)與客戶端(Client)之分,文件傳輸雙方是點對點的平等對接,所以在建立AS2連接初期,文件傳輸雙方需要交換AS2配置信息方可建立安全連接通道。

建立AS2傳輸基本參數?

雙方建立AS2傳輸需要交換如下三個基本參數:AS2 ID、AS2 證書、AS2 URL。

如下列出需要確認的所有AS2配置參數表。

Trading Partner Implementation(AS2)

Company Name: 

Customer Address:

Contact: 

 AS2 Software

 AS2 Compliant Software Vendor: RSSBus Connect/KA Software Inc.

Is Software Drummond Certified: Yes

AS2 Specifications

Environment:PROD

AS2 Identifier:


AS2 URL: 

AS2 Public Certificate:

Message Format Type: S/MIME Signed/Encrypted

Encryption Algorithm: 3DES

Signing Algorithm: SHA256

Receipt Type&Capability:

MDN Type:

 

AS2 傳輸流程?

AS2協議是一種基於HTTP&S/MIME的安全傳輸協議,首先通過證書對傳輸文件進行加密與簽名,加密的數據包通過HTTP/HTTPS進行或者TCP/IP網絡進行數據傳輸與交換。

以下根據下述配圖介紹AS2整個傳輸流程:

Image result for AS2

  1. 準備傳輸文件:AS2傳輸不限制傳輸文件格式,支持EDI、CSV、xlsx、pdf、zip、json等任意格式文件
  2. 簽名加密數據包: 對於傳輸的文件,首先用發送方私鑰證書籤名,之後再用接收方公鑰證書加密,完成傳輸文件的安全加密並封裝
  3. 通過HTTP/HTTPS傳輸數據包
  4. 解密並驗證數據包:接收方網關收到數據包後,首先用接收方私鑰證書解密,再用發送方公鑰證書驗證簽名,並解封裝
  5. 接收方處理收到的原始數據
  6. 回復MDN:接收方通過HTTP/HTTPS回覆信息處理通知MDN給發送方
  7. 驗證MDN: 發送方根據接收方回復的MDN信息驗證發送成功

原文出處:浅谈EDI AS2 传输/连接 - EDI电子数据交换 | 杨欢 - CSDN博客
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]使用AS2(http)協議實現 B2B 商用數據交換 (一)

使用AS2(http)協議實現 B2B 商用數據交換 (一) [譯]

前言

譯自: https://dzone.com/articles/as...
公司的 B2B 系統要使用 AS2 這種古老的協議跟客戶做對接,主要面向國外客戶,國內基本上都是 FTP。網上關於 AS2 的文章和 github 上可用的輪子都非常少,所以我翻譯了一些 AS2 的文章供參考學習。
Applicability Statement 2或叫 AS2 協議規格書定義了一種在互聯網上傳輸商業數據的安全可靠的機制。

AS2 消息內容

AS2 協議本身並沒有限制 AS2 消息的內容。不過,AS2 的消息內容通常是結構化的商業文檔,例如發票,採購訂單等。所以 AS2 系統通常用來處理 EDI (電子數據交換)。EDI 的標準主要有:

  • 聯合國推薦的 UN/EDIFACT 是唯一的國際標準,主要是北美洲以外的地區在使用
  • 美國標準的 ANSI ASC X12 (X12),主要是美國佬在使用
  • TRADACOMS,英國零售業在用
  • ODETTE 標準,歐洲汽車工業在用

AS2 消息能夠攜帶非 EDI 的內容,例如 XML, CSV, 文本或二進制文件。

MDN - Message Disposition Notice (消息處理通知)


MDN 是由接收方通過 AS2 協議簽發的電子收據。通常,接收方使用私鑰,生成 digital signature (數字簽名),數字簽名的生成主要基於 MIC (數據完整性校驗碼) 和其他 AS2 屬性,例如 From/To AS2 ID, message ID 等。發送方收到 MDN 後校驗 MDN 中的 MIC 是否跟發送時計算出來的 MIC 相同 (計算 MIC 使用散列算法,例如 MD5, SHA),確認接收方是否成功接收到完整的消息。MDN 總會附帶 (接收方) 簽名,這樣雙方都不能否認這個電子收據。
MDN 並不意味著接收方商業夥伴成功處理了 AS2 消息文檔,僅僅說明 AS2 消息傳輸成功 (被商業夥伴接收)。

AS2 vs 傳統 B2B 協議

相比傳統的 B2B 協議,AS2 (在不借助專用設備,軟件或私有網絡的情況下) 提供了一種安全,高效,易用的交易環境。AS2 優點主要有:

  • 對消息內容進行加密(使用非對稱加密技術,例如RSA)——所以只有目標用戶才能解密這個消息。
  • (發送方) 通過 (接收方) 簽署過的 MDN 確認 AS2 消息內容被完整傳輸——接收方基於 (AS2消息內容的) 散列碼進行簽名並附在電子收據 (MDN) 上。
  • 防止惡意模仿——接收方通過 AS2 消息簽名驗證消息是來自可信任的交易夥伴,而不是其他可疑模仿者。
  • 防火牆友好,節約成本—— AS2 不使用昂貴的增值網絡。


既然 AS2 協議運行在 HTTP 之上,因此消息很容易通過防火牆。AS2 還可使用 SSL 加密技術或 HTTP 認證這些額外的安全措施。AS2 協議使用交易夥伴的數字證書 (中的公鑰) 加密消息內容,消息內容也附帶了 (已方私鑰簽署的) 電子簽名保證消息的完整性和不可否認性。通過接收方簽發的 MDN,發送方可以確認 AS2 傳輸過程是否安全,內容是否被篡改。MDN 作為 AS2 消息的一對一電子收據,在推進 B2B 貿易中扮演著重要的角色。


原文出處: 使用AS2(http)协议实现 B2B 商用数据交换 (一) [译] - 个人文章 - SegmentFault 思否
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]使用AS2(http)協議實現 B2B 商用數據交換 (二)

使用AS2(http)協議實現 B2B 商用數據交換 (二) [譯]

前言

設計 AS2 協議的主要目的,是基於 HTTP 協議之上實現安全的結構化電子商業數據交換。在這系列文章的第一部分,我們大體瞭解了 AS2 為何這麼優秀。我們作為 B2B 集成平台 AS2Gateway 的開發者,已經在 AS2 協議這方面工作了很多年。在本篇文章中,我們希望給予更多的見解關於 AS2 協議,如何使用幾行 java 代碼和 S/MIME 格式去構造一個 AS2 消息。

廢話不多說,讓我們現在開始。AS2 消息的基本結構:他由 MIME 格式數據組成,並存在於 HTTP 消息體裡面,再加上一些特有的 AS2 消息頭部。
AS2 消息的最終結構如下圖所示。在本文中,我們會從一個簡單的文檔開始,一步一步生成最終的加密過的 HTTP 消息體。

譯者註:我們看到最外層是 HTTP 數據包,AS2 消息的實際內容 (使用非對稱加密算法加密過的) 是掛載到 HTTP BODY (HTTP請求體) 裡面的。AS2 協議重點就在於如何生成/解析這個 Encrypted HTTP Body (加密過的 HTTP 請求體)。
解密過後的 AS2 消息中還包含了基礎文檔 (Functional Document) 和數字簽名 (Ditital Signature),AS2 協議規定應用軟件需要校驗這個數據簽名 (Digital Signature) 來確保數據完整性,具體做法是

  1. 使用遠程客戶公鑰解密數字簽名,得到一個散列碼,記為 HASH-CODE-1
  2. 使用約定好的散列算法 (例如 MD5, SHA) 計算出基礎文檔 (Functional Document) 的散列碼,記為 HASH-CODE-2
  3. 比較這兩個散列碼 HASH-CODE-1, HASH-CODE-2 從而確認數據是否被篡改

生成 MIME 消息


首先,讓我們看一個 MIME 消息樣例。下面的樣例代碼使用了 JavaMail 和 Apache Tika,用來生成一個 MIME 消息


Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage finalMessage = new MimeMessage(session);
Tika tika = new Tika();
File file = new File("/home/rajind/sample-text-file.txt");
String mimeType = tika.detect(file);
finalMessage.setDataHandler(new DataHandler(new FileDataSource(file)));
finalMessage.setHeader("Content-Type", mimeType);
finalMessage.setHeader("Content-Transfer-Encoding", "base64");
finalMessage.setFileName(file.getName());

生成的 MIME 消息結構如下所示,注意 MIME 的頭部信息和消息內容 (消息內容通過 base64 編碼,因為我們在頭部指定了該編碼格式)


Message-ID: <1642534850.0.1512980924095@rajind-ENVY>
MIME-Version: 1.0
Content-Type: text/plain; name=sample-text-file.txt
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=sample-text-file.txt
c2FtcGxlIHRleHQgY29udGVudCBvbmUK

簽署 MIME 消息


現在我們看看 S/MIME 如何發揮作用。S/MIME 提供了兩種安全措施,數字簽名 (Digital Signature) 和信息加密 (Message Encryption)。這兩項措施是 S/MIME 消息安全性的基礎。數字簽名提供身份認證,消息不可否認性以及數據完整性校驗。信息加密服務則提供了數據機密性以及數據完整性。下面的代碼片斷展示了如何對 MIME 消息進行簽名,這裡我們使用了 Bouncy Castle S/MIME API, Bouncy Castle Crypto package, 以及 Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation.


// loading identity store
FileInputStream is = new FileInputStream("/home/rajind/Downloads/keystore.jks");
KeyStore identityKeystore = KeyStore.getInstance(KeyStore.getDefaultType());
String password = "password";
identityKeystore.load(is, password.toCharArray());
// extracting certificate from identity store
X509Certificate signCert = (X509Certificate) identityKeystore.getCertificate("as2gx");
List certList = new ArrayList();
certList.add(signCert);
Store certs = new JcaCertStore(certList);
// create the generator for creating an smime/signed message
SMIMESignedGenerator signer = new SMIMESignedGenerator();
signer.setContentTransferEncoding("base64");
// extracting private key from identity store
Key key = identityKeystore.getKey("as2gx", password.toCharArray());
KeyPair keyPair;
if (key instanceof PrivateKey) {
Certificate cert = identityKeystore.getCertificate("as2gx");
PublicKey publicKey = cert.getPublicKey();
keyPair = new KeyPair(publicKey, (PrivateKey) key);
} else {
throw new UnrecoverableKeyException("Identity store does not contain keypair for alias " + "as2gx");
}
// add a signer to the generator
signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC")
.build("SHA1WITHRSA", keyPair.getPrivate(), signCert));
// add our pool of certs and certs (if any) to go with the signature
signer.addCertificates(certs);
MimeMultipart signedMimeMultipart = signer.generate(finalMessage, "BC");
finalMessage = new MimeMessage(session);
// set the content of the signed message
finalMessage.setContent(signedMimeMultipart);
finalMessage.saveChanges();

簽署過後,MIME 消息如下如示
譯者註:第一部分為實際內容 "sample text content one" (經base64編碼),第二部分為數字簽名


Message-ID: <1990160809.3.1512983999570@rajind-ENVY>
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-1;
boundary="----=_Part_2_77269878.1512983999569"
------=_Part_2_77269878.1512983999569
Content-Type: text/plain; name=sample-text-file.txt
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=sample-text-file.txt
c2FtcGxlIHRleHQgY29udGVudCBvbmUK
------=_Part_2_77269878.1512983999569
Content-Type: application/pkcs7-signature; name=smime.p7s; smime-type=signed-data
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature
MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIAwggOLMIIC
c6ADAgECAgRzIbxvMA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNVBAYTAlNMMRAwDgYDVQQIEwdXZXN0
ZXJuMRAwDgYDVQQHEwdDb2xvbWJvMRQwEgYDVQQKEwtBZHJvaXRMb2dpYzERMA8GA1UECxMIRGV2
LUFTMkcxGjAYBgNVBAMTEVJhamluZCBSdXBhcmF0aG5hMB4XDTE3MTIxMTA1Mzg0NFoXDTE4MDMx
MTA1Mzg0NFowdjELMAkGA1UEBhMCU0wxEDAOBgNVBAgTB1dlc3Rlcm4xEDAOBgNVBAcTB0NvbG9t
Ym8xFDASBgNVBAoTC0Fkcm9pdExvZ2ljMREwDwYDVQQLEwhEZXYtQVMyRzEaMBgGA1UEAxMRUmFq
aW5kIFJ1cGFyYXRobmEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCNRy9JKmdiX84V
8dk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13
wPL/8mopwFqKuk0wDQYJKoZIhvcNAQEBBQAEggEACxCnEunose/i7kHI1fKSKAKJeUEPTprqxqIt
SmetJiffCNrGU1rf9l33h7AjKQPWHD9HkCDNHyC5F6qviezOZxEAh9e/v8uLwRn4wPorVLqP11wv
mEzPoD9ph82DzK/tCSO1Mtbu9ibB4YtirHNlSw7sFKKTyaXQU/rup2aW6YG2xjeflz6EDrxVhAh+
lgRuuNZPELzpDhuDgYajmbatzxP45s6OzSSRRHfrdoxEVEpNfV915WTPSh5DQ52sCC28RWZC9u1u
wkp0Dqhhg68JrO4cuZgCsUyhdUPzEGKhZ+ibxXzqzwx0yweaw01QgHm34b1qjXVLO4LTlJCm3UIq
agAAAAAAAA==
------=_Part_2_77269878.1512983999569--

加密 MIME 消息


// 加載partner的數字證書
CertificateFactory fact = CertificateFactory.getInstance("X.509");
FileInputStream is = new FileInputStream("/home/rajind/Downloads/partner-cert.pem");
X509Certificate cert = (X509Certificate) fact.generateCertificate(is);
// 創建加密器
SMIMEEnvelopedGenerator encryptor = new SMIMEEnvelopedGenerator();
encryptor.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider("BC"));
encryptor.setContentTransferEncoding("base64");
JceCMSContentEncryptorBuilder jceCMSContentEncryptorBuilder =
new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(SMIMEEnvelopedGenerator.DES_EDE3_CBC)).setProvider("BC");
jceCMSContentEncryptorBuilder.setSecureRandom(new SecureRandom());
// 進行加密
MimeBodyPart encryptedPart = encryptor.generate(finalMessage, jceCMSContentEncryptorBuilder.build());
// 設置加密後的內容
finalMessage = new MimeMessage(session);
finalMessage.setContent(encryptedPart.getContent(), encryptedPart.getContentType());
finalMessage.setHeader("Content-Transfer-Encoding", "base64");
finalMessage.saveChanges();

經過簽字 (sign) 和加密 (encrypt) 後,MIME 消息變成了下面那樣


Message-ID: <347808407.5.1512984099462@rajind-ENVY>
MIME-Version: 1.0
Content-Type: application/pkcs7-mime; name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XRZXf4aSYoZrOt2JUJYshfi/EW7fexATQyBxPqefRzTgE3PCljC7qNCdkmJAAAAAAA
AAAAAAA=

你可能注意到上面代碼片段中硬編碼的證書算法。在實際的 AS2 B2B 通信場景中,這些參數需要非常方便去配置。
下一步就是要加入與 AS2 有關的 HTTP 頭部,並把消息發送出去,接著是解析收到的消息。這些將會在未來的文章中介紹。

P.S. 請注意上述代碼片斷只是給你一個關於 AS2 消息處理的初印象,他們也許不符合編程標準,也沒有異步處理。


原文出處:使用AS2(http)协议实现 B2B 商用数据交换 (二) [译] - 个人文章 - SegmentFault 思否
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]BizTalk for AS2 加密/加簽傳輸練習

BizTalk for AS2 加密/加簽傳輸練習

BizTalk for AS2 加密/加簽傳輸練習

AS2是互聯網上安全,可靠地傳輸數據的最常用的方式。AS2為信息建立信封並通過電子證書和加密在互聯網上安全地發送出去。

因此被很多大公司特別是國外的公司在B2B領域廣泛使用。

BizTalk從2006開始內建支持AS2;而且配置很簡單(如果你知道了AS2基本原理和BizTalk的基本配置)

AS2傳輸方式

AS2簡單的說類似SSL,通過HTTP/HTTPS協議傳輸;利用證書實現加簽和加密,因此必須要可用於交換和加簽的證書(說白了就是需要帶私鑰的證書,下面會提到怎麼申請證書)。

練習的環境

一台BizTalk(Fabrikam),從文件目錄下把XML文件通過AS2的方式發送給另外一台BizTalk(Contoso),Contoso BizTalk把接收的http請求落地到一個文件目錄。

這裡沒有使用https(SSL)如果要使用https只需要把接收的地址配置成https即可。

申請證書

這個環境裡面我需要2本證書,一本給 Fabrikam,一本給Contoso;然後導出並交換公鑰。

申請證書最簡單的方式還是自己創建一個CA服務這樣跟證書,證書鏈都有了,使用命令創建太繁瑣,我搞了半天沒有搞出想要的證書。

申請證書的時候一定勾選


證書就有了私鑰

2本證書申請好後就要導入證書(如果是通過IE申請的,系統會自動安裝)。

將各自的證書導入到當前用戶的個人下面。如圖

將對方導出的公鑰證書導入到當前用戶的其他人下面

注意:如果BizTalk報 "The Signing Certificate has not been configured" error using certificates with EDI/AS2,這可能是你的當前用戶和BizTalk實例運行配置的賬戶不是同一個,因此找不到證書。所以必須要用BizTalk服務的賬戶來導 允許命令 runas /user:BizTalkServiceAccount mmc

證書配置好後就完成了一大半。

在BizTalk上配置證書

下面瞭解一下證書的用途。


BizTalk證書的配置參見

http://msdn.microsoft.com/zh-cn/library/bb728096.aspx

用於簽名的證書部署在

解密的證書部署在

驗證簽名的證書部署在

配置BizTalk Parties

Fabrikam BizTalk配置

Parties的配置非常關鍵,Party的意思是你的合作夥伴和你通訊的一方

在Fabrikam BizTalk新建一個Contoso的Party,這裡不用傻呼呼再一個Fabrikam。

制定以下發送端口


這樣發送端口(SendToContoso)就可以讀取這個party配置的屬性寫入到http的上下文中一起post到遠程地址實現通訊了

配置AS2 Properties

對於Fabrikam來說Contoso就是接收放,因此我們這裡只需要配置[Party as AS2 Message Receiver] Fabrikam出站的消息需要加簽/加密。AS2-From/AS2-To定義好。

Request MDN就是類似一個ACK,但HTTP/HTTPS本身就有request/response,如果調用時候會立即返回http錯誤代碼401,500,所以一般不需要配置。

Contoso BizTalk配置

在Contoso BizTalk Parties只需要見一個Fabrikam。Fabrikam對於Contoso來說就是發送方

配置驗證簽名的Fabrikam導出的公鑰的證書

配置AS2 Properties

默認即可


這樣就配置完成了

測試

在Fabrikam BizTalk新建一個接收端口從文件目錄接收,SendToContoso發送端口地址填寫對方的接收網址。

Contoso BizTalk 新建一個http接收端口接收Fabrikam Post過來的數據並且保存到文件目錄下

OK,完成了希望對初次使用BizTalk開發AS2項目的有所幫助。需要支持的請留言。

本文參與 騰訊雲自媒體分享計劃,歡迎正在閱讀的你也加入,一起分享。


原文出處:BizTalk for AS2 加密/加签传输练习 - 云+社区 - 腾讯云
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Getting Started With AS2 Protocol Using AS2Gateway and OpenAS2

Getting Started With AS2 Protocol Using AS2Gateway and OpenAS2

Most of the large retail providers and consumer product suppliers such as Walmart, Amazon, Morgan Foods, etc. have decided to go with AS2 protocol in the last few years. Based on this trend, all of their suppliers are asked to send their invoices, purchase orders, and other B2B trading messages over AS2. Because of that, the trend for usage of AS2 has been significantly increased over the last couple of years. In this blog, I’m going to explain how to get started with AS2 protocol and how you send and receive AS2 messages using two software applications which provide AS2 capabilities.

What Is AS2?


In simple terms, the Applicability Statement 2 or AS2 specification defines a mechanism for secure and reliable transfer of structured business data over the Internet. In contrast to other traditional B2B trading protocols, AS2 offers a secure, efficient, and simple to use trading environment without a need for proprietary devices, software, or expensive private networks or value added networks. If you are new to AS2 protocol, I highly recommend you read
this description of AS2 protocol before going to use it in your production requirements. It describes what AS2 is, why we need AS2, and its key benefits in simple terms, and you don’t have to have a technical background to understand it. If you have some technical background and you want to know how the protocol operates over the HTTP/S protocol, you can refer to  this and get a better understanding of the implementation of the AS2 protocol.


There are a few software applications (on-premise and SaaS) which provide AS2 capability. For this exercise, I have used AS2Gateway and OpenAS2 to explain how to configure these two applications to send messages back and forth.

What Is OpenAS2?

OpenAS2 is a Java-based implementation of the AS2 standard which supports XML file-based configuration — user interface configuration is not yet implemented, but it’s there on their roadmap. You can download OpenAS2 from the above location. Make sure you download the latest version to minimize the effect of already fixed issues.

What Is AS2Gateway?


AS2Gateway is a SaaS application which implements the AS2 specification while providing the ability to configure AS2 stations and trading partners from a nice and simple user interface. Compared to OpenAS2, it’s quite easy to configure AS2Gateway for your AS2 requirements - especially if you are a user who doesn’t have a good technical background and are not familiar with server type applications working without a graphical UI. You will understand the difference while reading this blog. Since it has a GUI, it provides additional utility functionalities for advanced requirements on AS2, such as certificate management, SFTP integration, and much more.


In this exercise, I’m using two hypothetical organizations — Company X and Company Y, which expect to send and receive AS2 messages back and forth based on their B2B trading requirements. Company names will be important here, because I’m going to use AS2 identifiers based on the company name; for Company X, the AS2 identifier will be company-x-as2-id and for Company Y, it company-y-as2-id. Company X uses OpenAS2 as the AS2 software, while Company Y uses AS2Gateway as its AS2 software.

First, I’ll explain how Company X should configure its AS2 Station and trading partners in OpenAS2 and then explain the same on the AS2Gateway.

Set Up OpenAS2

First, you need to install OpenAS2 on your machine.

Installation

You just need to download and extract the ZIP file for the installation. Once it’s extracted, you can start the AS2Server by executing the bin/start-openas2.sh file. Make sure scripts are executable.

Configuration


In OpenAS2, there isn’t a concept called AS2 Station. It identifies both station and partner as two different partners and configures their relationship as a partnership. There are two main configuration files that you need to focus on basic AS2 options.

The first one is the config/config.xml. In this file, you can configure modules for AS2 message handling. You need to configure a set of AS2DirectoryPollingModule modules to fetch files to send to different partner. For each partnership between two partners, you need to have an AS2DirectoryPollingModule module element to send files from one partner to another.

The second one is the config/partnership.xml. There you need to configure declarations of each partner and relationships between those declared partners. To declare partners, you should have a partner type XML element with partner name, partner AS2 ID, partner x509 alias (for certificate management) and email — just focus on partner name, AS2 ID, and partner alias.


All the relationships between each partner should be defined as a partnership XML element in the partnerships.xml file. This element represents one-way relationships between one partner to another. If you want to send messages in both sides, you have to configure two partnership XML elements.

The next main important thing is certificate management which is the tricky part. Here you have to import and export your certificates manually to/from your keystore. By default, it uses config/as2_certs.p12 as the keystore. You can configure the keystore path by changing the filename attribute of the certificates XML element in the config/config.xml file. In the default keystore, there are two keys for two default partners — openas2a and openas2b.

For keystore configuration, there are two things you have to do:


  1. Import your trading partner’s certificate into keystore using a keystore managing software or keytool — you can get the certificate of the AS2Gateway station (company-y-as2-id) using “View partner configuration” option in the AS2Gateway.
  2. Export certificate chain of the key of your side partner (or in other words, your AS2 station — in this example, this should be the key of AS2 station with AS2 ID company-x-as2-id) and use it to configure your trading partner at the other end (in this example, the other end is the Company Y).

To configure OpenAS2, as explained in the following section, you need information about the AS2Gateway side station. You can get this information from the “Partner Configuration” view of your AS2 station — AS2Station view -> View Partner Configuration. This view will have all the required information to configure AS2Gateway side station in some other AS2 server as a trading partner. Generally, users’ of the AS2Gateway will use this and send this information to their trading partners via Share Configuration option in the Partner Configuration view page

Configure OpenAS2 for the Example Use Case

From the OpenAS2 side, sending party would be AS2Station with AS2 ID — company-x-as2-id and receiving party AS2 ID should be company-y-as2-id.

1. For this, you first have to configure partnerships.xml file as below — from the Company X point for view, Company X is the AS2 station and Company Y is the trading partner.


<partnerships>
    <partner name="CompanyXStation"
             as2_id="company-x-as2-id"
             x509_alias="company-x"
             email="companyx@gmail.com"/>
    <partner name="CompanyYPartner"
             as2_id="company-y-as2-id"
             x509_alias="company-y"
             email="companyy@gmail.com"/>
    <partnership name="CompanyXStation-to-CompanyYPartner">    <!-- partnership to send messages from CompanyXStation to CompanyYPartner -->
        <sender name="CompanyXStation"/>   <!-- sending party name-->
        <receiver name="CompanyYPartner"/>  <!-- receiving party name-->
        <attribute name="protocol" value="as2"/>
        <attribute name="content_transfer_encoding" value="8bit"/> <!-- content transfer encoding - seems like this is not working as expected -->
        <attribute name="compression_type" value="ZLIB"/>  <!-- compression type to used to compress AS2 message -->
        <attribute name="subject" value="From OpenAS2A to OpenAS2B"/>
        <attribute name="mdnsubject" value="Your requested MDN response from $receiver.as2_id$"/>
        <attribute name="as2_url" value="http://service.beta.as2gateway.com:8280/service/as2-receiver"/>
				<!-- This should be the CompanyXStation message receiving URL -->
        <attribute name="as2_mdn_to" value="http://receipt.beta.as2gateway.com:8284/service/as2-async-mdn-receiver"/>
				<!-- This should be the CompanyXStation MDN receiving URL -->
        <attribute name="as2_mdn_options" value="signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha-256"/>
				<!-- configure how do you want to get MDN - whether it should be signed or not etc.
				This will be added directly to Disposition-Notification-Options transport header without any modification -->
        <attribute name="encrypt" value="3DES"/>    <!-- Encryption algorithm-->
        <attribute name="sign" value="SHA1"/>    <!-- Sign digest algorithm-->
        <attribute name="resend_max_retries" value="3"/>
        <attribute name="prevent_canonicalization_for_mic" value="false"/>   <!-- should verify the mic -->
        <attribute name="no_set_transfer_encoding_for_signing" value="false"/>
				<!-- better to go with the default values for the rest of the configurations -->
        <attribute name="no_set_transfer_encoding_for_encryption" value="false"/>
        <attribute name="rename_digest_to_old_name" value="false"/>
        <attribute name="remove_cms_algorithm_protection_attrib" value="false"/>
    </partnership>
    <partnership name="CompanyYPartner-to-CompanyXStation">  <!-- partnership to send messages from CompanyYPartner to CompanyXStation -->
        <sender name="CompanyYPartner"/>
        <receiver name="CompanyXStation"/>
        <attribute name="protocol" value="as2"/>
        <attribute name="content_transfer_encoding" value="8bit"/>
        <attribute name="subject" value="From OpenAS2B to OpenAS2A"/>
        <attribute name="as2_url" value="http://my-public-ip:10080"/>
				<!-- AS2 message receiving URL at the OpenAS2 side. IP of this URL should be replaced with your public IP.
				This IP should be publically reachble. If you are using default configuration, then use above IP together with your IP -->
        <attribute name="as2_mdn_to" value="http://my-public-ip:10081"/>
				<!-- AS2 message receiving URL at the OpenAS2 side. IP of this URL should be replaced with your public IP.
				This IP should be publically reachble. If you are using default configuration, then use above IP together with your IP -->
        <attribute name="as2_mdn_options" value="signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha256"/>
        <attribute name="encrypt" value="3DES"/>
        <attribute name="sign" value="SHA256"/>
        <attribute name="prevent_canonicalization_for_mic" value="false"/>
        <attribute name="remove_cms_algorithm_protection_attrib" value="false"/>
        <attribute name="no_set_transfer_encoding_for_signing" value="false"/>
        <attribute name="no_set_transfer_encoding_for_encryption" value="false"/>
        <attribute name="rename_digest_to_old_name" value="false"/>
        <attribute name="remove_cms_algorithm_protection_attrib" value="false"/>
    </partnership>
</partnerships>


2. Next, you need to configure config/config.xml file for file polling configurations — OpenAS2 gets input files (to send out as an AS2 message), by polling directories configured from following XML elements.


<partnerships>
    <partner name="CompanyXStation"
             as2_id="company-x-as2-id"
             x509_alias="company-x"
             email="companyx@gmail.com"/>
    <partner name="CompanyYPartner"
             as2_id="company-y-as2-id"
             x509_alias="company-y"
             email="companyy@gmail.com"/>
    <partnership name="CompanyXStation-to-CompanyYPartner">
		<!-- partnership to send messages from CompanyXStation to CompanyYPartner -->
        <sender name="CompanyXStation"/>   <!-- sending party name-->
        <receiver name="CompanyYPartner"/>  <!-- receiving party name-->
        <attribute name="protocol" value="as2"/>
        <attribute name="content_transfer_encoding" value="8bit"/>
				<!-- content transfer encoding - seems like this is not working as expected -->
        <attribute name="compression_type" value="ZLIB"/>
				<!-- compression type to used to compress AS2 message -->
        <attribute name="subject" value="From OpenAS2A to OpenAS2B"/>
        <attribute name="mdnsubject" value="Your requested MDN response from $receiver.as2_id$"/>
        <attribute name="as2_url" value="http://service.beta.as2gateway.com:8280/service/as2-receiver"/>
				<!-- This should be the CompanyXStation message receiving URL -->
        <attribute name="as2_mdn_to" value="http://receipt.beta.as2gateway.com:8284/service/as2-async-mdn-receiver"/>
				<!-- This should be the CompanyXStation MDN receiving URL -->
        <attribute name="as2_mdn_options" value="signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha-256"/>
				<!-- configure how do you want to get MDN - whether it should be signed or not etc.
				This will be added directly to Disposition-Notification-Options transport header without any modification -->
        <attribute name="encrypt" value="3DES"/>    <!-- Encryption algorithm-->
        <attribute name="sign" value="SHA1"/>    <!-- Sign digest algorithm-->
        <attribute name="resend_max_retries" value="3"/>
        <attribute name="prevent_canonicalization_for_mic" value="false"/>   <!-- should verify the mic -->
        <attribute name="no_set_transfer_encoding_for_signing" value="false"/>
				<!-- better to go with the default values for the rest of the configurations -->
        <attribute name="no_set_transfer_encoding_for_encryption" value="false"/>
        <attribute name="rename_digest_to_old_name" value="false"/>
        <attribute name="remove_cms_algorithm_protection_attrib" value="false"/>
    </partnership>
    <partnership name="CompanyYPartner-to-CompanyXStation">  <!-- partnership to send messages from CompanyYPartner to CompanyXStation -->
        <sender name="CompanyYPartner"/>
        <receiver name="CompanyXStation"/>
        <attribute name="protocol" value="as2"/>
        <attribute name="content_transfer_encoding" value="8bit"/>
        <attribute name="subject" value="From OpenAS2B to OpenAS2A"/>
        <attribute name="as2_url" value="http://my-public-ip:10080"/>
				<!-- AS2 message receiving URL at the OpenAS2 side. IP of this URL should be replaced with your public IP.
				This IP should be publically reachble. If you are using default configuration, then use above IP together with your IP -->
        <attribute name="as2_mdn_to" value="http://my-public-ip:10081"/>
				<!-- AS2 message receiving URL at the OpenAS2 side. IP of this URL should be replaced with your public IP.
				This IP should be publically reachble. If you are using default configuration, then use above IP together with your IP -->
        <attribute name="as2_mdn_options" value="signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha256"/>
        <attribute name="encrypt" value="3DES"/>
        <attribute name="sign" value="SHA256"/>
        <attribute name="prevent_canonicalization_for_mic" value="false"/>
        <attribute name="remove_cms_algorithm_protection_attrib" value="false"/>
        <attribute name="no_set_transfer_encoding_for_signing" value="false"/>
        <attribute name="no_set_transfer_encoding_for_encryption" value="false"/>
        <attribute name="rename_digest_to_old_name" value="false"/>
        <attribute name="remove_cms_algorithm_protection_attrib" value="false"/>
    </partnership>
</partnerships>


3. Then you have to configure certificates and your keystore. For that, you first have to create a key pair for your Company-X side station. You can easily do that using a tool like Portacle. Since we have configured CompanyXStaion partner’s x509 alias as company-x, you have to give the entry name/alias for the key pair that you’re going to create for your Company-X.

4. Then you can export your OpenAS2 station’s certificate chain, as shown in the below screenshot. You just have to select the correct key and export the certificate chain via keystore management utility — Portacle.


5. Then, you have to import your CompanyYPartner’s certificate to your OpenAS2 side trust store. For that, you have to get this from the Company-Y side. In this case, you can get this certificate from the AS2Gateway.

With this, you are done with the OpenAS2 side configuration.

Set Up the AS2 Gateway

For AS2Gateway, you just have to sign up as a free user and get an evaluation period of one month with the exact same features, like a premium/paid user. For the registration, you don’t have to provide any credit card information, you just need a valid email address for that. You can sign up/register for AS2Gateway from here. Go to that link and click on Create Account option to create a new account for you.


From the configuration point of view, I think I don’t have to introduce anything for that. Since there is a user interface and it’s self-explainable, you should be able to identify key components of that. For our example, you just have to create a Station with AS2 ID company-y-as2-id and trading partner for Company X. I’ll explain this in next steps.

Configure AS2Gateway for the Example Use Case

As per our example, Company-Y should configure AS2Gateway to send/ receive messages with Company-X. From the AS2 point of view, we should send messages to AS2 station with AS2 ID, company-y-as2-id to the trading partner with AS2 ID, company-x-as2-id. Go through following steps to configure AS2Gateway.


  1. Assuming that you have already registered with AS2Gateway, you just have to create AS2Station using the graphical UI. You can easily navigate to Stations view using left navigation menu of the AS2Gateway. Click on New Station button at the top of the page. Then you just have to give an AS2 ID for your station. In our example, AS2 ID should be company-y-as2-id. And then click the Save button.

  2. Then you should create a Partner within the AS2Gateway to represent your trading partner — in our case, Company-X is the trading partner for Company-Y. For that, you just have to go to the Partner view using left navigation menu and then click on New Partner button at the top of the page.

  3. In partner creation page, you have to specify the AS2 ID of the partner — company-x-as2-id in our example.


  4. Specify the URI to be used while sending messages to this partner. In our example, this URI should be “http://my-public-ip:10080" — my-public-IP part should be replaced with your current public IP and it makes sure it’s publicly reachable.

  5. Then you have to upload your partner’s certificate for the Encryption Certificate field. This should get from the OpenAS2 side (as explained in the following section you have to export certificate chain of your OpenAS2 side station) since it’s the partner for this example.

  6. Optionally, you can configure a subject to be included while sending messages to this partner. Then click on the Save button to complete the partner creation.


Now it’s all done and you should be able to send and receive AS2 messages between AS2Gateway and OpenAS2. To send messages from the AS2Gateway side, you just have to navigate to the messages view using left navigation menu, and send a new message using the Compose Message option. All the received messages to the AS2Gateway will be there in the Inbox tab of the messages view and you can see all the information including transport headers, MDN related information and message payload using the view message option.

To send a message from OpenAS2 side to AS2Gateway, you have placed an input file to the configured input file folder. As per above configuration, it should be the

data/toAS2GStation. Received MDNs will be saved in data/OpenAS2A-to-AS2GStation/mdn folder. Received messages from AS2Gateway to OpenAS2, should be saved to the data/AS2GStation-to-OpenAS2A/inbox folder.


As you have already felt, configuring AS2Gateway for AS2 communication is much easier since it has a simple user interface and utility functionalities for certificate management and SFTP integration.

I hope you have enjoyed the blog and it’s useful to you. If you have any comments or suggestions, feel free to share in the comments.


原文出處:Getting Started With AS2 Protocol Using AS2Gateway and OpenAS2 - DZone Integration
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Manage business documents with OpenAS2 on Fedora

Manage business documents with OpenAS2 on Fedora

Business documents often require special handling. Enter Electronic Document Interchange, or EDI. EDI is more than simply transferring files using email or http (or ftp), because these are documents like orders and invoices. When you send an invoice, you want to be sure that:

1. It goes to the right destination, and is not intercepted by competitors.
2. Your invoice cannot be forged by a 3rd party.
3. Your customer can’t claim in court that they never got the invoice.

The first two goals can be accomplished by HTTPS or email with S/MIME, and in some situations, a simple HTTPS POST to a web API is sufficient. What EDI adds is the last part.


This article does not cover the messy topic of formats for the files exchanged. Even when using a standardized format like ANSI or EDIFACT, it is ultimately up to the business partners. It is not uncommon for business partners to use an ad-hoc CSV file format. This article shows you how to configure Fedora to send and receive in an EDI setup.

Centralized EDI

The traditional solution is to use a Value Added Network, or VAN. The VAN is a central hub that transfers documents between their customers. Most importantly, it keeps a secure record of the documents exchanged that can be used as evidence in disputes. The VAN can use different transfer protocols for each of its customers

AS Protocols and MDN


The AS protocols are a specification for adding a digital signature with optional encryption to an electronic document. What it adds over HTTPS or S/MIME is the Message Disposition Notification, or MDN. The MDN is a signed and dated response that says, in essence, “We got your invoice.” It uses a secure hash to identify the specific document received. This addresses point #3 without involving a third party.

The AS2 protocol uses HTTP or HTTPS for transport. Other AS protocols target FTP and SMTP. AS2 is used by companies big and small to avoid depending on (and paying) a VAN.

OpenAS2

OpenAS2 is an open source Java implemention of the AS2 protocol. It is available in Fedora since 28, and installed with:


$ sudo dnf install openas2
$ cd /etc/openas2

Configuration is done with a text editor, and the config files are in XML. The first order of business before starting OpenAS2 is to change the factory passwords.

Edit /etc/openas2/config.xml and search for ChangeMe. Change those passwords. The default password on the certificate store is testas2, but that doesn’t matter much as anyone who can read the certificate store can read config.xml and get the password.

What to share with AS2 partners

There are 3 things you will exchange with an AS2 peer.

AS2 ID


Don’t bother looking up the official AS2 standard for legal AS2 IDs. While OpenAS2 implements the standard, your partners will likely be using a proprietary product which doesn’t. While AS2 allows much longer IDs, many implementations break with more than 16 characters. Using otherwise legal AS2 ID chars like ‘:’ that can appear as path separators on a proprietary OS is also a problem. Restrict your AS2 ID to upper and lower case alpha, digits, and ‘_’ with no more than 16 characters.

SSL certificate

For real use, you will want to generate a certificate with SHA256 and RSA. OpenAS2 ships with two factory certs to play with. Don’t use these for anything real, obviously. The certificate file is in PKCS12 format. Java ships with keytool which can maintain your PKCS12 “keystore,” as Java calls it. This article skips using openssl to generate keys and certificates. Simply note that
sudo keytool -list -keystore as2_certs.p12 will list the two factory practice certs.

AS2 URL

This is an HTTP URL that will access your OpenAS2 instance. HTTPS is also supported, but is redundant. To use it you have to uncomment the https module configuration in config.xml, and supply a certificate signed by a public CA. This requires another article and is entirely unnecessary here.

By default, OpenAS2 listens on 10080 for HTTP and 10443 for HTTPS. OpenAS2 can talk to itself, so it ships with two partnerships using http://localhost:10080 as the AS2 URL. If you don’t find this a convincing demo, and can install a second instance (on a VM, for instance), you can use private IPs for the AS2 URLs. Or install Cjdns to get IPv6 mesh addresses that can be used anywhere, resulting in AS2 URLs like http://[fcbf:fc54:e597:7354:8250:2b2e:95e6:d6ba]:10080.


Most businesses will also want a list of IPs to add to their firewall. This is actually bad practice. An AS2 server has the same security risk as a web server, meaning you should isolate it in a VM or container. Also, the difficulty of keeping mutual lists of IPs up to date grows with the list of partners. The AS2 server rejects requests not signed by a configured partner.

OpenAS2 Partners

With that in mind, open partnerships.xml in your editor. At the top is a list of “partners.” Each partner has a name (referenced by the partnerships below as “sender” or “receiver”), AS2 ID, certificate, and email. You need a partner definition for yourself and those you exchange documents with. You can define multiple partners for yourself. OpenAS2 ships with two partners, OpenAS2A and OpenAS2B, which you’ll use to send a test document.

OpenAS2 Partnerships


Next is a list of “partnerships,” one for each direction. Each partnership configuration includes the sender, receiver, and the AS2 URL used to send the documents. By default, partnerships use synchronous MDN. The MDN is returned on the same HTTP transaction. You could uncomment the as2_receipt_option for asynchronous MDN, which is sent some time later. Use synchronous MDN whenever possible, as tracking pending MDNs adds complexity to your application.

The other partnership options select encryption, signature hash, and other protocol options. A fully implemented AS2 receiver can handle any combination of options, but AS2 partners may have incomplete implementations or policy requirements. For example, DES3 is a comparatively weak encryption algorithm, and may not be acceptable. It is the default because it is almost universally implemented.


If you went to the trouble to set up a second physical or virtual machine for this test, designate one as OpenAS2A and the other as OpenAS2B. Modify the as2_url on the OpenAS2A-to-OpenAS2B partnership to use the IP (or hostname) of OpenAS2B, and vice versa for the OpenAS2B-to-OpenAS2A partnership. Unless they are using the FedoraWorkstation firewall profile, on both machines you’ll need:

# sudo firewall-cmd --zone=public --add-port=10080/tcp

Now start the openas2 service (on both machines if needed):

# sudo systemctl start openas2

Resetting the MDN password

This initializes the MDN log database with the factory password, not the one you changed it to. This is a packaging bug to be fixed in the next release. To avoid frustration, here’s how to change the h2 database password:


alter user sa set password '$2';
exit
EOF
DONE
$ sudo sh h2passwd ChangeMe yournewpasswordsetabove
$ sudo systemctl start openas2

Testing the setup

With that out of the way, let’s send a document. Assuming you are on OpenAS2A machine:

$ cat >testdoc <<'DONE'
This is not a real EDI format, but is nevertheless a document.
DONE
$ sudo chown openas2 testdoc
$ sudo mv testdoc /var/spool/openas2/toOpenAS2B
$ sudo journalctl -f -u openas2
... log output of sending file, Control-C to stop following log
^C

OpenAS2 does not send a document until it is writable by the openas2 user or group. As a consequence, your actual business application will copy, or generate in place, the document. Then it changes the group or permissions to send it on its way, to avoid sending a partial document.

Now, on the OpenAS2B machine, /var/spool/openas2/OpenAS2A_OID-OpenAS2B_OID/inbox
shows the message received. That should get you started!


原文出處:Manage business documents with OpenAS2 on Fedora - Fedora Magazine
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|