I'm running Ubuntu 12.04 with Postfix and Mailman. I want to set up DKIM. DomainKeys Identified Mail, or DKIM, is the successor to Yahoo's "DomainKeys". It incorporates Cisco's Identified Mail.
What are the steps for setting this up?
Is opendkim recommended?
The only reference I have is HowToForge, but I prefer to get help here (even if it is just a confirmation of the steps at that link). Actually, I think the info at HowToForge is outdated because it mentions dkim-filter instead of opendkim.
openDKIM and Postfix on Ubuntu Server 12.04LTS
I'll try to come back and format this better. But since there was a request to post my answer, I wanted to post it now rather than wait until I had time to format it properly. Due to lack of time, I wrapped my entire answer in a blockquote. I hope this solution is helpful.
These are my references:
man opendkim-testkey
man opendkim.conf
and Wikipedia has a good entry on the subject
At a minimum you will need:
Install opendkim from the repositories:
You must decide on what “selector” you wish to use. The selector is essentially a word to describe the key you wish to use. Here I am going to use the selector 201205 as the key became valid in May 2012 (cunning eh?). I give two examples for variety, which will hopefully add clarity. You only need to generate ONE key. However, I am giving both examples so you can compare them.
My domain will be
example.com
, but I'll use a subdomain for my second example:I decided to work in the following directory:
Generate the keys in the current directory, using your chosen selector and domain.
You may or may not need to change ownership. See details in my example for the 2nd key below for what ownership and permissions should be.
First you should check if there is a
opendkim
user (your user/group IDs may be different):And you probably need to do this:
NOTE: These next two commands are NOT needed on Ubuntu 12.04. But if the command above didn't show that user opendkim was set up properly, do it similarly to this:
Now check the public key and notice that there is a bug (in openDKIM 2.5.2 on Ubuntu 12.04)! Where is contains,
;=rsa;
, it should contain;k=rsa;
. Thek
is missing. Please insert it.After being fixed, it will look like this:
Furthermore, you probably need to escape the semicolons like this. If you don't want the ending comment, just delete it. Also note that you should add the t=y flag to indicate to receiving servers that you are testing DKIM but not actively using it yet. You are left with a viable resource record:
You must publish the content of the above public key to your authoritative DNS server. I recommend using a TXT record. There seems to be a bit of controversy on whether to use an SPF record or both types. After a bit of reading, I elected to stick with the TXT record type exclusively, although I don't believe this is the final word on this topic.
You should use a short TTL (time to live) so that you can change the key without waiting ages for it to propagate though DNS. I used 180 seconds.
The second example of generating a key pair was a bit trickier for me. I'll describe what I did. The first element is that I used the domain value "example.com" even though the key will be used for "mail.example.com". I arrived at this via trial and error. It works, while using "mail.example.com" did not work. Unfortunately, I am not aware of the reasons behind this. This is really the only difference I encountered, but it was troubling enough that I felt I should document my experiences with using subdomains. None of the other beginning level tutorials I found did this. Generate a second key:
check ownership and permissions of the private key, as above. Here's what they should look like:
After publishing the DNS record, check it with
dig
. It should return exactly what you entered in the resource record (RR).Now, test the key. The commands below assume you are in the directory where the key resides (/etc/opendkim for me).
These results are expected. The "key not secure" does not indicate an error. It is an expected consequence of not using DNSSSEC. DNSSEC is coming, but it isn't ready for prime time yet, according to my reading.
Example with 2nd key:
Note that opendkim is reporting that the key is not secure. This relates to the fact that DNSSEC is not implemented on my DNS server and theoretically somebody could intercept the DNS lookup and replace it with their own key.
Edit the OpenDKIM config file:
If you are using my 2nd key example, with the targeted domain “mail.example.com” the entry would still only reference the main domain:
Note from one of my sources: If you run multiple instances of Postfix you need to add this to the opendkim.conf for each instance (or the ones you want to use opendkim)
Create a file with your text editor
/etc/opendkim/TrustedHosts
:Add domains, hostnames and/or ip’s that should be handled by OpenDKIM. Don’t forget localhost.
(the last line above probably won't be needed. If you do have an IP address to add, make sure you use your own, not the example above.)
Edit
/etc/default/opendkim
:Uncomment this row and use port 8891:
Make sure your firewall (iptables) allows loopback on localhost:
Next, Create a file with your text editor
/etc/opendkim/KeyTable
and add the domain to the KeyTableAdd line:
Next Create a file with your text editor
/etc/opendkim/SigningTable
and add the domain to the SigningTableI show both examples. Note that for my 2nd key, I now have to use the full domain name "mail.example.com":
Note that in OpenDKIM 2.0.1 domain names are case sensitive. In this example we're using a newer version of OpenDKIM and this does not appear to be a problem.
Configure postfix. Edit /etc/postfix/main.cf and add the lines to the end
Also change the hostname:
You should also change the corresponding entry in /etc/hosts. These changes are effective after a reboot (although you can set it immediately with the command:
hostname NEW_NAME
).Restart postfix and opendkim if you didn't reboot:
Testing
The best way to check that your signed mail is being authenticated and that your DNS records are properly set up is to use one of the free testing services. I used these:
Send a signed email to: [email protected] (you can put all of the test email addresses in the To: field of a single outgoing message to test)
Send a signed email to: [email protected] <--- BROKEN!!! Don't use this one.
Each of these will tell you if things are working properly, and give you some pointers on troubleshooting if needed.
If you have a Gmail account, you can also send a signed message there for a quick and easy test.
Once you are happy that all is well, you can remove the testing flag in the DNS TXT record and increase TTL.
Done!
This is a good guide.
It explains that opendkim is indeed recommended and that the steps to implement your dkim signing are the same as with dkim-filter.
BTW Domainkeys is the deprecated predecessor of DKIM. Add TXT records to your DNS Zone for SPF and DKIM but it's no longer necessary to bother with Domainkeys.
http://wiki.zimbra.com/wiki/Configuring_for_DKIM_Signing
I always make sure to cross ref a few guides on anything. This tut on set-up works, I just verified it and it validates this one. But, you might want to display an example TXT for the domain record to be detailed. People might get confused and explicitly put everything of the key itself into the p value, which I am not entirely sure is correct. ie...including -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- . That may lead some to be confused. Just make sure to put just the encryption part and not the markers.