| 1 |
Metadata-Version: 2.1 |
| 2 |
Name: dkimpy-milter |
| 3 |
Version: 1.2.3 |
| 4 |
Summary: Domain Keys Identified Mail (DKIM) signing/verifying milter for Postfix/Sendmail. |
| 5 |
Home-page: https://launchpad.net/dkimpy-milter |
| 6 |
Author: Scott Kitterman |
| 7 |
Author-email: [email protected] |
| 8 |
License: UNKNOWN |
| 9 |
Download-URL: https://pypi.python.org/pypi/dkimpy-milter |
| 10 |
Description: # OVERVIEW |
| 11 |
|
| 12 |
This is a DKIM signing and verification milter. It has been tested with both |
| 13 |
Postfix and Sendmail. |
| 14 |
|
| 15 |
The configuration file is designed to be compatible with OpenDKIM, but only |
| 16 |
a subset of OpenDKIM options are supported. If an unsupported option is |
| 17 |
specified, an error will be raised. |
| 18 |
|
| 19 |
|
| 20 |
# INSTALLATION |
| 21 |
|
| 22 |
This package includes a default configuration file and man pages. For those |
| 23 |
to be installed when installing using setup.py, the following incantation is |
| 24 |
required because setuptools developers decided not being able to do this by |
| 25 |
default is a feature: |
| 26 |
|
| 27 |
[sudo] python3 setup.py install --single-version-externally-managed --record=/dev/null |
| 28 |
|
| 29 |
For users of Debian Stable (Debian 9, Codename Squeeze), all dependencies are |
| 30 |
available in either the main or backports repositories: |
| 31 |
|
| 32 |
[sudo] apt install python3-milter python3-nacl python3-dnspython |
| 33 |
[sudo] apt install -t stretch-backports python3-authres python3-dkim |
| 34 |
|
| 35 |
It is also available in the Debian package archive: |
| 36 |
|
| 37 |
[sudo] apt install dkimpy-milter [Debian 10 or later] |
| 38 |
[sudo] apt install -t stretch-backports dkimpy-milter [Debian 9] |
| 39 |
|
| 40 |
When installing using the Debian package, all dependencies are automatically |
| 41 |
installed. |
| 42 |
|
| 43 |
The preferred method of installation is from PyPi using pip (if distribution |
| 44 |
packages are not available): |
| 45 |
|
| 46 |
[sudo] pip install dkimpy_milter |
| 47 |
|
| 48 |
Using pip will cause required packages to be installed via easy_install if they |
| 49 |
have not been previously installed. Because pymilter and PyNaCl are compiled |
| 50 |
Python extensions, the system will need appropriate development packages and |
| 51 |
an C compiler. Alternately, install these dependencies from distribution/OS |
| 52 |
packages and then pip install dkimpy_milter. |
| 53 |
|
| 54 |
The milter will work with either py3dns (DNS) or dnspython (dns), preferring |
| 55 |
dnspython if both are available. The dkimpy DKIM module also works with |
| 56 |
either. |
| 57 |
|
| 58 |
## NON-STANDARD INSTALLATION PATHS |
| 59 |
|
| 60 |
The package includes a custom setup command called expand. It allows various |
| 61 |
file locations in init scripts, man pages, and config files to be over-ridden |
| 62 |
at install time. |
| 63 |
|
| 64 |
|
| 65 |
expand: Expand @@ variables in input files, simlar to make macros. |
| 66 |
user_options: |
| 67 |
--sysconfigdir=, e: Specify system configuration directory. |
| 68 |
--sbindir=, s: Specify system binary directory [not used]. |
| 69 |
--bindir=, b: Specify binary directory. |
| 70 |
--rundir=,r: Specify run state directory. |
| 71 |
|
| 72 |
As an example, to change the run directory to /var/run, one would do: |
| 73 |
|
| 74 |
python3 setup.py expand --rundir=/var/run |
| 75 |
[sudo] python3 setup.py install --single-version-externally-managed \ |
| 76 |
--record=/dev/null |
| 77 |
|
| 78 |
or in a single step (the order matters): |
| 79 |
|
| 80 |
[sudo] python3 setup.py expand --rundir=/var/run install \ |
| 81 |
--single-version-externally-managed \ |
| 82 |
--record=/dev/null |
| 83 |
|
| 84 |
# SETUP |
| 85 |
|
| 86 |
## SIGNING KEYS |
| 87 |
|
| 88 |
In order to create DKIM signatures, a private key must be available. Signing |
| 89 |
keys should be protected (owned by root:root with permissions 600 in a |
| 90 |
directory that is not world readable). Different keys are required for RSA |
| 91 |
and (if used) Ed25519. |
| 92 |
|
| 93 |
### RSA |
| 94 |
|
| 95 |
Both public and private keys for RSA have standard formats and there are many |
| 96 |
tools available to create them. Keys must (RFC 8302) have a minimum size of |
| 97 |
1024 bits and should have a size of at least 2048 bits. The dknewkey script |
| 98 |
that is provided with dkimpy is one such tool: |
| 99 |
|
| 100 |
dknewkey exampleprivkey |
| 101 |
|
| 102 |
will produce both the private key file (.key suffix) and a file with the DKIM |
| 103 |
public key record to be published DNS (.dns suffix). RSA is the default key |
| 104 |
type. 2048 bits is the default key size. |
| 105 |
|
| 106 |
### ED25519 |
| 107 |
|
| 108 |
There is no standardized non-binary representation for Ed25519 private keys, |
| 109 |
so in order to generate Ed25519 keys for dkimpy-milter, dkimpy specific tools |
| 110 |
must be used to be compatible. The same dknewkey script support Ed25519: |
| 111 |
|
| 112 |
dknewkey --ktype ed25519 anothernewkey |
| 113 |
|
| 114 |
will provide both the private key file (.key suffix) and a file with the DKIM |
| 115 |
public key record to be published DNS (.dns suffix). Ed25519 keys do not have |
| 116 |
variable bit lengths. |
| 117 |
|
| 118 |
### COMPLEX SIGNING CONFIGURATIONS |
| 119 |
|
| 120 |
The KeyTable, KeyTableEd25519, and SigningTable are used to define signing |
| 121 |
instructions to the filter where use of Domain, Selector and KeyFile together |
| 122 |
are insufficient. |
| 123 |
|
| 124 |
First, select the type of database you will use for each. They need not |
| 125 |
be the same. The "DATA SETS" portion of the dkimpy-milter(8) man page |
| 126 |
describes the possibilities and how they are formatted. Then, construct those |
| 127 |
databases. |
| 128 |
|
| 129 |
Let's suppose you want to sign for two domains, example.com and example.net. |
| 130 |
Within example.com, you want to sign for user "president" differently than |
| 131 |
everyone else. Let's say further that you want to use a flat text file. |
| 132 |
|
| 133 |
You've generated private key files for each of these and stored them |
| 134 |
in the directory /usr/local/etc/dkim/keys as files "president", "excom" and |
| 135 |
"exnet", with the obvious intents. You want to use selectors "foo", "bar" |
| 136 |
and "baz" for those, respectively. The signing domains match the senders |
| 137 |
(i.e. the signatures for example.com's stuff will be held by example.com, |
| 138 |
and example.net likewise). |
| 139 |
|
| 140 |
First, write the KeyTable. This is a list of the keys you intend to use, |
| 141 |
and you just assign arbitrary names to them. So as a flat file, the KeyTable |
| 142 |
for the above might look like this: |
| 143 |
|
| 144 |
preskey example.com:foo:/usr/local/etc/dkim/keys/president |
| 145 |
comkey example.com:bar:/usr/local/etc/dkim/keys/excom |
| 146 |
netkey example.net:baz:/usr/local/etc/dkim/keys/exnet |
| 147 |
|
| 148 |
If also signing with ed25519, specify a KeyTableEd25519, with the same |
| 149 |
names, pointing to the keys needed for ed25519. Both KeyTable and |
| 150 |
KeyTableEd25519 are evaluated if there is a SigningTable (see below). |
| 151 |
|
| 152 |
Per the documentation, multi-field data sets that are made of flat files have |
| 153 |
the fields separated by colons, but the key and value(s) are separated by |
| 154 |
whitespace. |
| 155 |
|
| 156 |
So now we've named each key file, and specified with which selector and domain |
| 157 |
each will be used, and then given each of those groupings a name. This |
| 158 |
is your KeyTable. Let's say you put it in /usr/local/etc/dkim/keytable. |
| 159 |
|
| 160 |
Next, write the SigningTable. This maps senders (by default, taken from the |
| 161 |
From: header field of a message passing through the filter) to which keys |
| 162 |
will be used to sign their mail. Wildcards are allowed. So to do what was |
| 163 |
described above, we write it as follows: |
| 164 |
|
| 165 |
[email protected] preskey |
| 166 |
*@example.com comkey |
| 167 |
*@example.net netkey |
| 168 |
|
| 169 |
Since we want to use wildcards, we can't actually use a regular flat file. |
| 170 |
Wildcards require a regular expression file, or "refile". The above is |
| 171 |
valid format for one of those. Let's say you put this in |
| 172 |
/usr/local/etc/dkim/signingtable. |
| 173 |
|
| 174 |
Finally, tell the filter that it should use these files by adding this to |
| 175 |
your configuration file: |
| 176 |
|
| 177 |
KeyTable /usr/local/etc/dkim/keytable |
| 178 |
SigningTable refile:/usr/local/etc/dkim/signingtable |
| 179 |
|
| 180 |
You could put "file:" in front of the filename for the KeyTable just to be |
| 181 |
precise, but "file:" is assumed if the value starts with a "/". |
| 182 |
|
| 183 |
Note: Unlike opendkim, dkimpy-milter will check for "\*" in the signing table |
| 184 |
regardless of if refile is specified or not. Use of refile is supported for |
| 185 |
compatibility with configurations initially developed for use with opendkim. |
| 186 |
|
| 187 |
## MTA INTEGRATION |
| 188 |
|
| 189 |
Both a systemd unit file and a sysv init file are provided. Both make |
| 190 |
assumptions about defaults being used, e.g. if a non-standard pidfile name is |
| 191 |
used, they will need to be updated. The sysv init file uses start-stop-deamon |
| 192 |
from Debian. It is not portable to systems without that available. |
| 193 |
|
| 194 |
The dkimpy-milter drops priviledges after setup to the user/group specified in |
| 195 |
UserID. During initial setup, this system user needs to be manually created. |
| 196 |
As an example, using the default dkimpy-user on Debian, the command would be: |
| 197 |
|
| 198 |
[sudo] adduser --system --no-create-home --quiet --disabled-password \ |
| 199 |
--disabled-login --shell /bin/false --group \ |
| 200 |
--home /run/dkimpy-milter dkimpy-milter |
| 201 |
|
| 202 |
Since /var/run or /run is sometimes on a tempfs, if the PID file directory is |
| 203 |
missing, the milter will create it on startup. |
| 204 |
|
| 205 |
To start dkimpy-milter with systemd for the first time, you will need to take |
| 206 |
the following steps: |
| 207 |
|
| 208 |
[sudo] systemctl daemon-reload |
| 209 |
[sudo] systemctl enable dkimpy-milter |
| 210 |
[sudo] systemctl start dkimpy-milter |
| 211 |
[sudo] systemctl status dkimpy-milter (to verify it started correctly) |
| 212 |
|
| 213 |
As with all milters, dkimpy-milter needs to be integrated with your MTA of |
| 214 |
choice (Sendmail or Postfix). When integrating with your MTA, the risk of |
| 215 |
signature invalidation due to content conversion of the message body needs to |
| 216 |
be considered. See RFC 6376, Section 5.3 for discussion of this issue. As a |
| 217 |
practical matter, when signing, configure the milter to follow all others that |
| 218 |
might modify the message body. When verifying, configure the milter before |
| 219 |
other processes that might modify the message body. |
| 220 |
|
| 221 |
### SENDMAIL |
| 222 |
|
| 223 |
Configuration is very similar to opendkim, but needs some adjustment for |
| 224 |
dkimpy-milter. Here's an example configuration line to include in your |
| 225 |
sendmail.mc: |
| 226 |
|
| 227 |
INPUT_MAIL_FILTER(`dkimpy-milter', `S=local:/run/dkimpy-milter/dkimpy-milter.sock')dnl |
| 228 |
|
| 229 |
Changing the sendmail.mc file requires a Make (to compile it into sendmail.cf) |
| 230 |
and a restart of sendmail. Note that S= needs to match the value of Socket in |
| 231 |
the dkimpy-milter configuration file. |
| 232 |
|
| 233 |
Milter support should be present by default in most versions of sendmail |
| 234 |
these days, but if not included in your Sendmail build, see: |
| 235 |
http://www.elandsys.com/resources/sendmail/milter.html |
| 236 |
|
| 237 |
#### ISSUES USING SENDMAIL TO SIGN AND VERIFY |
| 238 |
|
| 239 |
When using the sendmail MTA in both signing and verifying mode, there are |
| 240 |
a few issues of which to be aware that might cause operational problems |
| 241 |
and deserve consideration. |
| 242 |
|
| 243 |
(a) When the MTA will be used for relaying emails, e.g. delivering to other |
| 244 |
hosts using the aliases mechanism, it is important not to break |
| 245 |
signatures inserted by the original sender. This is particularly sensitive |
| 246 |
particular when the sending domain has published a "reject" DMARC policy. |
| 247 |
|
| 248 |
By default, sendmail quotes to address header fields when there are no |
| 249 |
quotes and the display part of the address contains a period or an |
| 250 |
apostrophe. However, dkimpy-milter only sees the raw, unmodified form of |
| 251 |
the header field, and so the content that gets verified and what gets |
| 252 |
signed will not be the same, guaranteeing the attached signature is not |
| 253 |
valid. |
| 254 |
|
| 255 |
To direct sendmail not to modify the headers, add this to your sendmail.mc: |
| 256 |
|
| 257 |
conf(`confMUST_QUOTE_CHARS', `') |
| 258 |
|
| 259 |
(b) As stated in sendmail's KNOWNBUGS file, sendmail truncates header field |
| 260 |
values longer than 256 characters, which could mean truncating the domain |
| 261 |
of a long From: header field value and invalidating the signature. |
| 262 |
You may wish to consider increasing MAXNAME in sendmail/conf.h to mitigate |
| 263 |
changing the messages and invalidating their signatures. This change |
| 264 |
requires recompiling sendmail. |
| 265 |
|
| 266 |
(c) Similar to (a) above, sendmail may wrap very long single-line recipient |
| 267 |
fields for presentation purposes; for example: |
| 268 |
|
| 269 |
To: very long name <[email protected]>,anotherloo...ong name b <[email protected]> |
| 270 |
|
| 271 |
...might be rewritten as: |
| 272 |
|
| 273 |
To: very long name <[email protected]>, |
| 274 |
anotherloo...ong name b <[email protected]> |
| 275 |
|
| 276 |
This rewrite is also done after dkimpy-milter has seen the message, |
| 277 |
meaning the signature dkimpy-milter attaches to the message does not match |
| 278 |
the content it signed. There is not a known configuration change to |
| 279 |
mitigate this mutation. |
| 280 |
|
| 281 |
The only known mechanism for dealing with this is to have distinct |
| 282 |
instances of dkimpy-milter do the verifying (inbound) and signing |
| 283 |
(outbound) so that the version that arrives at the signing instance is |
| 284 |
already in the rewritten form, guaranteeing the input and output are the |
| 285 |
same and thus the signature matches the payload. |
| 286 |
|
| 287 |
### POSTFIX |
| 288 |
|
| 289 |
Integration of dkimpy-milter into Postfix is like any milter (See Postfix's |
| 290 |
README_FILES/MILTER_README). Here's an example master.cf excerpt that talks |
| 291 |
to two dkimpy-milter instances, one configured for signing and one configured |
| 292 |
for verification: |
| 293 |
|
| 294 |
smtp inet n - - - - smtpd |
| 295 |
... |
| 296 |
-o smtpd_milters=inet:localhost:8892 |
| 297 |
... |
| 298 |
|
| 299 |
submission inet n - - - - smtpd |
| 300 |
... |
| 301 |
-o smtpd_milters=inet:localhost:8891 |
| 302 |
... |
| 303 |
|
| 304 |
These need to match the Socket value for each dkimpy-milter instance. |
| 305 |
|
| 306 |
Care is required to segregate outbound mail to be signed and inbound mail to |
| 307 |
be verified. The above example uses two instances of dkimpy-milter to do |
| 308 |
this. There are many possible ways. Here is another example using milter |
| 309 |
macros to keep the mail streams segregated: |
| 310 |
|
| 311 |
Postfix master.cf: |
| 312 |
|
| 313 |
smtp inet n - - - - smtpd |
| 314 |
... |
| 315 |
-o smtpd_milters=inet:localhost:8891 |
| 316 |
-o milter_macro_daemon_name=VERIFYING |
| 317 |
... |
| 318 |
|
| 319 |
submission inet n - - - - smtpd |
| 320 |
-o syslog_name=postfix/submission |
| 321 |
-o smtpd_tls_security_level=encrypt |
| 322 |
-o smtpd_sasl_auth_enable=yes |
| 323 |
... |
| 324 |
-o milter_macro_daemon_name=ORIGINATING |
| 325 |
-o smtpd_milters=inet:localhost:8891 |
| 326 |
... |
| 327 |
|
| 328 |
Dkimpy-milter.conf: |
| 329 |
|
| 330 |
... |
| 331 |
Mode sv |
| 332 |
MacroList dameon_name|ORIGINATING |
| 333 |
MacroListVerify daemon_name|VERIFYING |
| 334 |
... |
| 335 |
|
| 336 |
|
| 337 |
# NOTES |
| 338 |
|
| 339 |
The python DKIM library, dkimpy, requires the entire message being signed or |
| 340 |
verified to be in memory, so dkimpy-milter does not write messages out to a |
| 341 |
temp file. This may impact performance on low-memory systems. |
| 342 |
|
| 343 |
DKIM with Ed25519 signatures are described in RFC 8463. Version 1.0.0 and |
| 344 |
later support Ed25519 signing and verification. RFC 8301 removed rsa-sha1 |
| 345 |
from DKIM. dkimpy-milter does not sign with rsa-sha1, but still considers |
| 346 |
rsa-sha1 signatures as valid for verification because they are still in |
| 347 |
common use and are not known to be cryptographically broken. |
| 348 |
|
| 349 |
Support for non-ASCII email messages: Anything UTF-8 should work (including |
| 350 |
correct signing/verification). For messages that contain header fields with |
| 351 |
non-ASCII or UTF-8 content, signatures are likely fail verification, but the |
| 352 |
milter should continue to run. RFC 8616 is not supported. |
| 353 |
|
| 354 |
Platform: UNKNOWN |
| 355 |
Classifier: Development Status :: 5 - Production/Stable |
| 356 |
Classifier: Environment :: No Input/Output (Daemon) |
| 357 |
Classifier: Intended Audience :: System Administrators |
| 358 |
Classifier: License :: OSI Approved :: GNU General Public License (GPL) |
| 359 |
Classifier: Natural Language :: English |
| 360 |
Classifier: Operating System :: POSIX |
| 361 |
Classifier: Programming Language :: Python :: 3 :: Only |
| 362 |
Classifier: Topic :: Communications :: Email :: Mail Transport Agents |
| 363 |
Classifier: Topic :: Communications :: Email :: Filters |
| 364 |
Classifier: Topic :: Security |
| 365 |
Description-Content-Type: text/markdown |