Menu

X509SerialNumber exi encoding/decoding

2022-03-24
2024-05-27
  • Zeungil_Kim

    Zeungil_Kim - 2022-03-24

    Hello.

    I updated the OpenV2G to support the Big number of X509 SerialNumber based on the commit. (struct type)
    But oddly the hash value was not match when communicating with other devices (These probably didn't use the OpenV2G library).
    There's no issue between the EVCC and SECC which use the OpenV2G library.
    I'm suspicious that the openV2G is adding 1byte more to handle positive & negative sign.
    Is there any problem to handle the big number of X509 serial number?
    Any advice is welcome.
    Thanks.

    Ben

     
  • Daniel Peintner

    Daniel Peintner - 2022-03-24

    Hi,

    X509SerialNumber is of XML schema type "integer". Hence a signed value.
    This means the transmission of a sign value in EXI is required.

    Moreover, I am not aware of any issue with this behavior.

    -- Daniel

     
  • Jordan Sautreau

    Jordan Sautreau - 2024-05-24

    Hello,

    We have found an issue in the encoding. It indeed adds a byte because of the encoding on 7 bits and 1 bit more to indicate if the encoding is done or not.
    For example, if the serial number is 9:
    This is 0b00001001 in binary. So we need 4 bits to encode it. Then openv2g considers that we need a byte, then 8 bits. As the bits are encoded 7 by 7, openv2g considers that we need 2 bytes to encode this number. We have patched this and tested it sucessfully. We might share a fix proposal for this issue.

     
  • Daniel Peintner

    Daniel Peintner - 2024-05-27

    Do you have an example XML (or EXI) message that you would like to encode and can point us to to where something goes wrong. Honestly I doubt that there is a problem since it is used for a very long time now without any issues.
    Note: please also let us know what codec you are using (e.g. iso1) etc
    Thanks!

     
  • Jordan Sautreau

    Jordan Sautreau - 2024-05-27

    Hi Daniel,

    I am using iso1 codec.
    The issue is not encoding/decoding directly but on computing the signature.
    The payload is encoded and received by a server using exificient. When receiving the request, the server decodes successfully the request. Then it has to encode the payload (without the signature) to check if the signature is correct. So it encodes back the content to compute a hash.
    That is when we face the issue because the payload is different (1 byte more for each root certificate) so the hash is different.

    Please find below an XML schema to be encoded.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <ns6:V2G_Message xmlns:ns6="urn:iso:15118:2:2013:MsgDef" xmlns:ns5=http://www.w3.org/2000/09/xmldsig#
                     xmlns:ns7="urn:iso:15118:2:2013:MsgBody" xmlns:ns2="urn:iso:15118:2:2010:AppProtocol"
                     xmlns:ns4="urn:iso:15118:2:2013:MsgDataTypes" xmlns:ns3="urn:iso:15118:2:2013:MsgHeader">
        <ns6:Header>
            <ns3:SessionID>A1AC629FE1432C7C</ns3:SessionID>
            <ns5:Signature>
                <ns5:SignedInfo>
                    <ns5:CanonicalizationMethod Algorithm=http://www.w3.org/TR/canonical-exi//>
                    <ns5:SignatureMethod Algorithm=http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256/>
                    <ns5:Reference URI="#ID1">
                        <ns5:Transforms>
                            <ns5:Transform Algorithm=http://www.w3.org/TR/canonical-exi//>
                        </ns5:Transforms>
                        <ns5:DigestMethod Algorithm=http://www.w3.org/2001/04/xmlenc#sha256/>
                        <ns5:DigestValue>u3poY7OmdWRptnIw4DMBYRICa0wwRHnCXiOc/CfsyQU=</ns5:DigestValue>
                    </ns5:Reference>
                </ns5:SignedInfo>
                <ns5:SignatureValue>
                    IPwo6RasUhWiLmJOmnL5bhOCeLOV/MKUrfoxWYQ3dRoeMam2gQWeQvmDlGa6I8GeB4F5XEYd/6gmWTQ4CGfqlA==
                </ns5:SignatureValue>
            </ns5:Signature>
        </ns6:Header>
        <ns6:Body>
            <ns7:CertificateInstallationReq ns7:Id="ID1">
                <ns7:OEMProvisioningCert>
                    MIICsTCCAligAwIBAgIIeSB/g55NUC8wCgYIKoZIzj0EAwIwajEiMCAGA1UEAwwZU3ViQ0EyLUItT0VNX0Zvcl9QQy1PRU0tQzEMMAoGA1UECwwDU1RHMQ4wDAYDVQQKDAVPRU0tQzEZMBcGCgmSJomT8ixkARkWCVN1YkNBMi1QQzELMAkGA1UEBhMCRlIwHhcNMjQwNTIxMTM0MjI2WhcNMjkwNTIwMTM0MjI1WjBYMRYwFAYDVQQDDA1GUlRSSUVWMDAwMDAxMQwwCgYDVQQLDANTVEcxDjAMBgNVBAoMBU9FTS1DMRMwEQYKCZImiZPyLGQBGRYDT0VNMQswCQYDVQQGEwJmcjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLu3tVLr0KoNxVhOgOoFOhAjrLKEjhsXT+l2mCh7ho0P5T+/AIUnUN5aaMaIv+tfNoZCfNhoT+gP6XD7PL0E6oCjgfkwgfYwDAYDVR0TAQH/BAIwADAfBgNVHSMEGDAWgBRU3ZiTX1VnO08hIbDNYYG2bNryXjCBlQYDVR0fBIGNMIGKMIGHoIGEoIGBhn9odHRwOi8vY3JsLnRrbWdpcnYuZXcxLmFpcy1zdGcwMy5hY2xvdWQuZ2VtYWx0by5jb206ODAvY3JsL2lzc3Vlci9DTj1TdWJDQTItQi1PRU1fRm9yX1BDLU9FTS1DLE9VPVNURyxPPU9FTS1DLERDPVN1YkNBMi1QQyxDPUZSMB0GA1UdDgQWBBQFJwZIwE64aqGrg9uzvUePDOjCvzAOBgNVHQ8BAf8EBAMCA4gwCgYIKoZIzj0EAwIDRwAwRAIgO+NCe2n9kjsaepTagkooWauRy+HxaoZ7rQOSSiOdO8gCIGqHjXcDF4GzEi0H6wbqWhcyE8hwk2XyXw9ThE2TzVAl
                </ns7:OEMProvisioningCert>
                <ns7:ListOfRootCertificateIDs>
                    <ns4:RootCertificateID>
                        <ns5:X509IssuerName>DC=V2G,C=FR,O=GIREVE,CN=V2GRootCA-B</ns5:X509IssuerName>
                        <ns5:X509SerialNumber>509275705288417072</ns5:X509SerialNumber>
                    </ns4:RootCertificateID>
                    <ns4:RootCertificateID>
                        <ns5:X509IssuerName>DC=MO,C=FR,O=Trialog,CN=MORootCA</ns5:X509IssuerName>
                        <ns5:X509SerialNumber>9</ns5:X509SerialNumber>
                    </ns4:RootCertificateID>
                </ns7:ListOfRootCertificateIDs>
            </ns7:CertificateInstallationReq>
        </ns6:Body>
    </ns6:V2G_Message>
    

    With the current version of openv2g I have this fragment as a result: 800f02a4a21896a0a61040562610404b140060402040410f240ff073c9aa05e60140c10550c919c7a08060460d4624460400c06aa08061832a6eac48682645a845a9e8a9abe8cdee4bea0865a9e8a9a5a86621860140c06aa08161806a6a88e621c60180c06aa0814180a9e8a9a5a866232602e0c1413244d1327e458c802322c12a6eac48682645aa086621660120c06aa080c26048ca4603c2e1a6468606a646262666864646cb42e1a6472606a646062666864646ab460b0622c60280c06aa0806181a8ca4a8a4928aac606060606062621860140c06aa08161806a6a88e621c60180c06aa0814180a9e8a9a5a86622660220c1413244d1327e458c802322c069e8a9a621660120c06aa080c2604cce460b260260c0e550c919c7a04020c10550c919c7a06020e06840009776f6aa5d7a1541b8ab09d01d40a7420475965091c362e9fd2ed3050f70d1a1fca7f7e010a4ea1bcb4d18d117fd6be6d0c84f9b0d09fd01fd2e1f6797a09d5014703f26103ec60180c06aa3a260203fe08046000603e0c06aa3a460830602d0028a9bb3126beaace769e4243619ac3036cd9b5e4bc61032a0c06aa3a3e09031a61031461030f4103094103030cfed0e8e8e0745e5ec6e4d85ce8d6daced2e4ec5ccaee625cc2d2e65ae6e8ce60665cc2c6d8deeac85ccecadac2d8e8de5cc6deda7470605ec6e4d85ed2e6e6eacae45e869c7aa6eac48682645a845a9e8a9abe8cdee4bea0865a9e8a9a5a86589eaa7aa6a88e589e7a9e8a9a5a865888867aa6eac48682645aa08658867a8ca4603a0c06aa3a1c082c08280a4e0c91809d70d5435707b7677a8f1e19d1857e601c0c06aa3a1e0203fe08080604071060140c10550c919c7a080604068e006088044077c684f6d3fb247634f529b5049450b3572397c3e2d50cf75a072494473a77900440d50f1aee062f0366245a0fd60dd4b42e642790e126cbe4be1ea7089b279aa04a02544433d5632472c433d46522c4f3d4749524556452c434e3d563247526f6f7443412d420b0becf93e4f1d38887000089110cf5353cb10cf51948b13cf551c9a585b1bd9cb10d38f5353d49bdbdd10
    With our patch, I get: 800f02a4a21896a0a61040562610404b140060402040410f240ff073c9aa05e60140c10550c919c7a08060460d4624460400c06aa08061832a6eac48682645a845a9e8a9abe8cdee4bea0865a9e8a9a5a86621860140c06aa08161806a6a88e621c60180c06aa0814180a9e8a9a5a866232602e0c1413244d1327e458c802322c12a6eac48682645aa086621660120c06aa080c26048ca4603c2e1a6468606a646262666864646cb42e1a6472606a646062666864646ab460b0622c60280c06aa0806181a8ca4a8a4928aac606060606062621860140c06aa08161806a6a88e621c60180c06aa0814180a9e8a9a5a86622660220c1413244d1327e458c802322c069e8a9a621660120c06aa080c2604cce460b260260c0e550c919c7a04020c10550c919c7a06020e06840009776f6aa5d7a1541b8ab09d01d40a7420475965091c362e9fd2ed3050f70d1a1fca7f7e010a4ea1bcb4d18d117fd6be6d0c84f9b0d09fd01fd2e1f6797a09d5014703f26103ec60180c06aa3a260203fe08046000603e0c06aa3a460830602d0028a9bb3126beaace769e4243619ac3036cd9b5e4bc61032a0c06aa3a3e09031a61031461030f4103094103030cfed0e8e8e0745e5ec6e4d85ce8d6daced2e4ec5ccaee625cc2d2e65ae6e8ce60665cc2c6d8deeac85ccecadac2d8e8de5cc6deda7470605ec6e4d85ed2e6e6eacae45e869c7aa6eac48682645a845a9e8a9abe8cdee4bea0865a9e8a9a5a86589eaa7aa6a88e589e7a9e8a9a5a865888867aa6eac48682645aa08658867a8ca4603a0c06aa3a1c082c08280a4e0c91809d70d5435707b7677a8f1e19d1857e601c0c06aa3a1e0203fe08080604071060140c10550c919c7a080604068e006088044077c684f6d3fb247634f529b5049450b3572397c3e2d50cf75a072494473a77900440d50f1aee062f0366245a0fd60dd4b42e642790e126cbe4be1ea7089b279aa04a02544433d5632472c433d46522c4f3d4749524556452c434e3d563247526f6f7443412d420b0becf93e4f1d388070089110cf5353cb10cf51948b13cf551c9a585b1bd9cb10d38f5353d49bdbdd10d040245e80

     

    Last edit: Jordan Sautreau 2024-05-27

Log in to post a comment.