{"id":113,"date":"2012-12-04T22:04:52","date_gmt":"2012-12-04T21:04:52","guid":{"rendered":"http:\/\/46.105.150.90\/tstnunix\/?p=113"},"modified":"2012-12-04T22:04:52","modified_gmt":"2012-12-04T21:04:52","slug":"2d-doc-verify-on-your-own-the-signature","status":"publish","type":"post","link":"https:\/\/nunix.fr\/?p=113","title":{"rendered":"2d-doc, verify on your own the signature"},"content":{"rendered":"<p>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 (<a href=\"http:\/\/www.2d-doc.com\/spip.php?page=article&#038;id_article=15\">http:\/\/www.2d-doc.com\/spip.php?page=article&#038;id_article=15<\/a>), that you can reuse if you don&rsquo;t have existing 2d-doc pictures and public key.<\/p>\n<p>You can find the demo material on github: <a href=\"https:\/\/github.com\/eirmag\/2ddoc\">https:\/\/github.com\/eirmag\/2ddoc.<\/a><\/p>\n<p \/>The facture picture contains several information, that you can again extract with &lsquo;dmtxread&rsquo;.  <!--more-->  {jcomments on}<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"http:\/\/www.2d-doc.com\/IMG\/png\/facture_v1_.png\" border=\"0\" alt=\"2d-doc-facture\" title=\"2d-doc-facture\" \/><\/p>\n<p>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\u00a0 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.<\/p>\n<pre>$ echo -ne \"\\x30\\x44\\x02\\x20\" >> $sigfile #asn.1 header for sequence of 0x44 bytes, and then integer value of 0x20 bytes<br \/>$ dd ...<br \/>$ echo -ne \"\\x02\\x20\" >> $sigfile #asn.1 for integer of 0x20 bytes<br \/>$ dd ...<\/pre>\n<p>The script currently uses public certificate that is called \u00ab\u00a0pubkey.pem\u00a0\u00bb 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.<\/p>\n<pre>$ openssl dgst -sha256 -verify pubkey.pem -signature $sigfile $datafile<br \/>Verified OK<br \/><\/pre>\n<p>Following, some resources that helped me in building the script:<\/p>\n<ul>\n<li><a href=\"http:\/\/crypto.stackexchange.com\/questions\/1795\/converting-a-der-ecdsa-signature-to-asn-1\">http:\/\/crypto.stackexchange.com\/questions\/1795\/converting-a-der-ecdsa-signature-to-asn-1<\/a><\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/ECDSA\">https:\/\/en.wikipedia.org\/wiki\/ECDSA<\/a><\/li>\n<li><a href=\"http:\/\/www.cryptopp.com\/wiki\/Elliptic_Curve_Digital_Signature_Algorithm#Signature_Sizes\">http:\/\/www.cryptopp.com\/wiki\/Elliptic_Curve_Digital_Signature_Algorithm#Signature_Sizes<\/a><\/li>\n<li><a href=\"https:\/\/www.eldos.com\/forum\/read.php?FID=7&#038;TID=2216\">https:\/\/www.eldos.com\/forum\/read.php?FID=7&#038;TID=2216<\/a><\/li>\n<\/ul>\n<p>Regards,<br \/>Gabriel<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#038;id_article=15), that you can reuse if you don&rsquo;t have existing 2d-doc pictures and public key. You can find the demo material on github: &hellip; <a href=\"https:\/\/nunix.fr\/?p=113\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;2d-doc, verify on your own the signature&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-113","post","type-post","status-publish","format-standard","hentry","category-news-news"],"_links":{"self":[{"href":"https:\/\/nunix.fr\/index.php?rest_route=\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nunix.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nunix.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nunix.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nunix.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=113"}],"version-history":[{"count":0,"href":"https:\/\/nunix.fr\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions"}],"wp:attachment":[{"href":"https:\/\/nunix.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nunix.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nunix.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}