From: Remi Gacogne Date: Mon, 5 Jul 2021 16:01:37 +0000 (+0200) Subject: rec: Make really sure we did not miss a cut on validation failure X-Git-Tag: dnsdist-1.7.0-alpha1~84^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc50925a50c6e956f612bb03db15893279fd052d;p=thirdparty%2Fpdns.git rec: Make really sure we did not miss a cut on validation failure --- diff --git a/pdns/recursordist/test-syncres_cc6.cc b/pdns/recursordist/test-syncres_cc6.cc index 9810e0161f..c83e1e9551 100644 --- a/pdns/recursordist/test-syncres_cc6.cc +++ b/pdns/recursordist/test-syncres_cc6.cc @@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(test_dnssec_ds_sign_loop) BOOST_CHECK_EQUAL(res, RCode::NoError); BOOST_CHECK_EQUAL(sr->getValidationState(), vState::BogusSelfSignedDS); BOOST_REQUIRE_EQUAL(ret.size(), 2U); - BOOST_CHECK_EQUAL(queriesCount, 7U); + BOOST_CHECK_EQUAL(queriesCount, 8U); /* again, to test the cache */ ret.clear(); @@ -235,7 +235,7 @@ BOOST_AUTO_TEST_CASE(test_dnssec_ds_sign_loop) BOOST_CHECK_EQUAL(res, RCode::NoError); BOOST_CHECK_EQUAL(sr->getValidationState(), vState::BogusSelfSignedDS); BOOST_REQUIRE_EQUAL(ret.size(), 2U); - BOOST_CHECK_EQUAL(queriesCount, 7U); + BOOST_CHECK_EQUAL(queriesCount, 8U); } BOOST_AUTO_TEST_CASE(test_dnssec_ds_root) @@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(test_dnssec_dnskey_signed_child) BOOST_CHECK_EQUAL(res, RCode::NoError); BOOST_CHECK_EQUAL(sr->getValidationState(), vState::BogusNoValidRRSIG); BOOST_REQUIRE_EQUAL(ret.size(), 2U); - BOOST_CHECK_EQUAL(queriesCount, 6U); + BOOST_CHECK_EQUAL(queriesCount, 8U); /* again, to test the cache */ ret.clear(); @@ -401,7 +401,7 @@ BOOST_AUTO_TEST_CASE(test_dnssec_dnskey_signed_child) BOOST_CHECK_EQUAL(res, RCode::NoError); BOOST_CHECK_EQUAL(sr->getValidationState(), vState::BogusNoValidRRSIG); BOOST_REQUIRE_EQUAL(ret.size(), 2U); - BOOST_CHECK_EQUAL(queriesCount, 6U); + BOOST_CHECK_EQUAL(queriesCount, 8U); } BOOST_AUTO_TEST_CASE(test_dnssec_dnskey_unpublished) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 4c34384137..a60339e062 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1714,7 +1714,7 @@ void SyncRes::computeNegCacheValidationStatus(const NegCache::NegCacheEntry& ne, vState neValidationState = ne.d_validationState; dState expectedState = res == RCode::NXDomain ? dState::NXDOMAIN : dState::NXQTYPE; dState denialState = getDenialValidationState(ne, expectedState, false); - updateDenialValidationState(neValidationState, ne.d_name, state, denialState, expectedState); + updateDenialValidationState(neValidationState, ne.d_name, state, denialState, expectedState, qtype == QType::DS, depth); } if (state != vState::Indeterminate) { /* validation succeeded, let's update the cache entry so we don't have to validate again */ @@ -2711,24 +2711,32 @@ vState SyncRes::getValidationStatus(const DNSName& name, bool hasSignatures, boo vState SyncRes::validateDNSKeys(const DNSName& zone, const std::vector& dnskeys, const std::vector >& signatures, unsigned int depth) { dsmap_t ds; - if (!signatures.empty()) { - DNSName signer = getSigner(signatures); + if (signatures.empty()) { + LOG(d_prefix<<": we have "<& records, const std::vector >& signatures) { skeyset_t keys; - if (!signatures.empty()) { - const DNSName signer = getSigner(signatures); - if (!signer.empty() && name.isPartOf(signer)) { - if ((qtype == QType::DNSKEY || qtype == QType::DS) && signer == qname) { - /* we are already retrieving those keys, sorry */ - if (type == QType::DS && signer == name && !signer.isRoot()) { - /* Unless we are getting the DS of the root zone, we should never see a - DS (or a denial of a DS) signed by the DS itself, since we should be - requesting it from the parent zone. Something is very wrong */ - LOG(d_prefix<<"The DS for "<& allowedAdditionals, const DNSRecord& rec) @@ -3340,8 +3392,10 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, LWResult& lwr /* we have an answer synthesized from a wildcard and aggressive NSEC is enabled, we need to store the wildcard in its non-expanded form in the cache to be able to synthesize wildcard answers later */ const auto& rrsig = i->second.signatures.at(0); + if (isWildcardExpanded(labelCount, rrsig) && !isWildcardExpandedOntoItself(i->first.name, labelCount, rrsig)) { DNSName realOwner = getNSECOwnerName(i->first.name, i->second.signatures); + std::vector content; content.reserve(i->second.records.size()); for (const auto& record : i->second.records) { @@ -3373,7 +3427,7 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, LWResult& lwr return RCode::NoError; } -void SyncRes::updateDenialValidationState(vState& neValidationState, const DNSName& neName, vState& state, const dState denialState, const dState expectedState) +void SyncRes::updateDenialValidationState(vState& neValidationState, const DNSName& neName, vState& state, const dState denialState, const dState expectedState, bool isDS, unsigned int depth) { if (denialState == expectedState) { neValidationState = vState::Secure; @@ -3402,8 +3456,16 @@ void SyncRes::updateDenialValidationState(vState& neValidationState, const DNSNa neValidationState = vState::Insecure; } else { - LOG(d_prefix<<"Invalid denial found for "<& dnskeys, const std::vector >& signatures, unsigned int depth); vState getDNSKeys(const DNSName& signer, skeyset_t& keys, unsigned int depth); dState getDenialValidationState(const NegCache::NegCacheEntry& ne, const dState expectedState, bool referralToUnsigned); - void updateDenialValidationState(vState& neValidationState, const DNSName& neName, vState& state, const dState denialState, const dState expectedState); + void updateDenialValidationState(vState& neValidationState, const DNSName& neName, vState& state, const dState denialState, const dState expectedState, bool isDS, unsigned int depth); void computeNegCacheValidationStatus(const NegCache::NegCacheEntry& ne, const DNSName& qname, QType qtype, const int res, vState& state, unsigned int depth); vState getTA(const DNSName& zone, dsmap_t& ds); vState getValidationStatus(const DNSName& subdomain, bool hasSignatures, bool typeIsDS, unsigned int depth);