Skip to content

Verification with InclusiveNamespaces #145

@majvan

Description

@majvan

Hi guys,

[Issue - short]
an xml document having this ds:SignedInfo
<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces PrefixList="soapenv" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><ds:Reference URI="#id-D4754E6D65BB527E86154893374299759"><ds:Transforms></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>/+OXEO9svqFKP48QWZ6dBgswc7Mk6EIlLGPOljjPpAE=</ds:DigestValue></ds:Reference></ds:SignedInfo>
is not correctly canonized (c14n-exc) => hence the signature digest is not correctly computed => hence it fails with verification.

[Reasoning]
The document with above SignedInfo was given to me as a verified document (the signature verification should pass).
After I digged into issue more, I used this tool:
https://www.cryptosys.net/sc14n/

So I ran 2 commands with 2 different results:

  1. Excluding the InclusiveNamespaces (not correct): sc14n -e -s "ds:SignedInfo" -i signed_info.xml -o signed_info.bin
    This computes the same c14n-exc output as signxml;
  2. Including the InclusiveNamespaces (correct): sc14n -e --prefix-list "soapenv" -s "ds:SignedInfo" -i signed_info.xml -o signed_info.bin
    This computes another c14n-exc output, but the output shall be correct and also the SignatureValue of such output would lead into correctly computed SignatureValue.

[Findings]
Please correct me if I am wrong, but if the ds:SignedInfo contains <ec:InclusiveNamespaces ...>, these must be included into the canonization.
So far I see this is not taking into account when verifying the document.
In fact, what is verified:
signed_info_c14n = self._c14n(signed_info, algorithm=c14n_algorithm)
where the _c14n function:
def c14n(cls, nodes, algorithm, inclusive_ns_prefixes=None): ... c14n = b"" for node in nodes: c14n += etree.tostring(node, method="c14n", exclusive=exclusive, with_comments=with_comments, inclusive_ns_prefixes=inclusive_ns_prefixes)
can take a parameter for inclusive prefixes, but none is given, because the inclusive prefixes are not searched for- for verification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions