xml-signaturexmlsecxmlsec1

xmlsec1 sign failed - id


In the SignInfo node I have

<ds:Reference URI="#Id-132">...

It refers to the node below:

<soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-132">

Command:

xmlsec1 --sign --output request-signed.xml --privkey-pem privatekey.pem raw_message.xml

I have this error: func=xmlSecXPathDataExecute:file=xpath.c:line=273:obj=unknown:subj=xmlXPtrEval:error=5:libxml2 library function failed:expr=xpointer(id('Id-132'))


Solution

  • To sign with ids references is necessary --id-attr: parameter. Example:

    <ds:Reference URI="#Id-132">
    
    <soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-132">
    

    Command: xmlsec1 --sign --output request-signed.xml --privkey-pem privatekey.pem --id-attr:Id raw_message.xml

    More information: https://snippets.aktagon.com/snippets/758-how-to-sign-xml-documents-using-xmldsig-xml-signature-