2 * validator/val_anchor.h - validator trust anchor storage.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
39 * This file contains storage for the trust anchors for the validator.
42 #ifndef VALIDATOR_VAL_ANCHOR_H
43 #define VALIDATOR_VAL_ANCHOR_H
44 #include "util/rbtree.h"
45 #include "util/locks.h"
48 struct ub_packed_rrset_key;
49 struct autr_point_data;
50 struct autr_global_data;
54 * The tree must be locked, while no other locks (from trustanchors) are held.
55 * And then an anchor searched for. Which can be locked or deleted. Then
56 * the tree can be unlocked again. This means you have to release the lock
57 * on a trust anchor and look it up again to delete it.
63 * Anchors are store in this tree. Sort order is chosen, so that
64 * dnames are in nsec-like order. A lookup on class, name will return
65 * an exact match of the closest match, with the ancestor needed.
66 * contents of type trust_anchor.
69 /** The DLV trust anchor (if one is configured, else NULL) */
70 struct trust_anchor* dlv_anchor;
71 /** Autotrust global data, anchors sorted by next probe time */
72 struct autr_global_data* autr;
81 /** rdata, in wireformat of the key RR. starts with rdlength. */
83 /** length of the rdata (including rdlength). */
85 /** DNS type (host format) of the key, DS or DNSKEY */
90 * A trust anchor in the trust anchor store.
91 * Unique by name, class.
94 /** rbtree node, key is this structure */
96 /** lock on the entire anchor and its keys; for autotrust changes */
98 /** name of this trust anchor */
100 /** length of name */
102 /** number of labels in name of rrset */
104 /** the ancestor in the trustanchor tree */
105 struct trust_anchor* parent;
107 * List of DS or DNSKEY rrs that form the trust anchor.
109 struct ta_key* keylist;
110 /** Autotrust anchor point data, or NULL */
111 struct autr_point_data* autr;
112 /** number of DSs in the keylist */
114 /** number of DNSKEYs in the keylist */
117 struct ub_packed_rrset_key* ds_rrset;
118 /** The DNSKEY RRset */
119 struct ub_packed_rrset_key* dnskey_rrset;
120 /** class of the trust anchor */
125 * Create trust anchor storage
126 * @return new storage or NULL on error.
128 struct val_anchors* anchors_create(void);
131 * Delete trust anchor storage.
132 * @param anchors: to delete.
134 void anchors_delete(struct val_anchors* anchors);
137 * Process trust anchor config.
138 * @param anchors: struct anchor storage
139 * @param cfg: config options.
140 * @return 0 on error.
142 int anchors_apply_cfg(struct val_anchors* anchors, struct config_file* cfg);
145 * Recalculate parent pointers. The caller must hold the lock on the
146 * anchors structure (say after removing an item from the rbtree).
147 * Caller must not hold any locks on trust anchors.
148 * After the call is complete the parent pointers are updated and an item
149 * just removed is no longer referenced in parent pointers.
150 * @param anchors: the structure to update.
152 void anchors_init_parents_locked(struct val_anchors* anchors);
155 * Given a qname/qclass combination, find the trust anchor closest above it.
156 * Or return NULL if none exists.
158 * @param anchors: struct anchor storage
159 * @param qname: query name, uncompressed wireformat.
160 * @param qname_len: length of qname.
161 * @param qclass: class to query for.
162 * @return the trust anchor or NULL if none is found. The anchor is locked.
164 struct trust_anchor* anchors_lookup(struct val_anchors* anchors,
165 uint8_t* qname, size_t qname_len, uint16_t qclass);
168 * Find a trust anchor. Exact matching.
169 * @param anchors: anchor storage.
170 * @param name: name of trust anchor (wireformat)
171 * @param namelabs: labels in name
172 * @param namelen: length of name
173 * @param dclass: class of trust anchor
174 * @return NULL if not found. The anchor is locked.
176 struct trust_anchor* anchor_find(struct val_anchors* anchors,
177 uint8_t* name, int namelabs, size_t namelen, uint16_t dclass);
180 * Store one string as trust anchor RR.
181 * @param anchors: anchor storage.
182 * @param buffer: parsing buffer, to generate the RR wireformat in.
183 * @param str: string.
184 * @return NULL on error.
186 struct trust_anchor* anchor_store_str(struct val_anchors* anchors,
187 ldns_buffer* buffer, const char* str);
190 * Get memory in use by the trust anchor storage
191 * @param anchors: anchor storage.
192 * @return memory in use in bytes.
194 size_t anchors_get_mem(struct val_anchors* anchors);
196 /** compare two trust anchors */
197 int anchor_cmp(const void* k1, const void* k2);
200 * Add insecure point trust anchor. For external use (locks and init_parents)
201 * @param anchors: anchor storage.
203 * @param nm: name of insecure trust point.
204 * @return false on alloc failure.
206 int anchors_add_insecure(struct val_anchors* anchors, uint16_t c, uint8_t* nm);
209 * Delete insecure point trust anchor. Does not remove if no such point.
210 * For external use (locks and init_parents)
211 * @param anchors: anchor storage.
213 * @param nm: name of insecure trust point.
215 void anchors_delete_insecure(struct val_anchors* anchors, uint16_t c,
218 #endif /* VALIDATOR_VAL_ANCHOR_H */