{"id":67268,"date":"2023-11-02T07:57:36","date_gmt":"2023-11-02T07:57:36","guid":{"rendered":"https:\/\/antonini.ddns.net\/?p=67268"},"modified":"2023-11-02T07:57:36","modified_gmt":"2023-11-02T07:57:36","slug":"opendkim","status":"publish","type":"post","link":"https:\/\/antonini.ddns.net\/?p=67268","title":{"rendered":"OpenDKIM"},"content":{"rendered":"<p style=\"text-align: justify;\">Protocolo de autentica\u00e7\u00e3o de e-mails para bloquear SPAMs<!--more--><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">The <strong>opendkim<\/strong> package contains a full-featured DKIM milter (<a class=\"https\" href=\"https:\/\/en.wikipedia.org\/wiki\/Milter\">mail filter<\/a>) implementation <span id=\"line-6\" class=\"anchor\"><\/span>suitable for use with MTAs (Message Transfer Agent mail servers) such as <a href=\"https:\/\/wiki.debian.org\/Postfix\">Postfix<\/a>. Upstream development at <a class=\"http\" href=\"http:\/\/www.opendkim.org\/\">OpenDKIM<\/a> is a community effort. <span id=\"line-7\" class=\"anchor\"><\/span><span id=\"line-8\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">DomainKeys Identified Mail (DKIM) combines several existing antiphishing and antispam methods to improve the quality of the classification and identification of legitimate e-mail. Instead of the traditional IP-address to determine the message sender, DKIM adds a digital signature associated with the domain name of the organization. In tandem, DNS is used to publish TXT records with the public portion of the cryptographic certificate used for digital signing. <span id=\"line-9\" class=\"anchor\"><\/span><span id=\"line-10\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">OpenDKIM can add DKIM signatures to outbound mail and check DKIM signatures on inbound mail. It can be configured to reject mail that has missing or invalid DKIM signatures. <span id=\"line-11\" class=\"anchor\"><\/span><span id=\"line-12\" class=\"anchor\"><\/span><span id=\"line-13\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">Jump to <a href=\"https:\/\/wiki.debian.org\/opendkim#Quickstart\">#Quickstart<\/a> for an overview and minimal setup, and refer to <span id=\"line-14\" class=\"anchor\"><\/span><a href=\"https:\/\/wiki.debian.org\/opendkim#Configuration\">#Configuration<\/a> for the complete picture. <span id=\"line-15\" class=\"anchor\"><\/span><span id=\"line-16\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<div class=\"table-of-contents\" style=\"text-align: justify;\">\n<p class=\"table-of-contents-heading\">Conte\u00fado<\/p>\n<ol>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Quickstart\">Quickstart<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Configuration\">Configuration<\/a>\n<ol>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Installation_details\">Installation details<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Generating_keys\">Generating keys<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#User_and_privileges\">User and privileges<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Key_selection\">Key selection<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Important_OpenDKIM_options\">Important OpenDKIM options<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Socket\">Socket<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#DNS_resolution\">DNS resolution<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Postfix_integration\">Postfix integration<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Troubleshooting\">Troubleshooting<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#DNS_Configuration\">DNS Configuration<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Testing\">Testing<\/a>\n<ol>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#opendkim-testkey\">opendkim-testkey<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#opendkim-testmsg\">opendkim-testmsg<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#email_tests\">email tests<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Mailman_and_DKIM_Configuration\">Mailman and DKIM Configuration<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#FAQ\">FAQ<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#See_also\">See also<\/a>\n<ol>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#upstream_specific_information\">upstream specific information<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/opendkim#Debian-specific_information\">Debian-specific information<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/div>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h1 id=\"Quickstart\" style=\"text-align: justify;\">Quickstart<\/h1>\n<p class=\"line874\" style=\"text-align: justify;\">The quickstart instructions in this section describe setting up a minimal, but <span id=\"line-21\" class=\"anchor\"><\/span>functional installation of opendkim for signing and verifying, integrated with <span id=\"line-22\" class=\"anchor\"><\/span><a href=\"https:\/\/wiki.debian.org\/Postfix\">Postfix<\/a>. This is the five-minute version of opendkim configuration for the <span id=\"line-23\" class=\"anchor\"><\/span>impatient. For a fuller discussion of the setup options available, please refer <span id=\"line-24\" class=\"anchor\"><\/span>to the subsequent sections. <span id=\"line-25\" class=\"anchor\"><\/span><span id=\"line-26\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Let\u2019s go! First, install opendkim: <span id=\"line-27\" class=\"anchor\"><\/span><span id=\"line-28\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1\" class=\"anchor\"><\/span>sudo apt install opendkim opendkim-tools<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">Next, generate the key pair for your DNS domain and <em>selector<\/em>: <span id=\"line-33\" class=\"anchor\"><\/span><span id=\"line-34\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-1\" class=\"anchor\"><\/span>sudo -u opendkim opendkim-genkey -D \/etc\/dkimkeys -d yourdomain.org -s 2021<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">Now, edit \/etc\/opendkim.conf. Four parameters need to be adapted: the <span id=\"line-39\" class=\"anchor\"><\/span>domain\/selector\/key file triple, and the socket. For the socket, the easiest <span id=\"line-40\" class=\"anchor\"><\/span>option is to use a TCP socket listening on a local port (bypassing socket file ownership or chroot access issues). <span id=\"line-41\" class=\"anchor\"><\/span><span id=\"line-42\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-2\" class=\"anchor\"><\/span>Domain   yourdomain.org\r\n<span id=\"line-2\" class=\"anchor\"><\/span>Selector 2021\r\n<span id=\"line-3\" class=\"anchor\"><\/span>KeyFile  \/etc\/dkimkeys\/2021.private\r\n<span id=\"line-4\" class=\"anchor\"><\/span>\r\n<span id=\"line-5\" class=\"anchor\"><\/span>Socket   inet:8891@localhost<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">That\u2019s it for opendkim. Restart the service with <span id=\"line-51\" class=\"anchor\"><\/span><tt>sudo&nbsp;systemctl&nbsp;restart&nbsp;opendkim<\/tt>. <span id=\"line-52\" class=\"anchor\"><\/span><span id=\"line-53\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">The final step is integrating the opendkim service with Postfix. Edit <span id=\"line-54\" class=\"anchor\"><\/span>\/etc\/postfix\/main.cf to connect the two: <span id=\"line-55\" class=\"anchor\"><\/span><span id=\"line-56\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-3\" class=\"anchor\"><\/span>smtpd_milters = inet:localhost:8891\r\n<span id=\"line-2-1\" class=\"anchor\"><\/span>non_smtpd_milters = $smtpd_milters<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">And finally reload the Postfix configuration with <span id=\"line-62\" class=\"anchor\"><\/span><tt>sudo&nbsp;systemctl&nbsp;reload&nbsp;postfix<\/tt>. <span id=\"line-63\" class=\"anchor\"><\/span><span id=\"line-64\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Done! Your mail is now being signed and verified. Don\u2019t forget to publish your <span id=\"line-65\" class=\"anchor\"><\/span>public key as a TXT record in DNS at <tt>2021._domainkey.yourdomain.org<\/tt>. The <span id=\"line-66\" class=\"anchor\"><\/span>generated file \/etc\/dkimkeys\/2021.txt contains that record for your convenience. <span id=\"line-67\" class=\"anchor\"><\/span><span id=\"line-68\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h1 id=\"Configuration\" style=\"text-align: justify;\">Configuration<\/h1>\n<p class=\"line874\" style=\"text-align: justify;\">The following sections discuss opendkim configuration options in more detail. <span id=\"line-71\" class=\"anchor\"><\/span>See the manual page <a class=\"https\" href=\"https:\/\/manpages.debian.org\/man\/opendkim.conf.5\">opendkim.conf(5)<\/a> <span id=\"line-72\" class=\"anchor\"><\/span>for reference. <span id=\"line-73\" class=\"anchor\"><\/span><span id=\"line-74\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<div class=\"note\" style=\"text-align: justify;\"><span id=\"line-1-1\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">The opendkim <strong>configuration file<\/strong> can be found at <tt class=\"backtick\">\/etc\/opendkim.conf<\/tt> . As of Debian 9 &#8220;stretch&#8221; all configuration parameters should be set in this file. <span id=\"line-2-1\" class=\"anchor\"><\/span><span id=\"line-3-1\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">This needs to be stated, because there is a lot of older, now misleading <span id=\"line-4-1\" class=\"anchor\"><\/span>information on this online. Previously (<a class=\"interwiki closed-bug\" title=\"Closed in opendkim\/2.11.0~alpha-11, opendkim\/2.11.0~alpha-10+deb9u1: #864162: opendkim: systemd ExecStart ignore configuration options\" href=\"https:\/\/bugs.debian.org\/cgi-bin\/bugreport.cgi?bug=864162\">#864162<\/a>), one would edit the default settings at <span id=\"line-5-1\" class=\"anchor\"><\/span><em>\/etc\/default\/opendkim<\/em>, and then execute <span id=\"line-6-1\" class=\"anchor\"><\/span>\/lib\/opendkim\/opendkim.service.generate to generate systemd override files at <span id=\"line-7-1\" class=\"anchor\"><\/span>\/etc\/systemd\/system\/opendkim.service.d\/override.conf and <span id=\"line-8-1\" class=\"anchor\"><\/span>\/etc\/tmpfiles.d\/opendkim.conf. While this is still possible, it is now <span id=\"line-9-1\" class=\"anchor\"><\/span>recommended to adjust the settings directly in \/etc\/opendkim.conf.<\/p>\n<\/div>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"Installation_details\" style=\"text-align: justify;\">Installation details<\/h2>\n<p class=\"line862\" style=\"text-align: justify;\">The opendkim and opendkim-tools packages should already be installed. See <a href=\"https:\/\/wiki.debian.org\/opendkim#Quickstart\">#Quickstart<\/a> for basic steps. <span id=\"line-89\" class=\"anchor\"><\/span><span id=\"line-90\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">The standard directory for DKIM keys on Debian 9 &#8220;stretch&#8221; and later releases, is \/etc\/dkimkeys.<br \/>\n<span id=\"line-91\" class=\"anchor\"><\/span>On Debian 8 &#8220;jessie&#8221; that directory must be created. This directory contains private encryption keys, and should thus be owned and set to only be accessible by user <em>opendkim<\/em>. <span id=\"line-92\" class=\"anchor\"><\/span><span id=\"line-93\" class=\"anchor\"><\/span><span id=\"line-94\" class=\"anchor\"><\/span><span id=\"line-95\" class=\"anchor\"><\/span><span id=\"line-96\" class=\"anchor\"><\/span><span id=\"line-97\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-4\" class=\"anchor\"><\/span># only for Debian 8 \"jessie\"\r\n<span id=\"line-2-2\" class=\"anchor\"><\/span>mkdir \/etc\/dkimkeys\/\r\n<span id=\"line-3-1\" class=\"anchor\"><\/span>chown opendkim:opendkim \/etc\/dkimkeys\r\n<span id=\"line-4-1\" class=\"anchor\"><\/span>chmod 0700 \/etc\/dkimkeys<\/pre>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"Generating_keys\" style=\"text-align: justify;\">Generating keys<\/h2>\n<p class=\"line874\" style=\"text-align: justify;\">For key generation, the opendkim-tools package provides the <span id=\"line-105\" class=\"anchor\"><\/span><strong>opendkim-genkey<\/strong> program. This program generates a private key named <span id=\"line-106\" class=\"anchor\"><\/span><tt>&lt;selector&gt;.private<\/tt> in the specified directory, as well as a public key <tt>&lt;selector&gt;.txt<\/tt> ready to be included in a bind DNS zone file. An example invocation: <span id=\"line-107\" class=\"anchor\"><\/span><span id=\"line-108\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-5\" class=\"anchor\"><\/span>sudo --user opendkim opendkim-genkey \\\r\n<span id=\"line-2-3\" class=\"anchor\"><\/span>    --directory=\/etc\/dkimkeys \\\r\n<span id=\"line-3-2\" class=\"anchor\"><\/span>    --domain=yourdomain.org \\\r\n<span id=\"line-4-2\" class=\"anchor\"><\/span>    --selector=2021 \\\r\n<span id=\"line-5-1\" class=\"anchor\"><\/span>    --nosubdomains<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">You will want to tweak some of these options. For example, you might not want <span id=\"line-117\" class=\"anchor\"><\/span>to forbid subdomain signing with <tt>--nosubdomains<\/tt>, or you might want to <span id=\"line-118\" class=\"anchor\"><\/span>restrict usage to email with <tt>--restrict<\/tt>. In Debian, the cryptographic <span id=\"line-119\" class=\"anchor\"><\/span>options use reasonably strong defaults, so it is usually not necessary to <span id=\"line-120\" class=\"anchor\"><\/span>specify <tt>--bits<\/tt> (default: 2048) and <tt>--hash-algorithms<\/tt> (default: <span id=\"line-121\" class=\"anchor\"><\/span>SHA-256). <span id=\"line-122\" class=\"anchor\"><\/span><span id=\"line-123\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">The <em>selector<\/em> allows for removing old keys from a domain and creating new ones. One common practice is to use the creation year as the selector.<br \/>\n<span id=\"line-124\" class=\"anchor\"><\/span>It&#8217;s also possible to have multiple keys for a domain, if there are multiple servers sending mail on behalf of a domain then each can have a unique key. Note that one can also have an unlimited number of domains with the same key. <span id=\"line-125\" class=\"anchor\"><\/span><span id=\"line-126\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">In Debian, the directory <strong>\/etc\/dkimkeys<\/strong> serves as the canonical key storage <span id=\"line-127\" class=\"anchor\"><\/span>location, and is created by the opendkim package on installation. The owner is <span id=\"line-128\" class=\"anchor\"><\/span>set to opendkim by default, and access is restricted to the user, so private keys remain safe. <span id=\"line-129\" class=\"anchor\"><\/span><span id=\"line-130\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Notice how we execute opendkim-genkey as user opendkim. That way, <span id=\"line-131\" class=\"anchor\"><\/span>opendkim-genkey produces key files with the correct, restricted permissions, <span id=\"line-132\" class=\"anchor\"><\/span>owned by opendkim. <span id=\"line-133\" class=\"anchor\"><\/span><span id=\"line-134\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">It is also possible to restrict key ownership further to user root by invoking <span id=\"line-135\" class=\"anchor\"><\/span>opendkim-genkey directly as root: <span id=\"line-136\" class=\"anchor\"><\/span><span id=\"line-137\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-6\" class=\"anchor\"><\/span>sudo opendkim-genkey ...<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">However, while this does work, opendkim will not be able to <em>reload<\/em> keys <span id=\"line-142\" class=\"anchor\"><\/span>during operation: during startup, the key file may be read into memory as root, <span id=\"line-143\" class=\"anchor\"><\/span>but subsequently, after root privileges are dropped, the keys will be accessed <span id=\"line-144\" class=\"anchor\"><\/span>as user opendkim. This is discussed in the following section. <span id=\"line-145\" class=\"anchor\"><\/span><span id=\"line-146\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"User_and_privileges\" style=\"text-align: justify;\">User and privileges<\/h2>\n<p class=\"line874\" style=\"text-align: justify;\">By default, the opendkim service runs as user opendkim. This is because the <span id=\"line-149\" class=\"anchor\"><\/span>default configuration contains a setting for parameter <tt>UserID<\/tt> in <span id=\"line-150\" class=\"anchor\"><\/span>\/etc\/opendkim.conf: <span id=\"line-151\" class=\"anchor\"><\/span><span id=\"line-152\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-7\" class=\"anchor\"><\/span>UserID opendkim<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">This setting instructs opendkim to <em>become<\/em> user opendkim. So, more <span id=\"line-157\" class=\"anchor\"><\/span>accurately, what happens is that the opendkim service is started <em>as root<\/em>, does <span id=\"line-158\" class=\"anchor\"><\/span>everything it needs to do as root \u2013 such as reading private keys and writing the <span id=\"line-159\" class=\"anchor\"><\/span>pid file \u2013, and then, before beginning normal operation, it drops the root <span id=\"line-160\" class=\"anchor\"><\/span>privileges and becomes user opendkim. This is a standard, secure procedure that <span id=\"line-161\" class=\"anchor\"><\/span>should be appropriate for most users. <span id=\"line-162\" class=\"anchor\"><\/span><span id=\"line-163\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">An alternative setup is possible where the opendkim service runs as an <span id=\"line-164\" class=\"anchor\"><\/span>unprivileged user from the very start, and this is described in the following <span id=\"line-165\" class=\"anchor\"><\/span>section. <span id=\"line-166\" class=\"anchor\"><\/span><span id=\"line-167\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h3 id=\"Running_as_an_unprivileged_user\" style=\"text-align: justify;\">Running as an unprivileged user<\/h3>\n<p class=\"line874\" style=\"text-align: justify;\">For setups that have additional security requirements, it is possible to run the <span id=\"line-170\" class=\"anchor\"><\/span>opendkim service as user opendkim from the very beginning, with no root <span id=\"line-171\" class=\"anchor\"><\/span>privileges involved at any stage. Please note that most users do not need this. <span id=\"line-172\" class=\"anchor\"><\/span><span id=\"line-173\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Create a systemd override file at <span id=\"line-174\" class=\"anchor\"><\/span>\/etc\/systemd\/system\/opendkim.service.d\/override.conf (you may need to create the <span id=\"line-175\" class=\"anchor\"><\/span>directory too), with the following contents: <span id=\"line-176\" class=\"anchor\"><\/span><span id=\"line-177\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-8\" class=\"anchor\"><\/span>[Service]\r\n<span id=\"line-2-4\" class=\"anchor\"><\/span>User=opendkim\r\n<span id=\"line-3-3\" class=\"anchor\"><\/span>Group=opendkim<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">The <tt>UserID&nbsp;opendkim<\/tt> setting in \/etc\/opendkim.conf can now be removed, as <span id=\"line-184\" class=\"anchor\"><\/span>no privilege dropping is necessary. Reload the systemd configuration with <span id=\"line-185\" class=\"anchor\"><\/span><tt>sudo&nbsp;systemctl&nbsp;daemon-reload<\/tt>, and restart the opendkim service. It now <span id=\"line-186\" class=\"anchor\"><\/span>runs as an unprivileged user. <span id=\"line-187\" class=\"anchor\"><\/span><span id=\"line-188\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Make sure that the unprivileged user can actually read the keys in <span id=\"line-189\" class=\"anchor\"><\/span>\/etc\/dkimkeys (see above), and write the pid file. (Since both \/etc\/dkimkeys and the runtime <span id=\"line-190\" class=\"anchor\"><\/span>directory \/run\/opendkim come owned by user\/group opendkim, this should work <span id=\"line-191\" class=\"anchor\"><\/span>without further adjustment.) <span id=\"line-192\" class=\"anchor\"><\/span><span id=\"line-193\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"Key_selection\" style=\"text-align: justify;\">Key selection<\/h2>\n<p class=\"line874\" style=\"text-align: justify;\">For a single-domain DKIM setup with only a single key, the configuration shown <span id=\"line-196\" class=\"anchor\"><\/span>in <a href=\"https:\/\/wiki.debian.org\/opendkim#Quickstart\">#Quickstart<\/a>, using the three parameters <tt>Domain<\/tt>, <tt>Selector<\/tt>, <span id=\"line-197\" class=\"anchor\"><\/span><tt>KeyFile<\/tt> is enough. However, opendkim configuration supports multiple <span id=\"line-198\" class=\"anchor\"><\/span>domains and keys, read from a variety of sources (files, SQL databases, Lua <span id=\"line-199\" class=\"anchor\"><\/span>scripts, \u2026). <strong><tt>KeyTable<\/tt><\/strong> and <strong><tt>SigningTable<\/tt><\/strong> are the <span id=\"line-200\" class=\"anchor\"><\/span>configuration parameters that enable this. For mail servers that are &#8220;smarthosts&#8221;, opendkim can be configured to sign messages from subnets of trusted systems via the <strong><tt>InternalHosts<\/tt><\/strong> parameter. <span id=\"line-201\" class=\"anchor\"><\/span><span id=\"line-202\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Setup the \/etc\/opendkim.conf: <span id=\"line-203\" class=\"anchor\"><\/span><span id=\"line-204\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-9\" class=\"anchor\"><\/span># Specify the list of keys\r\n<span id=\"line-2-5\" class=\"anchor\"><\/span>KeyTable file:\/etc\/dkimkeys\/keytable\r\n<span id=\"line-3-4\" class=\"anchor\"><\/span># Match keys and domains. To use regular expressions in the file, use refile: instead of file:\r\n<span id=\"line-4-3\" class=\"anchor\"><\/span>SigningTable refile:\/etc\/dkimkeys\/signingtable \r\n<span id=\"line-5-2\" class=\"anchor\"><\/span># Match a list of hosts whose messages will be signed. By default, only localhost is considered as internal host.\r\n<span id=\"line-6\" class=\"anchor\"><\/span>InternalHosts refile:\/etc\/dkimkeys\/trustedhosts<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">Now in the file \/etc\/dkimkeys\/keytable, put information about the private key: <span id=\"line-214\" class=\"anchor\"><\/span><span id=\"line-215\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-10\" class=\"anchor\"><\/span>mail._domainkey.yourdomain.org yourdomain.org:mail:\/etc\/dkimkeys\/mail.private<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">In the file \/etc\/dkimkeys\/signingtable, specify which key will sign a domain: <span id=\"line-218\" class=\"anchor\"><\/span><span id=\"line-219\" class=\"anchor\"><\/span><span id=\"line-220\" class=\"anchor\"><\/span><span id=\"line-221\" class=\"anchor\"><\/span><span id=\"line-222\" class=\"anchor\"><\/span><span id=\"line-223\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-11\" class=\"anchor\"><\/span># Domain yourdomain.org\r\n<span id=\"line-2-6\" class=\"anchor\"><\/span>*@yourdomain.org mail._domainkey.yourdomain.org\r\n<span id=\"line-3-5\" class=\"anchor\"><\/span># You can specify multiple domains\r\n<span id=\"line-4-4\" class=\"anchor\"><\/span># Example.net www._domainkey.example.net<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">In the file \/etc\/dkimkeys\/trustedhosts, specify which hosts will have messages signed. If needed, include localhost as it is not implicit: <span id=\"line-226\" class=\"anchor\"><\/span><span id=\"line-227\" class=\"anchor\"><\/span><span id=\"line-228\" class=\"anchor\"><\/span><span id=\"line-229\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-12\" class=\"anchor\"><\/span>127.0.0.1\r\n<span id=\"line-2-7\" class=\"anchor\"><\/span>10.1.0.0\/16\r\n<span id=\"line-3-6\" class=\"anchor\"><\/span>1.2.3.4\/24<\/pre>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"Important_OpenDKIM_options\" style=\"text-align: justify;\">Important OpenDKIM options<\/h2>\n<p class=\"line862\" style=\"text-align: justify;\">The <strong><tt>Canonicalization<\/tt><\/strong> configuration parameter changes the signing options which can allow messages to be verified after being munged a bit by list servers etc. The &#8220;relaxed\/simple&#8221; option specifies that headers can be munged a bit without breaking a message validation. The &#8220;relaxed&#8221; checks on headers MIGHT allow messages that have been through a Mailman list server to be validated, it&#8217;s almost certain that they won&#8217;t be validated if relaxed isn&#8217;t used. <span id=\"line-236\" class=\"anchor\"><\/span><span id=\"line-237\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">The default is to accept mail with bad signatures. If you want to reject such mail, use the <strong><tt>On-BadSignature<\/tt><\/strong> parameter. <span id=\"line-238\" class=\"anchor\"><\/span><span id=\"line-239\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">The <strong><tt>BodyLengthDB<\/tt><\/strong> parameter specifies a dataset that controls which messages are signed with the <tt class=\"backtick\">l=<\/tt> option to specify the length. When <tt class=\"backtick\">l=<\/tt> is used a hostile party could append data to the end of the message without breaking a signature, but it also means that a list server can add a footer to the message without breaking it. Unless you are running a list server (which should not be sending to other list servers) or other automated system you generally want <tt class=\"backtick\">l=<\/tt> on all mail. If the bodylengthdb.cfg has the contents &#8220;.*&#8221; it will cause every message to have the <tt class=\"backtick\">l=<\/tt> option. <span id=\"line-240\" class=\"anchor\"><\/span><span id=\"line-241\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-13\" class=\"anchor\"><\/span>Canonicalization    relaxed\/simple\r\n<span id=\"line-2-8\" class=\"anchor\"><\/span>On-BadSignature     reject\r\n<span id=\"line-3-7\" class=\"anchor\"><\/span>BodyLengthDB        refile:\/etc\/mail\/bodylengthdb.cfg<\/pre>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"Socket\" style=\"text-align: justify;\">Socket<\/h2>\n<p class=\"line874\" style=\"text-align: justify;\">The opendkim service has to provide a communication channel for the MTA <span id=\"line-251\" class=\"anchor\"><\/span>(Postfix). A TCP socket listening on a port only accessible locally is a <span id=\"line-252\" class=\"anchor\"><\/span>reasonable choice that is also easy to set up. <span id=\"line-253\" class=\"anchor\"><\/span><span id=\"line-254\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-14\" class=\"anchor\"><\/span>Socket inet:8891@localhost<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">Sockets can be of IPv4 or IPv6 type, and can listen on all interfaces or on a <span id=\"line-259\" class=\"anchor\"><\/span>specific interface only. <span id=\"line-260\" class=\"anchor\"><\/span><span id=\"line-261\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Some prefer setting up a UNIX domain socket instead, as a faster and more secure <span id=\"line-262\" class=\"anchor\"><\/span>channel (though opinion on this point varies). This requires a little more <span id=\"line-263\" class=\"anchor\"><\/span>configuration work, and is described in the following section. <span id=\"line-264\" class=\"anchor\"><\/span><span id=\"line-265\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h3 id=\"Using_a_UNIX_domain_socket\" style=\"text-align: justify;\">Using a UNIX domain socket<\/h3>\n<p class=\"line874\" style=\"text-align: justify;\">The UNIX domain socket file must be accessible to the MTA. In Debian, Postfix <span id=\"line-268\" class=\"anchor\"><\/span>runs in a chroot jail in \/var\/spool\/postfix by default, so the socket must be <span id=\"line-269\" class=\"anchor\"><\/span>below that path. <span id=\"line-270\" class=\"anchor\"><\/span><span id=\"line-271\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Postfix does not prescribe a standard location for UNIX sockets in its chroot. <span id=\"line-272\" class=\"anchor\"><\/span>You can mimic the \/run directory hierarchy, and place the socket below <span id=\"line-273\" class=\"anchor\"><\/span>\/var\/spool\/postfix\/run\/opendkim, or you can simply claim a top-level directory <span id=\"line-274\" class=\"anchor\"><\/span>like \/var\/spool\/postfix\/opendkim. Here we go with the latter. <span id=\"line-275\" class=\"anchor\"><\/span><span id=\"line-276\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">First, create the directory, owned by opendkim and world-inaccessible: <span id=\"line-277\" class=\"anchor\"><\/span><span id=\"line-278\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-15\" class=\"anchor\"><\/span>sudo mkdir -m o-rwx \/var\/spool\/postfix\/opendkim\r\n<span id=\"line-2-9\" class=\"anchor\"><\/span>sudo chown opendkim: \/var\/spool\/postfix\/opendkim<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">Then, configure the socket in \/etc\/opendkim.conf: <span id=\"line-284\" class=\"anchor\"><\/span><span id=\"line-285\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-16\" class=\"anchor\"><\/span>Socket local:\/var\/spool\/postfix\/opendkim\/opendkim.sock<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">Next, add user postfix to group opendkim. Postfix then relies on the group <span id=\"line-290\" class=\"anchor\"><\/span>permissions to actually access the socket: <span id=\"line-291\" class=\"anchor\"><\/span><span id=\"line-292\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-17\" class=\"anchor\"><\/span>sudo adduser postfix opendkim<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">Finally, adjust the Postfix configuration in \/etc\/postfix\/main.cf to use the <span id=\"line-297\" class=\"anchor\"><\/span>desired socket path: <span id=\"line-298\" class=\"anchor\"><\/span><span id=\"line-299\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-18\" class=\"anchor\"><\/span>smtpd_milters = unix:opendkim\/opendkim.sock\r\n<span id=\"line-2-10\" class=\"anchor\"><\/span>non_smtpd_milters = $smtpd_milters<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">Note that when Postfix runs chrooted (the default in Debian), an absolute pathname <span id=\"line-305\" class=\"anchor\"><\/span>here is interpreted relative to the Postfix queue directory \/var\/spool\/postfix. <span id=\"line-306\" class=\"anchor\"><\/span><span id=\"line-307\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Don\u2019t forget to restart opendkim and postfix to apply the settings. <span id=\"line-308\" class=\"anchor\"><\/span><span id=\"line-309\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"DNS_resolution\" style=\"text-align: justify;\">DNS resolution<\/h2>\n<p class=\"line862\" style=\"text-align: justify;\">In Debian, opendkim is compiled with <strong>libunbound<\/strong>, a DNSSEC-capable <span id=\"line-312\" class=\"anchor\"><\/span>asynchronous resolver library. It is important to be aware of this, because it <span id=\"line-313\" class=\"anchor\"><\/span>means opendkim does DNS queries for DKIM keys independently, that is, it does <span id=\"line-314\" class=\"anchor\"><\/span>not go through any local resolver and does not take into account configuration <span id=\"line-315\" class=\"anchor\"><\/span>at \/etc\/resolv.conf. <span id=\"line-316\" class=\"anchor\"><\/span><span id=\"line-317\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">The default opendkim configuration ships with a valid trust anchor setting, <span id=\"line-318\" class=\"anchor\"><\/span><tt>TrustAnchorFile&nbsp;\/usr\/share\/dns\/root.key<\/tt>, thus letting opendkim do DNSSEC <span id=\"line-319\" class=\"anchor\"><\/span>queries out-of-the-box. <span id=\"line-320\" class=\"anchor\"><\/span><span id=\"line-321\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Advanced users should be aware of two additional configuration parameters. <span id=\"line-322\" class=\"anchor\"><\/span><span id=\"line-323\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">The <strong><tt>Nameservers<\/tt><\/strong> parameter can be used to override the name servers <span id=\"line-324\" class=\"anchor\"><\/span>that libunbound uses. For example, you may already have an Unbound resolver <span id=\"line-325\" class=\"anchor\"><\/span>running locally (a relatively typical setup in a mail server). In that case, a <span id=\"line-326\" class=\"anchor\"><\/span>setting like the following instructs opendkim to send DNS queries through that <span id=\"line-327\" class=\"anchor\"><\/span>resolver: <span id=\"line-328\" class=\"anchor\"><\/span><span id=\"line-329\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-19\" class=\"anchor\"><\/span>Nameservers 127.0.0.1<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">The <strong><tt>ResolverConfiguration<\/tt><\/strong> parameter can be used to pass an Unbound <span id=\"line-334\" class=\"anchor\"><\/span>configuration file <span id=\"line-335\" class=\"anchor\"><\/span>(<a class=\"https\" href=\"https:\/\/nlnetlabs.nl\/documentation\/unbound\/unbound.conf\/\">unbound.conf(5)<\/a>) <span id=\"line-336\" class=\"anchor\"><\/span>to libunbound. Using this, more sophisticated customization regarding DNS <span id=\"line-337\" class=\"anchor\"><\/span>resolution in opendkim is possible. <span id=\"line-338\" class=\"anchor\"><\/span><span id=\"line-339\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-20\" class=\"anchor\"><\/span>ResolverConfiguration \/etc\/opendkim\/unbound.conf<\/pre>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<div class=\"warning\" style=\"text-align: justify;\"><span id=\"line-1-2\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">The Debian unbound package installs a default configuration file at <span id=\"line-2-2\" class=\"anchor\"><\/span><strong>\/etc\/unbound\/unbound.conf<\/strong>. Do not attempt to use this file unchanged with <span id=\"line-3-2\" class=\"anchor\"><\/span><tt>ResolverConfiguration<\/tt>! opendkim will just quietly shut down. <span id=\"line-4-2\" class=\"anchor\"><\/span><span id=\"line-5-2\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">The reason for the incompatibility is that the shipped unbound.conf includes an <span id=\"line-6-2\" class=\"anchor\"><\/span><tt>auto-trust-anchor-file<\/tt> setting, for which opendkim does not have the <span id=\"line-7-2\" class=\"anchor\"><\/span>necessary permissions. Unfortunately, libunbound is rather fragile in this area. <span id=\"line-8-2\" class=\"anchor\"><\/span>Prepare your own unbound.conf for opendkim and test carefully.<\/p>\n<\/div>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"Postfix_integration\" style=\"text-align: justify;\">Postfix integration<\/h2>\n<p class=\"line862\" style=\"text-align: justify;\">The opendkim service functions as a <em>milter<\/em>, that is, a plugin software <span id=\"line-357\" class=\"anchor\"><\/span>hooked into the SMTP processing of the Postfix MTA. To enable a milter, it is <span id=\"line-358\" class=\"anchor\"><\/span>enough to tell Postfix on which socket the milter application is listening. <span id=\"line-359\" class=\"anchor\"><\/span>Example \/etc\/postfix\/main.cf: <span id=\"line-360\" class=\"anchor\"><\/span><span id=\"line-361\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-21\" class=\"anchor\"><\/span>smtpd_milters = inet:localhost:8891\r\n<span id=\"line-2-11\" class=\"anchor\"><\/span>non_smtpd_milters = $smtpd_milters<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">With opendkim, two additional milter configuration parameters in <span id=\"line-367\" class=\"anchor\"><\/span>\/etc\/postfix\/main.cf are useful. <span id=\"line-368\" class=\"anchor\"><\/span><span id=\"line-369\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">The <strong><tt>milter_default_action<\/tt><\/strong> parameter determines what to do when a <span id=\"line-370\" class=\"anchor\"><\/span>milter fails, for example, when it does not respond after a crash. In order to <span id=\"line-371\" class=\"anchor\"><\/span>avoid losing mail, it is best to set this to <tt>accept<\/tt>: <span id=\"line-372\" class=\"anchor\"><\/span><span id=\"line-373\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-22\" class=\"anchor\"><\/span>milter_default_action = accept<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">Postfix does not pass internally-generated messages such as bounce messages to <span id=\"line-378\" class=\"anchor\"><\/span>opendkim, so by default bounces are not DKIM-signed. This can be a problem if <span id=\"line-379\" class=\"anchor\"><\/span>you also use a strict DMARC policy, because it may cause your unsigned bounce <span id=\"line-380\" class=\"anchor\"><\/span>messages themselves to get rejected. The <span id=\"line-381\" class=\"anchor\"><\/span><strong><tt>internal_mail_filter_classes<\/tt><\/strong> parameter can be used to pass bounces <span id=\"line-382\" class=\"anchor\"><\/span>through the milters as well: <span id=\"line-383\" class=\"anchor\"><\/span><span id=\"line-384\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-23\" class=\"anchor\"><\/span>internal_mail_filter_classes = bounce<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">Further details of milter usage in Postfix can be found in its <span id=\"line-389\" class=\"anchor\"><\/span><a class=\"http\" href=\"http:\/\/www.postfix.org\/MILTER_README.html\">MILTER_README<\/a>. <span id=\"line-390\" class=\"anchor\"><\/span><span id=\"line-391\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h1 id=\"Troubleshooting\" style=\"text-align: justify;\">Troubleshooting<\/h1>\n<p class=\"line862\" style=\"text-align: justify;\">Try to send a mail. If you see in \/var\/log\/mail.log something like <span id=\"line-394\" class=\"anchor\"><\/span><span id=\"line-395\" class=\"anchor\"><\/span><span id=\"line-396\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-24\" class=\"anchor\"><\/span>Aug 13 13:18:00 yourhostname opendkim[15765]: OpenDKIM Filter: Unable to bind to port local:\/var\/spool\/postfix\/opendkim\/opendkim.sock: No such file or directory\r\n<span id=\"line-2-12\" class=\"anchor\"><\/span>Aug 13 13:18:00 yourhostname opendkim[15765]: OpenDKIM Filter: Unable to create listening socket on conn local:\/var\/spool\/postfix\/opendkim\/opendkim.sock<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">then that probably means that you did not create the directory for the socket (see above) or you gave it the wrong permissions. Double-check! <span id=\"line-398\" class=\"anchor\"><\/span><span id=\"line-399\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">If you see <span id=\"line-400\" class=\"anchor\"><\/span><span id=\"line-401\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-25\" class=\"anchor\"><\/span>Aug 13 13:46:19 yourhostname postfix\/cleanup[17588]: warning: connect to Milter service unix:\/opendkim\/opendkim.sock: No such file or directory<\/pre>\n<p class=\"line874\" style=\"text-align: justify;\">then that means postfix could not read the socket. Did you put postfix in group opendkim? Are the permissions on \/var\/spool\/postfix\/opendkim\/opendkim.sock correct? <span id=\"line-403\" class=\"anchor\"><\/span><span id=\"line-404\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">If everything is correct, that does not mean your configuration of DKIM is complete: you must configure the DNS. <span id=\"line-405\" class=\"anchor\"><\/span><span id=\"line-406\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h1 id=\"DNS_Configuration\" style=\"text-align: justify;\">DNS Configuration<\/h1>\n<p class=\"line862\" style=\"text-align: justify;\">Add a <tt class=\"backtick\">_domainkey<\/tt> TXT record for yourdomain.org and <em>selector<\/em> (e.g. 2021). <span id=\"line-409\" class=\"anchor\"><\/span><span id=\"line-410\" class=\"anchor\"><\/span><\/p>\n<div style=\"text-align: justify;\">\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong>Record Name<\/strong><\/p>\n<\/td>\n<td>\n<p class=\"line891\"><strong>Record Type<\/strong><\/p>\n<\/td>\n<td>\n<p class=\"line891\"><strong>Text<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><span id=\"line-411\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">2021._domainkey<\/p>\n<\/td>\n<td>\n<p class=\"line862\">TXT<\/p>\n<\/td>\n<td>\n<p class=\"line862\">v=DKIM1; k=rsa; p=MI.. (take it from \/etc\/dkimkeys\/2021.txt file; remove the &gt;&#8221;&lt; and connect the lines after p= to one key.)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line862\" style=\"text-align: justify;\">BIND Configuration : The public key file \/etc\/dkimkeys\/2021.txt created by <tt class=\"backtick\">opendkim-genkey<\/tt> is in a format ready to be included in a DNS bind9 zone data file. It can be copied to a bind9 server, and pasted into a zone file, or the <a class=\"https\" href=\"https:\/\/bind9.readthedocs.io\/en\/latest\/reference.html#the-include-directive\">$INCLUDE<\/a> statement may be used. <span id=\"line-415\" class=\"anchor\"><\/span><\/p>\n<ul style=\"text-align: justify;\">\n<li><span id=\"line-416\" class=\"anchor\"><\/span><span id=\"line-417\" class=\"anchor\"><\/span>\n<pre><span id=\"line-1-26\" class=\"anchor\"><\/span>$INCLUDE \/etc\/dkimkeys\/2021.txt<\/pre>\n<p><span id=\"line-418\" class=\"anchor\"><\/span><span id=\"line-419\" class=\"anchor\"><\/span><span id=\"line-420\" class=\"anchor\"><\/span><span id=\"line-421\" class=\"anchor\"><\/span><span id=\"line-422\" class=\"anchor\"><\/span><span id=\"line-423\" class=\"anchor\"><\/span><\/li>\n<\/ul>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h1 id=\"Testing\" style=\"text-align: justify;\">Testing<\/h1>\n<p class=\"line874\" style=\"text-align: justify;\">There are several checks one can perform to validate an OpenDKIM installation. <span id=\"line-425\" class=\"anchor\"><\/span><span id=\"line-426\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"opendkim-testkey\" style=\"text-align: justify;\">opendkim-testkey<\/h2>\n<p class=\"line862\" style=\"text-align: justify;\">The command <tt class=\"backtick\">opendkim-testkey<\/tt> will read the configuration of the opendkim daemon and do DNS checks to determine if the configuration is likely to work. It can take multiple &#8220;-v&#8221; options for verbosity. A specific domain to check can be specified with optional &#8220;-d&#8221; option. <span id=\"line-429\" class=\"anchor\"><\/span><span id=\"line-430\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-27\" class=\"anchor\"><\/span># opendkim-testkey -v -v\r\n<span id=\"line-2-13\" class=\"anchor\"><\/span>opendkim-testkey: using default configfile \/etc\/opendkim.conf\r\n<span id=\"line-3-8\" class=\"anchor\"><\/span>opendkim-testkey: key loaded from \/etc\/dkimkeys\/2021.private\r\n<span id=\"line-4-5\" class=\"anchor\"><\/span>opendkim-testkey: checking key '2021._domainkey.etbe.yourdomain.org'\r\n<span id=\"line-5-3\" class=\"anchor\"><\/span>opendkim-testkey: key not secure<\/pre>\n<p class=\"line862\" style=\"text-align: justify;\">In the example above &#8220;key not secure&#8221; means that DNSSEC is not in use (someone should add a DNSSEC section to the <a href=\"https:\/\/wiki.debian.org\/Bind9\">Bind9<\/a> page). <span id=\"line-439\" class=\"anchor\"><\/span><span id=\"line-440\" class=\"anchor\"><\/span><span id=\"line-441\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">One issue with opendkim-testkey is that by default it (and the opendkim daemon) will do all its checks against external DNS servers, so it can&#8217;t do anything useful on a test environment like an example.org domain unless you redirect all it&#8217;s queries to a recursive DNS server you control. Here are example iptables commands to do that: <span id=\"line-442\" class=\"anchor\"><\/span><span id=\"line-443\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<pre><span id=\"line-1-28\" class=\"anchor\"><\/span>iptables -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to $RECURSIVE:53\r\n<span id=\"line-2-14\" class=\"anchor\"><\/span>iptables -t nat -A OUTPUT -p tcp --dport 53 -j DNAT --to $RECURSIVE:53<\/pre>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"opendkim-testmsg\" style=\"text-align: justify;\">opendkim-testmsg<\/h2>\n<p class=\"line862\" style=\"text-align: justify;\">The command <tt class=\"backtick\">opendkim-testmsg<\/tt> will sign or verify a message. To verify a message just redirect stdin to the message and it will say something on stderr if it thinks there&#8217;s a problem. If there are no problems it will be silent. <span id=\"line-451\" class=\"anchor\"><\/span><span id=\"line-452\" class=\"anchor\"><\/span><span id=\"line-453\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h2 id=\"email_tests\" style=\"text-align: justify;\">email tests<\/h2>\n<p class=\"line862\" style=\"text-align: justify;\">In addition to the local testing commands listed above, a public DKIM configuration can be tested by sending an empty email to <tt class=\"backtick\">check-auth@verifier.port25.com<\/tt> . An automated reply should be received within a few minutes. <span id=\"line-456\" class=\"anchor\"><\/span><span id=\"line-457\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">Another option may be <a class=\"https\" href=\"https:\/\/www.mail-tester.com\/\">https:\/\/www.mail-tester.com\/<\/a> . Visit the website, email the test address, and click the website link to get feedback on junk email and DKIM ratings. <span id=\"line-458\" class=\"anchor\"><\/span><span id=\"line-459\" class=\"anchor\"><\/span><span id=\"line-460\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h1 id=\"Mailman_and_DKIM_Configuration\" style=\"text-align: justify;\">Mailman and DKIM Configuration<\/h1>\n<p class=\"line862\" style=\"text-align: justify;\">Mailman tends to break DKIM signatures. It doesn&#8217;t pass headers through, it parses them into an internal format and regenerates them so is almost guaranteed to break messages that don&#8217;t have signatures with &#8220;relaxed&#8221; or &#8220;relaxed\/simple&#8221; <a href=\"https:\/\/wiki.debian.org\/opendkim#Important_OpenDKIM_options\">canonicalization<\/a>. It can also rewrite the body into a different MIME encoding. <span id=\"line-463\" class=\"anchor\"><\/span><span id=\"line-464\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Edit &#8220;\/etc\/mailman\/mm_cfg.py&#8221; to have the directive &#8220;REMOVE_DKIM_HEADERS = Yes&#8221;. The OpenDKIM instance on the list server should reject mail that is not signed correctly so there is no need for the headers to be forwarded on. Removing the DKIM headers removes the possibility of broken signatures. You must restart Mailman after doing this. <span id=\"line-465\" class=\"anchor\"><\/span><span id=\"line-466\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">Configure the list server to use DKIM on outbound mail. As a general rule list servers don&#8217;t send mail to other list servers so there aren&#8217;t going to be many problems with this. <span id=\"line-467\" class=\"anchor\"><\/span><span id=\"line-468\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">For messages that use DMARC (which uses DNS to tell the recipient that they should be signed) you need to rewrite the header to not have the original sender address. You can set the &#8220;dmarc_moderation_action&#8221; (in the web based configuration for each list) to &#8220;Munge From&#8221; to do this. But this doesn&#8217;t seem to apply to ADSP (the other standard method of using DNS to tell the recipient the signing policy) and also won&#8217;t apply to custom settings (EG a MTA specially configured to insist on signatures from it&#8217;s own domains). <span id=\"line-469\" class=\"anchor\"><\/span><span id=\"line-470\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\" style=\"text-align: justify;\">To properly handle mail from domains using ADSP or other non-DMARC ways of specifying that mail must be signed the solution is to set &#8220;from_is_list&#8221; (in the web based configuration for each list) to &#8220;Rewrite&#8221;. That will munge the From field on all mail to say that it&#8217;s from the list. <span id=\"line-471\" class=\"anchor\"><\/span><span id=\"line-472\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\" style=\"text-align: justify;\">See the <a class=\"https\" href=\"https:\/\/wiki.list.org\/DEV\/DMARC\">Mailman DMARC Wiki page<\/a> for a summary of the DMARC options and the <a class=\"https\" href=\"https:\/\/wiki.list.org\/DEV\/DKIM\">Mailman DKIM Wiki page<\/a> for a lot of background information. <span id=\"line-473\" class=\"anchor\"><\/span><span id=\"line-474\" class=\"anchor\"><\/span><span id=\"line-475\" class=\"anchor\"><\/span><span id=\"line-476\" class=\"anchor\"><\/span><span id=\"line-477\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\" style=\"text-align: justify;\">&nbsp;<\/p>\n<h1 id=\"FAQ\" style=\"text-align: justify;\">FAQ<\/h1>\n<dl>\n<dt>Q. OpenDKIM fails to start after upgrading from Debian 8 &#8220;jessie&#8221; to stretch<\/dt>\n<dd>A) If OpenDKIM fails to start after upgrading from Debian 8 &#8220;jessie&#8221; to stretch it seems that you have to auto-generate the Systemd service file for OpenDKIM. <span id=\"line-480\" class=\"anchor\"><\/span><span id=\"line-481\" class=\"anchor\"><\/span><\/p>\n<ul style=\"text-align: justify;\">\n<li>Run these commands: <span id=\"line-482\" class=\"anchor\"><\/span><\/li>\n<\/ul>\n<p><span id=\"line-483\" class=\"anchor\"><\/span><span id=\"line-484\" class=\"anchor\"><\/span><span id=\"line-485\" class=\"anchor\"><\/span><span id=\"line-486\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-29\" class=\"anchor\"><\/span>\/lib\/opendkim\/opendkim.service.generate\r\n<span id=\"line-2-15\" class=\"anchor\"><\/span>systemctl daemon-reload\r\n<span id=\"line-3-9\" class=\"anchor\"><\/span>service opendkim restart<\/pre>\n<\/dd>\n<\/dl>\n<p style=\"text-align: center;\">[<a href=\"javascript:history.go(-1)\">Voltar<\/a>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Protocolo de autentica\u00e7\u00e3o de e-mails para bloquear SPAMs<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-67268","post","type-post","status-publish","format-standard","hentry","category-informatica"],"_links":{"self":[{"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=\/wp\/v2\/posts\/67268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=67268"}],"version-history":[{"count":1,"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=\/wp\/v2\/posts\/67268\/revisions"}],"predecessor-version":[{"id":67269,"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=\/wp\/v2\/posts\/67268\/revisions\/67269"}],"wp:attachment":[{"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=67268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=67268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/antonini.ddns.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=67268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}