[PATCH] Body length not cast as bytes

Bug #1541341 reported by toxinu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dkimpy
Fix Released
Medium
Unassigned

Bug Description

This bug only occur with Python 3 (tested with 3.4).
When building signed headers with `length=True`, `sign` crash.

Test that show bug:

```
    def test_add_body_length(self):
        sig = dkim.sign(
            self.message, b"test", b"example.com", self.key, length=True)
        msg = email.message_from_string(self.message)
        self.assertIn('\n l=%s' % len(msg.get_payload() + '\n'), sig)
        res = dkim.verify(sig + self.message, dnsfunc=self.dnsfunc)
        self.assertTrue(res)
```

======================================================================
ERROR: test_add_body_length (dkim.tests.test_dkim.TestSignAndVerify)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/glehee/Documents/Repositories/dkimpy/dkim/tests/test_dkim.py", line 93, in test_add_body_length
    self.message, b"test", b"example.com", self.key, length=True)
  File "/home/glehee/Documents/Repositories/dkimpy/dkim/__init__.py", line 620, in sign
    return d.sign(selector, domain, privkey, identity=identity, canonicalize=canonicalize, include_headers=include_headers, length=length)
  File "/home/glehee/Documents/Repositories/dkimpy/dkim/__init__.py", line 481, in sign
    sig_value = fold(b"; ".join(b"=".join(x) for x in sigfields))
  File "/home/glehee/Documents/Repositories/dkimpy/dkim/__init__.py", line 481, in <genexpr>
    sig_value = fold(b"; ".join(b"=".join(x) for x in sigfields))
TypeError: sequence item 1: expected a bytes-like object, int found

You can found this work on our github branch here:

https://github.com/oasiswork/dkimpy/commit/b103863a54a420a74584a00754740f606198e6f2

Revision history for this message
toxinu (toxinu) wrote :
description: updated
summary: - Body length not cast as bytes
+ [PATCH] Body length not cast as bytes
Revision history for this message
Scott Kitterman (kitterman) wrote :

Fixed in revision 134. Will be included in 0.6.2.

Changed in dkimpy:
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Scott Kitterman (kitterman) wrote :

2017-05-30 Version 0.6.2
    - Fixed problem with header folding that caused the first line to be
      folded too long (Updated test test_add_body_length since l= tag is no
      longer at the beginning of a line)
    - Fixed python3.4 string interpolation issue
    - Fix some byte casting issues & typos
    - Add test case for verification when should headers are signed
    - Check and update references:
      * Replace RFC 4871 withRFC 6376
      * Replaace RFC 3447 with RFC 8017
      * Add mention of DCRUP working group addressing key length issues

Changed in dkimpy:
status: Fix Committed → Fix Released
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.