2d-doc, verify on your own the signature

Following the last article where I present 2d-doc, I present here a script I wrote to verify the signature on my own. There is a set of examples on the official web-site (http://www.2d-doc.com/spip.php?page=article&id_article=15), that you can reuse if you don’t have existing 2d-doc pictures and public key.

You can find the demo material on github: https://github.com/eirmag/2ddoc.

The facture picture contains several information, that you can again extract with ‘dmtxread’. {jcomments on}

2d-doc-facture

The information extracted from the figure comes into a format that is not directly interpretable by openssl. Openssl is here used to validate an ECDSA signature contained in the extracted information. But openssl needs encapsulation in ASN.1 format. The script located in github creates  first bytes to inform of collection of byte of a certain size. Thanks to 2D-doc specifications, the size of the signature is known in advance. There is two blocs (a pair of values which is the elliptic curve signature) of 32 bits.

$ echo -ne "\x30\x44\x02\x20" >> $sigfile #asn.1 header for sequence of 0x44 bytes, and then integer value of 0x20 bytes
$ dd ...
$ echo -ne "\x02\x20" >> $sigfile #asn.1 for integer of 0x20 bytes
$ dd ...

The script currently uses public certificate that is called « pubkey.pem » by convention. Just replace it with the official public key, or with the example public key. Openssl is convenient to create digital signature or to verify them. The following command indicates to use the sha256 message digest algorithm, as indicated in the specifications. The ECDSA algorithm is detected by openssl directly given the certificate.

$ openssl dgst -sha256 -verify pubkey.pem -signature $sigfile $datafile
Verified OK

Following, some resources that helped me in building the script:

Regards,
Gabriel

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *