When a client sends us a signed financial transaction as an xmlnode over https it fails to verify the signature. We narrowed down the issue to the fact that newline characters and spaces are added to the xml during the https call.
We can successfully verify the signature when we manually get the data in a file from the client (notice there are only two lines and no spaces…)
But the data that is received when the service is called is this (notice every tag is in a new line, well intended with spaces etc). This data received fails to verify the signature…
Any signature verification need to be done with the original binary bytes/stream. Once parsed, it’s not the same.
Try to get the bytes or stream of the xml before verification.
I am the receiver. I receive the data as xml node. The content type is verified to be text/xml
These are the steps that I perform when I receive the xml node
a) pub.xml: xmlNodeToDocument
b) pub.xml:documentToXMLString
c) pub.xml:queryXMLNode - extract the signature and signed msg from the xml
d) pub.string:base64Decode - signatue
e) pub.string:stringToBytes - convert the body into bytes
f) pub.security.pkcs7:verify - the signature
The update: Now the client deliberately gave ‘\r\n’ after each tag and I can verify it correctly when I get it from the file they send me, but my service still fails and I could see there are space characters in the xml. Now if I manually remove space characters the verification will pass, what could be done on the client side since I have other working clients (dotNet) here.
Original Msg Tried from the input file that they provided (with new line chars inserted by client)
I cannot use string:replace to remove them since if there was one inserted by the client then the signature verification would fail. There is no point in signature verification if I could modify the message right.
I asked them to send it as stream and found that I can receive the message intact. I guess I would have to stick with stream with this customer.