Commit Graph

111 Commits

Author SHA1 Message Date
Scott Kitterman e930257b6b - Delete own_socketfile to resolve race condition where the permissions
change fails on a Unix socket because it hasn't been created yet (libmilter
   will do this correctly on its own based on umask, the milter doesn't need
   to do it) (LP: #1849712)
2019-10-29 02:50:40 -04:00
Scott Kitterman 887a0c4b2a SigningTable refactor to work with the revised table structure - mostly works, but not thoroughly tested 2019-10-29 02:42:48 -04:00
Scott Kitterman 5b956b9c7d Refactor SigningTable and KeyTables based on more careful reading of the documentation 2019-10-29 01:50:28 -04:00
Scott Kitterman 82542e4ca0 Remove vestiges of SigningTableEd25519, separate per algorithm table not needed 2019-10-23 15:54:51 -04:00
Scott Kitterman 0115bf7c7c Add support for using signing table with % only - still very incomplete. 2019-10-22 23:35:58 -04:00
Scott Kitterman 5349d1b3ae Refactor multi-line datasets so it works with single and multiline (both KeyTable and SigningTable) 2019-10-22 23:33:31 -04:00
Scott Kitterman f93dbeb966 Move _get_parent_domain into dkimMilter classs as get_parent_domain 2019-10-22 20:14:18 -04:00
Scott Kitterman d6b0acb101 Refactor signing domain determination into get_identities_sign function and add support for passing i= when signing in prepartation for parsing the signing table 2019-10-22 19:45:18 -04:00
Scott Kitterman ec55aac974 Refactor util.read_keytable to work with multi-line dataset format from util._dataset_to_list 2019-10-21 14:05:58 -04:00
Scott Kitterman 43f6272b0d Complete multi-row dataset implementation for KeyTable* and SingingTable* 2019-10-21 14:00:17 -04:00
Scott Kitterman 5588748795 Refactor and update loading keys (file and table) to both are now loaded 2019-10-20 02:43:06 -04:00
Scott Kitterman 1097894eac Editorial nits 2019-10-19 12:34:22 -04:00
Scott Kitterman e9f95e0937 Refactor: move reading keys into util.get_keys in preparation for table variants 2019-10-19 03:50:17 -04:00
Scott Kitterman 0ac431a1bb Add new Table config items to nameConversion, not setting defaults 2019-10-19 03:38:56 -04:00
Scott Kitterman d0bc03453f Use self.conf vice milterconfig in dkimMilter to make sure config doesn't change while running 2019-10-19 03:31:29 -04:00
Scott Kitterman 2106e2b1f6 Refactor private key internal storage, it is now part of the milterconfig dict 2019-10-19 02:51:44 -04:00
Scott Kitterman 70d10f9b1a Make error logging more explicit to aid debugging 2019-10-18 23:24:12 -04:00
Scott Kitterman 3b3e64c058 More reslience fixes 2019-09-23 11:35:44 -04:00
Scott Kitterman d24b298dce Merge branch 'master' of git+ssh://git.launchpad.net/dkimpy-milter 2019-09-23 11:23:30 -04:00
Scott Kitterman 47b7e9892f Catch more ascii encoding errors to improve resilience against bad data
(LP: #1844189)
2019-09-23 11:01:32 -04:00
Scott Kitterman 68e61d419b Catch more ascii encoding errors to improve resilience against bad data
(LP: #1844189)
2019-09-23 10:28:43 -04:00
Scott Kitterman 5800d25e0c Fix variable initialization so mailformed mails missing body From do not
cause a traceback (LP: #1844161)
2019-09-16 20:05:11 -04:00
Scott Kitterman 708e94f266 Add debug logging for content type to assist troubleshooting MIME
conversion issues
2019-09-11 15:31:15 -04:00
Scott Kitterman f0871078ac Add support for SignHeaders feature, thanks to Ralph Seichter for the patch 2019-09-11 13:53:54 -04:00
Scott Kitterman 34d440c7a7 Fixup missing i= processing 2019-09-06 00:27:26 -04:00
Scott Kitterman 5a68cf9e25 - Fix message extraction so that signing in the same pass through the milter
as verifying works correctly
2019-09-05 23:52:07 -04:00
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