From 5770740587482fdd48ae6b6a9bcfada95b162936 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 23 Jul 2020 09:47:49 +1000 Subject: [PATCH 1/2] Map DNS_R_BADTSIG to FORMERR Now that the log message has been printed set the result code to DNS_R_FORMERR. We don't do this via dns_result_torcode() as we don't want upstream errors to produce FORMERR if that processing end with DNS_R_BADTSIG. (cherry picked from commit 20488d6ad36c7b48f043e583ff32eb14ca52f035) --- bin/named/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/named/client.c b/bin/named/client.c index 9a0d3c8009..f4a5ff9f9b 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -2685,7 +2685,7 @@ client_request(isc_task_t *task, isc_event_t *event) { NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(1), "message parsing failed: %s", isc_result_totext(result)); - if (result == ISC_R_NOSPACE) { + if (result == ISC_R_NOSPACE || result == DNS_R_BADTSIG) { result = DNS_R_FORMERR; } ns_client_error(client, result); From d3281b80a915e47b9a73287ae28c66a5c820891f Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Fri, 31 Jul 2020 20:36:14 +1000 Subject: [PATCH 2/2] Check rcode is FORMERR (cherry picked from commit 88ff6b846c652ea903913d58787fb4fe4c82ab91) --- bin/tests/system/packet.pl | 37 +++++++++++++++++++++++++++++-- bin/tests/system/tsig/badlocation | 37 +++++++++++++++++++++++++++++++ bin/tests/system/tsig/clean.sh | 1 + bin/tests/system/tsig/tests.sh | 12 ++++++++++ util/copyrights | 1 + 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 bin/tests/system/tsig/badlocation diff --git a/bin/tests/system/packet.pl b/bin/tests/system/packet.pl index 4cf1a775c1..30500630ec 100644 --- a/bin/tests/system/packet.pl +++ b/bin/tests/system/packet.pl @@ -46,12 +46,12 @@ use IO::File; use IO::Socket; sub usage { - print ("Usage: packet.pl [-a address] [-p port] [-t (tcp|udp)] [file]\n"); + print ("Usage: packet.pl [-a address] [-p port] [-t (tcp|udp)] -d [file]\n"); exit 1; } my %options={}; -getopts("a:p:t:", \%options); +getopts("a:dp:t:", \%options); my $addr = "127.0.0.1"; $addr = $options{a} if defined $options{a}; @@ -96,5 +96,38 @@ if ($proto eq "udp") { } print ("sent $bytes bytes to $addr:$port\n"); +if (defined $options{d}) { + use Net::DNS; + use Net::DNS::Packet; + + my $rin; + my $rout; + $rin = ''; + vec($rin, fileno($sock), 1) = 1; + select($rout = $rin, undef, undef, 1); + if (vec($rout, fileno($sock), 1)) {{ + my $buf; + if ($proto eq "udp") { + $sock->recv($buf, 512); + } else { + my $n = $sock->sysread($buf, 2); + last unless $n == 2; + my $len = unpack("n", $buf); + $n = $sock->sysread($buf, $len); + last unless $n == $len; + } + + my $response; + if ($Net::DNS::VERSION > 0.68) { + $response = new Net::DNS::Packet(\$buf, 0); + $@ and die $@; + } else { + my $err; + ($response, $err) = new Net::DNS::Packet(\$buf, 0); + $err and die $err; + } + $response->print; + }} +} $sock->close; close $file; diff --git a/bin/tests/system/tsig/badlocation b/bin/tests/system/tsig/badlocation new file mode 100644 index 0000000000..4477423644 --- /dev/null +++ b/bin/tests/system/tsig/badlocation @@ -0,0 +1,37 @@ +# Transaction ID +1122 +# Standard query +0000 +# Questions: 1, Additional: 1 +0001 0000 0001 0000 +# QNAME: isc.org +03 69 73 63 03 6F 72 67 00 +# Type: A (Host Address) +0001 +# Class: IN +0001 +# Specially crafted TSIG Resource Record +# Name: "sha256" +06 73 68 61 32 35 36 00 +# Type: TSIG (Transaction Signature) +00fa +# Class: ANY +00ff +# TTL: 0 +00000000 +# RdLen: 29 +001d +# Algorithm Name: hmac-sha256 +0b 68 6D 61 63 2D 73 68 61 32 35 36 00 +# Time Signed: Jan 1, 1970 01:00:00.000000000 CET +00 00 00 00 00 00 +# Fudge: 300 +012c +# MAC Size: 0; MAC: empty +0000 +# Original ID: 0 +0000 +# Error: no error +0000 +# Other Data Length: 0 +0000 diff --git a/bin/tests/system/tsig/clean.sh b/bin/tests/system/tsig/clean.sh index 576ec70f76..ef92a3263b 100644 --- a/bin/tests/system/tsig/clean.sh +++ b/bin/tests/system/tsig/clean.sh @@ -20,3 +20,4 @@ rm -f */named.run rm -f ns*/named.lock rm -f Kexample.net.+163+* rm -f keygen.out? +rm -f packet.out diff --git a/bin/tests/system/tsig/tests.sh b/bin/tests/system/tsig/tests.sh index fdce9155b2..526dbca74c 100644 --- a/bin/tests/system/tsig/tests.sh +++ b/bin/tests/system/tsig/tests.sh @@ -227,5 +227,17 @@ if [ $ret -eq 1 ] ; then echo_i "failed"; status=1 fi +if "$PERL" -e 'use Net::DNS; use Net::DNS::Packet;' > /dev/null 2>&1 +then + echo_i "check that TSIG in the wrong place returns FORMERR" + ret=0 + $PERL ../packet.pl -a 10.53.0.1 -p ${PORT} -t udp -d < badlocation > packet.out + grep "rcode = FORMERR" packet.out > /dev/null || ret=1 + if [ $ret -eq 1 ] ; then + echo_i "failed"; status=1 + fi +fi + + echo_i "exit status: $status" [ $status -eq 0 ] || exit 1 diff --git a/util/copyrights b/util/copyrights index 1b1005d95a..13caa5b821 100644 --- a/util/copyrights +++ b/util/copyrights @@ -2366,6 +2366,7 @@ ./bin/tests/system/tkey/prereq.sh SH 2001,2004,2006,2007,2009,2012,2014,2016,2018,2019,2020 ./bin/tests/system/tkey/setup.sh SH 2001,2004,2007,2009,2012,2013,2014,2016,2018,2019,2020 ./bin/tests/system/tkey/tests.sh SH 2001,2004,2007,2009,2011,2012,2013,2014,2016,2018,2019,2020 +./bin/tests/system/tsig/badlocation X 2020 ./bin/tests/system/tsig/badtime X 2020 ./bin/tests/system/tsig/clean.sh SH 2005,2006,2007,2012,2014,2016,2018,2019,2020 ./bin/tests/system/tsig/ns1/example.db ZONE 2005,2006,2007,2009,2012,2016,2018,2019,2020