Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Canonicalized XML ouput

iklovski
Active Contributor
0 Likes
2,482

Hello,

I'm composing an XML message to be sent through SWIFT services. As part of a message, I have to calculate a digest, based on SHA256 algorithm. The condition to calculate this digest correctly, is to apply the calculation method on 'canonicalized' XML output.

For example, if XML has an empty tag, e.g. <SWIFTNetNetworkInfo/>, canonicalized version of it would be:

<SWIFTNetNetworkInfo></SWIFTNetNetworkInfo>.

Do you have an idea/experience how to handle it properly? Is there some method in ABAP which would allow me to canonicalize my XML?

Currently, I'm constructing the XML using CALL TRANSFORMATION /RESULT XML functionality. Then, I have no choice, but to play with the strings in order to have my digest calculated correctly.

Thanks in advance,

Eli

6 REPLIES 6
Read only

SimoneMilesi
Active Contributor
2,178

Hi Eli.

Good luck!

No, seriously, there are some packages/algorythms doing that.

I faced the same issue when i developed the Electronic Invoice for Hungary where the body was hashed via SHA256.

What i did was: read the xml node, hash them, update the node, but not via Transformation.


I changed my job, but if i can retrieve the code, i'll be happy to share with you!

Read only

0 Likes
2,178

Ciao Simone,

Yes, that's what I'm forced to do: touching my right ear by my right arm around my head 🙂

I just hoped that ABAP transformation could be not that smart, and that it could keep 'canonicalized' format, when I need it to.

Still, if it's not a big burden for you to retrieve your code, I'd be delighted to have it.

Eli

Read only

2,178

eli.klovski i should check my hd at home (or bother former collegue), but i used this wiki to play with XML

https://wiki.scn.sap.com/wiki/display/ABAP/Parse+an+xml+file+and+insert+values+in+ABAP

and then, once i read the node into a string, i used CL_ABAP_MESSAGE_DIGEST (method CALCULATE_HASH_FOR_CHAR) to calculate the SHA256 value.

Read only

0 Likes
2,178

OK, I see... Well, I'm doing similar things, I guess. My problem, that this string I'm putting through CL_ABAP_MESSAGE_DIGEST has to be in a certain format (C14n, to be specific) and for this I seem not to have built-in SAP tool to perform such conversion. So, what I'm forced to do is, having a canonicalized version before my eyes, play with XML nodes, while combining the string, in order to get the desired result.

Read only

2,178

eli.klovski C14N is... a string? a what? If it's a string, it's not a problem, that class takes the string, calculate the control character and turn it out.

I guess your problem is "take a readable string and convert to C14N format?" I had the same issue (AES-128) and had to rely on a GitHub project (quite cool), but for C14n you have standard CL_SEC_SXML_XENCRYPTION

Read only

iklovski
Active Contributor
0 Likes
2,178

Finally, managed to do it with some string doing and fancy tricks. But, still, if there is some more inteligent way to deal with it, it would be intersting to know it.