Qmail
[Top] [All Lists]

Re: DomainKey Shell Scripts

To: qmail@list.cr.yp.to
Subject: Re: DomainKey Shell Scripts
From: "Erik A. Espinoza" <erik.espinoza@gmail.com>
Date: Wed, 4 Apr 2007 21:44:20 -0700
Delivered-to: sp-com-lists@consult.net
Delivered-to: gmail-qmail@securepoint.com
Delivered-to: sp.com.list@gmail.com
Delivered-to: mailing list qmail@list.cr.yp.to
Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=JK6u0boJjhJDVXs2fOBuss8mKzvP8OTdf0HdrkxfhgnV7Kdur0wQeKAOn69OajaHrgZRyntB9L6BNneCbxV7Ot2Pm8UBT0LTGXlu2MrvH358doGT1NEyQOTnfEuv36Ciu8n3Upp5W4rZy9nFuAh5u+h058r8wriBm69xCFSSA6w=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LOgNmyPl9VkUeS3SLxtIEnNfcvIQAHb672mWqaBI8eiGs5xRcz2exF50veDSieVF7MZGPf2mo1uJDi1E1pGyGJnYNGaLTD1TLMDNaodVjnaK0/b/dZxKFJT3NQkt7drtToVqnIznNKiR72fOQvNydrEjdCtWpX+wcy8xfDH2khc=
Domainkey-status: good (test mode)
In-reply-to: <20070405043608.GH27526@aleut.local>
Mailing-list: contact qmail-help@list.cr.yp.to; run by ezmlm
References: <20070405043608.GH27526@aleut.local>
Nice preliminary work there Kyle.

This does look interesting indeed.

Erik

On 4/4/07, Kyle Wheeler <kyle-qmail@memoryhole.net> wrote:
Hello,

I whipped up some shell scripts to do DomainKey verification and
signing, using the dktest program that comes with libdomainkeys. The
verifier is a qmail-queue wrapper, and the signer is a qmail-remote
wrapper. They aren't *optimal*, because they use temporary files,
rather than operating on just pipes. If you use `seek0`, you can avoid
that, but I figured being general was better than adding more
dependencies.

I've tested these scripts briefly, and they seem to work well. YMMV.

They do *not* block email based on DomainKey signature status; just
tag. For blocking and/or using policy information, you'll have to
modify them (for the sake of the rest of us, please post such
modifications).

The first one is dkverifier.sh:

     #!/bin/sh
     [ "$DKQUEUE" ] || DKQUEUE=/var/qmail/bin/qmail-queue
     if printenv | grep -q '^DKVERIFY=' ; then
         tmp=`mktemp -t dk.verify.XXXXXXXXXXXXXXX`
         cat - >"$tmp"
         ( /usr/local/bin/dktest -v <"$tmp" 2>/dev/null | \
             /bin/awk 'NR>1'; /bin/cat "$tmp" ) | \
             $DKQUEUE
         retval=$?
         rm "$tmp"
         exit $retval
     else
         exec $DKQUEUE
     fi

The second one is a qmail-remote wrapper; it assumes that you've moved
qmail-remote to qmail-remote.orig, and that this script is stored in
/var/qmail/bin/qmail-remote. To set the environment variables to
control this, add them to your qmail-send run script. The script is a
little simplistic; it assumes all domains will be signed with the same
key:

     #!/bin/sh
     [ "$DOMAIN" ] || DOMAIN=`head -n 1 /var/qmail/control/me`
     [ "$DKREMOTE" ] || DKREMOTE=/var/qmail/bin/qmail-remote.orig
     [ "$DKSIGN" ] || DKSIGN="/etc/domainkeys/$DOMAIN/default"
     tmp=`mktemp -t dk.sign.XXXXXXXXXXXXXXX`
     cat - >"$tmp"
     ( /usr/local/bin/dktest -s "$DKSIGN" -c nofws -h <"$tmp" \
         2>/dev/null | \
         /bin/sed 's/; d=.*;/; d='"$DOMAIN"';/'; \
         /bin/cat "$tmp" ) | \
         "$DKREMOTE" "$@"
     retval=$?
     rm "$tmp"
     exit $retval

We can add a little more intelligence to they key choice, at the
expense of making it a little less readable (and bash-dependent).
Like so:

     #!/bin/bash
     [ "$DKSIGN" ] || DKSIGN="/etc/domainkeys/%/default"
     [ "$DKREMOTE" ] || DKREMOTE=/var/qmail/bin/qmail-remote.orig
     if [[ $DKSIGN == *%* ]] ; then
         DOMAIN=${2##*@}
         DKSIGN="${DKSIGN%%%*}${DOMAIN}${DKSIGN#*%}"
     fi
     if [ -f "$DKSIGN" ] ; then
         tmp=`mktemp -t dk.sign.XXXXXXXXXXXXXXX`
         cat - >"$tmp"
         ( /usr/local/bin/dktest -s "$DKSIGN" -c nofws -h <"$tmp" \
             2>/dev/null | \
             /bin/sed 's/; d=.*;/; d='"$DOMAIN"';/'; \
             /bin/cat "$tmp" ) | \
             "$DKREMOTE" "$@"
         retval=$?
         rm "$tmp"
         exit $retval
     else
         exec "$DKREMOTE" "$@"
     fi

I hope that helps someone. :)

~Kyle
--
Those who do not understand Unix are condemned to reinvent it, poorly.
                                                       -- Henry Spencer



<Prev in Thread] Current Thread [Next in Thread>