We are trying to send and encrypted EDI(Electronic Data Interchange) String along with a digital signature in the form of SMIME to Canada Border Services Agency ,but getting Error everytime we try different approaches. The request SMIME payload we are sending is :
Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1;
boundary="----=_Part_0_1964847681.1577187780616"
------=_Part_0_1964847681.1577187780616
Content-Type: application/edi-edifact
Content-Length: 881
UNA:+.?'
UNB+UNOA:3+KAGATEWAY:CBSANETWORKID+191017:0930+REF12345'UNG+CUSDEC+ +IIDT+191017:0930+GREF12345+UN+D:13A:IID'
UNH+MREF12345+GOVCBR:D:13A:UN:IID'
BGM+929+119081234567X+9'
DTM+132:CCYYMMDDHHMMZZZ:303'MOA+134:10000:CAD'
RFF+CN:WXYZ12345678987654321'
GOR++5'LOC+23+0809+3470'
NAD+IM+868929415RM0001++ INC+6955 AVE+NEWARK+CA+94560+US'UNS+D'
SEQ+1'NAD+VN+++ZOY HOME FURNISHING CO+BUILDING 2-5:TANGPU INDUSTRIAL PARK+DIPU,ANJI+ZJ+313301+CN'
NAD+UC+868929415RM0001++ CAN+123 +VANCOUVERBC+V5K1A5+CA'LOC+35+CN'
DTM+757:20191001:102'DOC+380+98027209'SEQ+1'DTM+3:20190901:102'MOA+39:10000CAD'MEA+AAE+AAB+KGM:5000'QTY+47:180:H87'LIN+1'NAD+MF+++ZOY HOME CO+BUILDING 2-5: INDUSTRIAL PARK+DIPU,ANJI+ZJ+313301+CN'
LOC+27+CN'PAC+180+3+BX'SEQ+1'GID+1'
IMD++8+:::METAL +AAE+ABS+KGM:4500'MOA+66:10000CAD'TCC+++9401791000:HS'CNT+51:180:EA'SEQ+1'HYN+3'UNS+S'UNT+20+MREF12345'UNE+1+GREF12345'UNZ+1+REF12345'
------=_Part_0_1964847681.1577187780616
Content-Type: application/pkcs7-signature
Content-Transfer-Encoding: base64
Content-Length: 1640
0�� *�H��
���0��1�u0�q0Y0Q1
0 UCA1
0 U
GC10U
cra-arc10
U
Extern10U
EXTTESTCASd=0
*�H��
� {/d�R'^J��o�����.�M5Q:��^��Ў�2�<�)9a �VS�|O�.�P/�(N�"�IJ��0_HH�m!��I.
j3�a �`����g�4|ll.�M��uVW�8��2�y[�$0_���j
���m�2���uul��9ehqS��N�O����������{m'� >�ϻ��cL���9�R�g�͜����{�O
�h-�UJ��(��W�dԼd\
Q7��|��:����P����0� *�H��
0 *�H��}B
0_.h�U�������"�q�����S �C2X������*a�
�eٲQ��>`˨�?�����|i���a��³ev�
��������`�����cY]�����#�Ӡ(n�o��Jm���!�F?J�1� �6]M�l#]��u֡p�;�Fn����
����w8Dz�Q�
����R�����~h�K��E��
�n{ϬA��3LA=����y�!��?7�h`\[%�y>�%10������� s�-��z=E�,�K�������:��9�?�F��
VpT#A�7�[=�� �y2�w�o:[�"�;���ŗp5�C�uk��qf5l�
Ȑ���:��X��Y1�ς�ˆ?P�]���^�����8�m�:3|���#Qm=0\���r �����X�
q�Eڂz�A�a\1l�D�4,x�V�g79c��)>T�ժ���d:��]<�.ri�@vl����C������|T��l��<;�n�,�H�p~D����;��VN�VT�*�o:���y%�jfh4�S���Pf)>Z����5��L�<�
R���������#�3Ҫ��T�a�nMh6q@cێ���eʯ�p$ƅv����� cb�zQc�&�5li���zg!��
E�)�i�$v��%Y'�
o�zX����q���P�)F��c<�`e�B~
&��SL�J��M��������o�M�K�Q{��<m�|��"�yo��(�%�_���g�����$���NiV�z�u����u��T��_#g���b��r�H��̨�'rw���:n[!�e@
o_�� �l2'2�
�T�Q��7�k7�(�4�e���G"����>{'1b�4,?Y���#)
��u(�ч���ܤ6weMLY��b�f�����8}&��v��?�Ti�R:g$�P5��v�Ž~���
܅��q��RK;��
*"N�G�O�[R����>��Cm8o懏�e�T_
------=_Part_0_1964847681.1577187780616--
The exception is: Response code : 400
Response Message : Bad Request
Error Message :
400 BAD REQUEST
Your transaction <<393BDE.000003.00179@yourhost.yourcompany.com>> could not be processed due to the following error(s):java.io.IOException: Unexpected response code received from servlet: 400
EERROR 2207:Smime does not conains 2 body parts
END: Communication with servlet
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)--
If anyone has worked with CBSA or worked with entrust or EDI ..please help we are stuck Any help related to the exception in SMIME will also be really helpful
The code I m using is:
mbp1.addHeader("Content-Length", String.valueOf(testMessage.length()));
PropUtil.getBooleanSystemProperty("mail.mime.multipart.ignoreexistingboundaryparameter", true);
// contentType = new ContentType("multipart","mixed",pml);
// contentType.setParameter("boundary", getBoundary());
//
// contentType1 = new ContentType("multipart","mixed",pml1);
// contentType1.setParameter("boundary", getBoundary());
//
// contentType2 = new ContentType("multipart","mixed",pml2);
// contentType2.setParameter("boundary", getBoundary());
// contentType = type.toString();
MimeMultipart mimeMultipart = new MyMimEMultipart("signed");
SMimeBodyPart ediEdiPart = new SMimeBodyPart();
ByteArrayOutputStream fout = new ByteArrayOutputStream();
fout.write(testMessage.getBytes());
ByteArrayOutputStream encoded = (ByteArrayOutputStream)MimeUtility.encode(fout, "7bit");
byte[] gg = encoded.toByteArray();
InternetHeaders internetHeaders = new InternetHeaders();
internetHeaders.addHeader("Content-Type", "application/edi-edifact");
internetHeaders.addHeader("Content-Length", String.valueOf(gg.length));
internetHeaders.addHeader("Content-Transfer-Encoding","7-bit");
SMimeBodyPart newthing= new SMimeBodyPart(internetHeaders,gg);
ByteArrayOutputStream consoleStream = new ByteArrayOutputStream();
newthing.writeTo(consoleStream);
// consoleStream.writeTo(System.out);
FileOutputStream f= new FileOutputStream("/Users/lakshyakumarsingh/Documents/kx-github/kn-cbsaproxy/src/main/resources/test1_decode.txt");
f.write(consoleStream.toByteArray());
// System.out.println("this is the input");
// System.out.println(consoleStream.toString("US-ASCII"));
// ediEdiPart.setHeader("Message-ID","29123185.1.1449072497221.JavaMail.axg129@WH12CU10178A");
// ediEdiPart.setHeader("Content-Type", "application/edi-edifact");
// int contentlength = testMessage.length();
ediEdiPart.setDataHandler(dataHandler);
// ediEdiPart.setText(finalString);
// ediEdiPart.setHeader("Content-Transfer-Encoding", "binary");
ediEdiPart.setHeader("Content-Length", String.valueOf(testMessage.length()));
// ediEdiPart.setContent(testMessage, "application/edi-edifact");
// mimeMultipart.setParent(PART.);
// System.out.println("contetnt type is : " + contentType.toString());
mimeMultipart.setSubType("signed");
mimeMultipart.setPreamble(
"Content-Type: multipart/signed; protocol=\"application/pkcs7-signature\"; micalg=sha1; \n" +
"\tboundary=\"----=_Part_0_1964847681.1577187780616\"");
mimeMultipart.addBodyPart(newthing);
SMimeBodyPart mbp2 = new SMimeBodyPart();
mbp2.addHeader("Content-Type", "application/pkcs7-signature");
mbp2.addHeader("Content-Transfer-Encoding", "binary");
// mbp2.addHeader("Content-Description", "S/MIME Cryptographic Signature");