Skip to content

Instantly share code, notes, and snippets.

@lmillucci
Created June 29, 2021 12:08
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lmillucci/48804b0598553689fc5054da10e63231 to your computer and use it in GitHub Desktop.
Save lmillucci/48804b0598553689fc5054da10e63231 to your computer and use it in GitHub Desktop.
Simple green pass decoder in JavaScript
/**
* 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));
@Mukinayi
Copy link

Lorenzo can you advise a library to encrypt and sign cbor message ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment