{"id":1064,"date":"2012-10-25T19:07:42","date_gmt":"2012-10-25T17:07:42","guid":{"rendered":"https:\/\/locallost.net\/?p=1064"},"modified":"2012-10-25T19:09:31","modified_gmt":"2012-10-25T17:09:31","slug":"rollout-your-own-domainkeys-like-signature-verification-in-php","status":"publish","type":"post","link":"https:\/\/locallost.net\/?p=1064","title":{"rendered":"Rollout your own DomainKeys-like signature verification in PHP"},"content":{"rendered":"<p>Reading documentation on <a title=\"DomainKeys Identified Mail\" href=\"http:\/\/en.wikipedia.org\/wiki\/DomainKeys_Identified_Mail\">DKIM<\/a>\u00a0I found it usefull to be able to distribute public keys through DNS to allow recipient to check signed content against it.<\/p>\n<p>So, here is a couple of DomainKeysSigner and DomainKeysVerifier PHP classes that implement the sign and verify operations, with the verify operation fetching the public key through a custom DNS TXT record.<\/p>\n<p>To start with, you need a public\/private RSA key that you can obtain with openssl:<\/p>\n<pre># openssl genrsa -out my.service.example.net.private.key 1024<\/pre>\n<p>Extract the public key:<\/p>\n<pre># openssl rsa -in private.key -text -pubout<\/pre>\n<p>Now, you need to setup a DNS TXT record for your host\/domain containing the base64 key from the previous command, without the \u00ab\u00a0&#8212;&#8211;BEGIN PUBLIC KEY&#8212;&#8211;\u00a0\u00bb and \u00ab\u00a0&#8212;&#8211;END PUBLIC KEY&#8212;&#8211;\u00a0\u00bb tags.<\/p>\n<p>Let say you wan&rsquo;t to set the key on \u00ab\u00a0foo.example.net\u00a0\u00bb:<\/p>\n<pre>foo.example.net. IN TXT \"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCyvgpjWK2w6FmlFxdxcSBwP0P50jsIUB3ZV0xYXolLF0jipXdjN\/TgZjBAlRYlF7u\/iXW7WmrbU\/mwpdlyiK0+dZvwZMGUzqBOC1ULz5i8xPVidutkBhMMWFovipibnvU6TePJjMdeBTlEDpi1p4\/V66yOxJ8sU1nYCTYJIqaX1QIDAQAB\"<\/pre>\n<p>Now you can use the DNSPubKeySigner and DNSPubKeyVerifier classes to sign and verify a data signature with the public key fetched from the DNS TXT record.<\/p>\n<p>&#8211;\u00a0<a title=\"DNSPubKeyVerifier\" href=\"https:\/\/github.com\/eguaj\/DNSPubKeyVerifier\">https:\/\/github.com\/eguaj\/DNSPubKeyVerifier<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reading documentation on DKIM\u00a0I found it usefull to be able to distribute public keys through DNS to allow recipient to check signed content against it. So, here is a couple of DomainKeysSigner and DomainKeysVerifier PHP classes that implement the sign &hellip; <a href=\"https:\/\/locallost.net\/?p=1064\">Continuer la lecture <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,17],"tags":[],"class_list":["post-1064","post","type-post","status-publish","format-standard","hentry","category-code","category-system"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2Bei9-ha","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/posts\/1064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/locallost.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1064"}],"version-history":[{"count":9,"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/posts\/1064\/revisions"}],"predecessor-version":[{"id":1079,"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/posts\/1064\/revisions\/1079"}],"wp:attachment":[{"href":"https:\/\/locallost.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/locallost.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/locallost.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}