Use parse_tag_value in verify().
This commit is contained in:
+11
-25
@@ -23,6 +23,11 @@ import time
|
|||||||
|
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
|
||||||
|
from dkim.util import (
|
||||||
|
InvalidTagValueList,
|
||||||
|
parse_tag_value,
|
||||||
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Simple",
|
"Simple",
|
||||||
"Relaxed",
|
"Relaxed",
|
||||||
@@ -498,19 +503,10 @@ def verify(message, debuglog=None, dnsfunc=dnstxt):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Currently, we only validate the first DKIM-Signature line found.
|
# Currently, we only validate the first DKIM-Signature line found.
|
||||||
|
try:
|
||||||
a = re.split(r"\s*;\s*", sigheaders[0][1].strip())
|
sig = parse_tag_value(sigheaders[0][1])
|
||||||
if debuglog is not None:
|
except InvalidTagValueList:
|
||||||
print >>debuglog, "a:", a
|
|
||||||
sig = {}
|
|
||||||
for x in a:
|
|
||||||
if x:
|
|
||||||
m = re.match(r"(\w+)\s*=\s*(.*)", x, re.DOTALL)
|
|
||||||
if m is None:
|
|
||||||
if debuglog is not None:
|
|
||||||
print >>debuglog, "invalid format of signature part: %s" % x
|
|
||||||
return False
|
return False
|
||||||
sig[m.group(1)] = m.group(2)
|
|
||||||
if debuglog is not None:
|
if debuglog is not None:
|
||||||
print >>debuglog, "sig:", sig
|
print >>debuglog, "sig:", sig
|
||||||
|
|
||||||
@@ -575,19 +571,9 @@ def verify(message, debuglog=None, dnsfunc=dnstxt):
|
|||||||
s = dnsfunc(sig['s']+"._domainkey."+sig['d']+".")
|
s = dnsfunc(sig['s']+"._domainkey."+sig['d']+".")
|
||||||
if not s:
|
if not s:
|
||||||
return False
|
return False
|
||||||
a = re.split(r"\s*;\s*", s)
|
try:
|
||||||
# Trailing ';' on signature record is valid, see RFC 4871 3.2
|
pub = parse_tag_value(s)
|
||||||
# tag-list = tag-spec 0*( ";" tag-spec ) [ ";" ]
|
except InvalidTagValueList:
|
||||||
if a[-1] == '':
|
|
||||||
a.pop(-1)
|
|
||||||
pub = {}
|
|
||||||
for f in a:
|
|
||||||
m = re.match(r"(\w+)=(.*)", f)
|
|
||||||
if m is not None:
|
|
||||||
pub[m.group(1)] = m.group(2)
|
|
||||||
else:
|
|
||||||
if debuglog is not None:
|
|
||||||
print >>debuglog, "invalid format in _domainkey txt record"
|
|
||||||
return False
|
return False
|
||||||
pk = parse_public_key(base64.b64decode(pub['p']))
|
pk = parse_public_key(base64.b64decode(pub['p']))
|
||||||
modlen = len(int2str(pk['modulus']))
|
modlen = len(int2str(pk['modulus']))
|
||||||
|
|||||||
Reference in New Issue
Block a user