berdav / greenpass

Scriptable green pass / Digital Covid Certificate verifier.
GNU Lesser General Public License v3.0
53 stars 21 forks source link

Suggestion: Notify about newline stripping in --qr mode #38

Closed psychoticbeef closed 2 years ago

psychoticbeef commented 2 years ago

Hello there,

thanks for this helpful tool! I "backed up" my vaccine certificates. After converting them back to QR, and validating them with "greenpass --qr", greenpass gave its okay. When trying to scan them with the German apps (there's two official), both failed to import the QR codes. One mentioned failure to decode base45. It took me a while to notice that I accidentally added a \n to my output.

As a suggestion, it would be nice if greenpass could identify broken base45, especially when taken from --qr as an input. The certificate could still validate okay, but issue a notice that it's actually corrupted.

Best Regards!

berdav commented 2 years ago

Hi! Thank you, I'm glad that this tool helped someone :)

It would be really nice, if I got it correctly the newline was added to the certificate string.

Therefore I've created a test script, could you test it with the strings you converted to qr codes?

If it fixes the problem you mentioned, I will integrate it in the tool.

Best regards and thank you again!

#!/usr/bin/env python3
import sys
import base45

data = ''

def isbase45(s):
    return all(c in base45.BASE45_CHARSET for c in s)

def nonbase45chars(s):
    out = set()
    for c in s:
        if c not in base45.BASE45_CHARSET:
            out.add(c)
    return out

with open(sys.argv[1], 'r') as f:
    data = f.read()

if not isbase45(data):
    print("Warning: This file can generate problems with base45 decoders")
    print(" it contains the following non base45 characters")
    for c in nonbase45chars(data):
        print("   {}".format(repr(c)))
print("Result: {}".format(base45.b45decode(data)))
psychoticbeef commented 2 years ago
Warning: This file can generate problems with base45 decoders
 it contains the following non base45 characters
   '\n'

Whoop whoop, thanks!

berdav commented 2 years ago

Integrated a similar fix in the master branch, closing.

Thank you again :)