Blame SOURCES/bind-9.11-CVE-2018-5745-testfix.patch

a2a915
From aea8a7bab922a8793f6c50af30bdfa424a7f706d Mon Sep 17 00:00:00 2001
a2a915
From: Petr Mensik <pemensik@redhat.com>
a2a915
Date: Thu, 5 Sep 2019 20:24:25 +0200
a2a915
Subject: [PATCH] Fix mkeys test changes backported
a2a915
MIME-Version: 1.0
a2a915
Content-Type: text/plain; charset=UTF-8
a2a915
Content-Transfer-Encoding: 8bit
a2a915
a2a915
Squashed commit of the following:
a2a915
a2a915
commit a6cbd45fcfe2b1dc5339da72eed0ffeb27afdf81
a2a915
Author: Petr Mensik <pemensik@redhat.com>
a2a915
Date:   Thu Sep 5 20:01:21 2019 +0200
a2a915
a2a915
    Backport fixes to mkeys test
a2a915
a2a915
    It relied on some features backported in more recent versions, but not
a2a915
    present in our version. Make test pass with current features. Fixes some
a2a915
    mistakes when backporting original upstream commits.
a2a915
a2a915
commit be97d4d9d9f9568aa497e618ffbe2aba0841d035
a2a915
Author: Michał Kępień <michal@isc.org>
a2a915
Date:   Tue Mar 26 10:51:16 2019 +0100
a2a915
a2a915
    Add "-r $RANDFILE" where it is missing
a2a915
a2a915
    If the path to the source of random data is not passed explicitly to
a2a915
    dnssec-keygen or dnssec-signzone and the --with-randomdev compile-time
a2a915
    switch is not used, the aforementioned utilities will hang if the
a2a915
    default source of random data (/dev/random) runs out of entropy.  Use
a2a915
    "-r $RANDFILE" to prevent that from happening in affected system tests.
a2a915
a2a915
    (cherry picked from commit 59e1329e9b3aff72d8e36db8d0ca980d540decb3)
a2a915
a2a915
commit fd651e87b9bddcae7ef894b165d209a9693dc204
a2a915
Author: Matthijs Mekking <matthijs@isc.org>
a2a915
Date:   Thu Dec 20 15:23:07 2018 +0100
a2a915
a2a915
    Remove dig_with_opts
a2a915
a2a915
    (cherry picked from commit bb2c242c396d3c6893eb6a27e59af5a3b53452bc)
a2a915
a2a915
commit 84264e082ffe0c5439a0c789ceb7f8308d1b9b7e
a2a915
Author: Matthijs Mekking <github@pletterpet.nl>
a2a915
Date:   Wed Dec 19 10:16:10 2018 +0100
a2a915
a2a915
    Replace DSA with Reserved algorithm
a2a915
a2a915
    (cherry picked from commit 17cdde1e56abae5c3bf5256ecbdacbd8cbef05b6)
a2a915
    (cherry picked from commit 0e9a8da68c89cb99b1892e8b0705b71c92532844)
a2a915
a2a915
commit e335f239aca4bdbf8160fe9bc1ef3cfba15ae06f
a2a915
Author: Matthijs Mekking <github@pletterpet.nl>
a2a915
Date:   Tue Dec 18 12:14:04 2018 +0100
a2a915
a2a915
    Allow unsupported alg in zone /w dnssec-signzone
a2a915
a2a915
    dnssec-signzone should sign a zonefile that contains a DNSKEY record
a2a915
    with an unsupported algorithm.  Current behavior is that it will
a2a915
    fail, hitting a fatal error.  The fix detects unsupported algorithms
a2a915
    and will not try to add it to the keylist.
a2a915
a2a915
    Also when determining the maximum iterations for NSEC3, don't take
a2a915
    into account DNSKEY records in the zonefile with an unsupported
a2a915
    algorithm.
a2a915
a2a915
    (cherry picked from commit 1dd11fc754baf396bb3040527087b14f0678dd83)
a2a915
    (cherry picked from commit 040e132f1692ce8bb1ac83032ee761b3278f0272)
a2a915
a2a915
commit a1c345c8ab39201fe6e0cd7f19696d6a2f8b5522
a2a915
Author: Matthijs Mekking <github@pletterpet.nl>
a2a915
Date:   Tue Dec 18 12:10:05 2018 +0100
a2a915
a2a915
    Add dnssec-signzone tests with unsupported alg
a2a915
a2a915
    dnssec-signzone should sign a zonefile that contains a DNSKEY record
a2a915
    with an unsupported algorithm.
a2a915
a2a915
    (cherry picked from commit 6d976b37c1b2b2c4bcede89252cf26b6f170c142)
a2a915
    (cherry picked from commit 8619318a1e6207e487438a93bd7a620967091347)
a2a915
    (cherry picked from commit 9f81119c0256378683c20e8e01a874378cabfcbc)
a2a915
---
a2a915
 bin/tests/system/dnssec/clean.sh              |  4 ++
a2a915
 bin/tests/system/dnssec/ns2/example.db.in     |  5 ++-
a2a915
 .../ns3/dnskey-unsupported-2.example.db.in    | 27 ++++++++++++
a2a915
 .../ns3/dnskey-unsupported.example.db.in      | 27 ++++++++++++
a2a915
 bin/tests/system/dnssec/ns3/named.conf.in     | 10 +++++
a2a915
 bin/tests/system/dnssec/ns3/sign.sh           | 42 ++++++++++++++++++-
a2a915
 .../dnssec/ns3/unsupported-algorithm.key      |  1 +
a2a915
 bin/tests/system/dnssec/tests.sh              | 20 +++++++++
a2a915
 bin/tests/system/dupsigs/ns1/reset_keys.sh    |  2 +
a2a915
 bin/tests/system/mkeys/ns6/setup.sh           |  2 +-
a2a915
 bin/tests/system/mkeys/setup.sh               |  2 +
a2a915
 bin/tests/system/mkeys/tests.sh               |  6 +--
a2a915
 lib/dns/dnssec.c                              |  8 ++++
a2a915
 lib/dns/include/dns/dnssec.h                  |  2 +-
a2a915
 lib/dns/nsec3.c                               | 11 ++++-
a2a915
 15 files changed, 161 insertions(+), 8 deletions(-)
a2a915
 create mode 100644 bin/tests/system/dnssec/ns3/dnskey-unsupported-2.example.db.in
a2a915
 create mode 100644 bin/tests/system/dnssec/ns3/dnskey-unsupported.example.db.in
a2a915
 create mode 100644 bin/tests/system/dnssec/ns3/unsupported-algorithm.key
a2a915
a2a915
diff --git a/bin/tests/system/dnssec/clean.sh b/bin/tests/system/dnssec/clean.sh
a2a915
index 1873c4b586..0fcff23797 100644
a2a915
--- a/bin/tests/system/dnssec/clean.sh
a2a915
+++ b/bin/tests/system/dnssec/clean.sh
a2a915
@@ -55,6 +55,10 @@ rm -f ns3/future.example.db ns3/trusted-future.key
a2a915
 rm -f ns3/inline.example.db.signed
a2a915
 rm -f ns3/kskonly.example.db
a2a915
 rm -f ns3/lower.example.db ns3/upper.example.db ns3/upper.example.db.lower
a2a915
+rm -f ./ns3/dnskey-unsupported.example.db
a2a915
+rm -f ./ns3/dnskey-unsupported.example.db.tmp
a2a915
+rm -f ./ns3/dnskey-unsupported-2.example.db
a2a915
+rm -f ./ns3/dnskey-unsupported-2.example.db.tmp
a2a915
 rm -f ns3/multiple.example.db ns3/nsec3-unknown.example.db ns3/nsec3.example.db
a2a915
 rm -f ns3/nsec3.nsec3.example.db
a2a915
 rm -f ns3/nsec3.optout.example.db
a2a915
diff --git a/bin/tests/system/dnssec/ns2/example.db.in b/bin/tests/system/dnssec/ns2/example.db.in
a2a915
index 0b831ec94e..6afffe00f3 100644
a2a915
--- a/bin/tests/system/dnssec/ns2/example.db.in
a2a915
+++ b/bin/tests/system/dnssec/ns2/example.db.in
a2a915
@@ -97,6 +97,9 @@ ns.optout-unknown	A	10.53.0.3
a2a915
 dnskey-unknown		NS	ns.dnskey-unknown
a2a915
 ns.dnskey-unknown	A	10.53.0.3
a2a915
 
a2a915
+dnskey-unsupported	NS	ns.dnskey-unsupported
a2a915
+ns.dnskey-unsupported	A	10.53.0.3
a2a915
+
a2a915
 dnskey-nsec3-unknown	NS	ns.dnskey-nsec3-unknown
a2a915
 ns.dnskey-nsec3-unknown	A	10.53.0.3
a2a915
 
a2a915
@@ -111,7 +114,7 @@ ns.rsasha256		A	10.53.0.3
a2a915
 rsasha512		NS	ns.rsasha512
a2a915
 ns.rsasha512		A	10.53.0.3
a2a915
 
a2a915
-kskonly 		NS	ns.kskonly
a2a915
+kskonly			NS	ns.kskonly
a2a915
 ns.kskonly		A	10.53.0.3
a2a915
 
a2a915
 update-nsec3		NS	ns.update-nsec3
a2a915
diff --git a/bin/tests/system/dnssec/ns3/dnskey-unsupported-2.example.db.in b/bin/tests/system/dnssec/ns3/dnskey-unsupported-2.example.db.in
a2a915
new file mode 100644
a2a915
index 0000000000..c9e7c2b3da
a2a915
--- /dev/null
a2a915
+++ b/bin/tests/system/dnssec/ns3/dnskey-unsupported-2.example.db.in
a2a915
@@ -0,0 +1,27 @@
a2a915
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
a2a915
+;
a2a915
+; This Source Code Form is subject to the terms of the Mozilla Public
a2a915
+; License, v. 2.0. If a copy of the MPL was not distributed with this
a2a915
+; file, You can obtain one at http://mozilla.org/MPL/2.0/.
a2a915
+;
a2a915
+; See the COPYRIGHT file distributed with this work for additional
a2a915
+; information regarding copyright ownership.
a2a915
+
a2a915
+$TTL 300	; 5 minutes
a2a915
+@			IN SOA	mname1. . (
a2a915
+				2000042407 ; serial
a2a915
+				20         ; refresh (20 seconds)
a2a915
+				20         ; retry (20 seconds)
a2a915
+				1814400    ; expire (3 weeks)
a2a915
+				3600       ; minimum (1 hour)
a2a915
+				)
a2a915
+			NS	ns
a2a915
+ns			A	10.53.0.3
a2a915
+
a2a915
+a			A	10.0.0.1
a2a915
+b			A	10.0.0.2
a2a915
+d			A	10.0.0.4
a2a915
+z			A	10.0.0.26
a2a915
+a.a.a.a			A	10.0.0.3
a2a915
+*.e			A	10.0.0.6
a2a915
+child			NS	ns2.example.
a2a915
diff --git a/bin/tests/system/dnssec/ns3/dnskey-unsupported.example.db.in b/bin/tests/system/dnssec/ns3/dnskey-unsupported.example.db.in
a2a915
new file mode 100644
a2a915
index 0000000000..c9e7c2b3da
a2a915
--- /dev/null
a2a915
+++ b/bin/tests/system/dnssec/ns3/dnskey-unsupported.example.db.in
a2a915
@@ -0,0 +1,27 @@
a2a915
+; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
a2a915
+;
a2a915
+; This Source Code Form is subject to the terms of the Mozilla Public
a2a915
+; License, v. 2.0. If a copy of the MPL was not distributed with this
a2a915
+; file, You can obtain one at http://mozilla.org/MPL/2.0/.
a2a915
+;
a2a915
+; See the COPYRIGHT file distributed with this work for additional
a2a915
+; information regarding copyright ownership.
a2a915
+
a2a915
+$TTL 300	; 5 minutes
a2a915
+@			IN SOA	mname1. . (
a2a915
+				2000042407 ; serial
a2a915
+				20         ; refresh (20 seconds)
a2a915
+				20         ; retry (20 seconds)
a2a915
+				1814400    ; expire (3 weeks)
a2a915
+				3600       ; minimum (1 hour)
a2a915
+				)
a2a915
+			NS	ns
a2a915
+ns			A	10.53.0.3
a2a915
+
a2a915
+a			A	10.0.0.1
a2a915
+b			A	10.0.0.2
a2a915
+d			A	10.0.0.4
a2a915
+z			A	10.0.0.26
a2a915
+a.a.a.a			A	10.0.0.3
a2a915
+*.e			A	10.0.0.6
a2a915
+child			NS	ns2.example.
a2a915
diff --git a/bin/tests/system/dnssec/ns3/named.conf.in b/bin/tests/system/dnssec/ns3/named.conf.in
a2a915
index 14ebbc8ea8..6aa5d5350d 100644
a2a915
--- a/bin/tests/system/dnssec/ns3/named.conf.in
a2a915
+++ b/bin/tests/system/dnssec/ns3/named.conf.in
a2a915
@@ -150,6 +150,16 @@ zone "dnskey-unknown.example" {
a2a915
 	file "dnskey-unknown.example.db.signed";
a2a915
 };
a2a915
 
a2a915
+zone "dnskey-unsupported.example" {
a2a915
+	type master;
a2a915
+	file "dnskey-unsupported.example.db.signed";
a2a915
+};
a2a915
+
a2a915
+zone "dnskey-unsupported-2.example" {
a2a915
+	type master;
a2a915
+	file "dnskey-unsupported-2.example.db.signed";
a2a915
+};
a2a915
+
a2a915
 zone "dnskey-nsec3-unknown.example" {
a2a915
 	type master;
a2a915
 	nsec3-test-zone yes;
a2a915
diff --git a/bin/tests/system/dnssec/ns3/sign.sh b/bin/tests/system/dnssec/ns3/sign.sh
a2a915
index f95a6b7ea8..99e9b4958f 100644
a2a915
--- a/bin/tests/system/dnssec/ns3/sign.sh
a2a915
+++ b/bin/tests/system/dnssec/ns3/sign.sh
a2a915
@@ -12,6 +12,12 @@
a2a915
 SYSTEMTESTTOP=../..
a2a915
 . $SYSTEMTESTTOP/conf.sh
a2a915
 
a2a915
+# Default algorithm for testing
a2a915
+# In more recent versions set in conf.sh, include here for backward copatibility
a2a915
+DEFAULT_ALGORITHM=RSASHA256
a2a915
+DEFAULT_ALGORITHM_NUMBER=8
a2a915
+DEFAULT_BITS=1280
a2a915
+
a2a915
 zone=secure.example.
a2a915
 infile=secure.example.db.in
a2a915
 zonefile=secure.example.db
a2a915
@@ -193,7 +199,7 @@ cat $infile $keyname.key >$zonefile
a2a915
 $SIGNER -P -3 - -U -A -r $RANDFILE -o $zone $zonefile > /dev/null 2>&1
a2a915
 
a2a915
 #
a2a915
-# A zone with a unknown DNSKEY algorithm.
a2a915
+# A zone that is signed with an unknown DNSKEY algorithm.
a2a915
 # Algorithm 7 is replaced by 100 in the zone and dsset.
a2a915
 #
a2a915
 zone=dnskey-unknown.example.
a2a915
@@ -211,6 +217,40 @@ awk '$4 == "DNSKEY" { $7 = 100; print } $4 == "RRSIG" { $6 = 100; print } { prin
a2a915
 DSFILE=dsset-`echo ${zone} |sed -e "s/\.$//g"`$TP
a2a915
 $DSFROMKEY -A -f ${zonefile}.signed $zone > $DSFILE
a2a915
 
a2a915
+#
a2a915
+# A zone that is signed with an unsupported DNSKEY algorithm (3).
a2a915
+# Algorithm 7 is replaced by 255 in the zone and dsset.
a2a915
+#
a2a915
+zone=dnskey-unsupported.example.
a2a915
+infile=dnskey-unsupported.example.db.in
a2a915
+zonefile=dnskey-unsupported.example.db
a2a915
+
a2a915
+keyname=$("$KEYGEN" -q -r $RANDFILE -a "$DEFAULT_ALGORITHM" -b "$DEFAULT_BITS" -n zone "$zone")
a2a915
+
a2a915
+cat "$infile" "$keyname.key" > "$zonefile"
a2a915
+
a2a915
+"$SIGNER" -P -3 - -r $RANDFILE -o "$zone" -O full -f ${zonefile}.tmp "$zonefile" > /dev/null 2>&1
a2a915
+
a2a915
+awk '$4 == "DNSKEY" { $7 = 255; print } $4 == "RRSIG" { $6 = 255; print } { print }' ${zonefile}.tmp > ${zonefile}.signed
a2a915
+
a2a915
+DSFILE="dsset-$(echo ${zone} |sed -e "s/\\.$//g")$TP"
a2a915
+$DSFROMKEY -A -f ${zonefile}.signed "$zone" > "$DSFILE"
a2a915
+
a2a915
+#
a2a915
+# A zone with a published unsupported DNSKEY algorithm (Reserved).
a2a915
+# Different from above because this key is not intended for signing.
a2a915
+#
a2a915
+zone=dnskey-unsupported-2.example.
a2a915
+infile=dnskey-unsupported-2.example.db.in
a2a915
+zonefile=dnskey-unsupported-2.example.db
a2a915
+
a2a915
+ksk=$("$KEYGEN" -f KSK -q -r $RANDFILE -a "$DEFAULT_ALGORITHM" -b "$DEFAULT_BITS" -n zone "$zone")
a2a915
+zsk=$("$KEYGEN" -q -r $RANDFILE -a "$DEFAULT_ALGORITHM" -b "$DEFAULT_BITS" -n zone "$zone")
a2a915
+
a2a915
+cat "$infile" "$ksk.key" "$zsk.key" unsupported-algorithm.key > "$zonefile"
a2a915
+
a2a915
+"$SIGNER" -P -3 - -r $RANDFILE -o "$zone" -f ${zonefile}.signed "$zonefile" > /dev/null 2>&1
a2a915
+
a2a915
 #
a2a915
 # A zone with a unknown DNSKEY algorithm + unknown NSEC3 hash algorithm (-U).
a2a915
 # Algorithm 7 is replaced by 100 in the zone and dsset.
a2a915
diff --git a/bin/tests/system/dnssec/ns3/unsupported-algorithm.key b/bin/tests/system/dnssec/ns3/unsupported-algorithm.key
a2a915
new file mode 100644
a2a915
index 0000000000..cc8bb9a51d
a2a915
--- /dev/null
a2a915
+++ b/bin/tests/system/dnssec/ns3/unsupported-algorithm.key
a2a915
@@ -0,0 +1 @@
a2a915
+dnskey-unsupported-2.example.	IN	DNSKEY	257 3 255 BJ0eV4dQC0pihdFXiVdlXjPDkzbv4fC+opEvK0RaDU7LLwFXPAi6DOc6tm7vcSr5Tgdnpoal3S4WqHuVw6I1pzy5mPPIZ3OpLSY/QeOyGc2QRAZtOXxiGxERHRjyAk7emlgGscM0Vty2oJVYRgTPX0lTwKX/V2H+mjEgp7u3tyG3cj5XBUQ8J0KUoqkrn1ZKrizH27aWiDaBUvqxJUcotaDhnydkNtcHoQIedm2b4qbyTQsdRkddJiSWxpveEcj3AMdt2PjU6Q4rgSWOc5ylPnW/O+GqqCEAkalGSF7ud0Nl3FVVR9iGwV/73FHzpBLawfkcHaODFmKRjzGqok8giKCih2vdNsxlx7gdJWJIPYYx/ZqNGc2ewzuAnnleJpZdXFo8uL3HYk6Pl51sSkfVUmcn/SM+ ;{id = 38688 (ksk), size = 768b}
a2a915
diff --git a/bin/tests/system/dnssec/tests.sh b/bin/tests/system/dnssec/tests.sh
a2a915
index b1907c73a5..fdbfbdb779 100644
a2a915
--- a/bin/tests/system/dnssec/tests.sh
a2a915
+++ b/bin/tests/system/dnssec/tests.sh
a2a915
@@ -3347,6 +3347,26 @@ n=`expr $n + 1`
a2a915
 if [ $ret != 0 ]; then echo_i "failed"; fi
a2a915
 status=`expr $status + $ret`
a2a915
 
a2a915
+echo_i "checking that unsupported DNSKEY algorithm validates as insecure ($n)"
a2a915
+ret=0
a2a915
+$DIG $DIGOPTS +noauth +noadd +nodnssec +adflag @10.53.0.3 dnskey-unsupported.example A > dig.out.ns3.test$n
a2a915
+$DIG $DIGOPTS +noauth +noadd +nodnssec +adflag @10.53.0.4 dnskey-unsupported.example A > dig.out.ns4.test$n
a2a915
+grep "status: NOERROR," dig.out.ns3.test$n > /dev/null || ret=1
a2a915
+grep "status: NOERROR," dig.out.ns4.test$n > /dev/null || ret=1
a2a915
+grep "flags:.*ad.*QUERY" dig.out.ns4.test$n > /dev/null && ret=1
a2a915
+n=$((n+1))
a2a915
+test "$ret" -eq 0 || echo_i "failed"
a2a915
+status=$((status+ret))
a2a915
+
a2a915
+echo_i "checking that unsupported DNSKEY algorithm is in DNSKEY RRset ($n)"
a2a915
+ret=0
a2a915
+$DIG $DIGOPTS +noauth +noadd +nodnssec +adflag @10.53.0.3 dnskey-unsupported-2.example DNSKEY > dig.out.test$n
a2a915
+grep "status: NOERROR," dig.out.test$n > /dev/null || ret=1
a2a915
+grep "dnskey-unsupported-2\.example\..*IN.*DNSKEY.*257 3 255" dig.out.test$n > /dev/null || ret=1
a2a915
+n=$((n+1))
a2a915
+test "$ret" -eq 0 || echo_i "failed"
a2a915
+status=$((status+ret))
a2a915
+
a2a915
 echo_i "check that a lone non matching CDNSKEY record is rejected ($n)"
a2a915
 ret=0
a2a915
 (
a2a915
diff --git a/bin/tests/system/dupsigs/ns1/reset_keys.sh b/bin/tests/system/dupsigs/ns1/reset_keys.sh
a2a915
index f03503f762..42ce8ac20b 100644
a2a915
--- a/bin/tests/system/dupsigs/ns1/reset_keys.sh
a2a915
+++ b/bin/tests/system/dupsigs/ns1/reset_keys.sh
a2a915
@@ -22,6 +22,8 @@ timetodnssec() {
a2a915
 }
a2a915
 
a2a915
 KEYDIR=keys/signing.test
a2a915
+KEYGEN="$KEYGEN -r $RANDFILE"
a2a915
+
a2a915
 KSK=`$KEYGEN -a RSASHA256 -b 1024 -K $KEYDIR -q -f KSK $zone`
a2a915
 
a2a915
 ZSK0=`$KEYGEN -a RSASHA256 -b 1024 -K $KEYDIR -q $zone`
a2a915
diff --git a/bin/tests/system/mkeys/ns6/setup.sh b/bin/tests/system/mkeys/ns6/setup.sh
a2a915
index 5ba1647da5..6f196c20db 100644
a2a915
--- a/bin/tests/system/mkeys/ns6/setup.sh
a2a915
+++ b/bin/tests/system/mkeys/ns6/setup.sh
a2a915
@@ -16,7 +16,7 @@ zone=.
a2a915
 zonefile=root.db
a2a915
 
a2a915
 # an RSA key
a2a915
-rsakey=`$KEYGEN -a rsasha256 -qfk rsasha256.`
a2a915
+rsakey=`$KEYGEN -a rsasha256 -b 2048 -r $RANDFILE -qfk rsasha256.`
a2a915
 
a2a915
 # a key with unsupported algorithm
a2a915
 unsupportedkey=Kunknown.+255+00000
a2a915
diff --git a/bin/tests/system/mkeys/setup.sh b/bin/tests/system/mkeys/setup.sh
a2a915
index 100a86959b..79c877f85d 100644
a2a915
--- a/bin/tests/system/mkeys/setup.sh
a2a915
+++ b/bin/tests/system/mkeys/setup.sh
a2a915
@@ -21,6 +21,8 @@ copy_setports ns1/named1.conf.in ns1/named.conf
a2a915
 copy_setports ns2/named.conf.in ns2/named.conf
a2a915
 copy_setports ns3/named.conf.in ns3/named.conf
a2a915
 copy_setports ns5/named.conf.in ns5/named.conf
a2a915
+copy_setports ns6/named.conf.in ns6/named.conf
a2a915
+copy_setports ns7/named.conf.in ns7/named.conf
a2a915
 
a2a915
 cp ns5/named1.args ns5/named.args
a2a915
 
a2a915
diff --git a/bin/tests/system/mkeys/tests.sh b/bin/tests/system/mkeys/tests.sh
a2a915
index b8410902d7..3533dbadbb 100644
a2a915
--- a/bin/tests/system/mkeys/tests.sh
a2a915
+++ b/bin/tests/system/mkeys/tests.sh
a2a915
@@ -297,7 +297,7 @@ if [ $ret != 0 ]; then echo_i "failed"; fi
a2a915
 status=`expr $status + $ret`
a2a915
 
a2a915
 echo_i "reinitialize trust anchors"
a2a915
-$PERL $SYSTEMTESTTOP/stop.pl --use-rndc . ns2
a2a915
+$PERL $SYSTEMTESTTOP/stop.pl --use-rndc --port ${CONTROLPORT} . ns2
a2a915
 rm -f ns2/managed-keys.bind*
a2a915
 nextpart ns2/named.run > /dev/null
a2a915
 $PERL $SYSTEMTESTTOP/start.pl --noclean --restart --port ${PORT} . ns2
a2a915
@@ -714,10 +714,10 @@ status=`expr $status + $ret`
a2a915
 
a2a915
 echo_i "reinitialize trust anchors, add unsupported algorithm ($n)"
a2a915
 ret=0
a2a915
-$PERL $SYSTEMTESTTOP/stop.pl --use-rndc --port ${CONTROLPORT} mkeys ns6
a2a915
+$PERL $SYSTEMTESTTOP/stop.pl --port ${CONTROLPORT} . ns6
a2a915
 rm -f ns6/managed-keys.bind*
a2a915
 nextpart ns6/named.run > /dev/null
a2a915
-$PERL $SYSTEMTESTTOP/start.pl --noclean --restart --port ${PORT} mkeys ns6
a2a915
+$PERL $SYSTEMTESTTOP/start.pl --noclean --restart --port ${PORT} . ns6
a2a915
 # log when an unsupported algorithm is encountered during startup
a2a915
 wait_for_log "skipping managed key for 'unsupported\.': algorithm is unsupported" ns6/named.run
a2a915
 if [ $ret != 0 ]; then echo_i "failed"; fi
a2a915
diff --git a/lib/dns/dnssec.c b/lib/dns/dnssec.c
a2a915
index 1045f8ff21..984f28be26 100644
a2a915
--- a/lib/dns/dnssec.c
a2a915
+++ b/lib/dns/dnssec.c
a2a915
@@ -1681,6 +1681,14 @@ dns_dnssec_keylistfromrdataset(dns_name_t *origin,
a2a915
 	     result = dns_rdataset_next(&keys)) {
a2a915
 		dns_rdata_reset(&rdata);
a2a915
 		dns_rdataset_current(&keys, &rdata);
a2a915
+
a2a915
+		/* Skip unsupported algorithms */
a2a915
+		REQUIRE(rdata.type == dns_rdatatype_key ||
a2a915
+			rdata.type == dns_rdatatype_dnskey);
a2a915
+		REQUIRE(rdata.length > 3);
a2a915
+		if (!dst_algorithm_supported(rdata.data[3]))
a2a915
+			goto skip;
a2a915
+
a2a915
 		RETERR(dns_dnssec_keyfromrdata(origin, &rdata, mctx, &pubkey));
a2a915
 		dst_key_setttl(pubkey, keys.ttl);
a2a915
 
a2a915
diff --git a/lib/dns/include/dns/dnssec.h b/lib/dns/include/dns/dnssec.h
a2a915
index 75e32202a9..9a638852d7 100644
a2a915
--- a/lib/dns/include/dns/dnssec.h
a2a915
+++ b/lib/dns/include/dns/dnssec.h
a2a915
@@ -299,7 +299,7 @@ dns_dnssec_findmatchingkeys2(dns_name_t *origin, const char *directory,
a2a915
 /*%<
a2a915
  * Search 'directory' for K* key files matching the name in 'origin'.
a2a915
  * Append all such keys, along with use hints gleaned from their
a2a915
- * metadata, onto 'keylist'.
a2a915
+ * metadata, onto 'keylist'.  Skip any unsupported algorithms.
a2a915
  *
a2a915
  *	Requires:
a2a915
  *\li		'keylist' is not NULL
a2a915
diff --git a/lib/dns/nsec3.c b/lib/dns/nsec3.c
a2a915
index 37b6a8a7fe..0729886c9f 100644
a2a915
--- a/lib/dns/nsec3.c
a2a915
+++ b/lib/dns/nsec3.c
a2a915
@@ -1801,8 +1801,17 @@ dns_nsec3_maxiterations(dns_db_t *db, dns_dbversion_t *version,
a2a915
 	     result == ISC_R_SUCCESS;
a2a915
 	     result = dns_rdataset_next(&rdataset)) {
a2a915
 		dns_rdata_t rdata = DNS_RDATA_INIT;
a2a915
-
a2a915
 		dns_rdataset_current(&rdataset, &rdata);
a2a915
+
a2a915
+		/* Skip unsupported algorithms when
a2a915
+		 * calculating the maximum iterations.
a2a915
+		 */
a2a915
+		REQUIRE(rdata.type == dns_rdatatype_key ||
a2a915
+			rdata.type == dns_rdatatype_dnskey);
a2a915
+		REQUIRE(rdata.length > 3);
a2a915
+		if (!dst_algorithm_supported(rdata.data[3]))
a2a915
+			continue;
a2a915
+
a2a915
 		isc_buffer_init(&buffer, rdata.data, rdata.length);
a2a915
 		isc_buffer_add(&buffer, rdata.length);
a2a915
 		CHECK(dst_key_fromdns(dns_db_origin(db), rdataset.rdclass,
a2a915
-- 
a2a915
2.20.1
a2a915