Asynchronous verification fails on missing header

Bug #2008723 reported by Nikita Sychev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dkimpy
Fix Released
High
Scott Kitterman

Bug Description

Hello!

Thanks for your library!

I'm trying to switch my old project from older dkimpy version and I decided to try new async functions.

Unfortunately, when I tried to send myself an e-mail without DKIM-Signature header at all, it failed. Here is the stacktrace:

  File "/usr/lib/python3.10/site-packages/aiosmtpd/smtp.py", line 741, in _handle_client
    await method(arg)
  File "/usr/lib/python3.10/site-packages/aiosmtpd/smtp.py", line 1460, in smtp_DATA
    status = await self._call_handler_hook('DATA')
  File "/usr/lib/python3.10/site-packages/aiosmtpd/smtp.py", line 473, in _call_handler_hook
    status = await hook(self, self.session, self.envelope, *args)
  File "/usr/lib/python3.10/site-packages/aiosmtpd/handlers.py", line 228, in handle_DATA
    await self.handle_message(message)
  File "<hidden>", line 26, in handle_message
    dkim_result = await dkim.verify_async(message.as_bytes())
  File "/usr/lib/python3.10/site-packages/dkim/asyncsupport.py", line 119, in verify_async
    return await d.verify(dnsfunc=dnsfunc)
  File "/usr/lib/python3.10/site-packages/dkim/asyncsupport.py", line 97, in verify
    sig, include_headers, sigheaders = self.verify_headerprep(idx=0)
TypeError: cannot unpack non-iterable bool object

Now I just catch TypeError on my side, but actually here the patch:

--- dkim/asyncsupport.py 2023-02-27 23:31:56.605726566 +0600
+++ dkim/asyncsupport.py.patched 2023-02-27 23:39:38.526180586 +0600
@@ -94,7 +94,10 @@

   async def verify(self,idx=0,dnsfunc=get_txt_async):
- sig, include_headers, sigheaders = self.verify_headerprep(idx=0)
+ prep = self.verify_headerprep(idx=0)
+ if not prep:
+ return False
+ sig, include_headers, sigheaders = prep
     return await self.verify_sig(sig, include_headers, sigheaders[idx], dnsfunc)

I didn't find a better way to send patches here, so I hope it's OK to do it here.

Revision history for this message
Scott Kitterman (kitterman) wrote :

Thanks. I'll look into it and plan to fix it for the next release.

Changed in dkimpy:
status: New → Triaged
importance: Undecided → High
milestone: none → 1.1.1
Revision history for this message
Scott Kitterman (kitterman) wrote :

That looks mostly correct. I did it slightly differently in the non-async version of verify. The only issue I see is that the prep = line should have (idx) vice (idx=0) as the idx=0 will override any idx value passed into the function. Thanks. I fixed it to be like the non-async version.

Your patch made it super easy to pinpoint what to do. Very much appreciated. Fix committed to git for the next release.

Changed in dkimpy:
assignee: nobody → Scott Kitterman (kitterman)
status: Triaged → Fix Committed
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.