Minor cleanup for ARC

This commit is contained in:
Gene Shuman
2017-07-27 13:12:57 -07:00
parent 45dbdeabcf
commit 17d7c39155
+19 -3
View File
@@ -37,9 +37,14 @@ import hashlib
import logging
import re
import time
import sys
# only needed for arc
try:
from authres import AuthenticationResultsHeader
except:
pass
from authres import *
from authres.arc import *
from dkim.canonicalization import (
CanonicalizationPolicy,
@@ -144,6 +149,10 @@ class ValidationError(DKIMException):
"""Validation error."""
pass
class AuthresNotFoundError(DKIMException):
""" Authres Package not installed, needed for ARC """
pass
def select_headers(headers, include_headers):
"""Select message header fields to be signed/verified.
@@ -499,7 +508,6 @@ class DomainSigner(object):
sig = dict(fields)
headers = canon_policy.canonicalize_headers(self.headers)
self.signed_headers = hash_headers(
h, canon_policy, headers, include_headers, header, sig)
self.logger.debug("sign %s headers: %r" % (header_name, h.hashed()))
@@ -777,6 +785,14 @@ class ARC(DomainSigner):
#: formed.
def sign(self, selector, domain, privkey, srv_id, include_headers=None,
timestamp=None, standardize=False):
# check if authres has been imported
try:
AuthenticationResultsHeader
except:
self.logger.debug("authres package not installed")
raise AuthresNotFoundError
try:
pk = parse_pem_private_key(privkey)
except UnparsableKeyError as e: