Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Validate XML signature

Question
Marcio Coelho · Dec 15, 2021

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>

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"




 

#XML #Caché

Source URL:https://community.intersystems.com/post/validate-xml-signature