From 17d7c391555f49b32f860a7811d3a7a7f00aea50 Mon Sep 17 00:00:00 2001 From: Gene Shuman Date: Thu, 27 Jul 2017 13:12:57 -0700 Subject: [PATCH] Minor cleanup for ARC --- dkim/__init__.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/dkim/__init__.py b/dkim/__init__.py index 272e2a1..25fd0a8 100644 --- a/dkim/__init__.py +++ b/dkim/__init__.py @@ -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: