dkimrotate
dkimrotate is a project that I intend to get ready for open source. I took over from a colleague who wrote some simple routines, but never got further than rotating keys manually, which is not the best way to do things when you have to do it for 3800+ domains.
what is DKIM?
DKIM stands for Domain Key Identificatied Mail, a framework to secure mail from end to end by sending a cryptographic signaturer based on some parts of the original email. It works by signing the mail cryptographically at the origin (or as near as the origin as possible), adding a header-field with the signature in base64-encoding - because binary content is not allowed inside email and its headers as per RFC ???. The public key part of the key pair used to sign the message is put in DNS - because everyone receiving email has to have working DNS, right - and the receiver can check the correctness of the signature by “decrypting” the signature with that key.
Now, to have this work you need four components:
- a private key that only the sender “knows”
- a public key that is shown to the world
- some software that does the signing with the private key
- a DNS server that shows the public key to the world
The official implementation of the DKIM standard as of RFC6376 is OpenDKIM, and it is (as the name implies) open source, so it feels logical to make this software open source as well.
why rotate?
The reason we have to rotate our DKIM keys is that there are limitations to most DNS implementations, such as limited length of TXT records (many implementations limit those records to <255 characters because that’s how it was “in the old days”). By the way, the same limitations apply to SPF records (see eg. PowerDMARC’s excellent page and the SPF checker linked from there to learn more, as SPF is not handled by dkimrotate).
Anyway, these limitations mean we have to restrict our key sizes somewhat, for RSA that means 1024-bit keys (which makes our TXT records 234 characters long - number taken from our implementation’s keys, your mileage might vary depending on the “subject” of the key). Yes, there are key formats that are “better” that RSA, they create shorter keys with better security, but support for them was added to the specification after the first implementations were put into production and thus can not be guaranteed to work (just like DMARC-reports that should be compressed with gzip, but there are still many which use zip, including the official open implementation of the protocol, OpenDMARC. I have a patch for that to be fixed, but there is absolutely no enthusiasm in the team to adopt those changes, so expect many reports will be sent as zip-files according to the draft specification. /rant).
The need to rotate the keys after comparatively short time stems from the “crackability” of the generated keys. An actor with the right resources could find our private key by brute-forcing it, so the goal is to rotate before that happens.
The best document I have found is the Messaging, Malware and Mobile Anti-Abuse Working Group’s recommendations. dmarcian also recommends automated rotation.