Signing Commercial Email with DKIM and ZXTM
Many systems have been developed over the past few years, to allow legitimate companies to distinguish their commercial email from that of your average Viagra pedlar, or Nigerian business opportunity. One of those methods is DKIM (DomainKeys Identified Mail). DKIM is the result of collaboration between a number of well known industry players, and is currently in use by Google, Yahoo!, Ebay, and PayPal, to name but a few. This article describes how to use ZXTM to control outgoing and incoming email (SMTP) traffic and manage DKIM signatures. ZXTM can add a DKIM signature to all outgoing mail to certify that it originated from your organization, and can verify any DKIM signatures in incoming mail for SPAM prevention purposes. More about DKIMThe DKIM.org website says: “DomainKeys Identified Mail (DKIM) lets an organization take responsibility for a message while it is in transit. The organization is a handler of the message, either as its originator or as an intermediary. Their reputation is the basis for evaluating whether to trust the message for delivery. Technically DKIM provides a method for validating a domain name identity that is associated with a message through cryptographic authentication.” DKIM doesn’t act as a spam filter, but rather it allows organisations to verify the source of the message. Which in turn makes it easy to identify an email as legitimate. Signing MailWhen an email is signed, the Signor adds an email header which indicates that they are prepared to take responsibility for the content of the message. The header contains a cryptographic signature of the data, which can then be verified by the receiving mail system (the Verifier). ZXTM can be used to Sign your outgoing mail, by routing the messages through the ZXTM. This could be done by creating a Virtual Server to load balance across a set of a SMTP smarthosts. Or you could use DNAT to redirect outgoing SMTP traffic through a ZXTM Virtual Server running in forward-proxy mode.
Verifying MailWhen an email is found to have a DKIM Signature, the Verifier process will create and compare a hash of the mail body against the body hash in the Signature, and then verify the Signature data against the public key for the signing domain. The public key is retrieved via the DNS system, using data found within the DKIM signature. ZXTM can be used to process incoming SMTP connections, and check all messages for DKIM signatures. When a signature is found, the header will be verified by our Java Extension, and a new header can be added to indicate the result of the verification attempt. Your spam checking systems may then use the outcome of ZXTMs verification as part of their own spam scoring calculations.
Java DKIM LibraryMost of the work in Signing and Verifying the DKIM signatures will be performed by the open source JavaDKIM Library. The Java Extensions provided in this article make use of JavaDKIM version 1.0.1. Using ZXTM to Sign Outgoing Mail1. Routing Traffic into our Virtual ServerIf you have smarthost(s) which deliver your mail, then you can place ZXTM between your mail server and the smarthost. All you need to do is configure a pool containing your smarthosts, and then configure your mail server to use ZXTM as its smarthost. Alternatively, if your mail server sends mail directly, then you can use ZXTM as a transparent SMTP proxy. On Linux, the following iptables command can be used to Destination NAT all traffic on port 25 into your ZXTM virtual server running on the Traffic IP specified.
For more information on how this works, review the Transparent Proxy article. You now need to create a TrafficScript rule to perform the ForwardProxy. The TrafficScript function request.getDestIP() will be used to retrieve the original destination of this connection to be used as the node end-point.
2. Signing the EmailOnce requests are routing through our Virtual Server, we need another TrafficScript rule to process the messages. For this purpose we will extend Julians SMTP Synchronisation rule.
The rule removes the ending <CRLF>.<CRLF> from the SMTP conversation, plus any dot “.” escapes which may have been added by the SMTP transfer. The message is now its original 7-bit format and can be passed to our DkimSigner Java Extension. The Java Extension will read the mail from ZXTMs connection data, create the Signature and then update the connection data with a signed copy of the message. The signed copy is then ready to be sent onto the waiting SMTP server. All of the requirements of Julians original SMTP Synchronisation script must be adhered to here, including setting this rule to run every time within the Virtual Server configuration. DkimSigner Java ExtensionThe Java Extension takes several initialisation parameters. It needs to know the signing domain (Domain), the signing identity (Identity), the Algorithm to use in the Signature (Algorithm), the canonicalization method (Canonicalizer), the DKIM selector (Selector), and Key information.
Using ZXTM to Verify Incoming MailYou may run an SMTP Virtual Server in order to pass all incoming messages. The service can load balance the messages across one or more mail servers, checking for, and verifying DKIM or DomainKey signatures found in each message. As with the DkimSigner, the DkimVerifier will again make use of Julian SMTP Synchronization script. The email body processing code is now....
The DkimVerifier expects to find the mail stored in ZXTM connection data, but instead of returning the message back to TrafficScript, it returns the result of the Verification attempt. Our TrafficScript will then insert a new header into the message, called DkimVerifier Java ExtensionThe Verifier Extension needs far fewer configuration parameters than the Signer did. It simple needs the name of a recursive name server it can use, and a cache time. Our Verifier will cache DKIM records found in DNS in order to improve performance.
Download the Binaries and Source codeBefore you can Sign or Verify any email messages, you will need to upload the Java extensions and JavaDKIM library to your ZXTM cluster. The DkimExtensions.jar file contains the DkimVerifier and the DkimSigner Java Extensions. The Java-DKIM-1.0.1.jar contains the JavaDKIM library. You should upload the library, before the Java Extensions.
Enjoy! |
Recently...
Other Resources
|







