summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Pipfile7
-rw-r--r--README.md18
-rw-r--r--verify.py34
3 files changed, 35 insertions, 24 deletions
diff --git a/Pipfile b/Pipfile
index 5300670..2ff3dea 100644
--- a/Pipfile
+++ b/Pipfile
@@ -1,4 +1,11 @@
+[[source]]
+url = "https://pypi.org/simple"
+verify_ssl = true
+name = "pypi"
+
[packages]
cryptography = "*"
pillow = "*"
pyzbar = "*"
+
+[dev-packages]
diff --git a/README.md b/README.md
index 4c86597..bf68784 100644
--- a/README.md
+++ b/README.md
@@ -10,32 +10,28 @@ A pythonic implementation of the verification process can be found in [`verify.p
### Setup
-Install [`pipenv`](https://pypi.org/project/pipenv/) and execute:
+Install [`pipenv`](https://pipenv.pypa.io/en/latest/) and sync the required dependencies:
+
```bash
-pipenv install
+pipenv sync
```
### Usage
#### Option 1 - from QR code image
+
Save your Green Pass as a `.png` file and execute:
+
```bash
pipenv run python verify.py -i green_pass_image.png
```
#### Option 2 - from QR code decoded textual content
-Decode the QR code payload yourself, put it in a txt file:
-
-*textual_payload.txt*
-```json
-base64EncodedSignature==#{"id":"01/IL/ABCD1234ABCD1234ABCD1234ABCD1234#ABCD1234","et":1,"ct":1,"c":"IL MOH","cn":null,"fn":null,"g":null,"f":null,"gl":null,"fl":null,"idp":null,"idl":null,"b":"0001-01-01","e":"0001-01-01","a":"0001-01-01","p":[{"idl":"012345678","e":"2021-01-01"}]}
-```
-
-And then execute:
+Decode the QR code payload yourself, put it in a txt file and then execute:
```bash
-pipenv run python verify.py -t textual_payload.txt
+pipenv run python verify.py -t green_pass_payload.txt
```
### Output example
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())