{"id":1643,"date":"2018-11-27T17:37:34","date_gmt":"2018-11-27T22:37:34","guid":{"rendered":"http:\/\/www.xavignu.com\/?p=1643"},"modified":"2018-11-27T17:41:17","modified_gmt":"2018-11-27T22:41:17","slug":"opendkim-in-debian","status":"publish","type":"post","link":"https:\/\/www.xavignu.com\/?p=1643","title":{"rendered":"OpenDKIM in Debian"},"content":{"rendered":"<p>Lately I&#8217;ve been playing with <a href=\"http:\/\/www.postfix.org\/\" target=\"_blank\">postfix<\/a> and ways to validate my mail. That&#8217;s how I reached <a href=\"https:\/\/support.dnsimple.com\/articles\/dkim-record\/\" target=\"_blanks\">DKIM<\/a> records. Something like ssh keys (a public and private key) but for mail. Installation in Debian GNU\/Linux is pretty simple via apt-get as usual, we need to install <a href=\"http:\/\/www.opendkim.org\/\" target=\"_blank\">opendkim<\/a> and opendkim-tools.<\/p>\n<pre id=\"terminal\">dpkg -l | grep dkim\r\nii  libmail-dkim-perl              0.40-1                           all          cryptographically identify the sender of email - perl library\r\nii  libopendkim9                   2.9.2-2+deb8u1                   amd64        Library for signing and verifying DomainKeys Identified Mail signatures\r\nii  opendkim                       2.9.2-2+deb8u1                   amd64        Milter implementation of DomainKeys Identified Mail\r\nii  opendkim-tools                 2.9.2-2+deb8u1                   amd64        Set of command line tools for OpenDKIM\r\n<\/pre>\n<p>We need to open a port for opendkim (8891 in my case), we need to edit \/etc\/default\/opendkim in order to do this as below.<\/p>\n<pre id=\"terminal\">grep -v \"^#\" \/etc\/default\/opendkim \r\nSOCKET=\"inet:8891@localhost\" # listen on loopback on port 8891\r\n<\/pre>\n<p><!--more--><\/p>\n<p>We need to edit \/etc\/opendkim.conf to something similar to below.<br \/>\n[text]<br \/>\nSyslog\t\t\tyes<br \/>\nUMask\t\t\t002<br \/>\nDomain\t\t\tmydomain.com<br \/>\nMode\t\t\tsv<br \/>\nOversignHeaders\t\tFrom<br \/>\nPidFile                 \/var\/run\/opendkim\/opendkim.pid<br \/>\nSignatureAlgorithm      rsa-sha256<br \/>\nUserID                  opendkim:opendkim<br \/>\nKeyFile\t\t\t\/etc\/opendkim\/keys\/mail.private<br \/>\nSelector\t\tmail<br \/>\nAutoRestart             Yes<br \/>\nCanonicalization        relaxed\/simple<br \/>\nAutoRestart             Yes<br \/>\nAutoRestartRate         10\/1h<br \/>\n[\/text]<br \/>\nWe then execute this small script that will create a dir where we will store the keys.<br \/>\n[bash]<br \/>\n#!\/bin\/bash<\/p>\n<p>mkdir -p \/etc\/opendkim\/keys<br \/>\ncd \/etc\/opendkim\/keys<br \/>\nopendkim-genkey    -s mail  -b 2048  &#8211;domain mydomain.com &#8211;verbose<br \/>\n[\/bash]<\/p>\n<p>It&#8217;s important to set the bit rate to 2048, else it will create a key of 1024 bits by default. Once done we will have a private and a public in \/etc\/opendkim\/keys.<\/p>\n<pre id=\"terminal\">ls -ltr \/etc\/opendkim\/keys\/; cat \/etc\/opendkim\/keys\/mail.txt \r\ntotal 8\r\n-rw------- 1 opendkim opendkim 1679 Nov 25 00:14 mail.private\r\n-rw------- 1 root     root      491 Nov 25 00:14 mail.txt\r\nmail._domainkey\tIN\tTXT\t( \"v=DKIM1; k=rsa; \"\r\n\t  \"p=testingNBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4XcAhtpsU3DtaWM0N2yiGs10Wh8wS7RpFWacv1lAk4EbxaGlHCdMpbpNQHqUWBu6Uikj+jadai2Bgyo1TvWGlUZs+JcCoQWcs6pDKkkvMK\/xee7pzmhZCXdyuDbf9QH\/7cNm7d7ZIYDRC92YCI9XNb\/8ANxg0UcxNsGBxA00ksjShl\/EPfCfdYpKODJbgubt+\/bP\/ZBguogHXT\"\r\n\t  \"BPcEWTu6X2B41DKiRCt+LP5RJWzA0XsfukR3y8r712FuRkqSitZsasCqBRtEZmYnuID8yjP92B3JJ9jwOLnJ3MVTnIqMeRDdtJtwxbTsYgND+0S5Q59bonO2CAGoPoVOgqyeXHKtesting\" )  ; ----- DKIM key mail for mydomain.com\r\n<\/pre>\n<p>We are almost done, we need to the public key part that&#8217;s between quotes to our DNS servers and create the record.<br \/>\n[text]<br \/>\n&#8220;v=DKIM1; k=rsa; p=testingNBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4XcAhtpsU3DtaWM0N2yiGs10Wh8wS7RpFWacv1lAk4EbxaGlHCdMpbpNQHqUWBu6Uikj+jadai2Bgyo1TvWGlUZs+JcCoQWcs6pDKkkvMK\/xee7pzmhZCXdyuDbf9QH\/7cNm7d7ZIYDRC92YCI9XNb\/8ANxg0UcxNsGBxA00ksjShl\/EPfCfdYpKODJbgubt+\/bP\/ZBguogHXTBPcEWTu6X2B41DKiRCt+LP5RJWzA0XsfukR3y8r712FuRkqSitZsasCqBRtEZmYnuID8yjP92B3JJ9jwOLnJ3MVTnIqMeRDdtJtwxbTsYgND+0S5Q59bonO2CAGoPoVOgqyeXHKtesting&#8221;<br \/>\n[\/text]<br \/>\nOnce uploaded and replied from the DNS servers, we can query the record. We should get an answer thats public key we just uploaded.<\/p>\n<pre id=\"terminal\">host -t TXT mail._domainkey.mydomain.com\r\nmail._domainkey.mydomain.com descriptive text \"v=DKIM1; k=rsa; p=testingNBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4XcAhtpsU3DtaWM0N2yiGs10Wh8wS7RpFWacv1lAk4EbxaGlHCdMpbpNQHqUWBu6Uikj+jadai2Bgyo1TvWGlUZs+JcCoQWcs6pDKkkvMK\/xee7pzmhZCXdyuDbf9QH\/7cNm7d7ZIYDRC92YCI9XNb\/8ANxg0UcxNsGBxA00ksjShl\/EPfCfdYpKODJbgubt+\" \"\/bP\/ZBguogHXTBPcEWTu6X2B41DKiRCt+LP5RJWzA0XsfukR3y8r712FuRkqSitZsasCqBRtEZmYnuID8yjP92B3JJ9jwOLnJ3MVTnIqMeRDdtJtwxbTsYgND+0S5Q59bonO2CAGoPoVOgqyeXHKtesting\"\r\n<\/pre>\n<p>DKIM is almost done, but we need to let Postfix that we will use opendkim. We need to add below entries to postfix main.conf file.<\/p>\n<pre id=\"terminal\"> egrep -B 1 -C 1 \"(dkim|milter)\" \/etc\/postfix\/main.cf\r\n\r\n# Added for Opendkim\r\nmilter_protocol = 2\r\nmilter_default_action = accept\r\nsmtpd_milters = inet:127.0.0.1:8891\r\nnon_smtpd_milters = inet:127.0.0.1:8891\r\n\r\n<\/pre>\n<p>Once done we are good to restart postfix and opendkim for the changes to take effect. If there are no errors we will see something like below in mail.log file.<\/p>\n<pre id=\"terminal\">\r\nOct 25 00:18:35 sd-129111 postfix\/master[27345]: daemon started -- version 2.11.1, configuration \/etc\/postfix\r\nOCt 25 00:18:38 sd-129111 opendkim[26170]: OpenDKIM Filter: mi_stop=1\r\nOct 25 00:18:38 sd-129111 opendkim[26170]: OpenDKIM Filter v2.9.1 terminating with status 0, errno = 0\r\nOct 25 00:18:38 sd-129111 opendkim[27361]: OpenDKIM Filter v2.9.1 starting (args: -x \/etc\/opendkim.conf -u opendkim -P \/var\/run\/opendkim\/opendkim.pid -p inet:8891@localhost)\r\n<\/pre>\n<p>Final confirmation will be sending an email to <b>check-auth&#64;verifier.port25.com<\/b> and we shall receive a reply email that if all went well will look like below.<br \/>\n[text]<br \/>\nThank you for using the verifier,<\/p>\n<p>The Port25 Solutions, Inc. team<\/p>\n<p>==========================================================<br \/>\nSummary of Results<br \/>\n==========================================================<br \/>\nSPF check:          pass<br \/>\n&#8220;iprev&#8221; check:      pass<br \/>\nDKIM check:         pass<br \/>\nSpamAssassin check: ham<br \/>\n[\/text]<br \/>\nReferences:<\/p>\n<li><a href=\"https:\/\/help.ubuntu.com\/community\/Postfix\/DKIM\" target=\"_blank\">Ubuntu<\/a><\/li>\n<li><a href=\"https:\/\/www.linode.com\/docs\/email\/postfix\/configure-spf-and-dkim-in-postfix-on-debian-8\/\" target=\"_blank\">Linode<\/a><\/li>\n<li><a href=\"https:\/\/linoxide.com\/mail\/setup-postfix-mail-server-dkim\/\" target=\"_blank\">Linoxide<\/a><\/li>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-configure-dkim-with-postfix-on-debian-wheezy\" target=\"_blank\">DigitalOcean<\/a><\/li>\n","protected":false},"excerpt":{"rendered":"<p>Lately I&#8217;ve been playing with postfix and ways to validate my mail. That&#8217;s how I reached DKIM records. Something like ssh keys (a public and private key) but for mail. Installation in Debian GNU\/Linux is pretty simple via apt-get as usual, we need to install opendkim and opendkim-tools. dpkg -l | grep dkim ii libmail-dkim-perl [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[92],"tags":[56,102,22,6,23,103],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pTQgt-qv","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1643"}],"collection":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1643"}],"version-history":[{"count":15,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1643\/revisions"}],"predecessor-version":[{"id":1662,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1643\/revisions\/1662"}],"wp:attachment":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}