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