1*ae8c6e27Sflorian /* 2*ae8c6e27Sflorian * validator/autotrust.h - RFC5011 trust anchor management for unbound. 3*ae8c6e27Sflorian * 4*ae8c6e27Sflorian * Copyright (c) 2009, NLnet Labs. All rights reserved. 5*ae8c6e27Sflorian * 6*ae8c6e27Sflorian * This software is open source. 7*ae8c6e27Sflorian * 8*ae8c6e27Sflorian * Redistribution and use in source and binary forms, with or without 9*ae8c6e27Sflorian * modification, are permitted provided that the following conditions 10*ae8c6e27Sflorian * are met: 11*ae8c6e27Sflorian * 12*ae8c6e27Sflorian * Redistributions of source code must retain the above copyright notice, 13*ae8c6e27Sflorian * this list of conditions and the following disclaimer. 14*ae8c6e27Sflorian * 15*ae8c6e27Sflorian * Redistributions in binary form must reproduce the above copyright notice, 16*ae8c6e27Sflorian * this list of conditions and the following disclaimer in the documentation 17*ae8c6e27Sflorian * and/or other materials provided with the distribution. 18*ae8c6e27Sflorian * 19*ae8c6e27Sflorian * Neither the name of the NLNET LABS nor the names of its contributors may 20*ae8c6e27Sflorian * be used to endorse or promote products derived from this software without 21*ae8c6e27Sflorian * specific prior written permission. 22*ae8c6e27Sflorian * 23*ae8c6e27Sflorian * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24*ae8c6e27Sflorian * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25*ae8c6e27Sflorian * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26*ae8c6e27Sflorian * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27*ae8c6e27Sflorian * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28*ae8c6e27Sflorian * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29*ae8c6e27Sflorian * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30*ae8c6e27Sflorian * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31*ae8c6e27Sflorian * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32*ae8c6e27Sflorian * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33*ae8c6e27Sflorian * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34*ae8c6e27Sflorian */ 35*ae8c6e27Sflorian 36*ae8c6e27Sflorian /** 37*ae8c6e27Sflorian * \file 38*ae8c6e27Sflorian * 39*ae8c6e27Sflorian * Contains autotrust definitions. 40*ae8c6e27Sflorian */ 41*ae8c6e27Sflorian 42*ae8c6e27Sflorian #ifndef VALIDATOR_AUTOTRUST_H 43*ae8c6e27Sflorian #define VALIDATOR_AUTOTRUST_H 44*ae8c6e27Sflorian #include "util/rbtree.h" 45*ae8c6e27Sflorian #include "util/data/packed_rrset.h" 46*ae8c6e27Sflorian struct val_anchors; 47*ae8c6e27Sflorian struct trust_anchor; 48*ae8c6e27Sflorian struct ub_packed_rrset_key; 49*ae8c6e27Sflorian struct module_env; 50*ae8c6e27Sflorian struct module_qstate; 51*ae8c6e27Sflorian struct val_env; 52*ae8c6e27Sflorian struct sldns_buffer; 53*ae8c6e27Sflorian 54*ae8c6e27Sflorian /** Autotrust anchor states */ 55*ae8c6e27Sflorian typedef enum { 56*ae8c6e27Sflorian AUTR_STATE_START = 0, 57*ae8c6e27Sflorian AUTR_STATE_ADDPEND = 1, 58*ae8c6e27Sflorian AUTR_STATE_VALID = 2, 59*ae8c6e27Sflorian AUTR_STATE_MISSING = 3, 60*ae8c6e27Sflorian AUTR_STATE_REVOKED = 4, 61*ae8c6e27Sflorian AUTR_STATE_REMOVED = 5 62*ae8c6e27Sflorian } autr_state_type; 63*ae8c6e27Sflorian 64*ae8c6e27Sflorian /** 65*ae8c6e27Sflorian * Autotrust metadata for one trust anchor key. 66*ae8c6e27Sflorian */ 67*ae8c6e27Sflorian struct autr_ta { 68*ae8c6e27Sflorian /** next key */ 69*ae8c6e27Sflorian struct autr_ta* next; 70*ae8c6e27Sflorian /** the RR */ 71*ae8c6e27Sflorian uint8_t* rr; 72*ae8c6e27Sflorian /** length of rr */ 73*ae8c6e27Sflorian size_t rr_len, dname_len; 74*ae8c6e27Sflorian /** last update of key state (new pending count keeps date the same) */ 75*ae8c6e27Sflorian time_t last_change; 76*ae8c6e27Sflorian /** 5011 state */ 77*ae8c6e27Sflorian autr_state_type s; 78*ae8c6e27Sflorian /** pending count */ 79*ae8c6e27Sflorian uint8_t pending_count; 80*ae8c6e27Sflorian /** fresh TA was seen */ 81*ae8c6e27Sflorian uint8_t fetched; 82*ae8c6e27Sflorian /** revoked TA was seen */ 83*ae8c6e27Sflorian uint8_t revoked; 84*ae8c6e27Sflorian }; 85*ae8c6e27Sflorian 86*ae8c6e27Sflorian /** 87*ae8c6e27Sflorian * Autotrust metadata for a trust point. 88*ae8c6e27Sflorian * This is part of the struct trust_anchor data. 89*ae8c6e27Sflorian */ 90*ae8c6e27Sflorian struct autr_point_data { 91*ae8c6e27Sflorian /** file to store the trust point in. chrootdir already applied. */ 92*ae8c6e27Sflorian char* file; 93*ae8c6e27Sflorian /** rbtree node for probe sort, key is struct trust_anchor */ 94*ae8c6e27Sflorian rbnode_type pnode; 95*ae8c6e27Sflorian 96*ae8c6e27Sflorian /** the keys */ 97*ae8c6e27Sflorian struct autr_ta* keys; 98*ae8c6e27Sflorian 99*ae8c6e27Sflorian /** last queried DNSKEY set 100*ae8c6e27Sflorian * Not all failures are captured in this entry. 101*ae8c6e27Sflorian * If the validator did not even start (e.g. timeout or localservfail), 102*ae8c6e27Sflorian * then the last_queried and query_failed values are not updated. 103*ae8c6e27Sflorian */ 104*ae8c6e27Sflorian time_t last_queried; 105*ae8c6e27Sflorian /** last successful DNSKEY set */ 106*ae8c6e27Sflorian time_t last_success; 107*ae8c6e27Sflorian /** next probe time */ 108*ae8c6e27Sflorian time_t next_probe_time; 109*ae8c6e27Sflorian 110*ae8c6e27Sflorian /** when to query if !failed */ 111*ae8c6e27Sflorian time_t query_interval; 112*ae8c6e27Sflorian /** when to retry if failed */ 113*ae8c6e27Sflorian time_t retry_time; 114*ae8c6e27Sflorian 115*ae8c6e27Sflorian /** 116*ae8c6e27Sflorian * How many times did it fail. diagnostic only (has no effect). 117*ae8c6e27Sflorian * Only updated if there was a dnskey rrset that failed to verify. 118*ae8c6e27Sflorian */ 119*ae8c6e27Sflorian uint8_t query_failed; 120*ae8c6e27Sflorian /** true if the trust point has been revoked */ 121*ae8c6e27Sflorian uint8_t revoked; 122*ae8c6e27Sflorian }; 123*ae8c6e27Sflorian 124*ae8c6e27Sflorian /** 125*ae8c6e27Sflorian * Autotrust global metadata. 126*ae8c6e27Sflorian */ 127*ae8c6e27Sflorian struct autr_global_data { 128*ae8c6e27Sflorian /** rbtree of autotrust anchors sorted by next probe time. 129*ae8c6e27Sflorian * When time is equal, sorted by anchor class, name. */ 130*ae8c6e27Sflorian rbtree_type probe; 131*ae8c6e27Sflorian }; 132*ae8c6e27Sflorian 133*ae8c6e27Sflorian /** 134*ae8c6e27Sflorian * Create new global 5011 data structure. 135*ae8c6e27Sflorian * @return new structure or NULL on malloc failure. 136*ae8c6e27Sflorian */ 137*ae8c6e27Sflorian struct autr_global_data* autr_global_create(void); 138*ae8c6e27Sflorian 139*ae8c6e27Sflorian /** 140*ae8c6e27Sflorian * Delete global 5011 data structure. 141*ae8c6e27Sflorian * @param global: global autotrust state to delete. 142*ae8c6e27Sflorian */ 143*ae8c6e27Sflorian void autr_global_delete(struct autr_global_data* global); 144*ae8c6e27Sflorian 145*ae8c6e27Sflorian /** 146*ae8c6e27Sflorian * See if autotrust anchors are configured and how many. 147*ae8c6e27Sflorian * @param anchors: the trust anchors structure. 148*ae8c6e27Sflorian * @return number of autotrust trust anchors 149*ae8c6e27Sflorian */ 150*ae8c6e27Sflorian size_t autr_get_num_anchors(struct val_anchors* anchors); 151*ae8c6e27Sflorian 152*ae8c6e27Sflorian /** 153*ae8c6e27Sflorian * Process probe timer. Add new probes if needed. 154*ae8c6e27Sflorian * @param env: module environment with time, with anchors and with the mesh. 155*ae8c6e27Sflorian * @return time of next probe (in seconds from now). 156*ae8c6e27Sflorian * If 0, then there is no next probe anymore (trust points deleted). 157*ae8c6e27Sflorian */ 158*ae8c6e27Sflorian time_t autr_probe_timer(struct module_env* env); 159*ae8c6e27Sflorian 160*ae8c6e27Sflorian /** probe tree compare function */ 161*ae8c6e27Sflorian int probetree_cmp(const void* x, const void* y); 162*ae8c6e27Sflorian 163*ae8c6e27Sflorian /** 164*ae8c6e27Sflorian * Read autotrust file. 165*ae8c6e27Sflorian * @param anchors: the anchors structure. 166*ae8c6e27Sflorian * @param nm: name of the file (copied). 167*ae8c6e27Sflorian * @return false on failure. 168*ae8c6e27Sflorian */ 169*ae8c6e27Sflorian int autr_read_file(struct val_anchors* anchors, const char* nm); 170*ae8c6e27Sflorian 171*ae8c6e27Sflorian /** 172*ae8c6e27Sflorian * Write autotrust file. 173*ae8c6e27Sflorian * @param env: environment with scratch space. 174*ae8c6e27Sflorian * @param tp: trust point to write. 175*ae8c6e27Sflorian */ 176*ae8c6e27Sflorian void autr_write_file(struct module_env* env, struct trust_anchor* tp); 177*ae8c6e27Sflorian 178*ae8c6e27Sflorian /** 179*ae8c6e27Sflorian * Delete autr anchor, deletes the autr data but does not do 180*ae8c6e27Sflorian * unlinking from trees, caller does that. 181*ae8c6e27Sflorian * @param tp: trust point to delete. 182*ae8c6e27Sflorian */ 183*ae8c6e27Sflorian void autr_point_delete(struct trust_anchor* tp); 184*ae8c6e27Sflorian 185*ae8c6e27Sflorian /** 186*ae8c6e27Sflorian * Perform autotrust processing. 187*ae8c6e27Sflorian * @param env: qstate environment with the anchors structure. 188*ae8c6e27Sflorian * @param ve: validator environment for verification of rrsigs. 189*ae8c6e27Sflorian * @param tp: trust anchor to process. 190*ae8c6e27Sflorian * @param dnskey_rrset: DNSKEY rrset probed (can be NULL if bad prime result). 191*ae8c6e27Sflorian * allocated in a region. Has not been validated yet. 192*ae8c6e27Sflorian * @param qstate: qstate with region. 193*ae8c6e27Sflorian * @return false if trust anchor was revoked completely. 194*ae8c6e27Sflorian * Otherwise logs errors to log, does not change return value. 195*ae8c6e27Sflorian * On errors, likely the trust point has been unchanged. 196*ae8c6e27Sflorian */ 197*ae8c6e27Sflorian int autr_process_prime(struct module_env* env, struct val_env* ve, 198*ae8c6e27Sflorian struct trust_anchor* tp, struct ub_packed_rrset_key* dnskey_rrset, 199*ae8c6e27Sflorian struct module_qstate* qstate); 200*ae8c6e27Sflorian 201*ae8c6e27Sflorian /** 202*ae8c6e27Sflorian * Debug printout of rfc5011 tracked anchors 203*ae8c6e27Sflorian * @param anchors: all the anchors. 204*ae8c6e27Sflorian */ 205*ae8c6e27Sflorian void autr_debug_print(struct val_anchors* anchors); 206*ae8c6e27Sflorian 207*ae8c6e27Sflorian /** callback for query answer to 5011 probe */ 208*ae8c6e27Sflorian void probe_answer_cb(void* arg, int rcode, struct sldns_buffer* buf, 209*ae8c6e27Sflorian enum sec_status sec, char* errinf, int was_ratelimited); 210*ae8c6e27Sflorian 211*ae8c6e27Sflorian #endif /* VALIDATOR_AUTOTRUST_H */ 212