Code Monkey home page Code Monkey logo

Comments (12)

jot2re avatar jot2re commented on June 14, 2024 1

I had a look at the files and experimented a bit I found that the issue is in the referenced files; token.en.shtml and enter.en.shtml. In these files are segments of CDATA. Whenever anything (even if it is just a single whitespace) is written in such a segment the verification fails. Thus it seems that the different libraries handle CDATA differently.
Since everything in CDATA is user-decided I guess a quick fix is simply to avoid using CDATA. In fact, since even a non-special character messes up the verification it seems that XMLDSIGjs might not support CDATA at all? But I am not sure about this.

from xmldsigjs.

SmartLayer avatar SmartLayer commented on June 14, 2024

My first thought is that there is some digest calculating issue when the file content has mixed namespaces. What is the underlying library that calculates the digest for xmldsigjs?

from xmldsigjs.

rmhrisk avatar rmhrisk commented on June 14, 2024

C14N is hardest part of XMLDSIG, there are lots of different nuances that could result in this.

The way we would debug is use another implementation, for example the .NET one, changing but by bit until we figured out how to get the same hash.

We will find time to look at this but can not commit to a timeline.

from xmldsigjs.

SmartLayer avatar SmartLayer commented on June 14, 2024

@rmhrisk Thanks. Since I use Java mostly, I can dump the result of Java C14N. It's native support for XMLDSig for quite some years and sing the same tune as xmlsec C library. If you can show me a few lines of how to dump the canonicalised XML from JavaScript, I can do a byte-to-byte comparison with the Java's dump and find the culprit there. How do you think?

from xmldsigjs.

rmhrisk avatar rmhrisk commented on June 14, 2024

I do recall there being some historic issue with CDATA; it’s entirely possible we don’t C14N it right.

from xmldsigjs.

microshine avatar microshine commented on June 14, 2024

@colourful-land You can print to console incoming data here https://github.com/PeculiarVentures/xmldsigjs/blob/master/src/signed_xml.ts#L358 or here https://github.com/PeculiarVentures/xmldsigjs/blob/master/src/algorithm.ts#L45

from xmldsigjs.

microshine avatar microshine commented on June 14, 2024

C14N CDATA

case XmlCore.XmlNodeType.CDATA:
case XmlCore.XmlNodeType.SignificantWhitespace:
case XmlCore.XmlNodeType.Text:
// CDATA sections are processed as text nodes
this.WriteTextNode(node);
break;

xmldsigjs/test/canon.ts

Lines 275 to 280 in 5dccd54

it("#32 CDATA sections are replaced with their character content", () => {
const xml = "<root><child><inner><![CDATA[foo & bar in the <x>123</x>]]></inner></child></root>";
const xpath = '//*[local-name(.)="child"]';
C14N(xml, xpath, "<child><inner>foo &amp; bar in the &lt;x&gt;123&lt;/x&gt;</inner></child>");
ExcC14N(xml, xpath, "<child><inner>foo &amp; bar in the &lt;x&gt;123&lt;/x&gt;</inner></child>");
});

from xmldsigjs.

rmhrisk avatar rmhrisk commented on June 14, 2024

@colourful-land it looks like this particular document works fine in browser but not in node; that seems to be a function of xmldom's handling of CDATA.

from xmldsigjs.

SmartLayer avatar SmartLayer commented on June 14, 2024

@colourful-land it looks like this particular document works fine in browser but not in node; that seems to be a function of xmldom's handling of CDATA.

Later this month I set out to find the exact cause of this problem by stripping off all CDATA, then I will close this issue and start another with a specific test-case.

from xmldsigjs.

rmhrisk avatar rmhrisk commented on June 14, 2024

SGTM!

from xmldsigjs.

SmartLayer avatar SmartLayer commented on June 14, 2024

SGTM!

OKay, I stripped all CDATA and still, the code fails on 1/2 of the files I sent to test. On the other hand, all these signed XML files verify correctly in Java and TCL.

https://github.com/AlphaWallet/TokenScript/tree/xmldsig-verification-examples/xmldsig

So this problem is not limited to or caused by CDATA.

The above link provided how to reproduce the test, including a xmldsigverify.js which verifies all files given as command-line parameters; then a suite of test-files which you can get with git clone.

from xmldsigjs.

SmartLayer avatar SmartLayer commented on June 14, 2024

Ah, spent more than 5 hours to narrow down this problem to a simple 3-line XML test case that can demonstrate the problem. Let's close this issue and move the discussion to the new issue where the test case is presented. #47

from xmldsigjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.