[Git][NTPsec/ntpsec][master] pylib/packet.py: check response MACs only on authenticated queries
Matt Selsky (@selsky)
gitlab at mg.gitlab.com
Wed Nov 4 03:22:43 UTC 2026
Matt Selsky pushed to branch master at NTPsec / ntpsec
Commits:
fb0c5a23 by James Browning at 2026-11-04T03:22:40+00:00
pylib/packet.py: check response MACs only on authenticated queries
ntpd MACs a mode 6 response only when the request was authenticated,
but getresponse() checked the MAC whenever the session had
credentials, so ntpq -a/-k warned "packet too short for MAC" on every
unauthenticated query. Pass the request's auth flag (or always_auth)
through to getresponse() and check the MAC only then.
Fixes #864.
- - - - -
2 changed files:
- pylib/packet.py
- tests/pylib/test_packet.py
Changes:
=====================================
pylib/packet.py
=====================================
@@ -953,7 +953,7 @@ class ControlSession:
pkt.extension += ntp.poly.polybytes(mac)
return pkt.send()
- def getresponse(self, opcode, associd, timeo):
+ def getresponse(self, opcode, associd, timeo, auth=False):
"Get a response expected to match a given opcode and associd."
# This is pretty tricky. We may get between 1 and MAXFRAG packets
# back in response to the request. We peel the data out of
@@ -1038,7 +1038,7 @@ class ControlSession:
continue
# Someday, perhaps, check authentication here
- if self._authpass and self.auth:
+ if auth and self._authpass and self.auth:
_pend = rpkt.count + MODE_SIX_HEADER_LENGTH
_pend += (-_pend % MODE_SIX_ALIGNMENT)
if len(rawdata) < (_pend + KEYID_LENGTH + MINIMUM_MAC_LENGTH):
@@ -1204,12 +1204,13 @@ class ControlSession:
if not self.havehost():
raise ControlException(SERR_NOHOST)
retry = True
+ auth |= self.always_auth
while True:
# Ship the request
self.sendrequest(opcode, associd, qdata, auth)
# Get the response.
try:
- res = self.getresponse(opcode, associd, not retry)
+ res = self.getresponse(opcode, associd, not retry, auth)
except ControlException as e:
if retry and e.message in (SERR_TIMEOUT, SERR_INCOMPLETE):
retry = False
=====================================
tests/pylib/test_packet.py
=====================================
@@ -1395,7 +1395,7 @@ class TestControlSession(unittest.TestCase):
gets = []
doerror = [False]
- def getresponse_jig(opcode, associd, retry):
+ def getresponse_jig(opcode, associd, retry, _auth):
gets.append((opcode, associd, retry))
if doerror[0]:
doerror[0] = False
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/fb0c5a23bbefafb79cd20f266ae1639018b26876
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/fb0c5a23bbefafb79cd20f266ae1639018b26876
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/df60d4d0/attachment-0001.htm>
More information about the vc
mailing list