berdav/greenpass

Unable to decode base45 string from zbarcam and from txt in general

rbicelli opened this issue · 6 comments

Hello,
tried every flavor of zbarcam:

zbarcam --raw /dev/video0 | greenpass --txt -

even if zbarcam reads a qr code it doesn't produce any output.
tried also to write zbarcam output to txt:

zbarcam --raw /dev/video0 > ./greenpass.txt

greenpass --txt ./greenpass.txt

and the output is:

File "/home/riccardo/.local/share/virtualenvs/pipass-4gGy4IGJ/bin/greenpass", line 707, in <module>
    res = verify_certificate(txt, "txt")
  File "/home/riccardo/.local/share/virtualenvs/pipass-4gGy4IGJ/bin/greenpass", line 485, in verify_certificate
    gpp = GreenPassParser(path, filetype)
  File "/home/riccardo/.local/share/virtualenvs/pipass-4gGy4IGJ/bin/greenpass", line 398, in __init__
    decoded = base45.b45decode(data)
  File "/home/riccardo/.local/share/virtualenvs/pipass-4gGy4IGJ/lib/python3.9/site-packages/base45/__init__.py", line 54, in b45decode
    raise ValueError("Invalid base45 string")
ValueError: Invalid base45 string

Tried also with an online qr decode, apsting the result in a text file and the result is still the same.

manually compiled zbar 0.23.1 with binary options and errors are still the same.

Hi,
it seems to be a problem with your greenpass.

Probably it is a different version that I never saw and relies on something different present in the specification.

Can you, please, in order:

  • Check if the raw data (the output of zbarcam --raw /dev/video0) starts with "HC1:". If not, let me know what are the symbols of you greenpass before the colon.

  • Check if the following bash pipeline (tested on ubuntu 21.04) returns the same result:

vagrant@ubuntu-hirsute:~$ zbarimg --version
0.23.90
vagrant@ubuntu-hirsute:~$ zbarimg --raw /vagrant/gp2.png | sed 's/^HC1://' | file -
scanned 1 barcode symbols from 1 images in 0.01 seconds

/dev/stdin: ASCII text, with very long lines
vagrant@ubuntu-hirsute:~$ zbarimg --raw /vagrant/gp2.png | sed 's/^HC1://' | base45 --decode | file -
scanned 1 barcode symbols from 1 images in 0.01 seconds

/dev/stdin: zlib compressed data

(you can substitute zbarcam to zbarimg, also try with zbarimg).

Thank you!
D

Hi! I tried to pass the pdf of my greenpass and crop the qr and export as png and it works, so I don't think the problem is my greenpass. However I'll try your suggestions as soon as I reach my computer.
Thanks

Hello here are the results,
Output of zbarcam strts with HC1:

0.23.92 

zbarimg --raw ./gp2.png | sed 's/^HC1://' | file -
scanned 1 barcode symbols from 1 images in 0,01 seconds

/dev/stdin: ASCII text, with very long lines

zbarimg --raw ./gp2.png | sed 's/^HC1://' | base45 --decode | file -
scanned 1 barcode symbols from 1 images in 0,01 seconds

/dev/stdin: zlib compressed data

Tried also:

zbarimg --raw ./gp2.png  | greenpass --txt -

and it decodes correctly.

But with
zbarcam --raw /dev/video0 | greenpass --txt -
no output is produced.

Even with

zbarimg (or zbarcam) --raw ./gp2.png > gp2.txt
greenpass --txt gp2.txt

the script produce error.

So I tried with this test script testpass.py:

#! /usr/bin/env python3
import json
import sys
import zlib
 
import base45
import cbor2
from cose.messages import CoseMessage
 
payload = sys.argv[1][4:]
print("decoding payload: "+ payload)
 
# decode Base45 (remove HC1: prefix)
decoded = base45.b45decode(payload)
 
# decompress using zlib
decompressed = zlib.decompress(decoded)
# decode COSE message (no signature verification done)
cose = CoseMessage.decode(decompressed)
# decode the CBOR encoded payload and print as json
print(json.dumps(cbor2.loads(cose.payload), indent=2))

and passing to this script the payload between single quotes

./testpass.py 'PASTED_CONTENT_OF_gp4.txt'

it decodes successfully.
Once I try to pipe the output, or read from text file, it fails to decode.

I'm scratching my head!

Ok, looking at the details, seems to be the stdin that is not closed.

Can you try using the following code?

zbarcam -q1 --raw | greenpass --txt -

I think that the problem is related to zbarcam continously piping into the script.

I think that using the current master (5b74940) would be sufficient, can you check it?

that invalidates the behaviour having a feed of greenpass on the pipe but I think it will be sufficient.

Closing due inactivity. I will reopen it if required.