00001 /* 00002 * Copyright (C) 2004-2010, 2013, 2014 Internet Systems Consortium, Inc. ("ISC") 00003 * Copyright (C) 2000-2003 Internet Software Consortium. 00004 * 00005 * Permission to use, copy, modify, and/or distribute this software for any 00006 * purpose with or without fee is hereby granted, provided that the above 00007 * copyright notice and this permission notice appear in all copies. 00008 * 00009 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 00010 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00011 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 00012 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00013 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00014 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00015 * PERFORMANCE OF THIS SOFTWARE. 00016 */ 00017 00018 /* $Id: validator.h,v 1.46 2010/02/25 05:08:01 tbox Exp $ */ 00019 00020 #ifndef DNS_VALIDATOR_H 00021 #define DNS_VALIDATOR_H 1 00022 00023 /***** 00024 ***** Module Info 00025 *****/ 00026 00027 /*! \file dns/validator.h 00028 * 00029 * \brief 00030 * DNS Validator 00031 * This is the BIND 9 validator, the module responsible for validating the 00032 * rdatasets and negative responses (messages). It makes use of zones in 00033 * the view and may fetch RRset to complete trust chains. It implements 00034 * DNSSEC as specified in RFC 4033, 4034 and 4035. 00035 * 00036 * It can also optionally implement ISC's DNSSEC look-aside validation. 00037 * 00038 * Correct operation is critical to preventing spoofed answers from secure 00039 * zones being accepted. 00040 * 00041 * MP: 00042 *\li The module ensures appropriate synchronization of data structures it 00043 * creates and manipulates. 00044 * 00045 * Reliability: 00046 *\li No anticipated impact. 00047 * 00048 * Resources: 00049 *\li TBS 00050 * 00051 * Security: 00052 *\li No anticipated impact. 00053 * 00054 * Standards: 00055 *\li RFCs: 1034, 1035, 2181, 4033, 4034, 4035. 00056 */ 00057 00058 #include <isc/lang.h> 00059 #include <isc/event.h> 00060 #include <isc/mutex.h> 00061 00062 #include <dns/fixedname.h> 00063 #include <dns/types.h> 00064 #include <dns/rdataset.h> 00065 #include <dns/rdatastruct.h> /* for dns_rdata_rrsig_t */ 00066 00067 #include <dst/dst.h> 00068 00069 /*% 00070 * A dns_validatorevent_t is sent when a 'validation' completes. 00071 * \brief 00072 * 'name', 'rdataset', 'sigrdataset', and 'message' are the values that were 00073 * supplied when dns_validator_create() was called. They are returned to the 00074 * caller so that they may be freed. 00075 * 00076 * If the RESULT is ISC_R_SUCCESS and the answer is secure then 00077 * proofs[] will contain the names of the NSEC records that hold the 00078 * various proofs. Note the same name may appear multiple times. 00079 */ 00080 typedef struct dns_validatorevent { 00081 ISC_EVENT_COMMON(struct dns_validatorevent); 00082 dns_validator_t * validator; 00083 isc_result_t result; 00084 /* 00085 * Name and type of the response to be validated. 00086 */ 00087 dns_name_t * name; 00088 dns_rdatatype_t type; 00089 /* 00090 * Rdata and RRSIG (if any) for positive responses. 00091 */ 00092 dns_rdataset_t * rdataset; 00093 dns_rdataset_t * sigrdataset; 00094 /* 00095 * The full response. Required for negative responses. 00096 * Also required for positive wildcard responses. 00097 */ 00098 dns_message_t * message; 00099 /* 00100 * Proofs to be cached. 00101 */ 00102 dns_name_t * proofs[4]; 00103 /* 00104 * Optout proof seen. 00105 */ 00106 isc_boolean_t optout; 00107 /* 00108 * Answer is secure. 00109 */ 00110 isc_boolean_t secure; 00111 } dns_validatorevent_t; 00112 00113 #define DNS_VALIDATOR_NOQNAMEPROOF 0 00114 #define DNS_VALIDATOR_NODATAPROOF 1 00115 #define DNS_VALIDATOR_NOWILDCARDPROOF 2 00116 #define DNS_VALIDATOR_CLOSESTENCLOSER 3 00117 00118 /*% 00119 * A validator object represents a validation in progress. 00120 * \brief 00121 * Clients are strongly discouraged from using this type directly, with 00122 * the exception of the 'link' field, which may be used directly for 00123 * whatever purpose the client desires. 00124 */ 00125 struct dns_validator { 00126 /* Unlocked. */ 00127 unsigned int magic; 00128 isc_mutex_t lock; 00129 dns_view_t * view; 00130 /* Locked by lock. */ 00131 unsigned int options; 00132 unsigned int attributes; 00133 dns_validatorevent_t * event; 00134 dns_fetch_t * fetch; 00135 dns_validator_t * subvalidator; 00136 dns_validator_t * parent; 00137 dns_keytable_t * keytable; 00138 dns_keynode_t * keynode; 00139 dst_key_t * key; 00140 dns_rdata_rrsig_t * siginfo; 00141 isc_task_t * task; 00142 isc_taskaction_t action; 00143 void * arg; 00144 unsigned int labels; 00145 dns_rdataset_t * currentset; 00146 isc_boolean_t seensig; 00147 dns_rdataset_t * keyset; 00148 dns_rdataset_t * dsset; 00149 dns_rdataset_t * soaset; 00150 dns_rdataset_t * nsecset; 00151 dns_rdataset_t * nsec3set; 00152 dns_name_t * soaname; 00153 dns_rdataset_t frdataset; 00154 dns_rdataset_t fsigrdataset; 00155 dns_fixedname_t fname; 00156 dns_fixedname_t wild; 00157 dns_fixedname_t nearest; 00158 dns_fixedname_t closest; 00159 ISC_LINK(dns_validator_t) link; 00160 dns_rdataset_t dlv; 00161 dns_fixedname_t dlvsep; 00162 isc_boolean_t havedlvsep; 00163 isc_boolean_t mustbesecure; 00164 unsigned int dlvlabels; 00165 unsigned int depth; 00166 unsigned int authcount; 00167 unsigned int authfail; 00168 isc_stdtime_t start; 00169 }; 00170 00171 /*% 00172 * dns_validator_create() options. 00173 */ 00174 #define DNS_VALIDATOR_DLV 0x0001U 00175 #define DNS_VALIDATOR_DEFER 0x0002U 00176 #define DNS_VALIDATOR_NOCDFLAG 0x0004U 00177 #define DNS_VALIDATOR_NONTA 0x0008U /*% Ignore NTA table */ 00178 00179 ISC_LANG_BEGINDECLS 00180 00181 isc_result_t 00182 dns_validator_create(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type, 00183 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset, 00184 dns_message_t *message, unsigned int options, 00185 isc_task_t *task, isc_taskaction_t action, void *arg, 00186 dns_validator_t **validatorp); 00187 /*%< 00188 * Start a DNSSEC validation. 00189 * 00190 * This validates a response to the question given by 00191 * 'name' and 'type'. 00192 * 00193 * To validate a positive response, the response data is 00194 * given by 'rdataset' and 'sigrdataset'. If 'sigrdataset' 00195 * is NULL, the data is presumed insecure and an attempt 00196 * is made to prove its insecurity by finding the appropriate 00197 * null key. 00198 * 00199 * The complete response message may be given in 'message', 00200 * to make available any authority section NSECs that may be 00201 * needed for validation of a response resulting from a 00202 * wildcard expansion (though no such wildcard validation 00203 * is implemented yet). If the complete response message 00204 * is not available, 'message' is NULL. 00205 * 00206 * To validate a negative response, the complete negative response 00207 * message is given in 'message'. The 'rdataset', and 00208 * 'sigrdataset' arguments must be NULL, but the 'name' and 'type' 00209 * arguments must be provided. 00210 * 00211 * The validation is performed in the context of 'view'. 00212 * 00213 * When the validation finishes, a dns_validatorevent_t with 00214 * the given 'action' and 'arg' are sent to 'task'. 00215 * Its 'result' field will be ISC_R_SUCCESS iff the 00216 * response was successfully proven to be either secure or 00217 * part of a known insecure domain. 00218 * 00219 * options: 00220 * If DNS_VALIDATOR_DLV is set the caller knows there is not a 00221 * trusted key and the validator should immediately attempt to validate 00222 * the answer by looking for an appropriate DLV RRset. 00223 */ 00224 00225 void 00226 dns_validator_send(dns_validator_t *validator); 00227 /*%< 00228 * Send a deferred validation request 00229 * 00230 * Requires: 00231 * 'validator' to points to a valid DNSSEC validator. 00232 */ 00233 00234 void 00235 dns_validator_cancel(dns_validator_t *validator); 00236 /*%< 00237 * Cancel a DNSSEC validation in progress. 00238 * 00239 * Requires: 00240 *\li 'validator' points to a valid DNSSEC validator, which 00241 * may or may not already have completed. 00242 * 00243 * Ensures: 00244 *\li It the validator has not already sent its completion 00245 * event, it will send it with result code ISC_R_CANCELED. 00246 */ 00247 00248 void 00249 dns_validator_destroy(dns_validator_t **validatorp); 00250 /*%< 00251 * Destroy a DNSSEC validator. 00252 * 00253 * Requires: 00254 *\li '*validatorp' points to a valid DNSSEC validator. 00255 * \li The validator must have completed and sent its completion 00256 * event. 00257 * 00258 * Ensures: 00259 *\li All resources used by the validator are freed. 00260 */ 00261 00262 ISC_LANG_ENDDECLS 00263 00264 #endif /* DNS_VALIDATOR_H */