1

Thank you for your help.

With the following sample script, I can successfully decode a (a) covid VACCINATION bar code and pass on the json to my application (I've tested this with the bar codes in my "green pass" application and this works).

However, when I scan a (b) TEST barcode (i.e. antigene test, PCR test, ...) from our local authorities and pass the string on to the script, the same script returns "ValueError: Invalid base45 string".

When comparing (a) the vaccination base45 code and (b) the test base45 code, both look legit to my untrained eye, but obviously something else needs to be done to (b) to make it valid base45?

For security reasons, I cannot paste my real data (sensitive information), so maybe you can help me figure out why (b) isn't base45 without seeing the entire string. So the only way you can possibly help me is if you scan your own (a) and (b) with a bar code scanner and then run the two strings that you get through my script, or maybe you know any publicly available test data that we can work with. Thanks so much, guys!!!

import json
import sys
import zlib
import base45
import cbor2
from cose.messages import CoseMessage

# payload = SEE COMMENTS
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))
awensch
  • 11
  • 1

1 Answers1

3

Each set of data has a prefix you shall remove before processing. Please have a look at the specification where the encoding process is well explained.

The prefix is usually HC1 and stands for Health Certificate version 1. It could also be HC2, HC3, HC200... so make sure you understand each version in the future.

In your code sample, I can read the comment # decode Base45 (remove HC1: prefix), but that prefix is not stripped at all by decoded = base45.b45decode(payload)

You should have something like payload = payload[4:] as showed in this blog post

Spomky-Labs
  • 15,473
  • 5
  • 40
  • 64