Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to sign nodes with namespace prefix #201

Closed
paulish opened this issue Dec 19, 2019 · 3 comments · Fixed by #218
Closed

unable to sign nodes with namespace prefix #201

paulish opened this issue Dec 19, 2019 · 3 comments · Fixed by #218

Comments

@paulish
Copy link
Contributor

paulish commented Dec 19, 2019

here is xml:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <soap:Header>
    <wsa:MessageID wsu:Id="id-9b50f86a-e0bb-47cc-ba3a-419b4f1cd4ec">38a8a055-8164-4738-a2f8-46bbc26ebb2a</wsa:MessageID>
    <wsa:Action wsu:Id="id-1e5921e0-a346-47f2-9888-571c6361e56b">registerDocument</wsa:Action>
    <wsa:ReplyTo wsu:Id="id-628661eb-a354-429b-a81d-5c9911fcf9f3"><Address>http://www.w3.org/2005/08/addressing/anonymous</Address></wsa:ReplyTo>
    <wsa:To wsu:Id="id-127ff435-8ec6-4698-a988-8d6bad9518aa">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
  </soap:Header>
  <soap:Body wsu:Id="BODY-5909a7c5-99d1-453f-a5d0-4f8b1254346b">
  </soap:Body>
</soap:Envelope>

I want to sign all nodes with wsu:Id attribute.

The code to sign is:

let sig = new xmlCrypto.SignedXml('', {
    signatureAlgorithm: algorithms.signatureAlgorithm
});

sig.addReference(
    '//*[@wsu:Id]',
    ["http://www.w3.org/2001/10/xml-exc-c14n#"],
    algorithms.digestAlgorithm
);

sig.computeSignature(xml);

The problem is that there is no way to pass namespaces to xpath. And that no default namespace resolver is used.

The error I get:

Error: Cannot resolve QName wsu
    at Function.NodeTest.nameSpaceMatches (c:\programming\web\gitlab\xml\node_modules\xpath\xpath.js:2311:15)
    at Object.matches (c:\programming\web\gitlab\xml\node_modules\xpath\xpath.js:2337:16)
    at Function.PathExpr.applyStep (c:\programming\web\gitlab\xml\node_modules\xpath\xpath.js:1855:27)
    at c:\programming\web\gitlab\xml\node_modules\xpath\xpath.js:2046:67
   ...
@Sufyan7262
Copy link

Any Solution for this?

@paulish
Copy link
Contributor Author

paulish commented Oct 19, 2020

A workaround is to use xpath //*[@*[local-name()='Id' and namespace-uri()='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd']] instead of //*[@wsu:Id].

But it would be better imo to create an uri resolver instance inside of xml-crypto code and to use selectWithResolver method instead of select.

@paulish
Copy link
Contributor Author

paulish commented Oct 19, 2020

Added pr #218

@LoneRifle LoneRifle mentioned this issue Mar 15, 2021
LoneRifle added a commit that referenced this issue Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants