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.
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.
This test makes use of DNSOverride and the new verifying milter to
ensure that signatures can be verified properly.
It doesn't test the actual interaction with the public DNS, but
getting that kind of test to work on arbitrary platforms might be more
trouble than it's worth.
I note that the DNSOverride only works as long as testkey.dns is a
single line, which is fine for ed25519, but maybe not for RSA.
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.
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)