summaryrefslogtreecommitdiff
path: root/dns/tsig.py
diff options
context:
space:
mode:
authorNick Hall <nick.hall@deshaw.com>2020-08-07 23:00:36 +0100
committerNick Hall <nick.hall@deshaw.com>2020-08-08 01:21:24 +0100
commita7ae91d15d62798567e9c6ef5758779ef2654bb6 (patch)
tree864c77c73e9009e5f10b7969d3b04d3c318a534b /dns/tsig.py
parent40bf9335e823a6760614b4a835ebd06af4279c66 (diff)
downloaddnspython-a7ae91d15d62798567e9c6ef5758779ef2654bb6.tar.gz
Support callable() TSIG keyrings for use-cases like GSSTSig.
Diffstat (limited to 'dns/tsig.py')
-rw-r--r--dns/tsig.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/dns/tsig.py b/dns/tsig.py
index 9361412..ab45951 100644
--- a/dns/tsig.py
+++ b/dns/tsig.py
@@ -102,6 +102,38 @@ class GSSTSig:
raise BadSignature
+class GSSTSigAdapter:
+ def __init__(self, keyring):
+ self.keyring = keyring
+
+ def __call__(self, message, keyname):
+ if keyname in self.keyring:
+ key = self.keyring[keyname]
+ if isinstance(key, Key) and key.algorithm == GSS_TSIG:
+ if message:
+ GSSTSigAdapter.parse_tkey_and_step(key, message, keyname)
+ return key
+ else:
+ return None
+
+ @classmethod
+ def parse_tkey_and_step(cls, key, message, keyname):
+ # if the message is a TKEY type, absorb the key material
+ # into the context using step(); this is used to allow the
+ # client to complete the GSSAPI negotiation before attempting
+ # to verify the signed response to a TKEY message exchange
+ try:
+ rrset = message.find_rrset(message.answer, keyname,
+ dns.rdataclass.ANY,
+ dns.rdatatype.TKEY)
+ if rrset:
+ token = rrset[0].key
+ gssapi_context = key.secret
+ return gssapi_context.step(token)
+ except KeyError:
+ pass
+
+
class HMACTSig:
"""
HMAC TSIG implementation. This uses the HMAC python module to handle the