Add USE_ASYNC flag to allow async to be disabled when aiodns is

installed (LP: #1954331) - see README.md for details
This commit is contained in:
Scott Kitterman
2023-02-25 16:25:20 -05:00
parent 50a81ab8d6
commit 233a9699ed
3 changed files with 21 additions and 8 deletions
+2
View File
@@ -13,6 +13,8 @@ Version 1.1
- Add support for PKCS#8 for private keys, openssl 3 default (LP: - Add support for PKCS#8 for private keys, openssl 3 default (LP:
#1978835) - Thanks to Adrien (spitap) for the change #1978835) - Thanks to Adrien (spitap) for the change
- Add limitations section to README to document current IDN status - 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 2019-12-31 Version 1.0.2
- dknewkey: On posix operating systems set file permissions to 600 for - dknewkey: On posix operating systems set file permissions to 600 for
+3
View File
@@ -197,6 +197,9 @@ Here is a simple example of dkim.verify_async usage:
This feature requires python3.5 or newer. 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) ## TLSRPT (TLS Report)
As of version 1.0, the RFC 8460 tlsrpt service type is supported: As of version 1.0, the RFC 8460 tlsrpt service type is supported:
+16 -8
View File
@@ -40,6 +40,9 @@ import sys
import time import time
import binascii import binascii
# Set to False to not use async functions even though aiodns is installed.
USE_ASYNC = True
# only needed for arc # only needed for arc
try: try:
from authres import AuthenticationResultsHeader from authres import AuthenticationResultsHeader
@@ -72,13 +75,17 @@ from dkim.crypto import (
try: try:
from dkim.dnsplug import get_txt from dkim.dnsplug import get_txt
except ImportError: except ImportError:
try: if USE_ASYNC:
import aiodns try:
from dkim.asyncsupport import get_txt_async as get_txt import aiodns
except: from dkim.asyncsupport import get_txt_async as get_txt
# Only true if not using async except:
def get_txt(s,timeout=5): # Only true if not using async
raise RuntimeError("DKIM.verify requires DNS or dnspython module") 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 ( from dkim.util import (
get_default_logger, get_default_logger,
InvalidTagValueList, InvalidTagValueList,
@@ -94,6 +101,7 @@ __all__ = [
"ValidationError", "ValidationError",
"AuthresNotFoundError", "AuthresNotFoundError",
"NaClNotFoundError", "NaClNotFoundError",
"USE_ASYNC",
"CV_Pass", "CV_Pass",
"CV_Fail", "CV_Fail",
"CV_None", "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 # 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: try:
import aiodns import aiodns
from dkim.asyncsupport import verify_async from dkim.asyncsupport import verify_async