• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

dkim/H09-Aug-2020-4,9263,336

dkimpy.egg-info/H03-May-2022-250177

man/H09-Aug-2020-805770

ChangeLogH A D09-Aug-202011.7 KiB262226

LICENSEH A D06-Apr-2020979 2016

MANIFEST.inH A D06-Apr-2020200 1110

PKG-INFOH A D09-Aug-202010.1 KiB250177

README.mdH A D08-Aug-20207.3 KiB223151

setup.cfgH A D09-Aug-202038 53

setup.pyH A D03-May-20223.4 KiB9869

test.pyH A D06-Apr-2020268 119

README.md

1dkimpy - DKIM (DomainKeys Identified Mail)
2https://launchpad.net/dkimpy/
3
4Friendly fork of:
5http://hewgill.com/pydkim/
6
7# INTRODUCTION
8
9dkimpy is a library that implements DKIM (DomainKeys Identified Mail) email
10signing and verification.  Basic DKIM requirements are defined in RFC 6376:
11
12https://tools.ietf.org/html/rfc6376
13
14# VERSION
15
16This is dkimpy 1.0.5.
17
18# REQUIREMENTS
19
20Dependencies will be automatically included for normal DKIM usage.  The
21extras_requires feature 'ed25519' will add the dependencies needed for signing
22and verifying using the new DCRUP ed25519-sha256 algorithm.  The
23extras_requires feature 'ARC' will add the extra dependencies needed for ARC.
24Similarly, extras_requires feature 'asyncio' will add the extra dependencies
25needed for asyncio.
26
27 - Python 2.x >= 2.7, or Python 3.x >= 3.5.  Recent versions have not been
28   tested on python < 2.7 or python3 < 3.4, but may still work on python2.6
29   and python 3.1 - 3.3.
30 - dnspython or pydns. dnspython is preferred if both are present and
31   installed to satisfy the DNS module requirement if neither are installed.
32 - argparse.  Standard library in python2.7 and later.
33 - authres.  Needed for ARC.
34 - PyNaCl.  Needed for use of ed25519 capability.
35 - aiodns.  Needed for asycnio (Requires python3.5 or later)
36
37# INSTALLATION
38
39This package includes a scripts and man pages.  For those to be installed when
40installing using setup.py, the following incantation is required because
41setuptools developers decided not being able to do this by default is a
42feature:
43
44```python3 setup.py install --single-version-externally-managed --record=/dev/null```
45
46# DOCUMENTATION
47
48An online version of the package documentation for the most recent release can
49be found at:
50
51https://pymilter.org/pydkim/
52
53# TESTING
54
55To run dkimpy's test suite:
56
57```PYTHONPATH=. python3 dkim```
58
59or
60
61```python3 test.py```
62
63or
64
65```PYTHONPATH=. python3 -m unittest dkim.tests.test_suite```
66
67
68Alternatively, if you have testrepository installed:
69
70```testr init```
71
72```testr run```
73
74You should install all optional dependencies required for the test suite, e.g.
75by creating a virtualenv and using:
76
77```pip install -e '.[testing]'```
78
79The included ARC tests are very limited.  The primary testing method for ARC
80is using the ARC test suite: https://github.com/ValiMail/arc_test_suite
81
82As of 0.6.0, all tests pass for both python2.7 and python3. The test suite
83 ships with test runners for dkimpy.  After downloading the test suite, you
84 can run the signing and validation tests like this:
85
86```python2.7 ./testarc.py sign runners/arcsigntest.py```
87```python2.7 ./testarc.py validate runners/arcverifytest.py```
88
89# USAGE
90
91The dkimpy library offers one module called dkim. The sign() function takes an
92RFC822 formatted message, along with some signing options, and returns a
93DKIM-Signature header line that can be prepended to the message. The verify()
94function takes an RFC822 formatted message, and returns True or False depending
95on whether the signature verifies correctly.  There is also a DKIM class which
96can be used to perform these functions in a more modern way.
97
98In version 0.9.0, the default set of header fields that are oversigned was
99changed from 'from', 'subject', 'date' to 'from' to reduce fragility of
100signatures.  To restore the previous behavior, you can add them back after
101instantiating your DKIM class using the add_frozen function as shown in the
102following example:
103
104```python
105>>> dkim = DKIM()
106>>> dkim.add_frozen((b'date',b'subject'))
107>>> [text(x) for x in sorted(dkim.frozen_sign)]
108['date', 'from', 'subject']
109```
110
111## DKIM RSA MODERNIZATION (RFC 8301)
112
113RFC8301 updated DKIM requirements in two ways:
114
1151.  It set the minimum valid RSA key size to 1024 bits.
1162.  It removed use of rsa-sha1.
117
118As of version 0.7, the dkimpy defaults largely support these requirements.
119
120It is possible to override the minimum key size to a lower value, but this is
121strongly discouraged.  As of 2018, keys much smaller than the minimum are not
122difficult to factor.
123
124The code for rsa-sha1 signing and verification is retained, but not used for
125signing by default.  Future releases will raise warnings and then errors when
126verifying rsa-sha1 signatures.  There are still some significant users of
127rsa-sha1 signatures, so operationally it's premature to disable verification
128of rsa-sha1.
129
130## ED25519 (RFC 8463) SUPPORT
131
132As of version 0.7, experimental signing and verifying of DKIM Ed25519
133signatures is supported as described in draft-ietf-dcrup-dkim-crypto:
134
135https://datatracker.ietf.org/doc/draft-ietf-dcrup-dkim-crypto/
136
137The RFC that documents ed25519 DKIM signatures, RFC 8463, has been released
138and dkimpy 0.7 and later are aligned to its requirements.  As of 0.8, ed25519
139need not be considered experimental.  The dkimpy implementation has
140successfully interoperated with three other implementations and the technical
141parameters for ed25519-sha256 are defined and stable.
142
143To install from pypi with the required optional depenencies, use the ed25519
144option:
145
146```pip install -e '.[ed25519]'```
147
148## DKIM SCRIPTS
149
150Three helper programs are also supplied: dknewkey, dkimsign and
151dkimverify
152
153dknewkey is s script that produces private and public key pairs suitable
154for use with DKIM.  Note that the private key file format used for ed25519 is
155not standardized (there is no standard) and is unique to dkimpy.
156
157dkimsign is a filter that reads an RFC822 message on standard input, and
158writes the same message on standard output with a DKIM-Signature line
159prepended. The signing options are specified on the command line:
160
161dkimsign selector domain privatekeyfile [identity]
162
163The identity is optional and defaults to "@domain".
164
165dkimverify reads an RFC822 message on standard input, and returns with exit
166code 0 if the signature verifies successfully. Otherwise, it returns with exit
167code 1.
168
169## ARC (Authenticated Receive Chain)
170
171As of version 0.6.0, dkimpy provides experimental support for ARC (Authenticated
172Received Chain).  See RFC 8617 for the current version of ARC:
173
174https://tools.ietf.org/html/rfc8617
175
176In addition to arcsign and arcverify, the dkim module now provides
177arc_sign and arc_verify functions as well as an ARC class.
178
179Both DKIM ed25519 and ARC are now considered stable (no longer experimantal).
180
181## ASYNC SUPPORT
182
183As of version 1.0, an alternative to dkim.verify for use in an async
184environment is provied.  It requires aiodns, https://pypi.org/project/aiodns/.
185Here is a simple example of dkim.verify_async usage:
186
187```python
188>>> sys.stdin = sys.stdin.detach()
189>>>
190>>> async def main():
191>>>     res = await dkim.verify_async(message)
192>>>     return res
193>>>
194>>> if __name__ == "__main__":
195>>>     res = asyncio.run(main())
196```
197
198This feature requires python3.5 or newer.
199
200## TLSRPT (TLS Report)
201
202As of version 1.0, the RFC 8460 tlsrpt service type is supported:
203
204https://tools.ietf.org/html/rfc8460
205
206A non-tlsrpt signed with a key record with s=tlsrpt won't verify.  Since the
207service type (s=) is optional in the DKIM public key record, it is not
208required by RFC 8460.  When checking for a tlsrpt signature, set the tlsrpt=
209flag when verifying the signature:
210
211```python
212>>> res = dkim.verify(smessage, tlsrpt='strict')
213```
214
215If tlsrpt='strict', only public key records with s=tlsrpt will be considered
216valid.  If set to tlsrpt=True, the service type is not required, but other
217RFC 8460 requirements are applied.
218
219# FEEDBACK
220
221Bug reports may be submitted to the bug tracker for the dkimpy project on
222launchpad.
223