[Git][NTPsec/ntpsec][master] ntpclients/ntpdig.py: mark the reply untrusted on MAC failure

Matt Selsky (@selsky) gitlab at mg.gitlab.com
Wed Nov 4 04:33:58 UTC 2026



Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
b27c2250 by Matt Selsky at 2026-11-04T04:32:14+00:00
ntpclients/ntpdig.py: mark the reply untrusted on MAC failure

read_append() checked the reply's MAC but marked the request bytes,
not the reply, so a MAC failure raised AttributeError instead of
reaching clock_select(), which drops untrusted replies. A reply with
no MAC crashed too: with -d, the debug message raised AttributeError
reading the request bytes' hostname; without it, verify_mac() raised
struct.error on the missing MAC.

Build the reply SyncPacket first, and mark it untrusted when it has
no MAC or its MAC fails verification.

- - - - -


1 changed file:

- ntpclients/ntpdig.py


Changes:

=====================================
ntpclients/ntpdig.py
=====================================
@@ -63,20 +63,21 @@ def read_append(s, packets, packet, sockaddr):
     d, a = s.recvfrom(1024)
     if debug >= 2:
         ntp.packet.dump_hex_printable(d)
+    pkt = ntp.packet.SyncPacket(d)
+    pkt.hostname = server
+    pkt.resolved = sockaddr[0]
     if credentials:
         if not ntp.packet.Authenticator.have_mac(d):
+            pkt.trusted = False
             if debug:
-                log("no MAC on reply from %s" % packet.hostname)
-        if not credentials.verify_mac(d, packet_end=48, mac_begin=48):
-            packet.trusted = False
+                log("no MAC on reply from %s" % sockaddr[0])
+        elif not credentials.verify_mac(d, packet_end=48, mac_begin=48):
+            pkt.trusted = False
             log("MAC verification on reply from %s failed"
                 % sockaddr[0])
         elif debug:
             log("MAC verification on reply from %s succeeded"
                 % sockaddr[0])
-    pkt = ntp.packet.SyncPacket(d)
-    pkt.hostname = server
-    pkt.resolved = sockaddr[0]
     packets.append(pkt)
     return packets
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/b27c2250117589e522d7b5bb07f775b5cd911b3b

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/b27c2250117589e522d7b5bb07f775b5cd911b3b
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20261104/8fe0d0c0/attachment-0001.htm>


More information about the vc mailing list