From 805ec6c7d2b987a5e4349ba5804c6ba210b21ce5 Mon Sep 17 00:00:00 2001 From: Ettore Dreucci Date: Sat, 18 Oct 2025 19:21:52 +0200 Subject: [PATCH] Correctly handle RRSIG records, converting numeric type codes into their textual equivalents --- src/helpers.py | 25 ------------------------- src/technitium.py | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/helpers.py b/src/helpers.py index 78fc6f7..fa0158c 100644 --- a/src/helpers.py +++ b/src/helpers.py @@ -1,6 +1,5 @@ import logging import subprocess -import dns.zone from pathlib import Path from datetime import datetime, UTC @@ -141,27 +140,3 @@ def export_all_zones(trigger_path: str = "filesystem-change") -> list[Path]: logging.info("No zone files were written; skipping commit.") return written_files - - -def validate_zone(zone_name, content) -> bool: - def replace_type_codes(content): - pattern = re.compile(r'(RRSIG\s+)(\d+)(\s+)') - - def repl(match): - num = int(match.group(2)) - try: - text_type = dns.rdatatype.to_text(dns.rdatatype.RdataType(num)) - return f"{match.group(1)}{text_type}{match.group(3)}" - except Exception as e: - logging.warning(e) - return match.group(0) - - return pattern.sub(repl, content) - - try: - dns.zone.from_text(replace_type_codes(content), zone_name + '.', relativize=False) - logging.info(f"Zone {zone_name} parsed successfully") - return True - except Exception as e: - logging.error(f"Parse failed for zone {zone_name}: {e}") - return False diff --git a/src/technitium.py b/src/technitium.py index 3724352..465c2ad 100644 --- a/src/technitium.py +++ b/src/technitium.py @@ -1,12 +1,38 @@ import logging import requests +import dns.zone +import dns.rdatatype + from config import * -from helpers import validate_zone session = requests.Session() +def validate_zone(zone_name, content) -> bool: + def replace_type_codes(content): + pattern = re.compile(r'(RRSIG\s+)(\d+)(\s+)') + + def repl(match): + num = int(match.group(2)) + try: + text_type = dns.rdatatype.to_text(dns.rdatatype.RdataType(num)) + return f"{match.group(1)}{text_type}{match.group(3)}" + except Exception as e: + logging.warning(e) + return match.group(0) + + return pattern.sub(repl, content) + + try: + dns.zone.from_text(replace_type_codes(content), zone_name + '.', relativize=False) + logging.info(f"Zone {zone_name} parsed successfully") + return True + except Exception as e: + logging.error(f"Parse failed for zone {zone_name}: {e}") + return False + + def list_zones() -> list[dict]: url = f"{TECHNITIUM_API_BASE.rstrip('/')}{LIST_ZONES_ENDPOINT}?token={API_TOKEN}" logging.debug(f"Listing zones from {url}")