From: Remi Gacogne Date: Wed, 22 Mar 2023 16:55:42 +0000 (+0100) Subject: validate: Stop passing shared pointers all the way down X-Git-Tag: dnsdist-1.9.0-alpha0^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12674%2Fhead;p=thirdparty%2Fpdns.git validate: Stop passing shared pointers all the way down --- diff --git a/pdns/recursordist/aggressive_nsec.cc b/pdns/recursordist/aggressive_nsec.cc index a3d84a9a6c..87500abdaf 100644 --- a/pdns/recursordist/aggressive_nsec.cc +++ b/pdns/recursordist/aggressive_nsec.cc @@ -342,7 +342,7 @@ void AggressiveNSECCache::insertNSEC(const DNSName& zone, const DNSName& owner, } /* the TTL is already a TTD by now */ - if (!nsec3 && isWildcardExpanded(owner.countLabels(), signatures.at(0))) { + if (!nsec3 && isWildcardExpanded(owner.countLabels(), *signatures.at(0))) { DNSName realOwner = getNSECOwnerName(owner, signatures); auto pair = zoneEntry->d_entries.insert({record.getContent(), signatures, std::move(realOwner), std::move(next), record.d_ttl}); if (pair.second) { @@ -557,7 +557,7 @@ bool AggressiveNSECCache::getNSEC3Denial(time_t now, std::shared_ptr(wcEntry.d_record); - denial = matchesNSEC(wc, type.getCode(), wcEntry.d_owner, nsecContent, wcEntry.d_signatures, log); + denial = matchesNSEC(wc, type.getCode(), wcEntry.d_owner, *nsecContent, wcEntry.d_signatures, log); if (denial == dState::NODENIAL || denial == dState::INCONCLUSIVE) { if (wcEntry.d_owner == wc) { diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index 122ad98aa5..3bb05d0474 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -3065,14 +3065,14 @@ static void harvestNXRecords(const vector& records, NegCache::NegCach if (rrsig) { if (rrsig->d_type == QType::SOA) { ne.authoritySOA.signatures.push_back(rec); - if (lowestTTL && isRRSIGNotExpired(now, rrsig)) { + if (lowestTTL && isRRSIGNotExpired(now, *rrsig)) { *lowestTTL = min(*lowestTTL, rec.d_ttl); *lowestTTL = min(*lowestTTL, getRRSIGTTL(now, rrsig)); } } if (nsecTypes.count(rrsig->d_type)) { ne.DNSSECRecords.signatures.push_back(rec); - if (lowestTTL && isRRSIGNotExpired(now, rrsig)) { + if (lowestTTL && isRRSIGNotExpired(now, *rrsig)) { *lowestTTL = min(*lowestTTL, rec.d_ttl); *lowestTTL = min(*lowestTTL, getRRSIGTTL(now, rrsig)); } @@ -3428,7 +3428,7 @@ uint32_t SyncRes::computeLowestTTD(const std::vector& records, const lowestTTD = min(lowestTTD, static_cast(signaturesTTL + d_now.tv_sec)); for (const auto& sig : signatures) { - if (isRRSIGNotExpired(d_now.tv_sec, sig)) { + if (isRRSIGNotExpired(d_now.tv_sec, *sig)) { // we don't decrement d_sigexpire by 'now' because we actually want a TTD, not a TTL */ lowestTTD = min(lowestTTD, static_cast(sig->d_sigexpire)); } @@ -3442,7 +3442,7 @@ uint32_t SyncRes::computeLowestTTD(const std::vector& records, const if (entry->d_type == QType::RRSIG && validationEnabled()) { auto rrsig = getRR(*entry); if (rrsig) { - if (isRRSIGNotExpired(d_now.tv_sec, rrsig)) { + if (isRRSIGNotExpired(d_now.tv_sec, *rrsig)) { // we don't decrement d_sigexpire by 'now' because we actually want a TTD, not a TTL */ lowestTTD = min(lowestTTD, static_cast(rrsig->d_sigexpire)); } @@ -4282,9 +4282,9 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, const string& count can be lower than the name's label count if it was synthesized from the wildcard. Note that the difference might be > 1. */ - if (rec.d_name == qname && isWildcardExpanded(labelCount, rrsig)) { + if (rec.d_name == qname && isWildcardExpanded(labelCount, *rrsig)) { gatherWildcardProof = true; - if (!isWildcardExpandedOntoItself(rec.d_name, labelCount, rrsig)) { + if (!isWildcardExpandedOntoItself(rec.d_name, labelCount, *rrsig)) { /* if we have a wildcard expanded onto itself, we don't need to prove that the exact name doesn't exist because it actually does. We still want to gather the corresponding NSEC/NSEC3 records @@ -4569,7 +4569,7 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, const string& 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)) { + if (isWildcardExpanded(labelCount, *rrsig) && !isWildcardExpandedOntoItself(i->first.name, labelCount, *rrsig)) { DNSName realOwner = getNSECOwnerName(i->first.name, i->second.signatures); std::vector content; diff --git a/pdns/validate.cc b/pdns/validate.cc index da16c70b0e..af4f9d69af 100644 --- a/pdns/validate.cc +++ b/pdns/validate.cc @@ -88,22 +88,22 @@ static bool nsecProvesENT(const DNSName& name, const DNSName& begin, const DNSNa using nsec3HashesCache = std::map, std::string>; -static std::string getHashFromNSEC3(const DNSName& qname, const std::shared_ptr& nsec3, nsec3HashesCache& cache) +static std::string getHashFromNSEC3(const DNSName& qname, const NSEC3RecordContent& nsec3, nsec3HashesCache& cache) { std::string result; - if (g_maxNSEC3Iterations && nsec3->d_iterations > g_maxNSEC3Iterations) { + if (g_maxNSEC3Iterations && nsec3.d_iterations > g_maxNSEC3Iterations) { return result; } - auto key = std::make_tuple(qname, nsec3->d_salt, nsec3->d_iterations); + auto key = std::make_tuple(qname, nsec3.d_salt, nsec3.d_iterations); auto it = cache.find(key); if (it != cache.end()) { return it->second; } - result = hashQNameWithSalt(nsec3->d_salt, nsec3->d_iterations, qname); + result = hashQNameWithSalt(nsec3.d_salt, nsec3.d_iterations, qname); cache[key] = result; return result; } @@ -139,7 +139,7 @@ bool denialProvesNoDelegation(const DNSName& zone, const std::vector& continue; } - const string h = getHashFromNSEC3(zone, nsec3, cache); + const string h = getHashFromNSEC3(zone, *nsec3, cache); if (h.empty()) { return false; } @@ -163,9 +163,9 @@ bool denialProvesNoDelegation(const DNSName& zone, const std::vector& Labels field of the covering RRSIG RR, then the RRset and its covering RRSIG RR were created as a result of wildcard expansion." */ -bool isWildcardExpanded(unsigned int labelCount, const std::shared_ptr& sign) +bool isWildcardExpanded(unsigned int labelCount, const RRSIGRecordContent& sign) { - if (sign && sign->d_labels < labelCount) { + if (sign.d_labels < labelCount) { return true; } @@ -180,12 +180,12 @@ static bool isWildcardExpanded(const DNSName& owner, const std::vector& sign) +bool isWildcardExpandedOntoItself(const DNSName& owner, unsigned int labelCount, const RRSIGRecordContent& sign) { - if (owner.isWildcard() && (labelCount - 1) == sign->d_labels) { + if (owner.isWildcard() && (labelCount - 1) == sign.d_labels) { /* this is a wildcard alright, but it has not been expanded */ return true; } @@ -200,7 +200,7 @@ static bool isWildcardExpandedOntoItself(const DNSName& owner, const std::vector const auto& sign = signatures.at(0); unsigned int labelsCount = owner.countLabels(); - return isWildcardExpandedOntoItself(owner, labelsCount, sign); + return isWildcardExpandedOntoItself(owner, labelsCount, *sign); } /* if this is a wildcard NSEC, the owner name has been modified @@ -228,17 +228,17 @@ DNSName getNSECOwnerName(const DNSName& initialOwner, const std::vector& nsec) +static bool isNSECAncestorDelegation(const DNSName& signer, const DNSName& owner, const NSECRecordContent& nsec) { - return nsec->isSet(QType::NS) && - !nsec->isSet(QType::SOA) && + return nsec.isSet(QType::NS) && + !nsec.isSet(QType::SOA) && signer.countLabels() < owner.countLabels(); } -bool isNSEC3AncestorDelegation(const DNSName& signer, const DNSName& owner, const std::shared_ptr& nsec3) +bool isNSEC3AncestorDelegation(const DNSName& signer, const DNSName& owner, const NSEC3RecordContent& nsec3) { - return nsec3->isSet(QType::NS) && - !nsec3->isSet(QType::SOA) && + return nsec3.isSet(QType::NS) && + !nsec3.isSet(QType::SOA) && signer.countLabels() < owner.countLabels(); } @@ -262,7 +262,7 @@ static bool provesNoDataWildCard(const DNSName& qname, const uint16_t qtype, con } VLOG(log, qname << ":\tWildcard matches"); - if (qtype == 0 || isTypeDenied(nsec, QType(qtype))) { + if (qtype == 0 || isTypeDenied(*nsec, QType(qtype))) { VLOG_NO_PREFIX(log, " and proves that the type did not exist"<& nsec, const std::vector>& signatures, const OptLog& log) +dState matchesNSEC(const DNSName& name, uint16_t qtype, const DNSName& nsecOwner, const NSECRecordContent& nsec, const std::vector>& signatures, const OptLog& log) { const DNSName signer = getSigner(signatures); if (!name.isPartOf(signer) || !nsecOwner.isPartOf(signer)) { @@ -440,7 +440,7 @@ dState matchesNSEC(const DNSName& name, uint16_t qtype, const DNSName& nsecOwner return dState::NXQTYPE; } - if (name.isPartOf(owner) && nsec->isSet(QType::DNAME)) { + if (name.isPartOf(owner) && nsec.isSet(QType::DNAME)) { /* rfc6672 section 5.3.2: DNAME Bit in NSEC Type Map In any negative response, the NSEC or NSEC3 [RFC5155] record type @@ -454,10 +454,10 @@ dState matchesNSEC(const DNSName& name, uint16_t qtype, const DNSName& nsecOwner return dState::NODENIAL; } - if (isCoveredByNSEC(name, owner, nsec->d_next)) { - VLOG_NO_PREFIX(log, name << ": is covered by ("<d_next<<")"); + if (isCoveredByNSEC(name, owner, nsec.d_next)) { + VLOG_NO_PREFIX(log, name << ": is covered by ("<d_next)) { + if (nsecProvesENT(name, owner, nsec.d_next)) { VLOG_NO_PREFIX(log, " denies existence of type "<& sig) +bool isRRSIGNotExpired(const time_t now, const RRSIGRecordContent& sig) { // Should use https://www.rfc-editor.org/rfc/rfc4034.txt section 3.1.5 - return sig->d_sigexpire >= now; + return sig.d_sigexpire >= now; } -bool isRRSIGIncepted(const time_t now, const shared_ptr& sig) +bool isRRSIGIncepted(const time_t now, const RRSIGRecordContent& sig) { // Should use https://www.rfc-editor.org/rfc/rfc4034.txt section 3.1.5 - return sig->d_siginception - g_signatureInceptionSkew <= now; + return sig.d_siginception - g_signatureInceptionSkew <= now; } -static bool checkSignatureWithKey(const DNSName& qname, time_t now, const shared_ptr& sig, const shared_ptr& key, const std::string& msg, vState& ede, const OptLog& log) +static bool checkSignatureWithKey(const DNSName& qname, time_t now, const RRSIGRecordContent& sig, const DNSKEYRecordContent& key, const std::string& msg, vState& ede, const OptLog& log) { bool result = false; try { @@ -917,16 +917,16 @@ static bool checkSignatureWithKey(const DNSName& qname, time_t now, const shared - The validator's notion of the current time MUST be greater than or equal to the time listed in the RRSIG RR's Inception field. */ if (isRRSIGIncepted(now, sig) && isRRSIGNotExpired(now, sig)) { - auto dke = DNSCryptoKeyEngine::makeFromPublicKeyString(key->d_algorithm, key->d_key); - result = dke->verify(msg, sig->d_signature); - VLOG(log, qname << ": Signature by key with tag "<d_tag<<" and algorithm "<d_algorithm)<<" was " << (result ? "" : "NOT ")<<"valid"<verify(msg, sig.d_signature); + VLOG(log, qname << ": Signature by key with tag "<d_siginception - g_signatureInceptionSkew) > now) ? vState::BogusSignatureNotYetValid : vState::BogusSignatureExpired; - VLOG(log, qname << ": Signature is "<<(ede == vState::BogusSignatureNotYetValid ? "not yet valid" : "expired")<<" (inception: "<d_siginception<<", inception skew: "<d_sigexpire<<", now: "< now) ? vState::BogusSignatureNotYetValid : vState::BogusSignatureExpired; + VLOG(log, qname << ": Signature is "<<(ede == vState::BogusSignatureNotYetValid ? "not yet valid" : "expired")<<" (inception: "< >& signatures); bool denialProvesNoDelegation(const DNSName& zone, const std::vector& dsrecords); -bool isRRSIGNotExpired(const time_t now, const std::shared_ptr& sig); -bool isRRSIGIncepted(const time_t now, const shared_ptr& sig); -bool isWildcardExpanded(unsigned int labelCount, const std::shared_ptr& sign); -bool isWildcardExpandedOntoItself(const DNSName& owner, unsigned int labelCount, const std::shared_ptr& sign); +bool isRRSIGNotExpired(const time_t now, const RRSIGRecordContent& sig); +bool isRRSIGIncepted(const time_t now, const RRSIGRecordContent& sig); +bool isWildcardExpanded(unsigned int labelCount, const RRSIGRecordContent& sign); +bool isWildcardExpandedOntoItself(const DNSName& owner, unsigned int labelCount, const RRSIGRecordContent& sign); void updateDNSSECValidationState(vState& state, const vState stateUpdate); -dState matchesNSEC(const DNSName& name, uint16_t qtype, const DNSName& nsecOwner, const std::shared_ptr& nsec, const std::vector>& signatures, const OptLog&); +dState matchesNSEC(const DNSName& name, uint16_t qtype, const DNSName& nsecOwner, const NSECRecordContent& nsec, const std::vector>& signatures, const OptLog&); -bool isNSEC3AncestorDelegation(const DNSName& signer, const DNSName& owner, const std::shared_ptr& nsec3); +bool isNSEC3AncestorDelegation(const DNSName& signer, const DNSName& owner, const NSEC3RecordContent& nsec3); DNSName getNSECOwnerName(const DNSName& initialOwner, const std::vector >& signatures); DNSName getClosestEncloserFromNSEC(const DNSName& name, const DNSName& owner, const DNSName& next); template bool isTypeDenied(const NSEC& nsec, const QType& type) { - if (nsec->isSet(type.getCode())) { + if (nsec.isSet(type.getCode())) { return false; } /* RFC 6840 section 4.3 */ - if (nsec->isSet(QType::CNAME)) { + if (nsec.isSet(QType::CNAME)) { return false; }