Commit Graph

85 Commits

Author SHA1 Message Date
Scott Kitterman 6f75a1a967 - Fix verify processing so missing (optional) i= tag doesn't cause the milter
to fail
2019-08-09 11:28:53 -04:00
Scott Kitterman 787e25325e Fix startup logging so it provides information at a useful time 2019-08-09 08:58:03 -04:00
Scott Kitterman 9cd67c1b25 Clarify usage statement on bad command line run 2019-04-28 03:37:25 -04:00
Scott Kitterman 5ebaf5d848 - Add support for passing PID file name on command line to make it easier to keep system init and daemon configuration in sync. 2019-04-26 20:24:34 -04:00
Scott Kitterman 8dc3ac6474 Add option to sign for subdomains - Thanks to Sagi for the patch 2019-04-12 22:31:24 -04:00
Scott Kitterman 564799402a Catch and log config items missing values 2019-04-12 22:01:56 -04:00
Scott Kitterman 357905bb68 Fix debugLevel for config._readConfigFile 2019-04-12 21:45:31 -04:00
Scott Kitterman 6b851f18df Changes in dkimpy_milter/__init__.py to harmonize logging messages and log text instead of bytestring. 2019-04-12 21:29:09 -04:00
Scott Kitterman fb72b9f6e7 Merge 1_0 into master 2019-03-12 22:06:42 -04:00
Daniel Kahn Gillmor 7092874729 Enable sd_listen_fds(3)-style socket-activation support
I've added straightforward systemd unit files in
system/socket-activation/ that make use of this approach, and a
README.md in the same location that describes the tradeoffs.
2019-02-21 19:22:11 -05:00
Daniel Kahn Gillmor 25fdd3b81c Do not create PidFile by default
By default, avoid creating a PIDFile.

PIDFiles are racy and potentially dangerous.  Modern system
supervision systems don't need them, because they manage the process
groups directly.

If the configuration file doesn't specify a PidFile, dkimpy-milter
shouldn't try to create one.
2019-02-21 19:22:11 -05:00
Daniel Kahn Gillmor 9d5316ca0e Handle defaults for Socket differently
We want to be able to select the default for Socket differently in the
future.

This change augments the API for dkimpy_milter.util.own_socketfile()
by adding an optional sockname argument.  This is a
backward-compatible change.  If we aren't committed to API stability
for this function, we could make a more invasive change that would
probably be a more reasonable API going forward, but this is probably
good enough.
2019-02-21 19:22:11 -05:00
Daniel Kahn Gillmor ea09bab1a8 Convert __init__.py to python3
The main work here is about bytes vs. strings.  This work was
confusing for several reasons:

 * pymilter thinks that headers are all strings, but body is bytes

 * dkimpy wants to deal with bytes objects generally (though it
   accepts a string object as an ed25519 secret key for some reason,
   despite requiring bytes as an RSA secret key)

 * authres.AuthenticationResultsHeader object converts easily to a
   string, but has no direct bytes conversion.  meanwhile, it wants
   its arguments as strings, but will accept them if they are bytes
   and convert them with something like str(), which leaves weird
   cruft like "header.a=b'ed25519-sha256'"

 * dkimpy_milter/utils.py contains fold() which expects bytes

 * self.fp needs to accumulate the on-the-wire version of the message
   as a whole (so it needs to be bytes).  That means converting the
   headers.  Header names and values are US-ASCII, per §2.2 of RFC
   5322, so they should be convertible cleanly, but we still have to
   convert them explicitly so that python knows the right thing to do.

At any rate, tests/runtests all passes with these changes, and the
output for both Authentication-Results: and DKIM-Signature headers
looks the same.
2019-02-21 19:22:11 -05:00
Daniel Kahn Gillmor 391b5352f3 Convert mostly to python3 (still need strings/bytes conversions)
This covers conversion of the whole project to python3, *except* for
the strings/bytes distinction in __init__.py, which i'm leaving for a
second commit.

The changes in this commit are intended to be relatively
uncontroversial, so that the following commit contains the tricky
bits.
2019-02-21 19:22:09 -05:00
Daniel Kahn Gillmor 7bfb87fab7 Set up __main__.py, use it in tests
This allows us to invoke dkimpy-milter as "python -m dkimpy_milter
dkimpy-milter.conf", which makes running the test suite easier.
2019-02-21 19:21:38 -05:00
Daniel Kahn Gillmor b3db013754 config: Reassemble strings sensibly
If a string-based configuation entry had whitespace in it, it would be
reassembled via a round-trip through the python interpreter, resulting
in a line like this:

    PidFile /home/dkimpy-milter/pid file

produces a string like "['/home/dkimpy-milter/pid', 'file']", which is
clearly wrong.

I don't want to encourage people to use paths or other strings with
whitespace in them, but if we're going to fail on them we should be
failing explicitly, not doing a weird transformation that will just
break.

This is concretely useful for the DNSOverride mechanism, which is
where i ran into the problem when trying to set up testing that could
work without setting up an emulated DNS system.
2019-02-21 19:21:38 -05:00
Daniel Kahn Gillmor bd1d25d83e Set up correct AuthservID defaults
Without this fix, a verifying dkimpy-milter that has no explicit
AuthservID produces the following crashing behavior as it tries to
create the authres header:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/Milter/__init__.py", line 772, in <lambda>
    milter.set_eom_callback(lambda ctx: ctx.getpriv().eom())
  File "…/dkimpy_milter/__init__.py", line 199, in eom
    h = fold(str(h))
  File "/usr/lib/python2.7/dist-packages/authres/core.py", line 476, in __str__
    return ''.join((self.HEADER_FIELD_NAME, ': ', self.header_value()))
  File "/usr/lib/python2.7/dist-packages/authres/core.py", line 496, in header_value
    return ''.join(strs)
2019-02-21 19:21:38 -05:00
Daniel Kahn Gillmor 1c6030024d add DNSOverride configuration for testing 2019-02-21 19:21:38 -05:00
Daniel Kahn Gillmor 71c0c3f20a Avoid failing to chown non-existent Unix-domain sockets
Changing ownership of sockets that doesn't exist isn't a great
practice.

A better approach would be to apply os.chown() to the file descriptor
of the open socket, but at the very least dkimpy-milter shouldn't
crash the way it currently does if the socket isn't already present.
2019-02-21 19:21:38 -05:00
Daniel Kahn Gillmor a9a6893c89 Handle unix: socket prefix the same as local:
sendmail's milter.c treats these two declarations the same way, so
what we do for one should also be done for the other.
2019-02-21 19:21:38 -05:00
Daniel Kahn Gillmor bb44f36519 When Socket is absolute path, do not strip leading /
This appears to just be an untested codepath.
2019-02-21 19:21:38 -05:00
Daniel Kahn Gillmor 9e11b75ec3 Avoid AttributeError on simple connection and disconnection
Without this patch, this simple script for miltertest:

----
conn = mt.connect("unix:milter.sock")
if conn == nil then
  error "mt.connect() failed"
end
if mt.conninfo(conn, nil, "unspec") ~= nil then
  error "mt.conninfo() failed"
end
if mt.getreply(conn) ~= SMFIR_CONTINUE then
     error "mt.conninfo() unexpected reply"
end
mt.disconnect(conn)
----

Produces the following error:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/Milter/__init__.py", line 702, in connect_callback
    return m.connect(hostname,family,hostaddr)
  File "/usr/lib/python2.7/dist-packages/Milter/__init__.py", line 173, in wrapper
    rc = func(self,*args)
  File "/home/dkg/src/dkimpy-milter/dkimpy-milter/dkimpy_milter/__init__.py", line 64, in connect
    self.receiver = self.getsymval('j').strip()
AttributeError: 'NoneType' object has no attribute 'strip'
2019-02-21 19:21:38 -05:00
Scott Kitterman 51c8fdcb6c Bump version to 1.0.1, update TODO, set release date 2019-02-11 15:14:11 -05:00
Scott Kitterman aa4dadc22f * Reorder milter start and dropping privileges so permissions on Unix socket
are correct (LP: 1797720)
2019-02-11 15:09:34 -05:00
Scott Kitterman b1abbf9d61 - Make domain checks case insensitive for determining if signing should be
done (LP: #1815311)
2019-02-11 14:55:35 -05:00
Scott Kitterman f38fed3bee Rip out unused whichbd module in preparation for python3 port 2019-02-11 03:16:53 -05:00
Scott Kitterman 4f21623f92 Add read_keytable function to util.py 2018-12-24 16:08:50 -05:00
Scott Kitterman c91a12f0d1 Documentation updates for 1.0.0 release 2018-05-11 14:29:15 -04:00
Scott Kitterman a2ff03727d - Put version directly in setup.py and do not import dkimpy_milter to ease
install via pip
2018-03-15 23:44:31 -04:00
Scott Kitterman f9483fea8c - Added protection for malformed From addresses. If the From does not at
least have an '@' in the address, then the signing domain is not extracted
   and the message will not be signed
2018-03-15 20:42:49 -04:00
Scott Kitterman 7a3a7bfb43 Bump version to 0.9.6 2018-03-12 22:08:07 -04:00
Scott Kitterman 8a0e1bdd97 - Fixed typo in path for fallback location of the config file if one is not
provided
2018-03-12 22:03:45 -04:00
Scott Kitterman 1d8c309da9 Fix setup.py install locations so they are installed correctly and drop unneeded README changes. 2018-03-10 20:06:21 -05:00
Scott Kitterman 4d5961e4d5 Bump version 2018-03-10 19:52:29 -05:00
Scott Kitterman 86eb152f93 Enhanced signature verification logging to provide more useful information, added signing success logging, and more PEP 8 2018-03-10 19:02:37 -05:00
Scott Kitterman 126966e110 - Update Authentication Results result comment not to mention key size for
ed25519 signatures, since it's irrelevant
2018-03-10 18:18:01 -05:00
Scott Kitterman 1843ca6244 - Added support for SyslogSuccess option
- Rationalized logging to be much less verbose unless SyslogSuccess or
   debugLevel are set - default is generally start/stop/errors only
2018-03-10 16:06:22 -05:00
Scott Kitterman f9358d594c Delete unused import 2018-03-10 15:36:40 -05:00
Scott Kitterman a8aa422b03 Post pep-8 cleanup 2018-03-10 15:34:56 -05:00
Scott Kitterman 70606ac58c pep8 and a few other cleanups 2018-03-10 02:45:35 -05:00
Scott Kitterman 6348bdcdc7 Cleanup, indentation, pyflakes 2018-03-10 00:52:45 -05:00
Scott Kitterman fd39384e78 Fix for DiagnosticDirectory 2018-03-09 23:49:57 -05:00
Scott Kitterman efeabd19d3 Added support for MacroListVerify option 2018-03-09 22:39:55 -05:00
Scott Kitterman a9b8a44bfc Add support for MacroList option 2018-03-09 21:53:58 -05:00
Scott Kitterman e795db7c69 Start 0.9.5: Beta 1 (updated Alpha -> Beta warning in README and trove classifiers) 2018-03-09 18:08:42 -05:00
Scott Kitterman 36ff60d8d3 - Added support for DiagnosticDirectory and updated dkimpy-milter specifics in
dkimpy-milter.conf.5
2018-03-09 17:10:48 -05:00
Scott Kitterman 4769bde19c - Added support for InternalHosts option (ipaddress and either dns (dnspython)
or pydns (DNS) modules are now required)
2018-03-09 16:29:49 -05:00
Scott Kitterman e6021dd960 Add dnsplug.py so either DNS or dns can be used for host/domain based dataset processing 2018-03-09 13:51:36 -05:00
Scott Kitterman df19aa081e - Added support for AuthservID option 2018-03-04 15:15:37 -05:00
Scott Kitterman fb32a8fe0b Implement detection of type db datasets, but not used yet 2018-03-04 13:56:06 -05:00