From 9cd7c05664faf468ff4d2b38549dcbde6071207c Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 9 Jul 2014 14:25:13 -0700 Subject: [PATCH] Added documentation, detailed a stub --- docs/User Manual.md | 65 +++++++++++++++++++++++++++++++++++++++++++++ flanker/dkim.py | 8 ------ 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/docs/User Manual.md b/docs/User Manual.md index 5a99f61..1f52bf1 100644 --- a/docs/User Manual.md +++ b/docs/User Manual.md @@ -14,6 +14,9 @@ * [Drawbacks](#drawbacks) * [Parsing MIME Messages](#parsing-mime-messages) * [Creating MIME Messages](#creating-mime-messages) +* [DKIM](#dkim) + * [Signing](#signing) + * [Verification](#verification) ### Introduction @@ -633,3 +636,65 @@ Content-Transfer-Encoding: 7bit --13f551bddf2e4759b125f70674288048-- ``` + +### DKIM + +DKIM (DomainKey Identified Mail) is an IETF standard that allows MTAs to attach +signatures to emails they send which allows an MTA receiving the email to +verify that the sender was allowed to send mail for that domain. flanker +provides support for generating DKIM signatures, as well as DomainKey +signatures (a previous standard for doing the same thing). + +#### Signing + +To sign a message, you need a few things: + +* `key`: An RSA private key. This should be an instance of + `cryptography.hazmat.primitives.interfaces.RSAPrivateKey`, you can consult + the [PyCA Cryptography documentation](https://cryptography.io/en/latest/hazma + t/primitives/asymmetric/rsa/) for more information on how to generate and + load keys. +* `selector`: A string which identifies a particular public key that the + receiving MTA should used to verify senders. It corresponds to a specific DNS + record. +* `domain`: A string which specifies the domain the message is from. +* `header_canonicalization` and `body_canonicalization` (optional): These + specify which of the canonicalization rules from the RFC can be used. Valid + values are `flanker.dkim.SimpleCanonicalization` (the default). +* `signed_headers` (optional): A list of strings which specify which headers + should be signed. If this argument is not supplied, all of the message's + headers will be supplied. + +Finally, you need a `message`, which is a string containing an RFC 822 +formatted email. + + +```pycon +>>> from flanker.dkim import DKIMSigner +>>> example_message = """ +... From: Joe SixPack +... To: Suzie Q +... Subject: Is dinner ready? +... Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT) +... Message-ID: <20030712040037.46341.5F8J@football.example.com> +... +... Hi. +... +... We lost the game. Are you hungry yet? +... +... Joe. +... """.strip() +>>> signer = DKIMSigner(rsa_key, selector="mx", domain="mailgun.net") +>>> signer.sign(example_message) +"DKIM-Signature: ..." +``` + +`sign()` will return the complete header line which can be added to the email +before sending. + +`flanker.dkim.DomainKeySigner` works similarly, except it does not allow +specifying the canonicalization rules. + +#### Verification + +flanker does not currently support verifying DKIM signatures, but it will soon. diff --git a/flanker/dkim.py b/flanker/dkim.py index 7ef2231..9630f41 100644 --- a/flanker/dkim.py +++ b/flanker/dkim.py @@ -154,11 +154,3 @@ class DKIMSigner(object): dkim_header=v, signature=_fold(base64.b64encode(signer.finalize())) ) - - -class DKIMVerifier(object): - def __init__(self, keys): - self._keys = keys - - def verify(self, message): - raise NotImplementedError -- 2.43.0