EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SB_AS_ERROR_NO_CONTENT_TYPE (10009) loading a receipt

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#24319
Posted: 03/27/2013 05:31:55
by John Anderson (Priority Standard support level)
Joined: 03/15/2013
Posts: 24

I am using an SSL version of your sample code from HTTPS Sender to test my AS2 Client/Server. When my code returns a signed receipt generated exactly as demonstrated in your sample by
Code
TElAS2Receipt receipt = new TElAS2Receipt();
receipt.Assign(message);
receipt.Text = "Your message has been received successfully. This does not guarantee that the message has been read or understood.";
FileStream receiptStream = new FileStream(Path.ChangeExtension(fileName, ".as2r"), FileMode.Create);

and eventually sent back to the caller by
Code
m_httpsServ.SendResponseHeaders(m_currentRequest, m_currentResponse);
if (responseStream != null)
{
    m_httpsServ.SendResponseData(responseStream);
    responseStream.Close();
}
m_httpsServ.ResponseComplete();

the receipt gets received OK but when I try to parse it by clicking on the buttonLoadReceipt I get an error at this line
Code
bool result = as2Receipt.Load(textLoadReceiptFile.Text);

The StackTrace of the SB_AS_ERROR_NO_CONTENT_TYPE (10009) error is
Code
   at SBASCommon.TElASReceipt.ProcessError(Int32 Code, String Message, Boolean Critical)
   at SBASCommon.TElASReceipt.DisassembleHeader(TElMessageHeader Header, UInt16& Scopes)
   at SBAS2.TElAS2Receipt.DisassembleHeader(TElMessageHeader Header, UInt16& Scopes)
   at SBASCommon.TElASReceipt.Load(Stream Stream)
   at SBASCommon.TElASReceipt.Load(String FileName)
   at Sender.Main.buttonLoadReceipt_Click(Object sender, EventArgs e) in C:\Dev\EldoS\SecureBlackbox.NET\Samples\C#\EDIBlackbox\AS2\SSLSender\Main.cs:line 606
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Sender.Program.Main() in C:\Dev\EldoS\SecureBlackbox.NET\Samples\C#\EDIBlackbox\AS2\SSLSender\Program.cs:line 18
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
   at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
   at System.Activator.CreateInstance(ActivationContext activationContext)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()


This is what the as2r file contains (redacted)
Code
AS2-From: IF31
AS2-To: Advance
AS2-Version: 1.0
Date: Wed, 27 Mar 2013 09:56:38 GMT
Message-ID: <201303270956380349@17465686>
Content-Type: multipart/signed;
   protocol="application/pkcs7-signature";
   micalg=sha1;
   boundary="----=_NextPart_029_5551_4136004143327431"


------=_NextPart_029_5551_4136004143327431
Content-Type: multipart/report;
   report-type="disposition-notification";
   boundary="----=_NextPart_802_9292_4136004143327431"


------=_NextPart_802_9292_4136004143327431
Content-Type: text/plain;
   charset="us-ascii"
Content-Transfer-Encoding: 8bit

Your message has been received successfully. This does not guarantee that the message has been read or understood.
------=_NextPart_802_9292_4136004143327431
Content-Type: message/disposition-notification;
   charset="us-ascii"
Content-Transfer-Encoding: 8bit

Original-Message-ID: <201303261037370988@14491289>
Received-Content-MIC: QTuoF4HLlEe8ICpyj42Dz7RkxOk=, sha1
Final-Recipient: rfc822; IF31
Original-Recipient: rfc822; IF31
Disposition: automatic-action/mdn-sent-automatically;
   processed

------=_NextPart_802_9292_4136004143327431--

------=_NextPart_029_5551_4136004143327431
Content-Type: application/pkcs7-signature;
   name="smime.p7s"
Content-Transfer-Encoding: binary
Content-Disposition: attachment;
   filename="smime.p7s"

@@binary stuff removed from here@@
------=_NextPart_029_5551_4136004143327431--

Any idea what the problem is? There does not seem to be an empty content-type.
#24320
Posted: 03/27/2013 06:57:26
by John Anderson (Priority Standard support level)
Joined: 03/15/2013
Posts: 24

On further investigation I have discovered that the receipt shown above (which is the copy of the receipt saved by the AS2 Client/Server in my new code's .../Files folder) is not the same as the receipt received by the SSL Sender I mentioned above. The SSL Sender is essentially the same as your AS2 Sender sample code but it is converted to talk via Https. The as2r saved by the SSL Sender (in its own .../Files folder) is like this
Code
Server: AS2 ServerLinkHandler/1.0
Content-Length: 1829
Accept-Ranges: bytes

That is to say it only contains the header values I manually added and not the content I assumed would be added during the call to
Code
receipt.Assign(message);

Can you spot where I'm missing a step?
#24323
Posted: 03/27/2013 07:49:05
by Alexander Ionov (EldoS Corp.)

Sorry, it's impossible for us to guess what is broken in the original samples because we didn't see what has been changed there.


--
Best regards,
Alexander Ionov
#24324
Posted: 03/27/2013 07:53:22
by John Anderson (Priority Standard support level)
Joined: 03/15/2013
Posts: 24

On continuing to investigate pending a reply I have discovered that in my AS2 Client/Server (after saving the receiptStream to the as2r file) and copying the receiptStream content to a responseStream I was not positioning the responseStream to zero. Fixing that results in the SSL Sender's received receipt containing
Code
Server: AS2 ServerLinkHandler/1.0
Content-Length: 1829
Accept-Ranges: bytes

AS2-From: IF31
AS2-To: Advance
AS2-Version: 1.0
Date: Wed, 27 Mar 2013 12:37:23 GMT
Message-ID: <201303271237230898@98469909>
Content-Type: multipart/signed;
   protocol="application/pkcs7-signature";
   micalg=sha1;
   boundary="----=_NextPart_315_0321_4136005259710417"


------=_NextPart_315_0321_4136005259710417
Content-Type: multipart/report;
   report-type="disposition-notification";
   boundary="----=_NextPart_628_3855_4136005259712269"


------=_NextPart_628_3855_4136005259712269
Content-Type: text/plain;
   charset="us-ascii"
Content-Transfer-Encoding: 8bit

Your message has been received successfully. This does not guarantee that the message has been read or understood.
------=_NextPart_628_3855_4136005259712269
Content-Type: message/disposition-notification;
   charset="us-ascii"
Content-Transfer-Encoding: 8bit

Original-Message-ID: <201303271107410876@09098748>
Received-Content-MIC: 3HJK8Y+91OWRifX+dopfgxFScFA=, sha1
Final-Recipient: rfc822; IF31
Original-Recipient: rfc822; IF31
Disposition: automatic-action/mdn-sent-automatically;
   processed

------=_NextPart_628_3855_4136005259712269--

------=_NextPart_315_0321_4136005259710417
Content-Type: application/pkcs7-signature;
   name="smime.p7s"
Content-Transfer-Encoding: binary
Content-Disposition: attachment;
   filename="smime.p7s"

@@binary stuff here@@
------=_NextPart_315_0321_4136005259710417--


Which is pretty much what the AS2 Client/Server has saved in it's as2r file.

Sadly, I still get the same 10009 error but now it hits the On_Error handler multiple times before its thrown by the
Code
bool result = as2Receipt.Load(textLoadReceiptFile.Text);


If you are following this explination have you any idea whats wrong with the format of that received as2r?
#24328
Posted: 03/27/2013 08:12:27
by Alexander Ionov (EldoS Corp.)

As you can see there is an empty line right after 3 lines of header. This empty line finishes the receipt header, so all other lines are supposed to be a receipt body. You should fix your code to remove this empty line.


--
Best regards,
Alexander Ionov
#24331
Posted: 03/27/2013 09:14:31
by John Anderson (Priority Standard support level)
Joined: 03/15/2013
Posts: 24

As far as I can see the first 3 headers are received as part of the
event handled thus
Code
this.as2Client.OnReceivingHeaders += new SBHTTPSClient.TSBHTTPHeadersEvent(this.as2Client_OnReceivingHeaders);

the blank line and the next few headers together with the body are received as part of the event handled thus
Code
as2Client.OnData += new SBSSLCommon.TSBDataEvent(as2Client_OnData);


Am I correct in thinking that the headers that form part of the receipt (AS2-From: IF31 onwards) need to be combined with Headers from the TElHTTPServerResponseParams in some way? If
Code
m_httpsServ.SendResponseHeaders(m_currentRequest, m_currentResponse);
m_httpsServ.SendResponseData(responseStream);

is not the correct way to do it can you please help me by suggesting the correct way? Your sample AS2 uses a HttpListener so I can't copy the method in there.
#24333
Posted: 03/27/2013 09:30:09
by Alexander Ionov (EldoS Corp.)

HTTP headers must be combined with message/receipt headers. The way to do this depends on what class/library you use to send a receipt. I don't know where are SendReponseHeaders and SendResponseData methods from?


--
Best regards,
Alexander Ionov
#24336
Posted: 03/27/2013 09:57:48
by John Anderson (Priority Standard support level)
Joined: 03/15/2013
Posts: 24

Thanks for trying to help me!

The
Code
m_httpsServ.SendResponseHeaders(m_currentRequest, m_currentResponse);
m_httpsServ.SendResponseData(responseStream);

operate on the m_httpsServ object which is of type TElHTTPSServer

m_currentRequest is of type TElHTTPSServerRequestParams

m_currentResponse is of type TElHTTPSServerResponseParams

responseStream is of type Stream containing the "receipt" content
#24337
Posted: 03/27/2013 10:09:07
by Alexander Ionov (EldoS Corp.)

Ok, TElHTTPSServer has the event named OnPreparedHeaders. This is the right place to combine the headers: you should read the receipt header, then combine it with the http header provided in the event parameter Headers.
Please make sure that the receipt header is not transferred by SendResponseData method also.


--
Best regards,
Alexander Ionov
#24340
Posted: 03/27/2013 11:03:58
by John Anderson (Priority Standard support level)
Joined: 03/15/2013
Posts: 24

Thanks, that has solved my problem.

I used
Code
byte[] binaryHeader = SBMIME.__Global.GetHeaderFromStream(receiptStream);
string stringHeader = SBUtils.__Global.StringOfBytes(binaryHeader);

to pull the headers from the stream and
Code
SBASUtils.__Global.CopyStream(receiptStream, responseStream, -1, -1, true, payload_OnProgress);

to copy it.

Can you please tell me where the documentation of these __Global methods is located, as I searched in vain to find the parameters for CopyStream and had to do it by trial and error...
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 1555 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!