X-Git-Url: https://git.ralfj.de/zonemaker.git/blobdiff_plain/6eba900abc6dc54d9ef740090d4522ee80b62ef6..111ccda4aef2cd5ac0c6ea7e94646b1d27b04e5f:/zone.py diff --git a/zone.py b/zone.py index 68a82b3..c311a21 100644 --- a/zone.py +++ b/zone.py @@ -56,6 +56,13 @@ def check_hex(data: str) -> str: return data raise Exception(data+" is not valid hex data") +def check_base64(data: str) -> str: + data = str(data) + if re.match('^[a-zA-Z0-9+/=]+$', data): + return data + raise Exception(data+" is not valid hex data") + + def check_ipv4(address: str) -> str: address = str(address) if re.match(REGEX_ipv4, address): @@ -135,7 +142,7 @@ class MX: class TXT: - def __init__(self, name: str, text: str) -> None: + def __init__(self, text: str) -> None: # test for bad characters for c in ('\n', '\r', '\t'): if c in text: @@ -149,6 +156,24 @@ class TXT: return zone.RR(owner, 'TXT', '"{0}"'.format(self._text)) +class DKIM(TXT): # helper class to treat DKIM more antively + class Version: + DKIM1 = "DKIM1" + + class Algorithm: + RSA = "rsa" + + def __init__(self, selector, version, alg, key): + self._selector = check_label(selector) + version = check_label(version) + alg = check_label(alg) + key = check_base64(key) + super().__init__("v={0}; k={1}; p={2}".format(version, alg, key)) + + def generate_rr(self, owner, zone): + return super().generate_rr('{0}._domainkey.{1}'.format(self._selector, zone.abs_hostname(owner)), zone) + + class SRV: def __init__(self, protocol: str, service: str, name: str, port: int, prio: int, weight: int) -> None: self._service = check_label(service)