val_kentry.h revision 1.1.1.2 1 1.1 christos /*
2 1.1 christos * validator/val_kentry.h - validator key entry definition.
3 1.1 christos *
4 1.1 christos * Copyright (c) 2007, NLnet Labs. All rights reserved.
5 1.1 christos *
6 1.1 christos * This software is open source.
7 1.1 christos *
8 1.1 christos * Redistribution and use in source and binary forms, with or without
9 1.1 christos * modification, are permitted provided that the following conditions
10 1.1 christos * are met:
11 1.1 christos *
12 1.1 christos * Redistributions of source code must retain the above copyright notice,
13 1.1 christos * this list of conditions and the following disclaimer.
14 1.1 christos *
15 1.1 christos * Redistributions in binary form must reproduce the above copyright notice,
16 1.1 christos * this list of conditions and the following disclaimer in the documentation
17 1.1 christos * and/or other materials provided with the distribution.
18 1.1 christos *
19 1.1 christos * Neither the name of the NLNET LABS nor the names of its contributors may
20 1.1 christos * be used to endorse or promote products derived from this software without
21 1.1 christos * specific prior written permission.
22 1.1 christos *
23 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 1.1 christos * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 1.1 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 1.1 christos * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 1.1 christos * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 1.1 christos * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 1.1 christos * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 1.1 christos * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1 christos */
35 1.1 christos
36 1.1 christos /**
37 1.1 christos * \file
38 1.1 christos *
39 1.1 christos * This file contains functions for dealing with validator key entries.
40 1.1 christos */
41 1.1 christos
42 1.1 christos #ifndef VALIDATOR_VAL_KENTRY_H
43 1.1 christos #define VALIDATOR_VAL_KENTRY_H
44 1.1 christos struct packed_rrset_data;
45 1.1 christos struct regional;
46 1.1 christos struct ub_packed_rrset_key;
47 1.1 christos #include "util/storage/lruhash.h"
48 1.1.1.2 christos #include "sldns/rrdef.h"
49 1.1 christos
50 1.1 christos /**
51 1.1 christos * A key entry for the validator.
52 1.1 christos * This may or may not be a trusted key.
53 1.1 christos * This is what is stored in the key cache.
54 1.1 christos * This is the key part for the cache; the key entry key.
55 1.1 christos */
56 1.1 christos struct key_entry_key {
57 1.1 christos /** lru hash entry */
58 1.1 christos struct lruhash_entry entry;
59 1.1 christos /** name of the key */
60 1.1 christos uint8_t* name;
61 1.1 christos /** length of name */
62 1.1 christos size_t namelen;
63 1.1 christos /** class of the key, host byteorder */
64 1.1 christos uint16_t key_class;
65 1.1 christos };
66 1.1 christos
67 1.1 christos /**
68 1.1 christos * Key entry for the validator.
69 1.1 christos * Contains key status.
70 1.1 christos * This is the data part for the cache, the key entry data.
71 1.1 christos *
72 1.1 christos * Can be in three basic states:
73 1.1 christos * isbad=0: good key
74 1.1 christos * isbad=1: bad key
75 1.1 christos * isbad=0 && rrset=0: insecure space.
76 1.1 christos */
77 1.1 christos struct key_entry_data {
78 1.1 christos /** the TTL of this entry (absolute time) */
79 1.1 christos time_t ttl;
80 1.1 christos /** the key rrdata. can be NULL to signal keyless name. */
81 1.1 christos struct packed_rrset_data* rrset_data;
82 1.1 christos /** not NULL sometimes to give reason why bogus */
83 1.1 christos char* reason;
84 1.1.1.2 christos /** not NULL to give reason why bogus */
85 1.1.1.2 christos sldns_ede_code reason_bogus;
86 1.1 christos /** list of algorithms signalled, ends with 0, or NULL */
87 1.1 christos uint8_t* algo;
88 1.1 christos /** DNS RR type of the rrset data (host order) */
89 1.1 christos uint16_t rrset_type;
90 1.1 christos /** if the key is bad: Bogus or malformed */
91 1.1 christos uint8_t isbad;
92 1.1 christos };
93 1.1 christos
94 1.1 christos /** function for lruhash operation */
95 1.1 christos size_t key_entry_sizefunc(void* key, void* data);
96 1.1 christos
97 1.1 christos /** function for lruhash operation */
98 1.1 christos int key_entry_compfunc(void* k1, void* k2);
99 1.1 christos
100 1.1 christos /** function for lruhash operation */
101 1.1 christos void key_entry_delkeyfunc(void* key, void* userarg);
102 1.1 christos
103 1.1 christos /** function for lruhash operation */
104 1.1 christos void key_entry_deldatafunc(void* data, void* userarg);
105 1.1 christos
106 1.1 christos /** calculate hash for key entry
107 1.1 christos * @param kk: key entry. The lruhash entry.hash value is filled in.
108 1.1 christos */
109 1.1 christos void key_entry_hash(struct key_entry_key* kk);
110 1.1 christos
111 1.1 christos /**
112 1.1 christos * Copy a key entry, to be region-allocated.
113 1.1 christos * @param kkey: the key entry key (and data pointer) to copy.
114 1.1 christos * @param region: where to allocate it
115 1.1 christos * @return newly region-allocated entry or NULL on a failure to allocate.
116 1.1 christos */
117 1.1 christos struct key_entry_key* key_entry_copy_toregion(struct key_entry_key* kkey,
118 1.1 christos struct regional* region);
119 1.1 christos
120 1.1 christos /**
121 1.1 christos * Copy a key entry, malloced.
122 1.1 christos * @param kkey: the key entry key (and data pointer) to copy.
123 1.1 christos * @return newly allocated entry or NULL on a failure to allocate memory.
124 1.1 christos */
125 1.1 christos struct key_entry_key* key_entry_copy(struct key_entry_key* kkey);
126 1.1 christos
127 1.1 christos /**
128 1.1 christos * See if this is a null entry. Does not do locking.
129 1.1 christos * @param kkey: must have data pointer set correctly
130 1.1 christos * @return true if it is a NULL rrset entry.
131 1.1 christos */
132 1.1 christos int key_entry_isnull(struct key_entry_key* kkey);
133 1.1 christos
134 1.1 christos /**
135 1.1 christos * See if this entry is good. Does not do locking.
136 1.1 christos * @param kkey: must have data pointer set correctly
137 1.1 christos * @return true if it is good.
138 1.1 christos */
139 1.1 christos int key_entry_isgood(struct key_entry_key* kkey);
140 1.1 christos
141 1.1 christos /**
142 1.1 christos * See if this entry is bad. Does not do locking.
143 1.1 christos * @param kkey: must have data pointer set correctly
144 1.1 christos * @return true if it is bad.
145 1.1 christos */
146 1.1 christos int key_entry_isbad(struct key_entry_key* kkey);
147 1.1 christos
148 1.1 christos /**
149 1.1 christos * Set reason why a key is bad.
150 1.1 christos * @param kkey: bad key.
151 1.1 christos * @param reason: string to attach, you must allocate it.
152 1.1 christos * Not safe to call twice unless you deallocate it yourself.
153 1.1 christos */
154 1.1 christos void key_entry_set_reason(struct key_entry_key* kkey, char* reason);
155 1.1 christos
156 1.1 christos /**
157 1.1.1.2 christos * Set the EDE (RFC8914) code why the key is bad, if it
158 1.1.1.2 christos * exists (so not LDNS_EDE_NONE).
159 1.1.1.2 christos * @param kkey: bad key.
160 1.1.1.2 christos * @param ede: EDE code to attach to this key.
161 1.1.1.2 christos */
162 1.1.1.2 christos void key_entry_set_reason_bogus(struct key_entry_key* kkey, sldns_ede_code ede);
163 1.1.1.2 christos
164 1.1.1.2 christos
165 1.1.1.2 christos /**
166 1.1 christos * Get reason why a key is bad.
167 1.1 christos * @param kkey: bad key
168 1.1 christos * @return pointer to string.
169 1.1 christos * String is part of key entry and is deleted with it.
170 1.1 christos */
171 1.1 christos char* key_entry_get_reason(struct key_entry_key* kkey);
172 1.1 christos
173 1.1 christos /**
174 1.1.1.2 christos * Get the EDE (RFC8914) code why a key is bad. Can return LDNS_EDE_NONE.
175 1.1.1.2 christos * @param kkey: bad key
176 1.1.1.2 christos * @return the ede code.
177 1.1.1.2 christos */
178 1.1.1.2 christos sldns_ede_code key_entry_get_reason_bogus(struct key_entry_key* kkey);
179 1.1.1.2 christos
180 1.1.1.2 christos /**
181 1.1 christos * Create a null entry, in the given region.
182 1.1 christos * @param region: where to allocate
183 1.1 christos * @param name: the key name
184 1.1 christos * @param namelen: length of name
185 1.1 christos * @param dclass: class of key entry. (host order);
186 1.1 christos * @param ttl: what ttl should the key have. relative.
187 1.1 christos * @param now: current time (added to ttl).
188 1.1 christos * @return new key entry or NULL on alloc failure
189 1.1 christos */
190 1.1 christos struct key_entry_key* key_entry_create_null(struct regional* region,
191 1.1 christos uint8_t* name, size_t namelen, uint16_t dclass, time_t ttl,
192 1.1 christos time_t now);
193 1.1 christos
194 1.1 christos /**
195 1.1 christos * Create a key entry from an rrset, in the given region.
196 1.1 christos * @param region: where to allocate.
197 1.1 christos * @param name: the key name
198 1.1 christos * @param namelen: length of name
199 1.1 christos * @param dclass: class of key entry. (host order);
200 1.1 christos * @param rrset: data for key entry. This is copied to the region.
201 1.1 christos * @param sigalg: signalled algorithm list (or NULL).
202 1.1 christos * @param now: current time (added to ttl of rrset)
203 1.1 christos * @return new key entry or NULL on alloc failure
204 1.1 christos */
205 1.1 christos struct key_entry_key* key_entry_create_rrset(struct regional* region,
206 1.1 christos uint8_t* name, size_t namelen, uint16_t dclass,
207 1.1 christos struct ub_packed_rrset_key* rrset, uint8_t* sigalg, time_t now);
208 1.1 christos
209 1.1 christos /**
210 1.1 christos * Create a bad entry, in the given region.
211 1.1 christos * @param region: where to allocate
212 1.1 christos * @param name: the key name
213 1.1 christos * @param namelen: length of name
214 1.1 christos * @param dclass: class of key entry. (host order);
215 1.1 christos * @param ttl: what ttl should the key have. relative.
216 1.1 christos * @param now: current time (added to ttl).
217 1.1 christos * @return new key entry or NULL on alloc failure
218 1.1 christos */
219 1.1 christos struct key_entry_key* key_entry_create_bad(struct regional* region,
220 1.1 christos uint8_t* name, size_t namelen, uint16_t dclass, time_t ttl,
221 1.1 christos time_t now);
222 1.1 christos
223 1.1 christos /**
224 1.1 christos * Obtain rrset from a key entry, allocated in region.
225 1.1 christos * @param kkey: key entry to convert to a rrset.
226 1.1 christos * @param region: where to allocate rrset
227 1.1 christos * @return rrset copy; if no rrset or alloc error returns NULL.
228 1.1 christos */
229 1.1 christos struct ub_packed_rrset_key* key_entry_get_rrset(struct key_entry_key* kkey,
230 1.1 christos struct regional* region);
231 1.1 christos
232 1.1 christos /**
233 1.1 christos * Get keysize of the keyentry.
234 1.1 christos * @param kkey: key, must be a good key, with contents.
235 1.1 christos * @return size in bits of the key.
236 1.1 christos */
237 1.1 christos size_t key_entry_keysize(struct key_entry_key* kkey);
238 1.1 christos
239 1.1 christos #endif /* VALIDATOR_VAL_KENTRY_H */
240