Postfix with dkfilter (DomainKeys Implementation)

Want to support HowtoForge? Become a subscriber!
 
Submitted by sohaileo (Contact Author) (Forums) on Mon, 2006-12-04 12:42. :: Anti-Spam/Virus | Postfix

Postfix with dkfilter (DomainKeys Implementation) 

Author: Sohail Riaz <sohail AT fastadmins DOT com>
                                   <sohail AT sohailriaz DOT com>

DomainKeys is an anti-spam software application in development at Yahoo that uses a form of public key cryptography to authenticate the sender's domain. dkfilter is an SMTP-proxy designed for Postfix. It implements DomainKeys message signing and verification. It comprises two separate filters, an "outbound" filter for signing outgoing email on port 587, and an "inbound" filter for verifying signatures of incoming email on port 25. This document is to describe step by step how to install dkfilter for postfix to deploy domainkeys signing and verification.

 

1 Install Postfix

Install postfix for your domain to send and receive mails.

 

2 Resolving Dependencies - Installing Perl Modules

Dkfilter is written in Perl. It requires the following Perl Modules from CPAN archive.

    * Crypt::OpenSSL::RSA
    * Mail::Address
    * MIME::Base64
    * Net::DNS
    * Test::More
    * Text::Wrap
    * Mail::DomainKeys

Following commands would help.

perl -MCPAN -e'CPAN::Shell->install("Crypt::OpenSSL::RSA")'
perl -MCPAN -e'CPAN::Shell->install("Mail::Address")'
perl -MCPAN -e'CPAN::Shell->install("MIME::Base64")'
perl -MCPAN -e'CPAN::Shell->install("Net::DNS")'
perl -MCPAN -e'CPAN::Shell->install("Test::More")'
perl -MCPAN -e'CPAN::Shell->install("Text::Wrap")'
perl -MCPAN -e'CPAN::Shell->install("Email::Address")'
perl -MCPAN -e'CPAN::Shell->install("Mail::DomainKeys")'

Note: Also resolve any dependent Perl Module required in installing the above Perl modules.

 

3 Installing dkfilter

The following steps are recommended for installing dkfilter:

i. Download dkfilter from following URL:
http://jason.long.name/dkfilter/dkfilter-0.11.tar.gz

ii. Installing dkfilter

tar xvf dkfilter-0.11.tar.gz
cd dkfilter-0.11
./configure --prefix=/usr/local/dkfilter
make install
useradd dkfilter

The filter scripts will be installed in /usr/local/dkfilter/bin and the Perl module files will be in /usr/local/dkfilter/lib.

 

4 Setting up Inbound Filter

We need to make relevant changes inside Postfix configuration files to check incoming mails for the signature.

vi /etc/postfix/master.cf

#
# Before-filter SMTP server. Receive mail from the network and
# pass it to the content filter on localhost port 10025.
#
smtp      inet  n       -       n       -       -       smtpd
    -o smtpd_proxy_filter=127.0.0.1:10025
    -o smtpd_client_connection_count_limit=10
#
# After-filter SMTP server. Receive mail from the content filter on
# localhost port 10026.
#
127.0.0.1:10026 inet n  -       n       -        -      smtpd
    -o smtpd_authorized_xforward_hosts=127.0.0.0/8
    -o smtpd_client_restrictions=
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o smtpd_data_restrictions=
    -o mynetworks=127.0.0.0/8
    -o receive_override_options=no_unknown_recipient_checks

Insert above lines in the last of the files. Here we define that mail will received after smtp for verification on 127.0.0.1 with port 10026. You can define your own desired IP address on which you want to listen for signature checking.

 

5 Setting up the outbound filter

The outbound filter needs access to the private key used for signing messages. In addition, in needs to know the name of the key selector being used, and what domain it should sign messages for. This information is specified with command-line arguments to dkfilter.out.

1. Generate a private/public key pair and publish the public key in DNS.

cd /usr/local/dkfilter
openssl genrsa -out private.key 1024
openssl rsa -in private.key -pubout -out public.key

This creates the files private.key and public.key in the current directory, containing the private key and public key. Make sure private.key is not world-readable, but still readable by the dkfilter user.

2. Pick a selector name... e.g. m1

3. Put the public-key data in DNS, in your domain, using the selector name you picked. Copy the contents of the public.key file and remove the PEM header and footer, and paste it in dns zone file by creating a TXT entry, like this:

_domainkey.sohailriaz.com        IN TXT  “t=y; o=-;”
m1._domainkey.sohailriaz.com  IN TXT "g=; k=rsa; p=MHwwDQYJK ... OprwIDAQAB;"

where m1 is the name of the selector chosen in the last step and the p= parameter contains the public-key as one long string of characters.

Finally, configure Postfix to filter outgoing, authorized messages only through the dkfilter.out service on port 10027. In the following example, messages sent via SMTP on port 587 (the submission port) will go through an After-Queue content filter that signs messages with DomainKeys.

vi /etc/postfix/master.cf

#
# modify the default submission service to specify a content filter
# and restrict it to local clients and SASL authenticated clients only
#
submission  inet  n     -       n       -       -       smtpd
    -o smtpd_etrn_restrictions=reject
    -o smtpd_sasl_auth_enable=yes
    -o content_filter=dksign:[127.0.0.1]:10027
    -o receive_override_options=no_address_mappings
    -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
#
# specify the location of the DomainKeys signing filter
#
dksign    unix  -       -       n       -       10      smtp
    -o smtp_send_xforward_command=yes
    -o smtp_discard_ehlo_keywords=8bitmime
#
# service for accepting messages FROM the DomainKeys signing filter
#
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

Execute postfix reload for Postfix to respond to changes in /etc/postfix/master.cf.

postfix reload

 

6 Startup Script

Download a startup/shutdown script from the following site:
http://www.enterux.com/files/dkfilter

Copy that script in /etc/rc.d/init.d and edit it as per your requirement.

 

7 References

http://www.postfix.org
http://antispam.yahoo.com/domainkeys
http://jason.long.name/dkfilter/


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Tue, 2010-03-02 21:21.
Plz reload link http://www.enterux.com/files/dkfilter page not found
Submitted by nextprogress (registered user) on Thu, 2009-02-19 09:39.

I had this error when installing OpenSSL::RSA (actually it's dependancy: OpenSSL::Random)

Random.xs:5:26: error: openssl/rand.h: No such file or directory

To solve it, I installed openssl-devel package, then tried again and it worked. I used "yum install openssl-devel", but whatever package installer you have should also be able to do that.

Also, I had trouble on installing Test::More, it errored out at "Test::Simple" dependancy, so I had to install "make" (yum install make), then download the source directly and install it manually: perl Makefile.PL, make, make test, make install.


 

 

Submitted by nima0102 (not registered) on Fri, 2009-06-26 21:34.
if your distro is Debian lenny you can install debian package related to Crypt::Openssl::perl nad others perl modules by apt-get install libmail-dkim-perl and apt-get install libssl-dev and then apt-get install dk-filter good luck
Submitted by Mike (not registered) on Wed, 2008-12-10 03:13.

In addition to the ones you list, I had to install the following:

perl -MCPAN -e'CPAN::Shell->install("Net::Server")'

 Thanks for the docs, good stuff.

~m

Submitted by ibux (registered user) on Fri, 2006-12-08 12:14.
In section 4, you should modify /etc/postfix/master.cf, not /etc/postfix/main.cf