mogest / nz_covid_pass_reader

Flutter application that reads, verifies and displays NZ COVID passes
MIT License
10 stars 4 forks source link

Invalid Base32 characters for some QR codes #1

Closed vkammerer closed 2 years ago

vkammerer commented 2 years ago

Hello and thank you for the great example,

I am building a NZ Covid Pass Reader application and your repo has been immensely helpful.

However, I have noticed that the QR code is not properly decoded for recent QR codes delivered by the ministry of health, and that it throws an Invalid Base32 characters Exception.

Do you know how this could be fixed?

In order to reproduce, I have used your first test and could verify that:

test('Holder information is returned from a valid COVID Pass', () async {
    var code = "NZCP:/1/2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVAYFE6VGU4MCDGK7DHLLYWHVPUS2YIDJOA6Y524TD3AZRM263WTY2BE4DPKIF27WKF3UDNNVSVWRDYIYVJ65IRJJJ6Z25M2DO4YZLBHWFQGVQR5ZLIWEQJOZTS3IQ7JTNCFDX";
    final pass = await CovidPass.parse(code, allowTestIssuers: true);
    expect(pass.givenName, "Jack");
    expect(pass.familyName, "Sparrow");
    expect(pass.dob, DateTime(1960, 4, 16));
});
vkammerer commented 2 years ago

I don't know if it helps, but I've also noticed that the buggy codes contain a different number of characters than the working ones.

mogest commented 2 years ago

Thanks @vkammerer, I knew that the base32 had to be padded but I thought the Flutter base32 library handled it. Turns out no, it has a bug in its "padding required" detection where it's checking whether it's a multiple of 2 instead of a multiple of 8! So manually adding in the padding seems to make things work :) Let me know how it goes for you.

vkammerer commented 2 years ago

Thanks @mogest, that fixes my issue and I am now able to scan the codes I couldn't before.

Question unrelated to this issue: would you be interested in externalising some of your core logic for decoding the QR code into a separate package? The code in cose.dart, covid_pass.dart and exceptions.dart could be hidden behind a public facing API that would be easier for others to consume in their own UI / with the QR code plugin of their choice.