]> khamidou — GitHub mirrors - flanker.git/commitdiff
Added documentation, detailed a stub
authorAlex Gaynor <alex.gaynor@gmail.com>
Wed, 9 Jul 2014 21:25:13 +0000 (14:25 -0700)
committerAlex Gaynor <alex.gaynor@gmail.com>
Wed, 9 Jul 2014 21:25:13 +0000 (14:25 -0700)
docs/User Manual.md
flanker/dkim.py

index 5a99f61eae66798d2f810e2604042a6c0c5a7991..1f52bf10300bbce75e858f5605c8674ad030cf74 100644 (file)
@@ -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 <joe@football.example.com>
+... To: Suzie Q <suzie@shopping.example.net>
+... 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.
index 7ef2231e810b8ad926e71f408bad45858bc939b0..9630f41c66a814536714aff245446d0f146b5c6f 100644 (file)
@@ -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