Add method to determine if a DKIM signature is present

Bug #1851141 reported by Scott Kitterman
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dkimpy
Fix Released
Wishlist
Scott Kitterman

Bug Description

I wish to use dkimpy to verify the authenticity of some emails, however not all of them have a DKIM check present in the header. I want to be able to differentiate between an invalid DKIM signature and no signature present.

I've looked at the source code for the verify() function (The one on line 848 of __init__.py) and it seems the first return is only triggered when no DKIM signature is present.

I've modified this function locally for my own purposes and it works great, but I was wondering if a "dkim.present()" feature could be added to the official dkimpy module so it becomes standard. I imagine it would have similar parameters to the verify() function, but it would just return "len([(x,y) for x,y in self.headers if x.lower() == b"dkim-signature"]) == 0" instead.

I've never made a patch before and I am rather new to Python so I'm not sure how that works, but this is what the new function would look like

  #: Checks if any DKIM signature is present
  #: @return: True if there is one or more DKIM signatures present or False otherwise
  def present(self):
    return (len([(x,y)] for x,y in self.headers if x.lower() == b"dkim-signature"]) > 0)

This function is a part of the dkim class (I put it just above the verify function. For reference here is how I call it:

message = *INSERT MESSAGE HERE*
d = dkim.DKIM(message)
present = d.present()
verify = d.verify()

I did have issues when trying to do "present = dkim.present(message)" so it seems I'm missing something (Claims module 'dkim' has no attribute 'present')

Changed in dkimpy:
assignee: nobody → Scott Kitterman (kitterman)
importance: Undecided → Wishlist
milestone: none → 1.0.0
status: New → Triaged
Revision history for this message
Scott Kitterman (kitterman) wrote :

This will be in the next release.

    - Add new DKIM.present function to allow applications to test if a DKIM
      signature is present without doing validation (LP: #1851141)

Changed in dkimpy:
status: Triaged → Fix Committed
Revision history for this message
Scott Kitterman (kitterman) wrote :

2019-12-09 Version 1.0.0
    - Add support for RFC 8460 tlsrpt DKIM signature processing (LP: #1847020)
    - Add async support with aiodns for DKIM verification (ARC not supported)
      (LP: #1847002)
    - Add new timeout parameter to enable DNS lookup timeouts to be adjusted
    - Add new DKIM.present function to allow applications to test if a DKIM
      signature is present without doing validation (LP: #1851141)
    - Support signature verification with RSAPublicKey formatted keys
      since, although rare, they are RFC 6376 specified (LP: #1851862)
    - Drop usage of pymilter Milter.dns in dnsplug since it doesn't support
      havine a timeout passed to it
    - Catch binascii related key format errors (LP: #1854477)

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.