-
-
Save lmillucci/48804b0598553689fc5054da10e63231 to your computer and use it in GitHub Desktop.
| /** | |
| * 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)); |
Hello Lorenzo, I wanted to know if there is a version in php language. Thanks
Thanks :-)
any browser-javascript version?
or at least a hint to decode the string I get after decoding BASE45 string and uncompressing with zlib, always in browser-javascript.
Hello! Do you know why I get errors on [headers1, headers2, cbor_data, signature] = results[0].value; -> 'headers1' is not defined, 'headers2 is not defined, 'cbor_data' is not defined, 'signature' is not defined ? Thank you!
Hello! Do you know why I get errors on [headers1, headers2, cbor_data, signature] = results[0].value; -> 'headers1' is not defined, 'headers2 is not defined, 'cbor_data' is not defined, 'signature' is not defined ? Thank you!
I don't know. I assume that something went wrong during CBOR decoding
Add some debug lines as follows, to figure out where the process failed:
// Data is Base45 encoded
const decodedData = base45.decode(greenpassBody);
console.log("decodedData ", decodedData );
// And zipped
const output = pako.inflate(decodedData);
console.log("output ",output );
const results = cbor.decodeAllSync(output);
console.log("results ",results );
[headers1, headers2, cbor_data, signature] = results[0].value;
const greenpassData = cbor.decodeAllSync(cbor_data);
You can also have a look at my page for greenpass decoding in browser standalone:
https://github.com/jumpjack/greenpass
Hello! Do you know why I get errors on [headers1, headers2, cbor_data, signature] = results[0].value; -> 'headers1' is not defined, 'headers2 is not defined, 'cbor_data' is not defined, 'signature' is not defined ? Thank you!
Because you have to declare those variables first. Like this:
let headers1, headers2, cbor_data, signature;
And then write this:
[headers1, headers2, cbor_data, signature] = results[0].value;
Suggestion for decoding/reading (not checking) the "signature" variable?
It should result in something like:
kid: 53FOjX/4aJs=
key: <EllipticCurvePublicNumbers(curve=secp256r1, x=59224424711316661084877973301841821584140021680113528472675651838972371380627, y=54841068689176540860306147861276004028606373898471432794562118907413910993957>
Suggestion for decoding/reading (not checking) the "signature" variable? It should result in something like:
kid: 53FOjX/4aJs= key: <EllipticCurvePublicNumbers(curve=secp256r1, x=59224424711316661084877973301841821584140021680113528472675651838972371380627, y=54841068689176540860306147861276004028606373898471432794562118907413910993957>
I have the same question
Hi Lorenzo!
Lorenzo can you advise a library to encrypt and sign cbor message ?
Not written by me ;)
I think it should be easy to write a PHP version