russellhaering / goxmldsig

Pure Go implementation of XML Digital Signatures
Apache License 2.0
154 stars 127 forks source link

C14N10 REC Canonicalizer does not follow #92

Open adamdecaf opened 1 year ago

adamdecaf commented 1 year ago

Taking Example 3.3 from the REC-xml-c14n-20010315 specification does not properly canonicalize the document.

--- FAIL: TestC14N10RecCanonicalizer (0.00s)
    canonicalize_test.go:31: 
            Error Trace:    canonicalize_test.go:31
                                        canonicalize_test.go:118
            Error:          Not equal: 
                            expected: "<doc>\n   <e1></e1>\n   <e2></e2>\n   <e3 id=\"elem3\" name=\"elem3\"></e3>\n   <e4 id=\"elem4\" name=\"elem4\"></e4>\n   <e5 xmlns=\"http://example.org\" xmlns:a=\"http://www.w3.org\" xmlns:b=\"http://www.ietf.org\" attr=\"I'm\" attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n   <e6 xmlns:a=\"http://www.w3.org\">\n      <e7 xmlns=\"http://www.ietf.org\">\n         <e8 xmlns=\"\">\n            <e9 xmlns:a=\"http://www.ietf.org\" attr=\"default\"></e9>\n         </e8>\n      </e7>\n   </e6>\n</doc>"
                            actual  : "<doc>\n   <e1></e1>\n   <e2></e2>\n   <e3 id=\"elem3\" name=\"elem3\"></e3>\n   <e4 id=\"elem4\" name=\"elem4\"></e4>\n   <e5 xmlns=\"http://example.org\" xmlns:a=\"http://www.w3.org\" xmlns:b=\"http://www.ietf.org\" attr=\"I'm\" attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n   <e6 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n      <e7 xmlns=\"http://www.ietf.org\">\n         <e8 xmlns=\"\">\n            <e9 xmlns=\"\"></e9>\n         </e8>\n      </e7>\n   </e6>\n</doc>"

                            Diff:
                            --- Expected
                            +++ Actual
                            @@ -6,6 +6,6 @@
                                <e5 xmlns="http://example.org" xmlns:a="http://www.w3.org" xmlns:b="http://www.ietf.org" attr="I'm" attr2="all" b:attr="sorted" a:attr="out"></e5>
                            -   <e6 xmlns:a="http://www.w3.org">
                            +   <e6 xmlns="" xmlns:a="http://www.w3.org">
                                   <e7 xmlns="http://www.ietf.org">
                                      <e8 xmlns="">
                            -            <e9 xmlns:a="http://www.ietf.org" attr="default"></e9>
                            +            <e9 xmlns=""></e9>
                                      </e8>
            Test:           TestC14N10RecCanonicalizer
FAIL
FAIL    github.com/russellhaering/goxmldsig 1.175s

It appears we are injecting empty xmlns attributes into the response.