de-bund-bsi-tr-esor / tr-esor-AIP-eIDAS-SigValidator

Apache License 2.0
5 stars 2 forks source link

Checksum verification for DataObject with xmlData doesn't follow the specification #4

Open tom-kuca opened 3 years ago

tom-kuca commented 3 years ago

I believe that the verification of a checksum for a DataObject with xmlData doesn't follow the specification. From BSI TR-ESOR-F, 1.2.2:

The subject of the checksum calculation is the Base64-decoded payload data object for <binaryData> elements and the XML data canonicalized pursuant to the <packageHeader>/<CanonicalizationMethod> for <xmlData> elements.`

Given XAIP xaip-with-xml-data.txt with an xmlData and a checksum,

      <esor:dataObject dataObjectID="DO-01">
        <esor:xmlData>
...
</esor:xmlData>
        <esor:checkSum>
          <esor:checkSumAlgorithm>http://www.w3.org/2001/04/xmlenc#sha256</esor:checkSumAlgorithm>
          <esor:checkSum>d13c5a91f88a296b32c212c0b31d056e50b3f635d6db0ad6708c26d595a00605</esor:checkSum>
        </esor:checkSum>
      </esor:dataObject>

using a call

java -jar tr-esor-AIP-eIDAS-SigValidator/aip-validator-cli/target/aip-validator-cli.jar -i xaip-with-xml-data.xml -Mvalidator.schemaDir=tr-esor-AIP-eIDAS-SigValidator/default-syntax-validator/src/main/resources/definitions -d

the tool generetes a verification report with result checkSumInvalid. I will try to claim that the checksum is correct.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:VerificationReport xmlns="urn:oasis:names:tc:dss:1.0:core:schema" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="urn:oasis:names:tc:dss-x:1.0:profiles:verificationreport:schema#" xmlns:ns4="http://uri.etsi.org/01903/v1.3.2#" xmlns:ns5="http://www.bsi.bund.de/ecard/api/1.1" xmlns:ns6="urn:iso:std:iso-iec:24727:tech:schema" xmlns:ns7="http://www.bsi.bund.de/tr-esor/api/1.2" xmlns:ns8="http://www.bsi.bund.de/tr-esor/xaip/1.2" xmlns:ns9="http://www.setcce.org/schemas/ers" xmlns:ns10="http://www.bsi.bund.de/tr-esor/vr/1.2">
  <VerificationTimeInfo>
    <VerificationTime>2021-08-13T14:09:07.977+02:00</VerificationTime>
  </VerificationTimeInfo>
  <ns3:IndividualReport>
    <ns3:SignedObjectIdentifier/>
    <Result>
      <ResultMajor>urn:oasis:names:tc:dss:1.0:resultmajor:Success</ResultMajor>
      <ResultMessage xml:lang="en">successfully validated the xaip structure and containing signatures</ResultMessage>
    </Result>
    <ns3:Details>
      <ns10:XAIPReport>
        <ns10:FormatOK>
          <ns3:ResultMajor>urn:oasis:names:tc:dss:1.0:detail:valid</ns3:ResultMajor>
          <ns3:ResultMessage xml:lang="en">xaip is schema conform</ns3:ResultMessage>
        </ns10:FormatOK>
        <ns10:packageHeader packageID="x78fea42d-88c8-4559-9f75-2b6e873c2ac4">
          <ns10:AOID>xaip-with-xml-data</ns10:AOID>
          <ns10:versionManifest VersionID="V001">
            <ns10:preservationInfo>
              <ns3:ResultMajor>urn:oasis:names:tc:dss:1.0:detail:valid</ns3:ResultMajor>
            </ns10:preservationInfo>
          </ns10:versionManifest>
          <ns10:canonicalizationMethod>
            <ns3:ResultMajor>urn:oasis:names:tc:dss:1.0:detail:valid</ns3:ResultMajor>
            <ns3:ResultMessage xml:lang="en">using valid algorithm http://www.w3.org/2001/10/xml-exc-c14n#</ns3:ResultMessage>
          </ns10:canonicalizationMethod>
        </ns10:packageHeader>
        <ns10:dataObjectsSection>
          <ns10:dataObject dataObjectID="DO-01">
            <ns10:checksum>
              <ns3:ResultMajor>urn:oasis:names:tc:dss:1.0:detail:invalid</ns3:ResultMajor>
              <ns3:ResultMinor>http://www.bsi.bund.de/tr-esor/api/1.2/resultminor/checkSumInvalid</ns3:ResultMinor>
            </ns10:checksum>
          </ns10:dataObject>
        </ns10:dataObjectsSection>
      </ns10:XAIPReport>
    </ns3:Details>
  </ns3:IndividualReport>
</ns3:VerificationReport>

Based on the specification, the checksum should be computed over canonicalized content of xmlData, with the canonicalization method http://www.w3.org/2001/10/xml-exc-c14n# from packageHeader. Canonicalized content of the xmlData is in the attachment canonicalized.txt, it starts with

<schema xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.bsi.bund.de/tr-esor/api/1.1">

    <import namespace="http://bsi.bund.de/tr-esor/xaip/1.1" schemaLocation="tr-esor-xaip-v1.1.xsd"></import>

    <import namespace="urn:oasis:names:tc:dss:1.0:core:schema" schemaLocation="oasis-dss-core-schema-v1.0-os.xsd"></import>
    <import namespace="urn:ietf:params:xml:ns:ers" schemaLocation="rfc6283_xmlers.xsd"></import>
    <import namespace="http://www.bsi.bund.de/ecard/api/1.1" schemaLocation="eCard.xsd"></import>
 ...

The SHA-256 checksum of canonicalized.txt is d13c5a91f88a296b32c212c0b31d056e50b3f635d6db0ad6708c26d595a00605. This checksum is in the XAIP, but it was marked as invalid in the report. I also have a signature over the data computed by a third party, that contains this checksum.

--

I checked how the checksum it computed by the tool. A added a debug output near https://github.com/de-bund-bsi-tr-esor/tr-esor-AIP-eIDAS-SigValidator/blob/14ae0b01dac99080d305787021085cdaef38fc4e/default-syntax-validator/src/main/java/de/bund/bsi/tresor/aip/validator/syntax/validators/DataObjectSectionValidator.java#L113 The tool computed the checksum over the content returned byAIPUtil.extractXmlData():

<?xml version="1.0" encoding="UTF-8"?><ns6:xmlData xmlns:ns6="http://www.bsi.bund.de/tr-esor/xaip/1.2" xmlns="urn:oasis:names:tc:dss:1.0:core:schema" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://www.bsi.bund.de/ecard/api/1.1" xmlns:ns4="urn:iso:std:iso-iec:24727:tech:schema" xmlns:ns5="http://www.bsi.bund.de/tr-esor/api/1.2" xmlns:ns7="http://uri.etsi.org/01903/v1.3.2#" xmlns:ns8="http://www.setcce.org/schemas/ers" xmlns:ns9="urn:oasis:names:tc:dss-x:1.0:profiles:verificationreport:schema#"><schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dss="urn:oasis:names:tc:dss:1.0:core:schema" xmlns:ec="http://www.bsi.bund.de/ecard/api/1.1" xmlns:ers="urn:ietf:params:xml:ns:ers" xmlns:esor="http://www.bsi.bund.de/tr-esor/xaip/1.2" xmlns:ns1="http://www.bsi.bund.de/tr-esor/api/1.2" xmlns:ns10="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ns11="http://www.w3.org/2001/04/xmlenc#" xmlns:ns12="urn:iso:std:iso-iec:24727:tech:schema" xmlns:ns13="http://www.setcce.org/schemas/ers" xmlns:ns14="http://www.w3.org/2001/04/xmldsig-more#" xmlns:ns3="urn:oasis:names:tc:dss:1.0:core:schema" xmlns:ns4="urn:ietf:params:xml:ns:ers" xmlns:ns5="http://www.bsi.bund.de/ecard/api/1.1" xmlns:ns6="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ns7="http://www.w3.org/2000/09/xmldsig#" xmlns:ns8="http://uri.etsi.org/01903/v1.3.2#" xmlns:tr="http://www.bsi.bund.de/tr-esor/api/1.1" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:xaip="http://bsi.bund.de/tr-esor/xaip/1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.bsi.bund.de/tr-esor/api/1.1"><xsd:import namespace="http://bsi.bund.de/tr-esor/xaip/1.1" schemaLocation="tr-esor-xaip-v1.1.xsd"/><xsd:import namespace="urn:oasis:names:tc:dss:1.0:core:schema" schemaLocation="oasis-dss-core-schema-v1.0-os.xsd"/><xsd:import namespace="urn:ietf:params:xml:ns:ers" schemaLocation="rfc6283_xmlers.xsd"/><xsd:import namespace="http://www.bsi.bund.de/ecard/api/1.1" schemaLocation="eCard.xsd"/><xsd:complexType name="RequestType"><xsd:complexContent><xsd:restriction base="dss:RequestBaseType"><xsd:sequence><xsd:element maxOccurs="1" minOccurs="0" ref="dss:OptionalInputs"/>
                </xsd:sequence>
            </xsd:restriction>
        </xsd:complexContent>
    </xsd:complexType>
    ...

I don't see any usage of the canonicalizer in the process, I don't think the data are canonicalized. As a result, the checksum doesn't match and it's reported as invalid.

What I think must be done:

Zekuro commented 3 years ago

@tom-kuca thanks for the detailed error description. We will investigate how to resolve this issue.