1b7579f77SDag-Erling Smørgrav /* 2b7579f77SDag-Erling Smørgrav * validator/val_nsec3.h - validator NSEC3 denial of existance functions. 3b7579f77SDag-Erling Smørgrav * 4b7579f77SDag-Erling Smørgrav * Copyright (c) 2007, NLnet Labs. All rights reserved. 5b7579f77SDag-Erling Smørgrav * 6b7579f77SDag-Erling Smørgrav * This software is open source. 7b7579f77SDag-Erling Smørgrav * 8b7579f77SDag-Erling Smørgrav * Redistribution and use in source and binary forms, with or without 9b7579f77SDag-Erling Smørgrav * modification, are permitted provided that the following conditions 10b7579f77SDag-Erling Smørgrav * are met: 11b7579f77SDag-Erling Smørgrav * 12b7579f77SDag-Erling Smørgrav * Redistributions of source code must retain the above copyright notice, 13b7579f77SDag-Erling Smørgrav * this list of conditions and the following disclaimer. 14b7579f77SDag-Erling Smørgrav * 15b7579f77SDag-Erling Smørgrav * Redistributions in binary form must reproduce the above copyright notice, 16b7579f77SDag-Erling Smørgrav * this list of conditions and the following disclaimer in the documentation 17b7579f77SDag-Erling Smørgrav * and/or other materials provided with the distribution. 18b7579f77SDag-Erling Smørgrav * 19b7579f77SDag-Erling Smørgrav * Neither the name of the NLNET LABS nor the names of its contributors may 20b7579f77SDag-Erling Smørgrav * be used to endorse or promote products derived from this software without 21b7579f77SDag-Erling Smørgrav * specific prior written permission. 22b7579f77SDag-Erling Smørgrav * 23b7579f77SDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24*17d15b25SDag-Erling Smørgrav * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25*17d15b25SDag-Erling Smørgrav * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26*17d15b25SDag-Erling Smørgrav * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27*17d15b25SDag-Erling Smørgrav * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28*17d15b25SDag-Erling Smørgrav * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29*17d15b25SDag-Erling Smørgrav * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30*17d15b25SDag-Erling Smørgrav * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31*17d15b25SDag-Erling Smørgrav * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32*17d15b25SDag-Erling Smørgrav * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33*17d15b25SDag-Erling Smørgrav * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34b7579f77SDag-Erling Smørgrav */ 35b7579f77SDag-Erling Smørgrav 36b7579f77SDag-Erling Smørgrav /** 37b7579f77SDag-Erling Smørgrav * \file 38b7579f77SDag-Erling Smørgrav * 39b7579f77SDag-Erling Smørgrav * This file contains helper functions for the validator module. 40b7579f77SDag-Erling Smørgrav * The functions help with NSEC3 checking, the different NSEC3 proofs 41b7579f77SDag-Erling Smørgrav * for denial of existance, and proofs for presence of types. 42b7579f77SDag-Erling Smørgrav * 43b7579f77SDag-Erling Smørgrav * NSEC3 44b7579f77SDag-Erling Smørgrav * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 45b7579f77SDag-Erling Smørgrav * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 46b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 47b7579f77SDag-Erling Smørgrav * | Hash Alg. | Flags | Iterations | 48b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 49b7579f77SDag-Erling Smørgrav * | Salt Length | Salt / 50b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 51b7579f77SDag-Erling Smørgrav * | Hash Length | Next Hashed Owner Name / 52b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 53b7579f77SDag-Erling Smørgrav * / Type Bit Maps / 54b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 55b7579f77SDag-Erling Smørgrav * 56b7579f77SDag-Erling Smørgrav * NSEC3PARAM 57b7579f77SDag-Erling Smørgrav * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 58b7579f77SDag-Erling Smørgrav * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 59b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 60b7579f77SDag-Erling Smørgrav * | Hash Alg. | Flags | Iterations | 61b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 62b7579f77SDag-Erling Smørgrav * | Salt Length | Salt / 63b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 64b7579f77SDag-Erling Smørgrav * 65b7579f77SDag-Erling Smørgrav */ 66b7579f77SDag-Erling Smørgrav 67b7579f77SDag-Erling Smørgrav #ifndef VALIDATOR_VAL_NSEC3_H 68b7579f77SDag-Erling Smørgrav #define VALIDATOR_VAL_NSEC3_H 69b7579f77SDag-Erling Smørgrav #include "util/rbtree.h" 70b7579f77SDag-Erling Smørgrav #include "util/data/packed_rrset.h" 71b7579f77SDag-Erling Smørgrav struct val_env; 72b7579f77SDag-Erling Smørgrav struct regional; 73b7579f77SDag-Erling Smørgrav struct module_env; 74b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key; 75b7579f77SDag-Erling Smørgrav struct reply_info; 76b7579f77SDag-Erling Smørgrav struct query_info; 77b7579f77SDag-Erling Smørgrav struct key_entry_key; 78*17d15b25SDag-Erling Smørgrav struct sldns_buffer; 79b7579f77SDag-Erling Smørgrav 80b7579f77SDag-Erling Smørgrav /** 81b7579f77SDag-Erling Smørgrav * 0 1 2 3 4 5 6 7 82b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+ 83b7579f77SDag-Erling Smørgrav * | |O| 84b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+ 85b7579f77SDag-Erling Smørgrav * The OPT-OUT bit in the NSEC3 flags field. 86b7579f77SDag-Erling Smørgrav * If enabled, there can be zero or more unsigned delegations in the span. 87b7579f77SDag-Erling Smørgrav * If disabled, there are zero unsigned delegations in the span. 88b7579f77SDag-Erling Smørgrav */ 89b7579f77SDag-Erling Smørgrav #define NSEC3_OPTOUT 0x01 90b7579f77SDag-Erling Smørgrav /** 91b7579f77SDag-Erling Smørgrav * The unknown flags in the NSEC3 flags field. 92b7579f77SDag-Erling Smørgrav * They must be zero, or the NSEC3 is ignored. 93b7579f77SDag-Erling Smørgrav */ 94b7579f77SDag-Erling Smørgrav #define NSEC3_UNKNOWN_FLAGS 0xFE 95b7579f77SDag-Erling Smørgrav 96b7579f77SDag-Erling Smørgrav /** The SHA1 hash algorithm for NSEC3 */ 97b7579f77SDag-Erling Smørgrav #define NSEC3_HASH_SHA1 0x01 98b7579f77SDag-Erling Smørgrav 99b7579f77SDag-Erling Smørgrav /** 100b7579f77SDag-Erling Smørgrav * Determine if the set of NSEC3 records provided with a response prove NAME 101b7579f77SDag-Erling Smørgrav * ERROR. This means that the NSEC3s prove a) the closest encloser exists, 102b7579f77SDag-Erling Smørgrav * b) the direct child of the closest encloser towards qname doesn't exist, 103b7579f77SDag-Erling Smørgrav * and c) *.closest encloser does not exist. 104b7579f77SDag-Erling Smørgrav * 105b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 106b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 107b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 108b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 109b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 110b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 111b7579f77SDag-Erling Smørgrav * @return: 112b7579f77SDag-Erling Smørgrav * sec_status SECURE of the Name Error is proven by the NSEC3 RRs, 113b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 114b7579f77SDag-Erling Smørgrav */ 115b7579f77SDag-Erling Smørgrav enum sec_status 116b7579f77SDag-Erling Smørgrav nsec3_prove_nameerror(struct module_env* env, struct val_env* ve, 117b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 118b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey); 119b7579f77SDag-Erling Smørgrav 120b7579f77SDag-Erling Smørgrav /** 121b7579f77SDag-Erling Smørgrav * Determine if the NSEC3s provided in a response prove the NOERROR/NODATA 122b7579f77SDag-Erling Smørgrav * status. There are a number of different variants to this: 123b7579f77SDag-Erling Smørgrav * 124b7579f77SDag-Erling Smørgrav * 1) Normal NODATA -- qname is matched to an NSEC3 record, type is not 125b7579f77SDag-Erling Smørgrav * present. 126b7579f77SDag-Erling Smørgrav * 127b7579f77SDag-Erling Smørgrav * 2) ENT NODATA -- because there must be NSEC3 record for 128b7579f77SDag-Erling Smørgrav * empty-non-terminals, this is the same as #1. 129b7579f77SDag-Erling Smørgrav * 130b7579f77SDag-Erling Smørgrav * 3) NSEC3 ownername NODATA -- qname matched an existing, lone NSEC3 131b7579f77SDag-Erling Smørgrav * ownername, but qtype was not NSEC3. NOTE: as of nsec-05, this case no 132b7579f77SDag-Erling Smørgrav * longer exists. 133b7579f77SDag-Erling Smørgrav * 134b7579f77SDag-Erling Smørgrav * 4) Wildcard NODATA -- A wildcard matched the name, but not the type. 135b7579f77SDag-Erling Smørgrav * 136b7579f77SDag-Erling Smørgrav * 5) Opt-In DS NODATA -- the qname is covered by an opt-in span and qtype == 137b7579f77SDag-Erling Smørgrav * DS. (or maybe some future record with the same parent-side-only property) 138b7579f77SDag-Erling Smørgrav * 139b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 140b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 141b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 142b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 143b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 144b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 145b7579f77SDag-Erling Smørgrav * @return: 146b7579f77SDag-Erling Smørgrav * sec_status SECURE of the proposition is proven by the NSEC3 RRs, 147b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 148b7579f77SDag-Erling Smørgrav */ 149b7579f77SDag-Erling Smørgrav enum sec_status 150b7579f77SDag-Erling Smørgrav nsec3_prove_nodata(struct module_env* env, struct val_env* ve, 151b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 152b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey); 153b7579f77SDag-Erling Smørgrav 154b7579f77SDag-Erling Smørgrav 155b7579f77SDag-Erling Smørgrav /** 156b7579f77SDag-Erling Smørgrav * Prove that a positive wildcard match was appropriate (no direct match 157b7579f77SDag-Erling Smørgrav * RRset). 158b7579f77SDag-Erling Smørgrav * 159b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 160b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 161b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 162b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 163b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 164b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 165b7579f77SDag-Erling Smørgrav * @param wc: The purported wildcard that matched. This is the wildcard name 166b7579f77SDag-Erling Smørgrav * as *.wildcard.name., with the *. label already removed. 167b7579f77SDag-Erling Smørgrav * @return: 168b7579f77SDag-Erling Smørgrav * sec_status SECURE of the proposition is proven by the NSEC3 RRs, 169b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 170b7579f77SDag-Erling Smørgrav */ 171b7579f77SDag-Erling Smørgrav enum sec_status 172b7579f77SDag-Erling Smørgrav nsec3_prove_wildcard(struct module_env* env, struct val_env* ve, 173b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 174b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey, uint8_t* wc); 175b7579f77SDag-Erling Smørgrav 176b7579f77SDag-Erling Smørgrav /** 177b7579f77SDag-Erling Smørgrav * Prove that a DS response either had no DS, or wasn't a delegation point. 178b7579f77SDag-Erling Smørgrav * 179b7579f77SDag-Erling Smørgrav * Fundamentally there are two cases here: normal NODATA and Opt-In NODATA. 180b7579f77SDag-Erling Smørgrav * 181b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 182b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 183b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 184b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 185b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 186b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 187b7579f77SDag-Erling Smørgrav * @param reason: string for bogus result. 188b7579f77SDag-Erling Smørgrav * @return: 189b7579f77SDag-Erling Smørgrav * sec_status SECURE of the proposition is proven by the NSEC3 RRs, 190b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 191b7579f77SDag-Erling Smørgrav * or if there was no DS in an insecure (i.e., opt-in) way, 192b7579f77SDag-Erling Smørgrav * INDETERMINATE if it was clear that this wasn't a delegation point. 193b7579f77SDag-Erling Smørgrav */ 194b7579f77SDag-Erling Smørgrav enum sec_status 195b7579f77SDag-Erling Smørgrav nsec3_prove_nods(struct module_env* env, struct val_env* ve, 196b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 197b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey, char** reason); 198b7579f77SDag-Erling Smørgrav 199b7579f77SDag-Erling Smørgrav /** 200b7579f77SDag-Erling Smørgrav * Prove NXDOMAIN or NODATA. 201b7579f77SDag-Erling Smørgrav * 202b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 203b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 204b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 205b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 206b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 207b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 208b7579f77SDag-Erling Smørgrav * @param nodata: if return value is secure, this indicates if nodata or 209b7579f77SDag-Erling Smørgrav * nxdomain was proven. 210b7579f77SDag-Erling Smørgrav * @return: 211b7579f77SDag-Erling Smørgrav * sec_status SECURE of the proposition is proven by the NSEC3 RRs, 212b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 213b7579f77SDag-Erling Smørgrav */ 214b7579f77SDag-Erling Smørgrav enum sec_status 215b7579f77SDag-Erling Smørgrav nsec3_prove_nxornodata(struct module_env* env, struct val_env* ve, 216b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 217b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey, int* nodata); 218b7579f77SDag-Erling Smørgrav 219b7579f77SDag-Erling Smørgrav /** 220b7579f77SDag-Erling Smørgrav * The NSEC3 hash result storage. 221b7579f77SDag-Erling Smørgrav * Consists of an rbtree, with these nodes in it. 222b7579f77SDag-Erling Smørgrav * The nodes detail how a set of parameters (from nsec3 rr) plus 223b7579f77SDag-Erling Smørgrav * a dname result in a hash. 224b7579f77SDag-Erling Smørgrav */ 225b7579f77SDag-Erling Smørgrav struct nsec3_cached_hash { 226b7579f77SDag-Erling Smørgrav /** rbtree node, key is this structure */ 227b7579f77SDag-Erling Smørgrav rbnode_t node; 228b7579f77SDag-Erling Smørgrav /** where are the parameters for conversion, in this rrset data */ 229b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key* nsec3; 230b7579f77SDag-Erling Smørgrav /** where are the parameters for conversion, this RR number in data */ 231b7579f77SDag-Erling Smørgrav int rr; 232b7579f77SDag-Erling Smørgrav /** the name to convert */ 233b7579f77SDag-Erling Smørgrav uint8_t* dname; 234b7579f77SDag-Erling Smørgrav /** length of the dname */ 235b7579f77SDag-Erling Smørgrav size_t dname_len; 236b7579f77SDag-Erling Smørgrav /** the hash result (not base32 encoded) */ 237b7579f77SDag-Erling Smørgrav uint8_t* hash; 238b7579f77SDag-Erling Smørgrav /** length of hash in bytes */ 239b7579f77SDag-Erling Smørgrav size_t hash_len; 240b7579f77SDag-Erling Smørgrav /** the hash result in base32 encoding */ 241b7579f77SDag-Erling Smørgrav uint8_t* b32; 242b7579f77SDag-Erling Smørgrav /** length of base32 encoding (as a label) */ 243b7579f77SDag-Erling Smørgrav size_t b32_len; 244b7579f77SDag-Erling Smørgrav }; 245b7579f77SDag-Erling Smørgrav 246b7579f77SDag-Erling Smørgrav /** 247b7579f77SDag-Erling Smørgrav * Rbtree for hash cache comparison function. 248b7579f77SDag-Erling Smørgrav * @param c1: key 1. 249b7579f77SDag-Erling Smørgrav * @param c2: key 2. 250b7579f77SDag-Erling Smørgrav * @return: comparison code, -1, 0, 1, of the keys. 251b7579f77SDag-Erling Smørgrav */ 252b7579f77SDag-Erling Smørgrav int nsec3_hash_cmp(const void* c1, const void* c2); 253b7579f77SDag-Erling Smørgrav 254b7579f77SDag-Erling Smørgrav /** 255b7579f77SDag-Erling Smørgrav * Obtain the hash of an owner name. 256b7579f77SDag-Erling Smørgrav * Used internally by the nsec3 proof functions in this file. 257b7579f77SDag-Erling Smørgrav * published to enable unit testing of hash algorithms and cache. 258b7579f77SDag-Erling Smørgrav * 259b7579f77SDag-Erling Smørgrav * @param table: the cache table. Must be inited at start. 260b7579f77SDag-Erling Smørgrav * @param region: scratch region to use for allocation. 261b7579f77SDag-Erling Smørgrav * This region holds the tree, if you wipe the region, reinit the tree. 262b7579f77SDag-Erling Smørgrav * @param buf: temporary buffer. 263b7579f77SDag-Erling Smørgrav * @param nsec3: the rrset with parameters 264b7579f77SDag-Erling Smørgrav * @param rr: rr number from d that has the NSEC3 parameters to hash to. 265b7579f77SDag-Erling Smørgrav * @param dname: name to hash 266b7579f77SDag-Erling Smørgrav * This pointer is used inside the tree, assumed region-alloced. 267b7579f77SDag-Erling Smørgrav * @param dname_len: the length of the name. 268b7579f77SDag-Erling Smørgrav * @param hash: the hash node is returned on success. 269b7579f77SDag-Erling Smørgrav * @return: 270b7579f77SDag-Erling Smørgrav * 1 on success, either from cache or newly hashed hash is returned. 271b7579f77SDag-Erling Smørgrav * 0 on a malloc failure. 272b7579f77SDag-Erling Smørgrav * -1 if the NSEC3 rr was badly formatted (i.e. formerr). 273b7579f77SDag-Erling Smørgrav */ 274*17d15b25SDag-Erling Smørgrav int nsec3_hash_name(rbtree_t* table, struct regional* region, 275*17d15b25SDag-Erling Smørgrav struct sldns_buffer* buf, struct ub_packed_rrset_key* nsec3, int rr, 276*17d15b25SDag-Erling Smørgrav uint8_t* dname, size_t dname_len, struct nsec3_cached_hash** hash); 277b7579f77SDag-Erling Smørgrav 278b7579f77SDag-Erling Smørgrav /** 279b7579f77SDag-Erling Smørgrav * Get next owner name, converted to base32 encoding and with the 280b7579f77SDag-Erling Smørgrav * zone name (taken from the nsec3 owner name) appended. 281b7579f77SDag-Erling Smørgrav * @param rrset: the NSEC3 rrset. 282b7579f77SDag-Erling Smørgrav * @param r: the rr num of the nsec3 in the rrset. 283b7579f77SDag-Erling Smørgrav * @param buf: buffer to store name in 284b7579f77SDag-Erling Smørgrav * @param max: size of buffer. 285b7579f77SDag-Erling Smørgrav * @return length of name on success. 0 on failure (buffer too short or 286b7579f77SDag-Erling Smørgrav * bad format nsec3 record). 287b7579f77SDag-Erling Smørgrav */ 288b7579f77SDag-Erling Smørgrav size_t nsec3_get_nextowner_b32(struct ub_packed_rrset_key* rrset, int r, 289b7579f77SDag-Erling Smørgrav uint8_t* buf, size_t max); 290b7579f77SDag-Erling Smørgrav 291b7579f77SDag-Erling Smørgrav /** 292b7579f77SDag-Erling Smørgrav * Convert hash into base32 encoding and with the 293b7579f77SDag-Erling Smørgrav * zone name appended. 294b7579f77SDag-Erling Smørgrav * @param hash: hashed buffer 295b7579f77SDag-Erling Smørgrav * @param hashlen: length of hash 296b7579f77SDag-Erling Smørgrav * @param zone: name of zone 297b7579f77SDag-Erling Smørgrav * @param zonelen: length of zonename. 298b7579f77SDag-Erling Smørgrav * @param buf: buffer to store name in 299b7579f77SDag-Erling Smørgrav * @param max: size of buffer. 300b7579f77SDag-Erling Smørgrav * @return length of name on success. 0 on failure (buffer too short or 301b7579f77SDag-Erling Smørgrav * bad format nsec3 record). 302b7579f77SDag-Erling Smørgrav */ 303b7579f77SDag-Erling Smørgrav size_t nsec3_hash_to_b32(uint8_t* hash, size_t hashlen, uint8_t* zone, 304b7579f77SDag-Erling Smørgrav size_t zonelen, uint8_t* buf, size_t max); 305b7579f77SDag-Erling Smørgrav 306b7579f77SDag-Erling Smørgrav /** 307b7579f77SDag-Erling Smørgrav * Get NSEC3 parameters out of rr. 308b7579f77SDag-Erling Smørgrav * @param rrset: the NSEC3 rrset. 309b7579f77SDag-Erling Smørgrav * @param r: the rr num of the nsec3 in the rrset. 310b7579f77SDag-Erling Smørgrav * @param algo: nsec3 hash algo. 311b7579f77SDag-Erling Smørgrav * @param iter: iteration count. 312b7579f77SDag-Erling Smørgrav * @param salt: ptr to salt inside rdata. 313b7579f77SDag-Erling Smørgrav * @param saltlen: length of salt. 314b7579f77SDag-Erling Smørgrav * @return 0 if bad formatted, unknown nsec3 hash algo, or unknown flags set. 315b7579f77SDag-Erling Smørgrav */ 316b7579f77SDag-Erling Smørgrav int nsec3_get_params(struct ub_packed_rrset_key* rrset, int r, 317b7579f77SDag-Erling Smørgrav int* algo, size_t* iter, uint8_t** salt, size_t* saltlen); 318b7579f77SDag-Erling Smørgrav 319b7579f77SDag-Erling Smørgrav /** 320b7579f77SDag-Erling Smørgrav * Get NSEC3 hashed in a buffer 321b7579f77SDag-Erling Smørgrav * @param buf: buffer for temp use. 322b7579f77SDag-Erling Smørgrav * @param nm: name to hash 323b7579f77SDag-Erling Smørgrav * @param nmlen: length of nm. 324b7579f77SDag-Erling Smørgrav * @param algo: algo to use, must be known. 325b7579f77SDag-Erling Smørgrav * @param iter: iterations 326b7579f77SDag-Erling Smørgrav * @param salt: salt for nsec3 327b7579f77SDag-Erling Smørgrav * @param saltlen: length of salt. 328b7579f77SDag-Erling Smørgrav * @param res: result of hash stored here. 329b7579f77SDag-Erling Smørgrav * @param max: maximum space for result. 330b7579f77SDag-Erling Smørgrav * @return 0 on failure, otherwise bytelength stored. 331b7579f77SDag-Erling Smørgrav */ 332*17d15b25SDag-Erling Smørgrav size_t nsec3_get_hashed(struct sldns_buffer* buf, uint8_t* nm, size_t nmlen, 333*17d15b25SDag-Erling Smørgrav int algo, size_t iter, uint8_t* salt, size_t saltlen, uint8_t* res, 334*17d15b25SDag-Erling Smørgrav size_t max); 335b7579f77SDag-Erling Smørgrav 336b7579f77SDag-Erling Smørgrav /** 337b7579f77SDag-Erling Smørgrav * see if NSEC3 RR contains given type 338b7579f77SDag-Erling Smørgrav * @param rrset: NSEC3 rrset 339b7579f77SDag-Erling Smørgrav * @param r: RR in rrset 340b7579f77SDag-Erling Smørgrav * @param type: in host order to check bit for. 341b7579f77SDag-Erling Smørgrav * @return true if bit set, false if not or error. 342b7579f77SDag-Erling Smørgrav */ 343b7579f77SDag-Erling Smørgrav int nsec3_has_type(struct ub_packed_rrset_key* rrset, int r, uint16_t type); 344b7579f77SDag-Erling Smørgrav 345b7579f77SDag-Erling Smørgrav /** 346b7579f77SDag-Erling Smørgrav * return if nsec3 RR has the optout flag 347b7579f77SDag-Erling Smørgrav * @param rrset: NSEC3 rrset 348b7579f77SDag-Erling Smørgrav * @param r: RR in rrset 349b7579f77SDag-Erling Smørgrav * @return true if optout, false on error or not optout 350b7579f77SDag-Erling Smørgrav */ 351b7579f77SDag-Erling Smørgrav int nsec3_has_optout(struct ub_packed_rrset_key* rrset, int r); 352b7579f77SDag-Erling Smørgrav 353b7579f77SDag-Erling Smørgrav /** 354b7579f77SDag-Erling Smørgrav * Return nsec3 RR next hashed owner name 355b7579f77SDag-Erling Smørgrav * @param rrset: NSEC3 rrset 356b7579f77SDag-Erling Smørgrav * @param r: RR in rrset 357b7579f77SDag-Erling Smørgrav * @param next: ptr into rdata to next owner hash 358b7579f77SDag-Erling Smørgrav * @param nextlen: length of hash. 359b7579f77SDag-Erling Smørgrav * @return false on malformed 360b7579f77SDag-Erling Smørgrav */ 361b7579f77SDag-Erling Smørgrav int nsec3_get_nextowner(struct ub_packed_rrset_key* rrset, int r, 362b7579f77SDag-Erling Smørgrav uint8_t** next, size_t* nextlen); 363b7579f77SDag-Erling Smørgrav 364b7579f77SDag-Erling Smørgrav /** 365b7579f77SDag-Erling Smørgrav * nsec3Covers 366b7579f77SDag-Erling Smørgrav * Given a hash and a candidate NSEC3Record, determine if that NSEC3Record 367b7579f77SDag-Erling Smørgrav * covers the hash. Covers specifically means that the hash is in between 368b7579f77SDag-Erling Smørgrav * the owner and next hashes and does not equal either. 369b7579f77SDag-Erling Smørgrav * 370b7579f77SDag-Erling Smørgrav * @param zone: the zone name. 371b7579f77SDag-Erling Smørgrav * @param hash: the hash of the name 372b7579f77SDag-Erling Smørgrav * @param rrset: the rrset of the NSEC3. 373b7579f77SDag-Erling Smørgrav * @param rr: which rr in the rrset. 374b7579f77SDag-Erling Smørgrav * @param buf: temporary buffer. 375b7579f77SDag-Erling Smørgrav * @return true if covers, false if not. 376b7579f77SDag-Erling Smørgrav */ 377b7579f77SDag-Erling Smørgrav int nsec3_covers(uint8_t* zone, struct nsec3_cached_hash* hash, 378*17d15b25SDag-Erling Smørgrav struct ub_packed_rrset_key* rrset, int rr, struct sldns_buffer* buf); 379b7579f77SDag-Erling Smørgrav 380b7579f77SDag-Erling Smørgrav #endif /* VALIDATOR_VAL_NSEC3_H */ 381