denysvitali / covid-cert-analysis

Other
148 stars 56 forks source link

How to put signature into readable format? #5

Closed jumpjack closed 2 years ago

jumpjack commented 2 years ago

Any idea how to process the results for "signature" coming from this javascript line?

[headers1, headers2, cbor_data, signature] = CBOR.decode(unzipped)

For signature of Mickey Mouse I get: d6bfd4244c5f5c532ed4229de23f683a471173c1a8940dbe853186ecce576d7c263f09c91ad5b9c072455dc4ebdda222b27c2bb75c118357ebe85d3286a52654

How do I turn it into something like this?

kid: 53FOjX/4aJs=
key: <EllipticCurvePublicNumbers(curve=secp256r1, x=59224424711316661084877973301841821584140021680113528472675651838972371380627, y=54841068689176540860306147861276004028606373898471432794562118907413910993957>

I decode cbor_data using:

    cbor_dataArr = typedArrayToBuffer(cbor_data);
    greenpassData  = CBOR.decode(cbor_dataArr);

But it does not work for signature.

RangeError: Offset is outside the bounds of the DataView

ndegendogo commented 2 years ago

@jumpjack what makes you expect that there is more encoded in the signature than just the binary data?

jumpjack commented 2 years ago

Your question includes the answer: if it's binary, it's encoding something. Anyway now I found that the X and Y I mentioned, which I found mentioned on a forum, are not in the signature, but in the certificate. Instead, the signature is in P1363 format, i.e. it's made of two strings representing R and S of the algorithm:

Last element of CBOR array contains the signature of the greenpass; it's made of 64 bytes, which must be split in 2 to get values "R" and "S"; in our example:

A4EE9016C1A74CCF9CAAB905492D698F6992A8FA30C20DB6180F06040C4870A845BB4B3A1CE3F4ED529CC78E66322547D62637C74AB17919C0AA52A614795E9E This is a sequence of alphamumeric couples, each one represeting an hexadecimal number. It should (to be confirmed) represent a signature in P1363 format, which should be converted to DER format to be used in OPENSSL.

Splitted:

R: A4EE9016C1A74CCF9CAAB905492D698F6992A8FA30C20DB6180F06040C4870A8 S: 45BB4B3A1CE3F4ED529CC78E66322547D62637C74AB17919C0AA52A614795E9E

https://github.com/jumpjack/greenpass

ndegendogo commented 2 years ago

@jumpjack so you can then close this ticket? 😁