diff --git a/scapy/layers/dns.py b/scapy/layers/dns.py index 432b0a06066..fe534abbc94 100644 --- a/scapy/layers/dns.py +++ b/scapy/layers/dns.py @@ -1138,11 +1138,11 @@ class DNSRRTSIG(_DNSRRdummy): DNSStrField("algo_name", "hmac-sha1"), TimeSignedField("time_signed", 0), ShortField("fudge", 0), - FieldLenField("mac_len", 20, fmt="!H", length_of="mac_data"), # noqa: E501 + FieldLenField("mac_len", None, fmt="!H", length_of="mac_data"), # noqa: E501 StrLenField("mac_data", "", length_from=lambda pkt: pkt.mac_len), # noqa: E501 ShortField("original_id", 0), ShortField("error", 0), - FieldLenField("other_len", 0, fmt="!H", length_of="other_data"), # noqa: E501 + FieldLenField("other_len", None, fmt="!H", length_of="other_data"), # noqa: E501 StrLenField("other_data", "", length_from=lambda pkt: pkt.other_len) # noqa: E501 ] diff --git a/test/scapy/layers/dns_dnssec.uts b/test/scapy/layers/dns_dnssec.uts index 631f7237921..2882aa3a1f6 100644 --- a/test/scapy/layers/dns_dnssec.uts +++ b/test/scapy/layers/dns_dnssec.uts @@ -132,11 +132,20 @@ t.type == 16 and t.rdlen == 312 and t.rdata[0][:5] == b"Scapy" and t.rdata[1][-1 = DNSRRTSIG basic instantiation t = DNSRRTSIG() -raw(t) == b"\x00\x00\xfa\x00\x01\x00\x00\x00\x00\x00\x1b\thmac-sha1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00" +raw(t) == b"\x00\x00\xfa\x00\x01\x00\x00\x00\x00\x00\x1b\thmac-sha1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" = DNSRRTSIG(), check parameters t = DNSRRTSIG(rrname="SAMPLE-ALG.EXAMPLE.", time_signed=853804800, fudge=300) -raw(t) == b"\nSAMPLE-ALG\x07EXAMPLE\x00\x00\xfa\x00\x01\x00\x00\x00\x00\x00\x1b\thmac-sha1\x00\x00\x002\xe4\x07\x00\x01,\x00\x14\x00\x00\x00\x00\x00\x00" +raw(t) == b"\nSAMPLE-ALG\x07EXAMPLE\x00\x00\xfa\x00\x01\x00\x00\x00\x00\x00\x1b\thmac-sha1\x00\x00\x002\xe4\x07\x00\x01,\x00\x00\x00\x00\x00\x00\x00\x00" + += DNSRRTSIG mac_len/other_len auto-computed, round-trips +# Regression: mac_len/other_len defaulted to a hardcoded 20/0 instead of None, +# so FieldLenField never auto-computed and a non-empty MAC did not round-trip +# (the length prefix stayed 20, truncating the MAC to 20 bytes on re-dissect). +t = DNSRRTSIG(mac_data=b"M" * 32, other_data=b"O" * 6) +raw_t = raw(t) +p = DNSRRTSIG(raw_t) +p.mac_len == 32 and p.other_len == 6 and p.mac_data == b"M" * 32 and p.other_data == b"O" * 6 and raw(p) == raw_t = TimeField methods