ehn-dcc-development / ehn-sign-verify-javascript-trivial

Trivial eHN-Simple implementation in plain/simplified javascript
European Union Public License 1.2
32 stars 12 forks source link

Unable to inflate: incorrect data check #2

Open raziel057 opened 3 years ago

raziel057 commented 3 years ago

Hello,

Sometimes we encounter an issue when inflating the compressed stream:

for example runing: npm run sign | tail -1 | npm run verify

With the following JSON gives this error:

node_modules\pako\lib\inflate.js:384
  if (inflator.err) throw inflator.msg || msg[inflator.err];

invalid distance too far back
{
    "sub": {
        "gn": "Gabriele",
        "fn": "Musterfrau",
        "id": [
            {
                "t": "PPN",
                "i": "12345ABC-321"
            }
        ],
        "dob": "1998-02-26",
        "gen": "female"
    },
    "vac": [
        {
            "dis": "840539006",
            "vap": "1119305005",
            "mep": "EU\/1\/20\/1528",
            "aut": "ORG-100030215",
            "seq": 1,
            "tot": 2,
            "dat": "2021-02-18",
            "cou": "AT",
            "lot": "C22-862FF-001",
            "adm": "Vaccination centre Vienna 23"
        },
        {
            "dis": "840539006",
            "vap": "1119305005",
            "mep": "EU\/1\/20\/1528",
            "aut": "ORG-100030215",
            "seq": 2,
            "tot": 2,
            "dat": "2021-03-12",
            "cou": "AT",
            "lot": "C22-H62FF-010",
            "adm": "Vaccination centre Vienna 23"
        }
    ],
    "cert": {
        "is": "Ministry of Health, Austria",
        "id": "01AT42196560275230427402470256520250042",
        "vf": "2021-04-04",
        "vu": "2021-10-04",
        "co": "AT",
        "vr": "v1.0"
    }
}
raziel057 commented 3 years ago

Please note that if I REMOVE or ADD a single char from the JSON data I don't have issues anymore.

raziel057 commented 3 years ago

I just checked the following code:

for (i = 1; i<200; ++i) {
  str = makeid(10);
  console.log('String: ' + i + ' : ' + str);
  str1 = zlib.deflate(str)
  console.log('zlib deflated: ' + str1);
  str1 = base45.encode(str1)
  console.log('Base45 encoded: ' + str1);
  str1 = base45.decode(str1)
  console.log('Base45 decoded: ' + str1);
  str2 = new TextDecoder().decode(zlib.inflate(str1))
  console.log('String decoded: ' + str2);
}

And I got the following result:

String: 1 : wDuEjKdFGU
zlib deflated: 120,156,43,119,41,117,205,242,78,113,115,15,5,0,19,215,3,113
Base45 encoded: 6BFCM5%A5R1QB-9POEKS0*M2QJ0
Base45 decoded: x�+w)u��Nqs☼♣‼�♥q
String decoded: wDuEjKdFGU

String: 2 : 0mjW3BzyOG
zlib deflated: 120,156,51,200,205,10,55,118,170,170,244,119,7,0,18,36,3,93
Base45 encoded: 6BFQO6K-PN07+PLX+U$*09D26J0
Base45 decoded: x�3��
7v���w↕$♥]
String decoded: 0mjW3BzyOG

...

String: 10 : AfShJrTBTl
zlib deflated: 120,156,115,76,11,206,240,42,10,113,10,201,1,0,18,186,3,117
Base45 encoded: 6BF-PE7M1CGUIE1GG1V50OG2UJ0
Base45 decoded: x�sL♂��*
q
�↕�♥u

X:\workspace-dgc\ehn-sign-verify-javascript-trivial\node_modules\pako\lib\inflate.js:384
  if (inflator.err) throw inflator.msg || msg[inflator.err];
                    ^
incorrect data check

I don't have any problem is I comment the base45 encode / decode.

raziel057 commented 3 years ago

The issue comes from https://github.com/dirkx/base45-js/issues/3