floysh / DCC-green-pass-decoder

A simple web app to decode EU Digital Covid Certificate/Green Pass QR codes.
https://floysh.github.io/DCC-green-pass-decoder/
MIT License
44 stars 13 forks source link

Extarcting KID and signature #1

Closed jumpjack closed 2 years ago

jumpjack commented 3 years ago

Hi, where did you find documentation to implement this line of code?

https://github.com/floysh/DCC-green-pass-decoder/blob/99344251c7eb9b37103352ae5341c9ad256211f6/src/source.js#L229

Does it exist similar documentation for decoding signature? I would like to manually decode it, rather than using a ready-made "signature.verify()" function copied from somewhere, by comparing its contents to the certificates found here:

https://raw.githubusercontent.com/lovasoa/sanipasse/master/src/assets/Digital_Green_Certificate_Signing_Keys.json

floysh commented 3 years ago

Hi, I'm not sure I understand what you want to do. You're not supposed to decode a signature, it's just a byte sequence used by the validation algorithm. If you're looking for a way to validate EDCC signatures, there's this documentation from the EU: https://github.com/ehn-dcc-development/hcert-spec/blob/main/hcert_spec.md#32-structure-of-the-payload

Keeping it short, since EDCCs are regular COSE structures you can verify the signature by following what is stated by the COSE RFC. In section 3 it states that the protected header is a serialized CBOR map, so you can decode it the same way as the payload (which is what I did in the code line you referenced to).

Let me know if I answered your question 😊

jumpjack commented 3 years ago

My problem is that I cannot use node.js, I need to use pure javascript, and I can't find any port of node.js cose.js to javascript; I tried importing cose-js into a javascript module using unpkg.com, jsdelivr.net and others but I can 't get it working, I receive errors about missing exports, missing default exports, wrong cbor dependencies,....

Since my original post, I found some info about the signature: it's in P1363 format, which means they are always 64 bytes, representing values R and S concatenated. But that's all, I can't understand how to manage it. I asked on jsrasign repo if that library could be compatible with DGC signature verification requirements, as I can successfully import it into a module; they replied it should be, because it supports all encrypting algorithms used in DGC, but they didn't provide any clue about how to use it.