berdav / greenpass

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

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

Closed rbicelli closed 2 years ago

rbicelli commented 2 years ago

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.

berdav commented 2 years ago

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:

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

rbicelli commented 2 years ago

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

rbicelli commented 2 years ago

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!

berdav commented 2 years ago

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.

berdav commented 2 years ago

I think that using the current master (5b74940aeb2e5b4c7c0ef7d07fca25e89953cc16) 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.

berdav commented 2 years ago

Closing due inactivity. I will reopen it if required.