validator.c revision dafcb997e390efa4423883dafd100c975c4095d6
/*
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: validator.c,v 1.118 2004/03/05 05:09:26 marka Exp $ */
#include <config.h>
#include <dns/keytable.h>
#include <dns/rdatastruct.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
#include <dns/resolver.h>
#include <dns/validator.h>
#define VALATTR_SHUTDOWN 0x0001
#define VALATTR_FOUNDNONEXISTENCE 0x0002
#define VALATTR_TRIEDVERIFY 0x0004
#define VALATTR_NEGATIVE 0x0008
#define VALATTR_INSECURITY 0x0010
#define VALATTR_NEEDNOQNAME 0x0100
#define VALATTR_NEEDNOWILDCARD 0x0200
#define VALATTR_NEEDNODATA 0x0400
#define VALATTR_FOUNDNOQNAME 0x1000
#define VALATTR_FOUNDNOWILDCARD 0x2000
#define VALATTR_FOUNDNODATA 0x4000
static void
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static void
ISC_FORMAT_PRINTF(5, 0);
static void
static void
static void
return;
/*
* Caller must be holding the lock.
*/
}
static inline isc_boolean_t
/*
* Caller must be holding the lock.
*/
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
}
static void
result == ISC_R_SUCCESS;
{
{
}
}
}
static isc_boolean_t
{
if (dbresult == DNS_R_NXRRSET)
else {
if (result != ISC_R_SUCCESS)
return (ISC_FALSE);
}
if (result == ISC_R_SUCCESS) {
}
return (found);
}
static void
if (eresult == ISC_R_SUCCESS) {
/*
* Only extract the dst key if the keyset is secure.
*/
if (result == ISC_R_SUCCESS)
}
if (result != DNS_R_WAIT)
} else {
"fetch_callback_validator: got %s",
if (eresult == ISC_R_CANCELED)
else
}
if (want_destroy)
}
static void
if (eresult == ISC_R_SUCCESS) {
if (result != DNS_R_WAIT)
} else if (eresult == DNS_R_NXRRSET ||
{
"falling back to insecurity proof");
if (result != DNS_R_WAIT)
} else {
"dsfetched: got %s",
if (eresult == ISC_R_CANCELED)
else
}
if (want_destroy)
}
/*
* XXX there's too much duplicated code here.
*/
static void
/*
* There is no DS. If this is a delegation, we're done.
*/
} else {
if (result != DNS_R_WAIT)
}
} else if (eresult == ISC_R_SUCCESS ||
eresult == DNS_R_NXDOMAIN ||
{
/*
* Either there is a DS or this is not a zone cut. Continue.
*/
if (result != DNS_R_WAIT)
} else {
if (eresult == ISC_R_CANCELED)
else
}
if (want_destroy)
}
static void
if (eresult == ISC_R_SUCCESS) {
/*
* Only extract the dst key if the keyset is secure.
*/
if (result != DNS_R_WAIT)
} else {
"keyvalidated: got %s",
}
if (want_destroy)
}
static void
if (eresult == ISC_R_SUCCESS) {
else
if (result != DNS_R_WAIT)
} else {
"dsvalidated: got %s",
}
if (want_destroy)
}
/*
* Return ISC_R_SUCCESS if we can determine that the name doesn't exist
* or we can determine whether there is data or not at the name.
* If the name does not exist return the wildcard name.
*/
static isc_result_t
{
int order;
if (result != ISC_R_SUCCESS) {
"failure processing NSEC set");
return (result);
}
if (order < 0) {
/*
* The name is not within the NSEC range.
*/
"NSEC does not cover name, before NSEC");
return (ISC_R_IGNORE);
}
if (order == 0) {
/*
* The names are the same.
*/
{
if (!atparent) {
/*
* This NSEC record is from somewhere higher in
* the DNS, and at the parent of a delegation.
* It can not be legitimately used here.
*/
"ignoring parent nsec");
return (ISC_R_IGNORE);
}
} else if (atparent) {
/*
* This NSEC record is from the child.
* It can not be legitimately used here.
*/
"ignoring child nsec");
return (ISC_R_IGNORE);
}
"nsec proves name exists (owner) data=%d",
*data);
return (ISC_R_SUCCESS);
}
if (relation == dns_namereln_subdomain &&
{
/*
* This NSEC record is from somewhere higher in
* the DNS, and at the parent of a delegation.
* It can not be legitimately used here.
*/
return (ISC_R_IGNORE);
}
if (result != ISC_R_SUCCESS)
return (result);
if (order == 0) {
"ignoring nsec matches next name");
return (ISC_R_IGNORE);
}
/*
* The name is not within the NSEC range.
*/
"ignoring nsec because name is past end of range");
return (ISC_R_IGNORE);
}
"nsec proves name exist (empty)");
return (ISC_R_SUCCESS);
}
} else {
}
if (result != ISC_R_SUCCESS) {
"failure generating wilcard name");
return (result);
}
}
return (ISC_R_SUCCESS);
}
static void
if (result != ISC_R_SUCCESS) {
"authvalidated: got %s",
if (result == ISC_R_CANCELED)
else {
if (result != DNS_R_WAIT)
}
} else {
== ISC_R_SUCCESS)
{
if (NEEDNODATA(val))
}
if (!exists) {
if (NEEDNOQNAME(val))
}
}
if (result != DNS_R_WAIT)
}
if (want_destroy)
/*
* Free stuff from the event.
*/
}
static void
if (eresult == ISC_R_SUCCESS) {
"nonexistence proof found");
} else {
"negauthvalidated: got %s",
}
if (want_destroy)
}
static inline isc_result_t
return (ISC_R_CANCELED);
}
static inline isc_boolean_t
{
"continuing validation would lead to "
"deadlock: aborting validation");
return (ISC_TRUE);
}
}
return (ISC_FALSE);
}
static inline isc_result_t
{
return (DNS_R_NOVALIDSIG);
&val->fsigrdataset,
}
static inline isc_result_t
{
return (DNS_R_NOVALIDSIG);
&val->subvalidator);
if (result == ISC_R_SUCCESS)
return (result);
}
/*
* Try to find a key that could have signed 'siginfo' among those
* in 'rdataset'. If found, build a dst_key_t for it and point
* val->key at it.
*
* If val->key is non-NULL, this returns the next matching key.
*/
static isc_result_t
{
isc_buffer_t b;
else {
}
if (result != ISC_R_SUCCESS)
goto failure;
do {
if (result != ISC_R_SUCCESS)
goto failure;
{
if (foundold)
/*
* This is the key we're looking for.
*/
return (ISC_R_SUCCESS);
{
}
}
} while (result == ISC_R_SUCCESS);
if (result == ISC_R_NOMORE)
return (result);
}
static isc_result_t
unsigned int nlabels;
int order;
/*
* Is the signer name appropriate for this signature?
*
* The signer name must be at the same level as the owner name
* or closer to the the DNS root.
*/
if (namereln != dns_namereln_subdomain &&
return (DNS_R_CONTINUE);
if (namereln == dns_namereln_equal) {
/*
* If this is a self-signed keyset, it must not be a zone key
* (since get_key is not called from validatezonekey).
*/
return (DNS_R_CONTINUE);
/*
* Records appearing in the parent zone at delegation
* points cannot be self-signed.
*/
return (DNS_R_CONTINUE);
}
/*
* Do we know about this key?
*/
if (result == ISC_R_SUCCESS) {
/*
* We have an rrset for the given keyname.
*/
{
/*
* We know the key but haven't validated it yet.
*/
&val->fsigrdataset,
"get_key");
if (result != ISC_R_SUCCESS)
return (result);
return (DNS_R_WAIT);
/*
* Having a pending key with no signature means that
* something is broken.
*/
/*
* The key is legitimately insecure. There's no
* point in even attempting verification.
*/
} else {
/*
* See if we've got the key used in the signature.
*/
"keyset with trust %d",
if (result != ISC_R_SUCCESS) {
/*
* Either the key we're looking for is not
* in the rrset, or something bad happened.
* Give up.
*/
}
}
} else if (result == ISC_R_NOTFOUND) {
/*
* We don't know anything about this key.
*/
fetch_callback_validator, "get_key");
if (result != ISC_R_SUCCESS)
return (result);
return (DNS_R_WAIT);
} else if (result == DNS_R_NCACHENXDOMAIN ||
result == DNS_R_NCACHENXRRSET ||
result == DNS_R_NXDOMAIN ||
result == DNS_R_NXRRSET)
{
/*
* This key doesn't exist.
*/
}
return (result);
}
static dns_keytag_t
isc_region_t r;
dns_rdata_toregion(rdata, &r);
}
/*
* Is this keyset self-signed?
*/
static isc_boolean_t
result == ISC_R_SUCCESS;
{
result == ISC_R_SUCCESS;
{
return (ISC_TRUE);
}
}
return (ISC_FALSE);
}
static isc_result_t
"verify rdataset: %s",
if (result == DNS_R_FROMWILDCARD) {
}
return (result);
}
/*
* Attempts positive response validation of a normal RRset.
*
* Returns:
* ISC_R_SUCCESS Validation completed successfully
* DNS_R_WAIT Validation has started but is waiting
* for an event.
* Other return codes are possible and all indicate failure.
*/
static isc_result_t
/*
* Caller must be holding the validator lock.
*/
if (resume) {
/*
* We already have a sigrdataset.
*/
} else {
}
for (;
result == ISC_R_SUCCESS;
{
return (ISC_R_NOMEMORY);
}
if (result != ISC_R_SUCCESS)
return (result);
/*
* At this point we could check that the signature algorithm
* was known and "sufficiently good".
*/
continue;
if (!resume) {
if (result == DNS_R_CONTINUE)
continue; /* Try the next SIG RR. */
if (result != ISC_R_SUCCESS)
return (result);
}
/*
* The key is insecure, so mark the data as insecure also.
*/
"marking as answer");
return (ISC_R_SUCCESS);
}
do {
if (result == ISC_R_SUCCESS)
break;
&nextnode);
if (result != ISC_R_SUCCESS) {
break;
}
} else {
!= ISC_R_SUCCESS)
break;
}
} while (1);
if (result != ISC_R_SUCCESS)
"failed to verify rdataset");
else {
}
else {
}
}
"no message available for noqname proof");
return (DNS_R_NOVALIDSIG);
}
"looking for noqname proof");
} else if (result == ISC_R_SUCCESS) {
"marking as secure");
return (result);
} else {
"verify failure: %s",
}
}
if (result != ISC_R_NOMORE) {
"failed to iterate signatures: %s",
return (result);
}
return (DNS_R_NOVALIDSIG);
}
/*
* Attempts positive response validation of an RRset containing zone keys.
*
* Returns:
* ISC_R_SUCCESS Validation completed successfully
* DNS_R_WAIT Validation has started but is waiting
* for an event.
* Other return codes are possible and all indicate failure.
*/
static isc_result_t
unsigned char dsbuf[DNS_DS_BUFFERSIZE];
/*
* Caller must be holding the validator lock.
*/
/*
* First, see if this key was signed by a trusted key.
*/
result == ISC_R_SUCCESS;
{
&sigrdata);
&keynode);
while (result == ISC_R_SUCCESS) {
if (result == ISC_R_SUCCESS) {
&keynode);
break;
}
&nextnode);
&keynode);
}
if (result == ISC_R_SUCCESS) {
"signed by trusted key; "
"marking as secure");
return (result);
}
}
/*
* If this is the root name and there was no trusted key,
* give up, since there's no DS at the root.
*/
return (DNS_R_NOVALIDSIG);
else
return (DNS_R_NOVALIDDS);
}
/*
* Otherwise, try to find the DS record.
*/
if (result == ISC_R_SUCCESS) {
/*
* We have DS records.
*/
{
&val->fsigrdataset,
"validatezonekey");
if (result != ISC_R_SUCCESS)
return (result);
return (DNS_R_WAIT);
/*
* There should never be an unsigned DS.
*/
"unsigned DS record");
return (DNS_R_NOVALIDSIG);
} else
} else if (result == ISC_R_NOTFOUND) {
/*
* We don't have the DS. Find it.
*/
"validatezonekey");
if (result != ISC_R_SUCCESS)
return (result);
return (DNS_R_WAIT);
} else if (result == DNS_R_NCACHENXDOMAIN ||
result == DNS_R_NCACHENXRRSET ||
result == DNS_R_NXDOMAIN ||
result == DNS_R_NXRRSET)
{
/*
* The DS does not exist.
*/
return (DNS_R_NOVALIDSIG);
}
}
/*
* We have a DS set.
*/
return (ISC_R_SUCCESS);
}
/*
* Look through the DS record and find the keys that can sign the
* key set and the matching signature. For each such key, attempt
* verification.
*/
result == ISC_R_SUCCESS;
{
continue;
result == ISC_R_SUCCESS;
{
continue;
dsbuf, &newdsrdata);
if (result != ISC_R_SUCCESS)
continue;
break;
}
if (result != ISC_R_SUCCESS) {
"no KEY matching DS");
continue;
}
result == ISC_R_SUCCESS;
{
&sigrdata);
continue;
&keyrdata,
&dstkey);
if (result != ISC_R_SUCCESS)
/*
* This really shouldn't happen, but...
*/
continue;
if (result == ISC_R_SUCCESS)
break;
}
if (result == ISC_R_SUCCESS)
break;
}
if (result == ISC_R_SUCCESS) {
return (result);
"no supported algorithm (ds)");
return (ISC_R_SUCCESS);
} else
return (DNS_R_NOVALIDSIG);
}
/*
* Starts a positive response validation.
*
* Returns:
* ISC_R_SUCCESS Validation completed successfully
* DNS_R_WAIT Validation has started but is waiting
* for an event.
* Other return codes are possible and all indicate failure.
*/
static isc_result_t
/*
* If this is not a key, go straight into validate().
*/
}
static isc_result_t
char namebuf[DNS_NAME_FORMATSIZE];
result == ISC_R_SUCCESS;
{
{
continue;
sigrdataset != NULL;
{
break;
}
if (sigrdataset == NULL)
continue;
continue;
== ISC_R_SUCCESS)
{
name;
if (!exists)
val->attributes |=
name;
return (ISC_R_SUCCESS);
}
}
}
if (result == ISC_R_NOMORE)
return (result);
}
static isc_result_t
if (!resume)
else {
}
for (;
result == ISC_R_SUCCESS;
{
if (resume) {
} else
for (;
{
continue;
sigrdataset != NULL;
link))
{
break;
}
if (sigrdataset == NULL)
continue;
/*
* If a signed zone is missing the zone key, bad
* things could happen. A query for data in the zone
* would lead to a query for the zone key, which
* would return a negative answer, which would contain
* an SOA and an NSEC signed by the missing key, which
* would trigger another query for the KEY (since the
* first one is still in progress), and go into an
* infinite loop. Avoid that.
*/
{
continue;
if (result != ISC_R_SUCCESS)
return (result);
if (dns_nsec_typepresent(&nsec,
continue;
}
"nsecvalidate");
if (result != ISC_R_SUCCESS)
return (result);
return (DNS_R_WAIT);
}
}
if (result == ISC_R_NOMORE)
if (result != ISC_R_SUCCESS)
return (result);
/*
* Do we only need to check for NOQNAME?
*/
"noqname proof found");
"marking as secure");
return (ISC_R_SUCCESS);
}
"noqname proof not found");
return (DNS_R_NOVALIDNSEC);
}
/*
* Do we need to check for the wildcard?
*/
if (result != ISC_R_SUCCESS)
return (result);
}
"nsecvalidate");
if (result != ISC_R_SUCCESS)
return (result);
return (DNS_R_WAIT);
}
"nonexistence proof not found");
return (DNS_R_NOVALIDNSEC);
} else {
"nonexistence proof found");
return (ISC_R_SUCCESS);
}
}
static isc_boolean_t
result == ISC_R_SUCCESS;
return (ISC_TRUE);
}
return (ISC_FALSE);
}
static isc_result_t
/*
* If the name is not under a security root, it must be insecure.
*/
if (result == ISC_R_NOTFOUND)
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
return (result);
if (!resume) {
} else {
"no supported algorithm (ds)");
goto out;
}
}
for (;
{
char namebuf[DNS_NAME_FORMATSIZE];
else
"checking existence of DS at '%s'",
namebuf);
/*
* There is no DS. If this is a delegation,
* we're done.
*/
/*
* This shouldn't happen, since the negative
* response should have been validated. Since
* there's no way of validating existing
* negative response blobs, give up.
*/
goto out;
}
return (ISC_R_SUCCESS);
}
continue;
} else if (result == ISC_R_SUCCESS) {
/*
* There is a DS here. Verify that it's secure and
* continue.
*/
"no supported algorithm (ds)");
goto out;
}
continue;
}
{
goto out;
}
&val->fsigrdataset,
"proveunsecure");
if (result != ISC_R_SUCCESS)
goto out;
return (DNS_R_WAIT);
} else if (result == DNS_R_NXDOMAIN ||
{
/*
* This is not a zone cut. Assuming things are
* as expected, continue.
*/
/*
* There should be an NSEC here, since we
* are still in a secure zone.
*/
goto out;
/*
* This shouldn't happen, since the negative
* response should have been validated. Since
* there's no way of validating existing
* negative response blobs, give up.
*/
goto out;
}
continue;
} else if (result == ISC_R_NOTFOUND) {
/*
* We don't know anything about the DS. Find it.
*/
dsfetched2, "proveunsecure");
if (result != ISC_R_SUCCESS)
goto out;
return (DNS_R_WAIT);
}
}
return (DNS_R_NOTINSECURE); /* Couldn't complete insecurity proof */
out:
return (result);
}
static void
/* If the validator has been cancelled, val->event == NULL */
return;
/*
* This looks like a simple validation. We say "looks like"
* because it might end up requiring an insecurity proof.
*/
"attempting positive response validation");
if (result == DNS_R_NOVALIDSIG &&
{
"falling back to insecurity proof");
if (result == DNS_R_NOTINSECURE)
}
/*
* This is either an unsecure subdomain or a response from
* a broken server.
*/
"attempting insecurity proof");
{
/*
* This is a nonexistence validation.
*/
"attempting negative response validation");
} else
} else {
/*
* This shouldn't happen.
*/
INSIST(0);
}
if (result != DNS_R_WAIT) {
}
if (want_destroy)
}
{
return (ISC_R_NOMEMORY);
event = (dns_validatorevent_t *)
sizeof(dns_validatorevent_t));
goto cleanup_val;
}
if (result != ISC_R_SUCCESS)
goto cleanup_event;
val->attributes = 0;
*validatorp = val;
return (ISC_R_SUCCESS);
return (result);
}
void
}
}
static void
}
void
val = *validatorp;
if (want_destroy)
*validatorp = NULL;
}
static void
{
char msgbuf[2048];
char namebuf[DNS_NAME_FORMATSIZE];
char typebuf[DNS_RDATATYPE_FORMATSIZE];
sizeof(typebuf));
msgbuf);
} else {
}
}
static void
return;
}
static void
{
char namestr[DNS_NAME_FORMATSIZE];
char typestr[DNS_RDATATYPE_FORMATSIZE];
}