From: JINMEI Tatuya Date: Wed, 19 Oct 2011 05:10:08 +0000 (-0700) Subject: [1307] added wildcard proof, case 1 X-Git-Tag: perftcpdns_before_epoll~75^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f546d730bb772a8a4b9ea1737ed63d888755673a;p=thirdparty%2Fkea.git [1307] added wildcard proof, case 1 --- diff --git a/src/bin/auth/query.cc b/src/bin/auth/query.cc index 9b47a7e8a2..feca81ab55 100644 --- a/src/bin/auth/query.cc +++ b/src/bin/auth/query.cc @@ -141,6 +141,7 @@ Query::process() const { response_.setRcode(Rcode::REFUSED()); return; } + ZoneFinder& zfinder = *result.zone_finder; // Found a zone which is the nearest ancestor to QNAME, set the AA bit response_.setHeaderFlag(Message::HEADERFLAG_AA); @@ -149,8 +150,7 @@ Query::process() const { keep_doing = false; std::auto_ptr target(qtype_is_any ? new RRsetList : NULL); const ZoneFinder::FindResult db_result( - result.zone_finder->find(qname_, qtype_, target.get(), - dnssec_opt_)); + zfinder.find(qname_, qtype_, target.get(), dnssec_opt_)); switch (db_result.code) { case ZoneFinder::DNAME: { // First, put the dname into the answer @@ -250,10 +250,26 @@ Query::process() const { // If DNSSEC proof is requested and we've got it, add it. if (dnssec_ && db_result.rrset) { + // TODO: Handle unexpected (buggy case): rrset is not NSEC + response_.addRRset( Message::SECTION_AUTHORITY, boost::const_pointer_cast(db_result.rrset), dnssec_); + const int qlabels = qname_.getLabelCount(); + const int olabels = qname_.compare( + db_result.rrset->getName()).getCommonLabels(); + const Name wildname(Name("*").concatenate( + qname_.split(qlabels - olabels))); + // TODO: check if we need NO_WILDCARD here. (we should do) + const ZoneFinder::FindResult fresult = + zfinder.find(wildname, RRType::NSEC(), NULL, + dnssec_opt_); + // TODO: check fresult: should be NXDOMAIN, and rrset is NSEC. + response_.addRRset( + Message::SECTION_AUTHORITY, + boost::const_pointer_cast(fresult.rrset), + dnssec_); } break; case ZoneFinder::NXRRSET: diff --git a/src/bin/auth/tests/query_unittest.cc b/src/bin/auth/tests/query_unittest.cc index b0a813230e..e40cbc3dfc 100644 --- a/src/bin/auth/tests/query_unittest.cc +++ b/src/bin/auth/tests/query_unittest.cc @@ -91,7 +91,9 @@ const char* const other_zone_rrs = "cnamemailer.example.com. 3600 IN CNAME www.example.com.\n" "cnamemx.example.com. 3600 IN MX 10 cnamemailer.example.com.\n" "mx.delegation.example.com. 3600 IN A 192.0.2.100\n"; -// NSEC records +// NSEC records. +const char* const nsec_apex_txt = + "example.com. 3600 IN NSEC cname.example.com. NS SOA NSEC RRSIG\n"; const char* const nsec_nxdomain_txt = "noglue.example.com. 3600 IN NSEC www.example.com. A\n"; @@ -132,7 +134,7 @@ public: zone_stream << soa_txt << zone_ns_txt << ns_addrs_txt << delegation_txt << mx_txt << www_a_txt << cname_txt << cname_nxdom_txt << cname_out_txt << dname_txt << dname_a_txt << - other_zone_rrs << nsec_nxdomain_txt; + other_zone_rrs << nsec_apex_txt << nsec_nxdomain_txt; masterLoad(zone_stream, origin_, rrclass_, boost::bind(&MockZoneFinder::loadRRset, this, _1)); @@ -472,11 +474,9 @@ TEST_F(QueryTest, apexAnyMatch) { // in the answer section from the additional. EXPECT_NO_THROW(Query(memory_client, Name("example.com"), RRType::ANY(), response).process()); - responseCheck(response, Rcode::NOERROR(), AA_FLAG, 4, 0, 3, - "example.com. 3600 IN SOA . . 0 0 0 0 0\n" - "example.com. 3600 IN NS glue.delegation.example.com.\n" - "example.com. 3600 IN NS noglue.example.com.\n" - "example.com. 3600 IN NS example.net.\n", + responseCheck(response, Rcode::NOERROR(), AA_FLAG, 5, 0, 3, + (string(soa_txt) + string(zone_ns_txt) + + string(nsec_apex_txt)).c_str(), NULL, ns_addrs_txt, mock_finder->getOrigin()); } @@ -530,14 +530,21 @@ TEST_F(QueryTest, nxdomain) { } TEST_F(QueryTest, nxdomainWithNSEC) { + // NXDOMAIN with DNSSEC proof. We should have SOA, NSEC that proves + // NXDOMAIN and NSEC that proves nonexistence of matching wildcard, + // as well as their RRSIGs. EXPECT_NO_THROW(Query(memory_client, Name("nxdomain.example.com"), qtype, response, true).process()); - responseCheck(response, Rcode::NXDOMAIN(), AA_FLAG, 0, 4, 0, + cout << response.toText() << endl; + responseCheck(response, Rcode::NXDOMAIN(), AA_FLAG, 0, 6, 0, NULL, (string(soa_txt) + string("example.com. 3600 IN RRSIG ") + getCommonRRSIGText("SOA") + "\n" + string(nsec_nxdomain_txt) + "\n" + string("noglue.example.com. 3600 IN RRSIG ") + + getCommonRRSIGText("NSEC") + "\n" + + string(nsec_apex_txt) + "\n" + + string("example.com. 3600 IN RRSIG ") + getCommonRRSIGText("NSEC")).c_str(), NULL, mock_finder->getOrigin()); }