moov-io / signedxml

pure go library for processing signed XML documents
MIT License
52 stars 44 forks source link

Signature at root #47

Closed nejcgorsic closed 6 months ago

nejcgorsic commented 6 months ago

Hello everyone, joining after coming across the need for a signed XML (https://github.com/moov-io/signedxml?tab=readme-ov-file) However (i hope this is the right channel and i apologize if it is not!) I have an issue with .Sign() method. This is the XML i am sending in:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    <SignedInfo>
        <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></CanonicalizationMethod>
        <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></SignatureMethod>
        <Reference URI="#test">
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod>
            <Transforms>
                <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></Transform>
            </Transforms>
            <DigestValue>YWJjMTIz</DigestValue>
        </Reference>
    </SignedInfo>
    <SignatureValue>YWJjMTIz</SignatureValue>
    <KeyInfo>
        <X509Data>
            <X509Certificate>testtest</X509Certificate>
        </X509Data>
    </KeyInfo>
    <Object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Id="test">
        ...
ends with
</Object>
</Signature>

ANd i get this errror: signedxml: unable to find Signature node Not really sure what I should change? According to the docs Generating signed XML It is expected that your XML contains the Signature element with all the parameters set (except DigestValue and SignatureValue). Sorry, could not find any examples on the internet

Can Signature be on the root?

adamdecaf commented 6 months ago

I think this is the same issue as https://github.com/moov-io/signedxml/issues/46

RazaGR commented 6 months ago

it doesn't seems same as #46 , signedxml: unable to find Signature node maybe move Signature to header? I am not using this package so no idea.

adamdecaf commented 6 months ago

Can you try out https://github.com/moov-io/signedxml/pull/48 and see if that helps? They may not be related. The other issue's XML is gone, but I thought part of that issue was a root level Signature element.

Edit: Are you using this signedxml package as part of another package?

nejcgorsic commented 6 months ago

Hey @adamdecaf this PR helped with this issue. Works as intended now! Thank you. will this be merged? I am using SignedXMl as part of another package

adamdecaf commented 6 months ago

Yea I can get it merged. Thanks I was just curious who / how people are using the library. Can you share the package or is it private?

Edit: Released in https://github.com/moov-io/signedxml/releases/tag/v1.2.0

nejcgorsic commented 6 months ago

Sorry, @adamdecaf it is private Thank you for this!