diff --git a/ChangeLog b/ChangeLog index ce3c884..d694d42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ Version 1.1 - Add support for PKCS#8 for private keys, openssl 3 default (LP: #1978835) - Thanks to Adrien (spitap) for the change - Add limitations section to README to document current IDN status + - Add USE_ASYNC flag to allow async to be disabled when aiodns is + installed (LP: #1954331) - see README.md for details 2019-12-31 Version 1.0.2 - dknewkey: On posix operating systems set file permissions to 600 for diff --git a/README.md b/README.md index ba3c652..17c5aef 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,9 @@ Here is a simple example of dkim.verify_async usage: This feature requires python3.5 or newer. +If aiodns is available, the async functions will be used. To avoide async +when aiodns is availale, set dkim.USE_ASYNC = False. + ## TLSRPT (TLS Report) As of version 1.0, the RFC 8460 tlsrpt service type is supported: diff --git a/dkim/__init__.py b/dkim/__init__.py index acdad51..f19b9d7 100644 --- a/dkim/__init__.py +++ b/dkim/__init__.py @@ -40,6 +40,9 @@ import sys import time import binascii +# Set to False to not use async functions even though aiodns is installed. +USE_ASYNC = True + # only needed for arc try: from authres import AuthenticationResultsHeader @@ -72,13 +75,17 @@ from dkim.crypto import ( try: from dkim.dnsplug import get_txt except ImportError: - try: - import aiodns - from dkim.asyncsupport import get_txt_async as get_txt - except: - # Only true if not using async - def get_txt(s,timeout=5): - raise RuntimeError("DKIM.verify requires DNS or dnspython module") + if USE_ASYNC: + try: + import aiodns + from dkim.asyncsupport import get_txt_async as get_txt + except: + # Only true if not using async + def get_txt(s,timeout=5): + raise RuntimeError("DKIM.verify requires DNS or dnspython module") + else: + raise RuntimeError("DKIM.verify requires DNS or dnspython module") + from dkim.util import ( get_default_logger, InvalidTagValueList, @@ -94,6 +101,7 @@ __all__ = [ "ValidationError", "AuthresNotFoundError", "NaClNotFoundError", + "USE_ASYNC", "CV_Pass", "CV_Fail", "CV_None", @@ -1369,7 +1377,7 @@ def verify(message, logger=None, dnsfunc=get_txt, minkey=1024, # aiodns requires Python 3.5+, so no async before that -if sys.version_info >= (3, 5): +if sys.version_info >= (3, 5) and USE_ASYNC: try: import aiodns from dkim.asyncsupport import verify_async