summaryrefslogtreecommitdiff
path: root/verify.py
diff options
context:
space:
mode:
Diffstat (limited to 'verify.py')
-rw-r--r--verify.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/verify.py b/verify.py
index fe873b3..57dd466 100644
--- a/verify.py
+++ b/verify.py
@@ -12,15 +12,15 @@ from pyzbar import pyzbar
def cert(name):
- return Path(__file__).absolute().parent / 'certs' / name
+ return Path(__file__).absolute().parent / "certs" / name
def verify(qr_code_bytes):
- b64, payload = qr_code_bytes.split(b'#', maxsplit=1)
+ b64, payload = qr_code_bytes.split(b"#", maxsplit=1)
sig = base64.decodebytes(b64)
h = hashes.Hash(hashes.SHA256())
- h.update(payload.decode().encode('utf8'))
+ h.update(payload.decode().encode("utf8"))
digest = h.finalize()
with open(cert("RamzorQRPubKey.pem"), "rb") as f:
@@ -35,13 +35,13 @@ def verify(qr_code_bytes):
print("Valid signature!")
data = json.loads(payload)
- if data['ct'] == 1:
- for i in range(len(data['p'])):
+ if data["ct"] == 1:
+ for i in range(len(data["p"])):
print(f"Details of person number {i+1}:")
print(f"\tIsraeli ID Number {data['p'][i]['idl']}")
print(f"\tID valid by {data['p'][i]['e']}")
print(f"Cert Unique ID {data['id']}")
- elif data['ct'] == 2:
+ elif data["ct"] == 2:
print(f"Israeli ID Number {data['idl']}")
print(f"ID valid by {data['e']}")
print(f"Cert Unique ID {data['id']}")
@@ -54,23 +54,31 @@ def read_qr_code(image_path):
def create_arg_parser():
- parser = argparse.ArgumentParser("GreenPass QR code verifier")
+ parser = argparse.ArgumentParser("Green Pass QR code verifier")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
- "-i", "--image_path", type=Path, help="Path to an image with the QR code", default=None)
+ "-i",
+ "--image-path",
+ type=Path,
+ help="Path to an image with the QR code",
+ default=None,
+ )
group.add_argument(
- "-t", "--txt_path", type=Path, help="Path to decoded QR code textual content", default=None)
+ "-t",
+ "--txt-path",
+ type=Path,
+ help="Path to decoded QR code textual content",
+ default=None,
+ )
return parser
-if __name__ == '__main__':
- # Parse arguments
+if __name__ == "__main__":
parser = create_arg_parser()
args = parser.parse_args()
- # Choose correct input
if args.image_path:
verify(read_qr_code(args.image_path))
elif args.txt_path:
- with open(args.txt_path, 'rb') as f:
+ with open(args.txt_path, "rb") as f:
verify(f.read().strip())