Created
June 29, 2021 12:08
-
-
Save lmillucci/48804b0598553689fc5054da10e63231 to your computer and use it in GitHub Desktop.
Simple green pass decoder in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple green pass decoder inspired by https://git.gir.st/greenpass.git/blob_plain/master:/greenpass.py | |
* | |
* 2021 Lorenzo Millucci | |
* | |
* Before usage install following dependecies `npm install base45 cbor jpeg-js jsqr pako` | |
*/ | |
const base45 = require('base45'); | |
const cbor = require('cbor'); | |
const fs = require('fs') | |
const jpeg = require('jpeg-js'); | |
const jsQR = require("jsqr"); | |
const pako = require('pako'); | |
// Set the path to the green pass QR | |
const FILE_PATH = __dirname + '/greenpass.jpg'; | |
// Read image file | |
const greenpassJpeg = fs.readFileSync(FILE_PATH); | |
const greenpassImageData = jpeg.decode(greenpassJpeg, {useTArray: true}); | |
// Decode QR | |
const decodedGreenpass = jsQR(greenpassImageData.data, greenpassImageData.width, greenpassImageData.height); | |
// Remove `HC1:` from the string | |
const greenpassBody = decodedGreenpass.data.substr(4); | |
// Data is Base45 encoded | |
const decodedData = base45.decode(greenpassBody); | |
// And zipped | |
const output = pako.inflate(decodedData); | |
const results = cbor.decodeAllSync(output); | |
[headers1, headers2, cbor_data, signature] = results[0].value; | |
const greenpassData = cbor.decodeAllSync(cbor_data); | |
console.log(JSON.stringify(greenpassData[0].get(-260).get(1), null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lorenzo can you advise a library to encrypt and sign cbor message ?