If you're reading this you probably know that spammers give all websites a bad name. There are various ways to try and combat this such as spf, reverse dns, and DomainKeys. We'll be focusing on the latter and it's implementation on Postfix 2.3.
DomainKeys uses asymmetrical (public key/private key) encryption to verify the sender of the email is valid. While it is an open standard, as far as we can tell, the only large company to adopt this is it's creator Yahoo!. Expect this to improve delivery rates to only Yahoo! Mail customers.
We will be implementing domain keys as basically a mail filter. Outbound mail will be signed with our private key for verification by other mail servers with our published public key in DNS TXT records.
I will *not* be going over verifying/filtering incoming mail. Only outgoing.
We'll be doing this on a Fedora Core 6 x86_64 machine.
Steps to great success...
- Install Postfix. You'll also need Perl, CPAN, OpenSSL and some luck.
- Upgrade CPAN - this is always good practice
> cpan
> install Bundle::CPAN - Use CPAN and install the following modules
> cpan
# answer all the questions to set this up.
> install Crypt::OpenSSL::RSA Mail::Address MIME::Base64 Net::DNS Net::Server Test::More
You may have to force install Net::DNS. We had to.
> force install Net::DNS - Download dkfilter - alternatively follow the directions at dkfilter.
> wget http://jason.long.name/dkfilter/dkfilter-0.11.tar.gz
> tar xzf dkfilter-0.11.tar.gz
> cd dkfilter-0.11
> ./configure --prefix=/usr/local/dkfilter
> make && make install
> useradd dkfilter - Generate your DomainKey
> openssl genrsa -out private.key 1024
#next line will generate the key published as a DNS TXT record.
> openssl rsa -in private.key -pubout -out public.key - You may have many domain keys. Each one is specified as a selector. For now we'll create a test selector. In your DNS records, add
test._domainkey.yourdomain.com IN TXT "k=rsa; p=KYwekEKRO....OKzcWK; t=y"
where p is the contents of public.key without the header/footer or newlines/spaces. Be careful not to cut off any characters on this step. The t refers to Test Mode. More information on DomainKey Implementation.
Test your entry by using the 'dig' tool.
> dig TXT test._domainkey.yourdomain.com
You should see something along the lines of...
;; QUESTION SECTION:
;test._domainkey.yourdomain.com. IN TXT
;; ANSWER SECTION:
test._domainkey.yourdomain.com. 7200 IN TXT "k=rsa\; p=MIGfMA0GC...9fOUedv02QIDAQAB\; t=y"
If not... try again until you do. - Startup the outgoing daemon.
> /usr/local/dkfilter.out --keyfile=/your/private.key --selector=test --domain=yourdomain.com --method=nofws 127.0.0.1:10027 127.0.0.1:10028 & - Configure postfix. In the master.cf file...
under the smtp and/or submission line, add
-o content_filter=dksign:[127.0.0.1]:10027
and at the end of the file, declare the filter itself. I don't know what any of this crap means so a copy/paste might be prudent.
dksign unix - - n - 10 smtp
-o smtp_send_xforward_command=yes
-o smtp_discard_ehlo_keywords=8bitmime
127.0.0.1:10028 inet n - n - 10 smtpd
-o content_filter=
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
-o smtpd_helo_restrictions=
-o smtpd_client_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
restart postfix
>service postfix restart - Test it! There are autoresponders to test this stuff. An easy way is to just send email to Yahoo! Mail. When you get it, look at the Full Headers and you should see something like this...
Authentication-Results: mta551.mail.mud.yahoo.com from=yourdomain.com; domainkeys=pass (ok)
If it doesn't work, check your TXT record and make sure there aren't any line breaks or what not. - When you're satified with the results, go ahead and turn test mode off by changing the TXT record from t=y to t=n. Add the dkfilter startup line to /etc/rc.local and you're good to go.
- DONE!
SpamEmail away!
References:
http://jason.long.name/dkfilter/