mDNSexport void InitializeAnonInfoForQuestion(mDNS *const m, CacheRecord **McastNSEC3Records, DNSQuestion *q) { CacheRecord *nsec3CR; if (q->qtype != kDNSType_PTR) return; nsec3CR = FindMatchingNSEC3ForName(m, McastNSEC3Records, &q->qname); if (nsec3CR) { q->AnonInfo = AllocateAnonInfo(mDNSNULL, mDNSNULL, 0, &nsec3CR->resrec); if (q->AnonInfo) { debugf("InitializeAnonInfoForQuestion: Found a matching NSEC3 record %s, for %##s (%s)", RRDisplayString(m, q->AnonInfo->nsec3RR), q->qname.c, DNSTypeName(q->qtype)); } ReleaseCacheRecord(m, nsec3CR); } }
mDNSlocal mDNSBool NSECNoWildcard(mDNS *const m, ResourceRecord *rr, domainname *qname, mDNSu16 qtype) { const domainname *ce; domainname wild; // If the query name is c.x.w.example and if the name does not exist, we should get // get a nsec back that looks something like this: // // w.example NSEC a.w.example // // First, we need to get the closest encloser which in this case is w.example. Wild // card synthesis works by finding the closest encloser first and then look for // a "*" label (assuming * label does not appear in the question). If it does not // exists, it would return the NSEC at that name. And the wildcard name at the // closest encloser "*.w.example" would be covered by such an NSEC. (Appending "*" // makes it bigger than w.example and "* is smaller than "a" for the above NSEC) // ce = NSECClosestEncloser(rr, qname); if (!ce) { LogMsg("NSECNoWildcard: No closest encloser for rr %s, qname %##s (%s)", qname->c, DNSTypeName(qtype)); return mDNSfalse; } wild.c[0] = 1; wild.c[1] = '*'; wild.c[2] = 0; if (!AppendDomainName(&wild, ce)) { LogMsg("NSECNoWildcard: ERROR!! Can't append domainname closest encloser name %##s, qname %##s (%s)", ce->c, qname->c, DNSTypeName(qtype)); return mDNSfalse; } if (NSECNameExists(m, rr, &wild, qtype) != 0) { LogDNSSEC("NSECNoWildcard: Wildcard name %##s exists or not valid qname %##s (%s)", wild.c, qname->c, DNSTypeName(qtype)); return mDNSfalse; } LogDNSSEC("NSECNoWildcard: Wildcard name %##s does not exist for record %s, qname %##s (%s)", wild.c, RRDisplayString(m, rr), qname->c, DNSTypeName(qtype)); return mDNStrue; }
mDNSexport void InitializeAnonInfoForCR(mDNS *const m, CacheRecord **McastNSEC3Records, CacheRecord *cr) { CacheRecord *nsec3CR; if (!(*McastNSEC3Records)) return; // If already initialized or not a PTR type, we don't have to do anything if (cr->resrec.AnonInfo || cr->resrec.rrtype != kDNSType_PTR) return; nsec3CR = FindMatchingNSEC3ForName(m, McastNSEC3Records, cr->resrec.name); if (nsec3CR) { cr->resrec.AnonInfo = AllocateAnonInfo(mDNSNULL, mDNSNULL, 0, &nsec3CR->resrec); if (cr->resrec.AnonInfo) { debugf("InitializeAnonInfoForCR: Found a matching NSEC3 record %s, for %##s (%s)", RRDisplayString(m, cr->resrec.AnonInfo->nsec3RR), cr->resrec.name->c, DNSTypeName(cr->resrec.rrtype)); } ReleaseCacheRecord(m, nsec3CR); } }
mDNSlocal void DNSSECProbeCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord) { if (!AddRecord) return; mDNS_Lock(m); if ((m->timenow - question->StopTime) >= 0) { mDNS_Unlock(m); LogDNSSEC("DNSSECProbeCallback: Question %##s (%s) timed out", question->qname.c, DNSTypeName(question->qtype)); mDNS_StopQuery(m, question); return; } mDNS_Unlock(m); // Wait till we get the DNSSEC results. If we get a negative response e.g., no DNS servers, the // question will be restarted by the core and we should have the DNSSEC results eventually. if (AddRecord != QC_dnssec) { LogDNSSEC("DNSSECProbeCallback: Question %##s (%s)", question->qname.c, DNSTypeName(question->qtype), RRDisplayString(m, answer)); return; } LogDNSSEC("DNSSECProbeCallback: Question %##s (%s), DNSSEC status %s", question->qname.c, DNSTypeName(question->qtype), DNSSECStatusName(question->ValidationStatus)); mDNS_StopQuery(m, question); }
// We get a NXDOMAIN error with no records in answer section. This proves // that qname does not exist. mDNSlocal void NameErrorProof(mDNS *const m, DNSSECVerifier *dv, CacheRecord *ncr) { CacheRecord **rp; ResourceRecord *nsec_wild = mDNSNULL; ResourceRecord *nsec_noname = mDNSNULL; mStatus status; // NXDOMAIN Error. We need to prove that the qname does not exist and there // is no wildcard that can be used to answer the question. rp = &(ncr->nsec); while (*rp) { if ((*rp)->resrec.rrtype == kDNSType_NSEC) { CacheRecord *cr = *rp; if (!NSECNameExists(m, &cr->resrec, &dv->q.qname, dv->q.qtype)) { LogDNSSEC("NameErrorProof: NSEC %s proves name does not exist for %##s (%s)", RRDisplayString(m, &(*rp)->resrec), dv->q.qname.c, DNSTypeName(dv->q.qtype)); // If we have a wildcard, then we should check to see if the closest // encloser is the same as the wildcard. dv->flags |= NSEC_PROVES_NONAME_EXISTS; nsec_noname = &cr->resrec; } if (NSECNoWildcard(m, &cr->resrec, &dv->q.qname, dv->q.qtype)) { dv->flags |= WILDCARD_PROVES_NONAME_EXISTS; nsec_wild = &cr->resrec; LogDNSSEC("NameErrorProof: NSEC %s proves wildcard cannot answer question for %##s (%s)", RRDisplayString(m, &(*rp)->resrec), dv->q.qname.c, DNSTypeName(dv->q.qtype)); } } rp=&(*rp)->next; } if (!nsec_noname || !nsec_wild) { LogMsg("NameErrorProof: Proof failed for %##s (%s) noname %p, wild %p", dv->q.qname.c, DNSTypeName(dv->q.qtype), nsec_noname, nsec_wild); goto error; } // First verify wildcard NSEC and then when we are done, we will verify the noname nsec. // Sometimes a single NSEC can prove both that the "qname" does not exist and a wildcard // could not have produced qname. These are a few examples where this can happen. // // 1. If the zone is example.com and you look up *.example.com and if there are no wildcards, // you will get a NSEC back "example.com NSEC a.example.com". This proves that both the // name does not exist and *.example.com also does not exist // // 2. If the zone is example.com and it has a record like this: // // example.com NSEC d.example.com // // any name you lookup in between like a.example.com,b.example.com etc. you will get a single // NSEC back. In that case we just have to verify only once. // if (nsec_wild != nsec_noname) { RRVerifier *r = AllocateRRVerifier(nsec_noname, &status); if (!r) goto error; dv->pendingNSEC = r; LogDNSSEC("NoDataProof: Verifying wild %s", RRDisplayString(m, nsec_wild)); VerifyNSEC(m, nsec_wild, mDNSNULL, dv, ncr, NameErrorNSECCallback); } else { LogDNSSEC("NoDataProof: Verifying only one %s", RRDisplayString(m, nsec_wild)); VerifyNSEC(m, nsec_wild, mDNSNULL, dv, ncr, mDNSNULL); } return; error: dv->DVCallback(m, dv, DNSSEC_Bogus); }
// We get a NODATA error with no records in answer section. This proves // that qname does not exist. mDNSlocal void NoDataProof(mDNS *const m, DNSSECVerifier *dv, CacheRecord *ncr) { CacheRecord **rp; domainname *wildcard = mDNSNULL; const domainname *ce = mDNSNULL; ResourceRecord *nsec_wild = mDNSNULL; ResourceRecord *nsec_noname = mDNSNULL; // NODATA Error could mean two things. The name exists with no type or there is a // wildcard that matches the name but no type. This is done by NSECNoDataError. // // If it is the case of wildcard, there are two NSECs. One is the wildcard NSEC and // the other NSEC to prove that there is no other closer match. wildcard = mDNSNULL; rp = &(ncr->nsec); while (*rp) { if ((*rp)->resrec.rrtype == kDNSType_NSEC) { CacheRecord *cr = *rp; if (NSECNoDataError(m, &cr->resrec, &dv->q.qname, dv->q.qtype, &wildcard)) { if (wildcard) { dv->flags |= WILDCARD_PROVES_NONAME_EXISTS; LogDNSSEC("NoDataProof: NSEC %s proves NODATA error for %##s (%s)", RRDisplayString(m, &(*rp)->resrec), dv->q.qname.c, DNSTypeName(dv->q.qtype)); } else { dv->flags |= NSEC_PROVES_NOTYPE_EXISTS; LogDNSSEC("NoDataProof: NSEC %s proves NOTYPE error for %##s (%s)", RRDisplayString(m, &(*rp)->resrec), dv->q.qname.c, DNSTypeName(dv->q.qtype)); } nsec_wild = &cr->resrec; } if (!NSECNameExists(m, &cr->resrec, &dv->q.qname, dv->q.qtype)) { LogDNSSEC("NoDataProof: NSEC %s proves that name %##s (%s) does not exist", RRDisplayString(m, &(*rp)->resrec), dv->q.qname.c, DNSTypeName(dv->q.qtype)); // If we have a wildcard, then we should check to see if the closest // encloser is the same as the wildcard. ce = NSECClosestEncloser(&cr->resrec, &dv->q.qname); dv->flags |= NSEC_PROVES_NONAME_EXISTS; nsec_noname = &cr->resrec; } } rp=&(*rp)->next; } if (!nsec_noname && !nsec_wild) { LogDNSSEC("NoDataProof: No valid NSECs for %##s (%s)", dv->q.qname.c, DNSTypeName(dv->q.qtype)); goto error; } // If the type exists, then we have to verify just that NSEC if (!(dv->flags & NSEC_PROVES_NOTYPE_EXISTS)) { // If we have a wildcard, then we should have a "ce" which matches the wildcard // If we don't have a wildcard, then we should have proven that the name does not // exist which means we would have set the "ce". if (wildcard && !ce) { LogMsg("NoDataProof: Cannot prove that the name %##s (%s) does not exist", dv->q.qname.c, DNSTypeName(dv->q.qtype)); goto error; } if (wildcard && !SameDomainName(wildcard, ce)) { LogMsg("NoDataProof: wildcard %##s does not match closest encloser %##s", wildcard->c, ce->c); goto error; } // If a single NSEC can prove both, then we just have validate that one NSEC. if (nsec_wild == nsec_noname) { nsec_noname = mDNSNULL; dv->flags &= ~NSEC_PROVES_NONAME_EXISTS; } } if ((dv->flags & (WILDCARD_PROVES_NONAME_EXISTS|NSEC_PROVES_NONAME_EXISTS)) == (WILDCARD_PROVES_NONAME_EXISTS|NSEC_PROVES_NONAME_EXISTS)) { mStatus status; RRVerifier *r = AllocateRRVerifier(nsec_noname, &status); if (!r) goto error; // First verify wildcard NSEC and then when we are done, we // will verify the noname nsec dv->pendingNSEC = r; LogDNSSEC("NoDataProof: Verifying wild and noname %s", RRDisplayString(m, nsec_wild)); VerifyNSEC(m, nsec_wild, mDNSNULL, dv, ncr, NoDataNSECCallback); } else if ((dv->flags & WILDCARD_PROVES_NONAME_EXISTS) || (dv->flags & NSEC_PROVES_NOTYPE_EXISTS)) { LogDNSSEC("NoDataProof: Verifying wild %s", RRDisplayString(m, nsec_wild)); VerifyNSEC(m, nsec_wild, mDNSNULL, dv, ncr, mDNSNULL); } else if (dv->flags & NSEC_PROVES_NONAME_EXISTS) { LogDNSSEC("NoDataProof: Verifying noname %s", RRDisplayString(m, nsec_noname)); VerifyNSEC(m, nsec_noname, mDNSNULL, dv, ncr, mDNSNULL); } return; error: LogDNSSEC("NoDataProof: Error return"); dv->DVCallback(m, dv, DNSSEC_Bogus); }
// We have a NSEC. Need to see if it proves that NODATA exists for the given name. Note that this // function does not prove anything as proof may require more than one NSEC and this function // processes only one NSEC at a time. // // Returns mDNSfalse if the NSEC does not prove the NODATA error // Returns mDNStrue if the NSEC proves the NODATA error // mDNSlocal mDNSBool NSECNoDataError(mDNS *const m, ResourceRecord *rr, domainname *name, mDNSu16 qtype, domainname **wildcard) { const domainname *oname = rr->name; // owner name if (wildcard) *wildcard = mDNSNULL; // RFC 4035 // // section 3.1.3.1 : Name matches. Prove that the type does not exist and also CNAME is // not set as in that case CNAME should have been returned ( CNAME part is mentioned in // section 4.3 of dnssec-bis-updates.) Without the CNAME check, a positive response can // be converted to a NODATA/NOERROR response. // // section 3.1.3.4 : No exact match for the name but there is a wildcard that could match // the name but not the type. There are two NSECs in this case. One of them is a wildcard // NSEC and another NSEC proving that the qname does not exist. We are called with one // NSEC at a time. We return what we matched and the caller should decide whether all // conditions are met for the proof. if (SameDomainName(oname, name)) { mDNSBool soa = RRAssertsExistence(rr, kDNSType_SOA); mDNSBool ns = RRAssertsExistence(rr, kDNSType_NS); if (qtype != kDNSType_DS) { // For non-DS type questions, we don't want to use the parent side records to // answer it if (ns && !soa) { LogDNSSEC("NSECNoDataError: Parent side NSEC %s, can't use for child qname %##s (%s)", RRDisplayString(m, rr), name->c, DNSTypeName(qtype)); return mDNSfalse; } } else { if (soa) { LogDNSSEC("NSECNoDataError: Child side NSEC %s, can't use for parent qname %##s (%s)", RRDisplayString(m, rr), name->c, DNSTypeName(qtype)); return mDNSfalse; } } if (RRAssertsExistence(rr, qtype) || RRAssertsExistence(rr, kDNSType_CNAME)) { LogMsg("NSECNoDataError: ERROR!! qtype %s exists in %s", DNSTypeName(qtype), RRDisplayString(m, rr)); return mDNSfalse; } LogDNSSEC("NSECNoDataError: qype %s does not exist in %s", DNSTypeName(qtype), RRDisplayString(m, rr)); return mDNStrue; } else { // Name does not exist. Before we check for a wildcard match, make sure that // this is not an ENT. if (NSECAnswersENT(rr, name)) { LogDNSSEC("NSECNoDataError: name %##s exists %s", name->c, RRDisplayString(m, rr)); return mDNSfalse; } // Wildcard check. If this is a wildcard NSEC, then check to see if we could // have answered the question using this wildcard and it should not have the // "qtype" passed in with its bitmap. // // See RFC 4592, on how wildcards are used to synthesize answers. Find the // closest encloser and the qname should be a subdomain i.e if the wildcard // is *.x.example, x.example is the closest encloser and the qname should be // a subdomain e.g., y.x.example or z.y.x.example and so on. if (oname->c[0] == 1 && oname->c[1] == '*') { int r, s; const domainname *ce = SkipLeadingLabels(oname, 1); r = DNSSECCanonicalOrder(name, ce, &s); if (s) { if (RRAssertsExistence(rr, qtype) || RRAssertsExistence(rr, kDNSType_CNAME)) { LogMsg("NSECNoDataError: ERROR!! qtype %s exists in wildcard %s", DNSTypeName(qtype), RRDisplayString(m, rr)); return mDNSfalse; } if (qtype == kDNSType_DS && RRAssertsExistence(rr, kDNSType_SOA)) { LogDNSSEC("NSECNoDataError: Child side wildcard NSEC %s, can't use for parent qname %##s (%s)", RRDisplayString(m, rr), name->c, DNSTypeName(qtype)); return mDNSfalse; } else if (qtype != kDNSType_DS && RRAssertsNonexistence(rr, kDNSType_SOA) && RRAssertsExistence(rr, kDNSType_NS)) { // Don't use the parent side record for this LogDNSSEC("NSECNoDataError: Parent side wildcard NSEC %s, can't use for child qname %##s (%s)", RRDisplayString(m, rr), name->c, DNSTypeName(qtype)); return mDNSfalse; } *wildcard = (domainname *)ce; LogDNSSEC("NSECNoDataError: qtype %s does not exist in wildcard %s", DNSTypeName(qtype), RRDisplayString(m, rr)); return mDNStrue; } } return mDNSfalse; } }
// Assumption: NSEC has been validated outside of this function // // Does the name exist given the name and NSEC rr ? // // Returns -1 if it is an inappropriate nsec // Returns 1 if the name exists // Returns 0 if the name does not exist // mDNSlocal int NSECNameExists(mDNS *const m, ResourceRecord *rr, domainname *name, mDNSu16 qtype) { const RDataBody2 *const rdb = (RDataBody2 *)rr->rdata->u.data; const domainname *nxt = (const domainname *)&rdb->data; const domainname *oname = rr->name; // owner name int ret1, subdomain1; int ret2, subdomain2; int ret3, subdomain3; ret1 = DNSSECCanonicalOrder(oname, name, &subdomain1); if (ret1 > 0) { LogDNSSEC("NSECNameExists: owner name %##s is bigger than name %##s", oname->c, name->c); return -1; } // Section 4.1 of draft-ietf-dnsext-dnssec-bis-updates-14: // // Ancestor delegation NSEC or NSEC3 RRs MUST NOT be used to assume non- // existence of any RRs below that zone cut, which include all RRs at // that (original) owner name other than DS RRs, and all RRs below that // owner name regardless of type. // // This also implies that we can't use the child side NSEC for DS question. if (!ret1) { mDNSBool soa = RRAssertsExistence(rr, kDNSType_SOA); mDNSBool ns = RRAssertsExistence(rr, kDNSType_NS); // We are here because the owner name is the same as "name". Make sure the // NSEC has the right NS and SOA bits set. if (qtype != kDNSType_DS && ns && !soa) { LogDNSSEC("NSECNameExists: Parent side NSEC %s can't be used for question %##s (%s)", RRDisplayString(m, rr), name->c, DNSTypeName(qtype)); return -1; } else if (qtype == kDNSType_DS && soa) { LogDNSSEC("NSECNameExists: Child side NSEC %s can't be used for question %##s (%s)", RRDisplayString(m, rr), name->c, DNSTypeName(qtype)); return -1; } LogDNSSEC("NSECNameExists: owner name %##s is same as name %##s", oname->c, name->c); return 1; } // If the name is a.b.com and NSEC's owner name is b.com i.e., a subdomain // and nsec comes from the parent (NS is set and SOA is not set), then this // NSEC can't be used for names below the owner name. // // Similarly if DNAME is set, we can't use it here. See RFC2672-bis-dname // appendix. if (subdomain1 && (RRAssertsExistence(rr, kDNSType_DNAME) || (RRAssertsNonexistence(rr, kDNSType_SOA) && RRAssertsExistence(rr, kDNSType_NS)))) { LogDNSSEC("NSECNameExists: NSEC %s comes from the parent, can't use it here", RRDisplayString(m, rr)); return -1; } // At this stage, we know that name is greater than the owner name and // the nsec is not from the parent side. // // Compare with the next field in the nsec. // ret2 = DNSSECCanonicalOrder(name, nxt, &subdomain2); // Exact match with the nsec next name if (!ret2) { LogDNSSEC("NSECNameExists: name %##s is same as nxt name %##s", name->c, nxt->c); return 1; } ret3 = DNSSECCanonicalOrder(oname, nxt, &subdomain3); if (!ret3) { // Pathological case of a single name in the domain. This means only the // apex of the zone itself exists. Nothing below it. "subdomain2" indicates // that name is a subdmain of "next" and hence below the zone. if (subdomain2) { LogDNSSEC("NSECNameExists: owner name %##s subdomain of nxt name %##s", oname->c, nxt->c); return 0; } else { LogDNSSEC("NSECNameExists: Single name in zone, owner name %##s is same as nxt name %##s", oname->c, nxt->c); return -1; } } if (ret3 < 0) { // Regular NSEC in the zone. Make sure that the "name" lies within // oname and next. oname < name and name < next if (ret1 < 0 && ret2 < 0) { LogDNSSEC("NSECNameExists: Normal NSEC name %##s lies within owner %##s and nxt name %##s", name->c, oname->c, nxt->c); return 0; } else { LogDNSSEC("NSECNameExists: Normal NSEC name %##s does not lie within owner %##s and nxt name %##s", name->c, oname->c, nxt->c); return -1; } } else { // Last NSEC in the zone. The "next" is pointing to the apex. All names // should be a subdomain of that and the name should be bigger than // oname if (ret1 < 0 && subdomain2) { LogDNSSEC("NSECNameExists: Last NSEC name %##s lies within owner %##s and nxt name %##s", name->c, oname->c, nxt->c); return 0; } else { LogDNSSEC("NSECNameExists: Last NSEC name %##s does not lie within owner %##s and nxt name %##s", name->c, oname->c, nxt->c); return -1; } } LogDNSSEC("NSECNameExists: NSEC %s did not match any case", RRDisplayString(m, rr)); return -1; }
// returns -1 if the caller should ignore the result // returns 1 if the record answers the question // returns 0 if the record does not answer the question mDNSexport int AnonInfoAnswersQuestion(const ResourceRecord *const rr, const DNSQuestion *const q) { mDNSexport mDNS mDNSStorage; ResourceRecord *nsec3RR; int i; AnonymousInfo *qai, *rai; mDNSu8 *AnonData; int AnonDataLen; rdataNSEC3 *nsec3; int hlen; const mDNSu8 hashName[NSEC3_MAX_HASH_LEN]; int nxtLength; mDNSu8 *nxtName; debugf("AnonInfoAnswersQuestion: question qname %##s", q->qname.c); // Currently only PTR records can have anonymous information if (q->qtype != kDNSType_PTR) { return -1; } // We allow anonymous questions to be answered by both normal services (without the // anonymous information) and anonymous services that are part of the same set. And // normal questions discover normal services and all anonymous services. // // The three cases have been enumerated clearly even though they all behave the // same way. if (!q->AnonInfo) { debugf("AnonInfoAnswersQuestion: not a anonymous type question"); if (!rr->AnonInfo) { // case 1 return -1; } else { // case 2 debugf("AnonInfoAnswersQuestion: Question %##s not answered using anonymous record %##s", q->qname.c, rr->name->c); return -1; } } else { // case 3 if (!rr->AnonInfo) { debugf("AnonInfoAnswersQuestion: not a anonymous type record"); return -1; } } // case 4: We have the anonymous information both in the question and the record. We need // two sets of information to validate. // // 1) Anonymous data that identifies the set/group // 2) NSEC3 record that contains the hash and the salt // // If the question is a remote one, it does not have the anonymous information to validate (just // the NSEC3 record) and hence the anonymous data should come from the local resource record. If the // question is local, it can come from either of them and if there is a mismatch between the // question and record, it won't validate. qai = q->AnonInfo; rai = rr->AnonInfo; if (qai->AnonData && rai->AnonData) { // Before a cache record is created, if there is a matching question i.e., part // of the same set, then when the cache is created we also set the anonymous // information. Otherwise, the cache record contains just the NSEC3 record and we // won't be here for that case. // // It is also possible that a local question is matched against the local AuthRecord // as that is also the case for which the AnonData would be non-NULL for both. // We match questions against AuthRecords (rather than the cache) for LocalOnly case and // to see whether a .local query should be suppressed or not. The latter never happens // because PTR queries are never suppressed. // If they don't belong to the same anonymous set, then no point in validating. if ((qai->AnonDataLen != rai->AnonDataLen) || mDNSPlatformMemCmp(qai->AnonData, rai->AnonData, qai->AnonDataLen) != 0) { debugf("AnonInfoAnswersQuestion: AnonData mis-match for record %s question %##s ", RRDisplayString(&mDNSStorage, rr), q->qname.c); return 0; } // AnonData matches i.e they belong to the same group and the same service. LogInfo("AnonInfoAnswersQuestion: Answering qname %##s, rname %##s, without validation", q->qname.c, rr->name->c); return 1; } else { debugf("AnonInfoAnswersQuestion: question %p, record %p", qai->AnonData, rai->AnonData); } if (qai->AnonData) { // If there is AnonData, then this is a local question. The // NSEC3 RR comes from the resource record which could be part // of the cache or local auth record. The cache entry could // be from a remote host or created when we heard our own // announcements. In any case, we use that to see if it matches // the question. AnonData = qai->AnonData; AnonDataLen = qai->AnonDataLen; nsec3RR = rai->nsec3RR; } else { // Remote question or hearing our own question back AnonData = rai->AnonData; AnonDataLen = rai->AnonDataLen; nsec3RR = qai->nsec3RR; } if (!AnonData || !nsec3RR) { // AnonData can be NULL for the cache entry and if we are hearing our own question back, AnonData is NULL for // that too and we can end up here for that case. debugf("AnonInfoAnswersQuestion: AnonData %p or nsec3RR %p, NULL for question %##s, record %s", AnonData, nsec3RR, q->qname.c, RRDisplayString(&mDNSStorage, rr)); return 0; } debugf("AnonInfoAnswersQuestion: Validating question %##s, ResourceRecord %s", q->qname.c, RRDisplayString(&mDNSStorage, nsec3RR)); nsec3 = (rdataNSEC3 *)nsec3RR->rdata->u.data; if (!NSEC3HashName(nsec3RR->name, nsec3, AnonData, AnonDataLen, hashName, &hlen)) { LogMsg("AnonInfoAnswersQuestion: NSEC3HashName failed for ##s", nsec3RR->name->c); return mDNSfalse; } if (hlen != SHA1_HASH_LENGTH) { LogMsg("AnonInfoAnswersQuestion: hlen wrong %d", hlen); return mDNSfalse; } NSEC3Parse(nsec3RR, mDNSNULL, &nxtLength, &nxtName, mDNSNULL, mDNSNULL); if (hlen != nxtLength) { LogMsg("AnonInfoAnswersQuestion: ERROR!! hlen %d not same as nxtLength %d", hlen, nxtLength); return mDNSfalse; } for (i = 0; i < nxtLength; i++) { if (nxtName[i] != hashName[i]) { debugf("AnonInfoAnswersQuestion: mismatch output %x, digest %x, i %d", nxtName[i+1], hashName[i], i); return 0; } } LogInfo("AnonInfoAnswersQuestion: ResourceRecord %s matched question %##s (%s)", RRDisplayString(&mDNSStorage, nsec3RR), q->qname.c, DNSTypeName(q->qtype)); return 1; }