From: Otto Moerbeek Date: Wed, 25 Jan 2023 09:18:01 +0000 (+0100) Subject: Process review comments from @rgacogne, thanks! X-Git-Tag: dnsdist-1.8.0-rc1~83^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12434%2Fhead;p=thirdparty%2Fpdns.git Process review comments from @rgacogne, thanks! --- diff --git a/pdns/logger.hh b/pdns/logger.hh index bbbc8cd50b..d05b532744 100644 --- a/pdns/logger.hh +++ b/pdns/logger.hh @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include #include #include "namespaces.hh" @@ -168,7 +170,7 @@ Logger& getLogger(); #endif // The types below are used by rec, which can log to g_log (general logging) or a string stream -// (trace-regexp). We feed an OptLog object to the code that should not know anything about this +// (trace-regexp). We pass an OptLog object to the code that should not know anything about this // That code should then log using VLOG struct LogVariant @@ -181,7 +183,7 @@ struct LogVariant using OptLog = std::optional; #ifndef RECURSOR -// Originally there was a flag but is was never set from !RECURSOR +// Originally there was a flag but it was never set from !RECURSOR #define VLOG(log, x) VLOG only works in recursor #else #define VLOG(log, x) \ diff --git a/pdns/validate.cc b/pdns/validate.cc index b75071b576..5a085feca1 100644 --- a/pdns/validate.cc +++ b/pdns/validate.cc @@ -896,41 +896,6 @@ dState getDenial(const cspmap_t &validrrsets, const DNSName& qname, const uint16 return dState::NODENIAL; } -/* - * Finds all the zone-cuts between begin (longest name) and end (shortest name), - * returns them all zone cuts, including end, but (possibly) not begin - */ -static const vector getZoneCuts(const DNSName& begin, const DNSName& end, DNSRecordOracle& dro) -{ - vector ret; - if(!begin.isPartOf(end)) - throw PDNSException(end.toLogString() + "is not part of " + begin.toLogString()); - - DNSName qname(end); - vector labelsToAdd = begin.makeRelative(end).getRawLabels(); - - // The shortest name is assumed to a zone cut - ret.push_back(qname); - while(qname != begin) { - bool foundCut = false; - if (labelsToAdd.empty()) - break; - - qname.prependRawLabel(labelsToAdd.back()); - labelsToAdd.pop_back(); - auto records = dro.get(qname, (uint16_t)QType::NS); - for (const auto& record : records) { - if(record.d_type != QType::NS || record.d_name != qname) - continue; - foundCut = true; - break; - } - if (foundCut) - ret.push_back(qname); - } - return ret; -} - bool isRRSIGNotExpired(const time_t now, const shared_ptr& sig) { // Should use https://www.rfc-editor.org/rfc/rfc4034.txt section 3.1.5 @@ -1038,23 +1003,6 @@ vState validateWithKeySet(time_t now, const DNSName& name, const sortedRecords_t return vState::BogusNoValidRRSIG; } -void validateWithKeySet(const cspmap_t& rrsets, cspmap_t& validated, const skeyset_t& keys, const OptLog& log) -{ - validated.clear(); - /* cerr<<"Validating an rrset with following keys: "<getTag()<<" -> "<getZoneRepresentation()<first.first)<<"/"<first.second)<<" with "<second.signatures.size()<<" sigs"<first.first, i->second.records, i->second.signatures, keys, log, true) == vState::Secure) { - validated[i->first] = i->second; - } - } -} - // returns vState // should return vState, zone cut and validated keyset // i.e. www.7bits.nl -> insecure/7bits.nl/[] @@ -1241,160 +1189,6 @@ vState validateDNSKeysAgainstDS(time_t now, const DNSName& zone, const dsmap_t& return vState::Secure; } -vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, skeyset_t& keyset, const OptLog& log) -{ - auto luaLocal = g_luaconfs.getLocal(); - const auto anchors = luaLocal->dsAnchors; - if (anchors.empty()) // Nothing to do here - return vState::Insecure; - - // Determine the lowest (i.e. with the most labels) Trust Anchor for zone - DNSName lowestTA("."); - for (auto const &anchor : anchors) - if (zone.isPartOf(anchor.first) && lowestTA.countLabels() < anchor.first.countLabels()) - lowestTA = anchor.first; - - // Before searching for the keys, see if we have a Negative Trust Anchor. If - // so, test if the NTA is valid and return an NTA state - const auto negAnchors = luaLocal->negAnchors; - - if (!negAnchors.empty()) { - DNSName lowestNTA; - - for (auto const &negAnchor : negAnchors) - if (zone.isPartOf(negAnchor.first) && lowestNTA.countLabels() <= negAnchor.first.countLabels()) - lowestNTA = negAnchor.first; - - if(!lowestNTA.empty()) { - VLOG(log, "Found a Negative Trust Anchor for "< "< > sigs; - sortedRecords_t toSign; - - skeyset_t tkeys; // tentative keys - validkeys.clear(); - - // cerr<<"got DS for ["< (rec); - if(rrc) { - VLOG(log, "Got signature: "<getZoneRepresentation()<<" with tag "<d_tag<<", for type "<d_type)<d_type != QType::DNSKEY) - continue; - sigs.push_back(rrc); - } - } - else if(rec.d_type == QType::DNSKEY) - { - auto drc=getRR (rec); - if(drc) { - tkeys.insert(drc); - VLOG(log, "Inserting key with tag "<getTag()<<" and algorithm "<d_algorithm)<<": "<getZoneRepresentation()<second.records.cbegin(); j!=cspiter->second.records.cend(); j++) - { - const auto dsrc=std::dynamic_pointer_cast(*j); - if(dsrc) { - dsmap.insert(*dsrc); - } - } - } - } - // There were no zone cuts (aka, we should never get here) - return vState::BogusUnableToGetDNSKEYs; -} - bool isSupportedDS(const DSRecordContent& ds, const OptLog& log) { if (!DNSCryptoKeyEngine::isAlgorithmSupported(ds.d_algorithm)) { diff --git a/pdns/validate.hh b/pdns/validate.hh index c211b2a4eb..3226c2c3d8 100644 --- a/pdns/validate.hh +++ b/pdns/validate.hh @@ -77,9 +77,7 @@ vState validateWithKeySet(time_t now, const DNSName& name, const sortedRecords_t bool isCoveredByNSEC(const DNSName& name, const DNSName& begin, const DNSName& next); bool isCoveredByNSEC3Hash(const std::string& h, const std::string& beginHash, const std::string& nextHash); bool isCoveredByNSEC3Hash(const DNSName& h, const DNSName& beginHash, const DNSName& nextHash); -void validateWithKeySet(const cspmap_t& rrsets, cspmap_t& validated, const skeyset_t& keys, const OptLog& log); cspmap_t harvestCSPFromRecs(const vector& recs); -vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, skeyset_t& keyset); bool getTrustAnchor(const map& anchors, const DNSName& zone, dsmap_t &res); bool haveNegativeTrustAnchor(const map& negAnchors, const DNSName& zone, std::string& reason); vState validateDNSKeysAgainstDS(time_t now, const DNSName& zone, const dsmap_t& dsmap, const skeyset_t& tkeys, const sortedRecords_t& toSign, const vector >& sigs, skeyset_t& validkeys, const OptLog&);