`dkimpy` in Python 3 does not work for 'verify' - AttributeError

Bug #1716968 reported by Thomas Ward
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dkimpy (Ubuntu)
Fix Released
High
Unassigned
Xenial
New
High
Unassigned

Bug Description

This is fixed in later releases of the `dkimpy` library, specifically tested was 0.6.2 to see if it's fixed.

`dkimpy` in Python 3 on Xenial *does not work* as expected when calling `verify` on a signed message in bytes form. It also fails for 'string' form, because it tries to use bytes patterns on a string object.

This affects 0.5.6-1, but is fixed in Artful and 0.6.2 already. (I'd go version by version to find a fix, but I'm not that concerned since I've already made a backport of `python3-dkim` in a PPA[1].

As this breaks one of the crucial functions (message verification with the `verify` function), I'm setting this as a "High" importance bug.

[1] https://launchpad.net/~teward/+archive/ubuntu/dkimpy-backports

Tags: xenial
Revision history for this message
Thomas Ward (teward) wrote :

When passing a signed message in as bytes to the function in Python 3:

Traceback (most recent call last):
  File "./dmarctests.py", line 45, in <module>
    print("VERIFY: ", dkim.verify(signedmsg))
  File "/usr/lib/python3/dist-packages/dkim/__init__.py", line 630, in verify
    return d.verify(dnsfunc=dnsfunc)
  File "/usr/lib/python3/dist-packages/dkim/__init__.py", line 563, in verify
    s = dnsfunc(name)
  File "/usr/lib/python3/dist-packages/dkim/dnsplug.py", line 84, in get_txt
    txt = txt.encode('utf-8')
AttributeError: 'bytes' object has no attribute 'encode'

Revision history for this message
Thomas Ward (teward) wrote :

When passing a signed message in as a UTF-8 string (decoded from bytes):

Traceback (most recent call last):
  File "./dmarctests.py", line 45, in <module>
    print("VERIFY: ", dkim.verify(signedmsg.decode('utf-8')))
  File "/usr/lib/python3/dist-packages/dkim/__init__.py", line 628, in verify
    d = DKIM(message,logger=logger,minkey=minkey)
  File "/usr/lib/python3/dist-packages/dkim/__init__.py", line 318, in __init__
    self.set_message(message)
  File "/usr/lib/python3/dist-packages/dkim/__init__.py", line 358, in set_message
    self.headers, self.body = rfc822_parse(message)
  File "/usr/lib/python3/dist-packages/dkim/__init__.py", line 207, in rfc822_parse
    lines = re.split(b"\r?\n", message)
  File "/usr/lib/python3.5/re.py", line 203, in split
    return _compile(pattern, flags).split(string, maxsplit)
TypeError: cannot use a bytes pattern on a string-like object

Thomas Ward (teward)
description: updated
Thomas Ward (teward)
Changed in dkimpy (Ubuntu):
status: New → Fix Released
Changed in dkimpy (Ubuntu Xenial):
importance: Undecided → High
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.