in a SOAP webservice I'm trying to consume there's the necessity of sending a XML with a structure that resembles this:
<?xml version="1.0"?>
<TheData>
<Father Id="zzz">
<SomeInfo>1</SomeInfo>
<List>
<ElementOfList>
<Child Id="foo">foo</Child>
<Signature>
...
</Signature>
</ElementOfList>
<ElementOfList>
<Child Id="bar">bar</Child>
<Signature>
...
</Signature>
</ElementOfList>
</List>
</Father>
<Signature>
...
</Signature>
</TheData>
In which <Signature>
has the contents:
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#[the _Id_ attr of this Signature's sibling element]">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>uCMzpgMnLCP9iESFQVgpmtQ5TRE=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>...</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>...</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
How can I do it?
I'm trying with xmlsec1 --id-attr:Id Father --id-attr:Id Child
, passing to it the file with Signature
fields blank, but it only fills the first of them.
I also tried signing the child alone, putting it inside the father template and them trying to sign the father, but xmlsec1
ignores the second element (and changes the value of the first signature -- wasn't it supposed to be encapsulated inside its element?).
Probably unrelated, but who knows?
I would rather do this from inside Python code, but the three libraries I tried to use, python-xmlsec, pyxmlsec and xmldsig were all uncapable of generating/reconizing the URI
attr of <Reference>
. Probably because they lack the --id-attr
of xmlsec1
, but these problems I'm getting reveal the fact that I don't really understand this XML-signing stuff and, because of that, I'm doing stuff wrong and messing it all up. Please help me understand it.
EDIT
I've seem a lot of people with difficulties in these XML signing subject, but none of them were trying to sign two different elements in the same XML file. This case is not listed also at the w3C Scenarios FAQ, which makes everything look strange, because my webservice requires me that multiple signatures. Or don't? Here's the Schema they publish: https://github.com/proge/PyNFSe/blob/master/pysped_nfse/nfse.xsd#L539 (see this element <xsd:element name="EnviarLoteRpsEnvio">
and childs).