EcoG-io / iso15118

Implementation of the ISO 15118 Communication Protocol (-2, -20, -8)
Apache License 2.0
169 stars 94 forks source link

EXICodec.jar seems to ignore ID attribute in SignedInfo fragment encoding #240

Open cgtlewis opened 1 year ago

cgtlewis commented 1 year ago

Using the following code, the EXI encoding can be shown to work correctly for the SignedInfo fragment encoding described in ISO15118-2 Annex J

sig = SignedInfo(
        canonicalization_method=CanonicalizationMethod(
            algorithm="[http://www.w3.org/TR/canonical-exi/](https://protect-us.mimecast.com/s/HOzOCDkokwTgB410iWc0im?domain=w3.org/)"
        ),
        signature_method=SignatureMethod(
            algorithm="[http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256](https://protect-us.mimecast.com/s/qrXICERpRKcRWEmMSw1gSI?domain=w3.org)"
        ),
        reference=[
            Reference(
                uri="#ID1",
                transforms=Transforms(
                    transform=[ Transform(
                        algorithm="[http://www.w3.org/TR/canonical-exi/](https://protect-us.mimecast.com/s/HOzOCDkokwTgB410iWc0im?domain=w3.org/)"
                    )
                    ]
                ),
                digest_method=DigestMethod(
                    algorithm="[http://www.w3.org/2001/04/xmlenc#sha256](https://protect-us.mimecast.com/s/1QWkCG6r6wsjJvmGcpQaEk?domain=w3.org)"
                ),
                digest_value=b64decode(b'0bXgPQBlvuVrMXmERTBR61TKGPwOCRYXT4s8d6mPSqk=')
            )
        ]
)

calling to_exi on this correctly gives an output of the following

808112b43a3a381d1797bbbbbb973b999737b93397aa2917b1b0b737b734b1b0b616b2bc3497a1ab43a3a381d1797bbbbbb973b999737b933979918181897981a17bc36b63239b4b396b6b7b93291b2b1b239b096b9b430991a9b220623494431025687474703a2f2f7777772e77332e6f72672f54522f63616e6f6e6963616c2d6578692f4852d0e8e8e0745e5eeeeeee5cee665cdee4ce5e646060625e60685ef0dad8cadcc646e6d0c2646a6c841a36bc07a00cb7dcad662f3088a60a3d6a99431f81c122c2e9f1678ef531e9552370

However, adding the attribute 'Id', as below, yields an identical output

sig = SignedInfo(
        canonicalization_method=CanonicalizationMethod(
            algorithm="[http://www.w3.org/TR/canonical-exi/](https://protect-us.mimecast.com/s/HOzOCDkokwTgB410iWc0im?domain=w3.org/)"
        ),
        signature_method=SignatureMethod(
            algorithm="[http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256](https://protect-us.mimecast.com/s/qrXICERpRKcRWEmMSw1gSI?domain=w3.org)"
        ),
        reference=[
            Reference(
                uri="#ID1",
                id='ID1',
                transforms=Transforms(
                    transform=[ Transform(
                        algorithm="[http://www.w3.org/TR/canonical-exi/](https://protect-us.mimecast.com/s/HOzOCDkokwTgB410iWc0im?domain=w3.org/)"
                    )
                    ]
                ),
                digest_method=DigestMethod(
                    algorithm="[http://www.w3.org/2001/04/xmlenc#sha256](https://protect-us.mimecast.com/s/1QWkCG6r6wsjJvmGcpQaEk?domain=w3.org)"
                ),
                digest_value=b64decode(b'0bXgPQBlvuVrMXmERTBR61TKGPwOCRYXT4s8d6mPSqk=')
            )
        ]
)

Exificient GUI encodes the xml without Id present

<xmlsig:SignedInfo xmlns:xmlsig="http://www.w3.org/2000/09/xmldsig#">
 <xmlsig:CanonicalizationMethod Algorithm="http://www.w3.org/TR/canonical-exi/"/>
 <xmlsig:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/>
 <xmlsig:Reference URI="#ID1">
 <xmlsig:Transforms>
 <xmlsig:Transform Algorithm="http://www.w3.org/TR/canonical-exi/"/>
 </xmlsig:Transforms>
 <xmlsig:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
 <xmlsig:DigestValue>0bXgPQBlvuVrMXmERTBR61TKGPwOCRYXT4s8d6mPSqk=</xmlsig:DigestValue>
 </xmlsig:Reference>
</xmlsig:SignedInfo>

to

808112b43a3a381d1797bbbbbb973b999737b93397aa2917b1b0b737b734b1b0b616b2bc3497a1ab43a3a381d1797bbbbbb973b999737b933979918181897981a17bc36b63239b4b396b6b7b93291b2b1b239b096b9b430991a9b220623494431025687474703a2f2f7777772e77332e6f72672f54522f63616e6f6e6963616c2d6578692f4852d0e8e8e0745e5eeeeeee5cee665cdee4ce5e646060625e60685ef0dad8cadcc646e6d0c2646a6c841a36bc07a00cb7dcad662f3088a60a3d6a99431f81c122c2e9f1678ef531e9552370

and the xml with Id present

<xmlsig:SignedInfo xmlns:xmlsig="http://www.w3.org/2000/09/xmldsig#">
 <xmlsig:CanonicalizationMethod Algorithm="http://www.w3.org/TR/canonical-exi/"/>
 <xmlsig:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/>
 <xmlsig:Reference URI="#ID1" Id="ID1">
 <xmlsig:Transforms>
 <xmlsig:Transform Algorithm="http://www.w3.org/TR/canonical-exi/"/>
 </xmlsig:Transforms>
 <xmlsig:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
 <xmlsig:DigestValue>0bXgPQBlvuVrMXmERTBR61TKGPwOCRYXT4s8d6mPSqk=</xmlsig:DigestValue>
 </xmlsig:Reference>
</xmlsig:SignedInfo>

to

808112b43a3a381d1797bbbbbb973b999737b93397aa2917b1b0b737b734b1b0b616b2bc3497a1ab43a3a381d1797bbbbbb973b999737b933979918181897981a17bc36b63239b4b396b6b7b93291b2b1b239b096b9b430991a9b200549443120c4692886204ad0e8e8e0745e5eeeeeee5cee665cdee4ce5ea8a45ec6c2dcdedcd2c6c2d85acaf0d25e90a5a1d1d1c0e8bcbddddddcb9dcccb9bdc99cbcc8c0c0c4bcc0d0bde1b5b195b98c8dcda184c8d4d908346d780f40196fb95acc5e61114c147ad532863f03824585d3e2cf1dea63d2aa46e

SiebrenW commented 8 months ago

This may well be by design, because according to the ISO15118:-2 and -20 standards ([V2G2-771] and [V2G20-771]) this field must not be used.

nvm you mean inside of the Reference element. That should not be the case.