- Add new DKIM.present function to allow applications to test if a DKIM

signature is present without doing validation (LP: #1851141)
This commit is contained in:
Scott Kitterman
2019-11-03 11:57:30 -05:00
parent 2dc071962d
commit 2973852fbb
3 changed files with 17 additions and 0 deletions
+5
View File
@@ -872,6 +872,11 @@ class DKIM(DomainSigner):
self.signature_fields = dict(sigfields)
return b'DKIM-Signature: ' + res
#: 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)
#: Verify a DKIM signature.
#: @type idx: int
#: @param idx: which signature to verify. The first (topmost) signature is 0.
+10
View File
@@ -300,6 +300,16 @@ p=11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo="""
res = dkim.verify(sig + self.message, dnsfunc=self.dnsfunc)
self.assertTrue(res)
def test_present(self):
# Test DKIM.present().
d = dkim.DKIM(self.message,signature_algorithm=b'rsa-sha256')
present = d.present()
self.assertFalse(present)
sig = d.sign(b"test", b"example.com", self.key)
signed = sig + self.message
d2 = dkim.DKIM(signed)
present = d2.present()
self.assertTrue(present)
def test_badly_encoded_domain_fails(self):
# Domains should be ASCII. Bad ASCII causes verification to fail.