Validate XML signature
I Have a problem with a Signature validator to XML file, when this file have more than one Signature tag.
Like This
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<NFe>
<infNFe Id="NFexxx" versao="4.00">
...
</infNFe>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="#NFexxx">
...
</Reference>
</SignedInfo>
...
</Signature>
</NFe>
<protNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<infProt Id="ID666">
...
</infProt>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="#ID666">
...
</Reference>
</SignedInfo>
...
</Signature>
</protNFe>
</nfeProc>
<NFe>
<infNFe Id="NFexxx" versao="4.00">
...
</infNFe>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="#NFexxx">
...
</Reference>
</SignedInfo>
...
</Signature>
</NFe>
<protNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<infProt Id="ID666">
...
</infProt>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="#ID666">
...
</Reference>
</SignedInfo>
...
</Signature>
</protNFe>
</nfeProc>
This is my method of validation
Validate(file,element,clazz) ; new reader,sc,data,xmlSignature ; set sc=reader.OpenFile(file) quit:$$$ISERR(sc) sc ; get elementet do reader.Correlate(element,clazz) if 'reader.Next(.data,.sc){ quit sc } ; do reader.Correlate("Signature","%XML.Security.Signature") if 'reader.Next(.xmlSignature,.sc) { quit sc } ; quit xmlSignature.ValidateDocument(data)
I Get this error when to try call Validate("file.xml","NFe","class")
<METHOD DOES NOT EXIST>zValidateElement+35^%XML.Security.Signature.1 *GetNode "class"
Try it like this:
From docs.
I talked to intersystems support. he asked me to break validation into two steps. one for each Tag. I'm trying to follow the support tips. But without success so far. In this example I'm trying to validate just the first <NFe> tag
I get this error
I believe that my "XmlToStream" rule is changing the original XML and therefore the validation was compromised. Does that make any sense?
HI all.....
I found a simple solution....