1b7579f77SDag-Erling Smørgrav /* 205ab2901SDag-Erling Smørgrav * validator/val_nsec3.h - validator NSEC3 denial of existence 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 2417d15b25SDag-Erling Smørgrav * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2517d15b25SDag-Erling Smørgrav * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2617d15b25SDag-Erling Smørgrav * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2717d15b25SDag-Erling Smørgrav * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2817d15b25SDag-Erling Smørgrav * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 2917d15b25SDag-Erling Smørgrav * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 3017d15b25SDag-Erling Smørgrav * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 3117d15b25SDag-Erling Smørgrav * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 3217d15b25SDag-Erling Smørgrav * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 3317d15b25SDag-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 4105ab2901SDag-Erling Smørgrav * for denial of existence, 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" 71*a39a5a69SCy Schubert #include "sldns/rrdef.h" 72b7579f77SDag-Erling Smørgrav struct val_env; 73b7579f77SDag-Erling Smørgrav struct regional; 74b7579f77SDag-Erling Smørgrav struct module_env; 75838e13ceSDag-Erling Smørgrav struct module_qstate; 76b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key; 77b7579f77SDag-Erling Smørgrav struct reply_info; 78b7579f77SDag-Erling Smørgrav struct query_info; 79b7579f77SDag-Erling Smørgrav struct key_entry_key; 8017d15b25SDag-Erling Smørgrav struct sldns_buffer; 81b7579f77SDag-Erling Smørgrav 82b7579f77SDag-Erling Smørgrav /** 83b7579f77SDag-Erling Smørgrav * 0 1 2 3 4 5 6 7 84b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+ 85b7579f77SDag-Erling Smørgrav * | |O| 86b7579f77SDag-Erling Smørgrav * +-+-+-+-+-+-+-+-+ 87b7579f77SDag-Erling Smørgrav * The OPT-OUT bit in the NSEC3 flags field. 88b7579f77SDag-Erling Smørgrav * If enabled, there can be zero or more unsigned delegations in the span. 89b7579f77SDag-Erling Smørgrav * If disabled, there are zero unsigned delegations in the span. 90b7579f77SDag-Erling Smørgrav */ 91b7579f77SDag-Erling Smørgrav #define NSEC3_OPTOUT 0x01 92b7579f77SDag-Erling Smørgrav /** 93b7579f77SDag-Erling Smørgrav * The unknown flags in the NSEC3 flags field. 94b7579f77SDag-Erling Smørgrav * They must be zero, or the NSEC3 is ignored. 95b7579f77SDag-Erling Smørgrav */ 96b7579f77SDag-Erling Smørgrav #define NSEC3_UNKNOWN_FLAGS 0xFE 97b7579f77SDag-Erling Smørgrav 98b7579f77SDag-Erling Smørgrav /** The SHA1 hash algorithm for NSEC3 */ 99b7579f77SDag-Erling Smørgrav #define NSEC3_HASH_SHA1 0x01 100b7579f77SDag-Erling Smørgrav 101b7579f77SDag-Erling Smørgrav /** 102b7579f77SDag-Erling Smørgrav * Determine if the set of NSEC3 records provided with a response prove NAME 103b7579f77SDag-Erling Smørgrav * ERROR. This means that the NSEC3s prove a) the closest encloser exists, 104b7579f77SDag-Erling Smørgrav * b) the direct child of the closest encloser towards qname doesn't exist, 105b7579f77SDag-Erling Smørgrav * and c) *.closest encloser does not exist. 106b7579f77SDag-Erling Smørgrav * 107b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 108b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 109b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 110b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 111b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 112b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 113b7579f77SDag-Erling Smørgrav * @return: 114b7579f77SDag-Erling Smørgrav * sec_status SECURE of the Name Error is proven by the NSEC3 RRs, 115b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 116b7579f77SDag-Erling Smørgrav */ 117b7579f77SDag-Erling Smørgrav enum sec_status 118b7579f77SDag-Erling Smørgrav nsec3_prove_nameerror(struct module_env* env, struct val_env* ve, 119b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 120b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey); 121b7579f77SDag-Erling Smørgrav 122b7579f77SDag-Erling Smørgrav /** 123b7579f77SDag-Erling Smørgrav * Determine if the NSEC3s provided in a response prove the NOERROR/NODATA 124b7579f77SDag-Erling Smørgrav * status. There are a number of different variants to this: 125b7579f77SDag-Erling Smørgrav * 126b7579f77SDag-Erling Smørgrav * 1) Normal NODATA -- qname is matched to an NSEC3 record, type is not 127b7579f77SDag-Erling Smørgrav * present. 128b7579f77SDag-Erling Smørgrav * 129b7579f77SDag-Erling Smørgrav * 2) ENT NODATA -- because there must be NSEC3 record for 130b7579f77SDag-Erling Smørgrav * empty-non-terminals, this is the same as #1. 131b7579f77SDag-Erling Smørgrav * 132b7579f77SDag-Erling Smørgrav * 3) NSEC3 ownername NODATA -- qname matched an existing, lone NSEC3 133b7579f77SDag-Erling Smørgrav * ownername, but qtype was not NSEC3. NOTE: as of nsec-05, this case no 134b7579f77SDag-Erling Smørgrav * longer exists. 135b7579f77SDag-Erling Smørgrav * 136b7579f77SDag-Erling Smørgrav * 4) Wildcard NODATA -- A wildcard matched the name, but not the type. 137b7579f77SDag-Erling Smørgrav * 138b7579f77SDag-Erling Smørgrav * 5) Opt-In DS NODATA -- the qname is covered by an opt-in span and qtype == 139b7579f77SDag-Erling Smørgrav * DS. (or maybe some future record with the same parent-side-only property) 140b7579f77SDag-Erling Smørgrav * 141b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 142b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 143b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 144b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 145b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 146b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 147b7579f77SDag-Erling Smørgrav * @return: 148b7579f77SDag-Erling Smørgrav * sec_status SECURE of the proposition is proven by the NSEC3 RRs, 149b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 150b7579f77SDag-Erling Smørgrav */ 151b7579f77SDag-Erling Smørgrav enum sec_status 152b7579f77SDag-Erling Smørgrav nsec3_prove_nodata(struct module_env* env, struct val_env* ve, 153b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 154b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey); 155b7579f77SDag-Erling Smørgrav 156b7579f77SDag-Erling Smørgrav 157b7579f77SDag-Erling Smørgrav /** 158b7579f77SDag-Erling Smørgrav * Prove that a positive wildcard match was appropriate (no direct match 159b7579f77SDag-Erling Smørgrav * RRset). 160b7579f77SDag-Erling Smørgrav * 161b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 162b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 163b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 164b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 165b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 166b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 167b7579f77SDag-Erling Smørgrav * @param wc: The purported wildcard that matched. This is the wildcard name 168b7579f77SDag-Erling Smørgrav * as *.wildcard.name., with the *. label already removed. 169b7579f77SDag-Erling Smørgrav * @return: 170b7579f77SDag-Erling Smørgrav * sec_status SECURE of the proposition is proven by the NSEC3 RRs, 171b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 172b7579f77SDag-Erling Smørgrav */ 173b7579f77SDag-Erling Smørgrav enum sec_status 174b7579f77SDag-Erling Smørgrav nsec3_prove_wildcard(struct module_env* env, struct val_env* ve, 175b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 176b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey, uint8_t* wc); 177b7579f77SDag-Erling Smørgrav 178b7579f77SDag-Erling Smørgrav /** 179b7579f77SDag-Erling Smørgrav * Prove that a DS response either had no DS, or wasn't a delegation point. 180b7579f77SDag-Erling Smørgrav * 181b7579f77SDag-Erling Smørgrav * Fundamentally there are two cases here: normal NODATA and Opt-In NODATA. 182b7579f77SDag-Erling Smørgrav * 183b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 184b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 185b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 186b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 187b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 188b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 189b7579f77SDag-Erling Smørgrav * @param reason: string for bogus result. 190*a39a5a69SCy Schubert * @param reason_bogus: EDE (RFC8914) code paired with the reason of failure. 191838e13ceSDag-Erling Smørgrav * @param qstate: qstate with region. 192b7579f77SDag-Erling Smørgrav * @return: 193b7579f77SDag-Erling Smørgrav * sec_status SECURE of the proposition is proven by the NSEC3 RRs, 194b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 195b7579f77SDag-Erling Smørgrav * or if there was no DS in an insecure (i.e., opt-in) way, 196b7579f77SDag-Erling Smørgrav * INDETERMINATE if it was clear that this wasn't a delegation point. 197b7579f77SDag-Erling Smørgrav */ 198b7579f77SDag-Erling Smørgrav enum sec_status 199b7579f77SDag-Erling Smørgrav nsec3_prove_nods(struct module_env* env, struct val_env* ve, 200b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 201838e13ceSDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey, char** reason, 202*a39a5a69SCy Schubert sldns_ede_code* reason_bogus, struct module_qstate* qstate); 203b7579f77SDag-Erling Smørgrav 204b7579f77SDag-Erling Smørgrav /** 205b7579f77SDag-Erling Smørgrav * Prove NXDOMAIN or NODATA. 206b7579f77SDag-Erling Smørgrav * 207b7579f77SDag-Erling Smørgrav * @param env: module environment with temporary region and buffer. 208b7579f77SDag-Erling Smørgrav * @param ve: validator environment, with iteration count settings. 209b7579f77SDag-Erling Smørgrav * @param list: array of RRsets, some of which are NSEC3s. 210b7579f77SDag-Erling Smørgrav * @param num: number of RRsets in the array to examine. 211b7579f77SDag-Erling Smørgrav * @param qinfo: query that is verified for. 212b7579f77SDag-Erling Smørgrav * @param kkey: key entry that signed the NSEC3s. 213b7579f77SDag-Erling Smørgrav * @param nodata: if return value is secure, this indicates if nodata or 214b7579f77SDag-Erling Smørgrav * nxdomain was proven. 215b7579f77SDag-Erling Smørgrav * @return: 216b7579f77SDag-Erling Smørgrav * sec_status SECURE of the proposition is proven by the NSEC3 RRs, 217b7579f77SDag-Erling Smørgrav * BOGUS if not, INSECURE if all of the NSEC3s could be validly ignored. 218b7579f77SDag-Erling Smørgrav */ 219b7579f77SDag-Erling Smørgrav enum sec_status 220b7579f77SDag-Erling Smørgrav nsec3_prove_nxornodata(struct module_env* env, struct val_env* ve, 221b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key** list, size_t num, 222b7579f77SDag-Erling Smørgrav struct query_info* qinfo, struct key_entry_key* kkey, int* nodata); 223b7579f77SDag-Erling Smørgrav 224b7579f77SDag-Erling Smørgrav /** 225b7579f77SDag-Erling Smørgrav * The NSEC3 hash result storage. 226b7579f77SDag-Erling Smørgrav * Consists of an rbtree, with these nodes in it. 227b7579f77SDag-Erling Smørgrav * The nodes detail how a set of parameters (from nsec3 rr) plus 228b7579f77SDag-Erling Smørgrav * a dname result in a hash. 229b7579f77SDag-Erling Smørgrav */ 230b7579f77SDag-Erling Smørgrav struct nsec3_cached_hash { 231b7579f77SDag-Erling Smørgrav /** rbtree node, key is this structure */ 2323005e0a3SDag-Erling Smørgrav rbnode_type node; 233b7579f77SDag-Erling Smørgrav /** where are the parameters for conversion, in this rrset data */ 234b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key* nsec3; 235b7579f77SDag-Erling Smørgrav /** where are the parameters for conversion, this RR number in data */ 236b7579f77SDag-Erling Smørgrav int rr; 237b7579f77SDag-Erling Smørgrav /** the name to convert */ 238b7579f77SDag-Erling Smørgrav uint8_t* dname; 239b7579f77SDag-Erling Smørgrav /** length of the dname */ 240b7579f77SDag-Erling Smørgrav size_t dname_len; 241b7579f77SDag-Erling Smørgrav /** the hash result (not base32 encoded) */ 242b7579f77SDag-Erling Smørgrav uint8_t* hash; 243b7579f77SDag-Erling Smørgrav /** length of hash in bytes */ 244b7579f77SDag-Erling Smørgrav size_t hash_len; 245b7579f77SDag-Erling Smørgrav /** the hash result in base32 encoding */ 246b7579f77SDag-Erling Smørgrav uint8_t* b32; 247b7579f77SDag-Erling Smørgrav /** length of base32 encoding (as a label) */ 248b7579f77SDag-Erling Smørgrav size_t b32_len; 249b7579f77SDag-Erling Smørgrav }; 250b7579f77SDag-Erling Smørgrav 251b7579f77SDag-Erling Smørgrav /** 252b7579f77SDag-Erling Smørgrav * Rbtree for hash cache comparison function. 253b7579f77SDag-Erling Smørgrav * @param c1: key 1. 254b7579f77SDag-Erling Smørgrav * @param c2: key 2. 255b7579f77SDag-Erling Smørgrav * @return: comparison code, -1, 0, 1, of the keys. 256b7579f77SDag-Erling Smørgrav */ 257b7579f77SDag-Erling Smørgrav int nsec3_hash_cmp(const void* c1, const void* c2); 258b7579f77SDag-Erling Smørgrav 259b7579f77SDag-Erling Smørgrav /** 260b7579f77SDag-Erling Smørgrav * Obtain the hash of an owner name. 261b7579f77SDag-Erling Smørgrav * Used internally by the nsec3 proof functions in this file. 262b7579f77SDag-Erling Smørgrav * published to enable unit testing of hash algorithms and cache. 263b7579f77SDag-Erling Smørgrav * 26405ab2901SDag-Erling Smørgrav * @param table: the cache table. Must be initialised at start. 265b7579f77SDag-Erling Smørgrav * @param region: scratch region to use for allocation. 266b7579f77SDag-Erling Smørgrav * This region holds the tree, if you wipe the region, reinit the tree. 267b7579f77SDag-Erling Smørgrav * @param buf: temporary buffer. 268b7579f77SDag-Erling Smørgrav * @param nsec3: the rrset with parameters 269b7579f77SDag-Erling Smørgrav * @param rr: rr number from d that has the NSEC3 parameters to hash to. 270b7579f77SDag-Erling Smørgrav * @param dname: name to hash 271b7579f77SDag-Erling Smørgrav * This pointer is used inside the tree, assumed region-alloced. 272b7579f77SDag-Erling Smørgrav * @param dname_len: the length of the name. 273b7579f77SDag-Erling Smørgrav * @param hash: the hash node is returned on success. 274b7579f77SDag-Erling Smørgrav * @return: 275b7579f77SDag-Erling Smørgrav * 1 on success, either from cache or newly hashed hash is returned. 276b7579f77SDag-Erling Smørgrav * 0 on a malloc failure. 277b7579f77SDag-Erling Smørgrav * -1 if the NSEC3 rr was badly formatted (i.e. formerr). 278b7579f77SDag-Erling Smørgrav */ 2793005e0a3SDag-Erling Smørgrav int nsec3_hash_name(rbtree_type* table, struct regional* region, 28017d15b25SDag-Erling Smørgrav struct sldns_buffer* buf, struct ub_packed_rrset_key* nsec3, int rr, 28117d15b25SDag-Erling Smørgrav uint8_t* dname, size_t dname_len, struct nsec3_cached_hash** hash); 282b7579f77SDag-Erling Smørgrav 283b7579f77SDag-Erling Smørgrav /** 284b7579f77SDag-Erling Smørgrav * Get next owner name, converted to base32 encoding and with the 285b7579f77SDag-Erling Smørgrav * zone name (taken from the nsec3 owner name) appended. 286b7579f77SDag-Erling Smørgrav * @param rrset: the NSEC3 rrset. 287b7579f77SDag-Erling Smørgrav * @param r: the rr num of the nsec3 in the rrset. 288b7579f77SDag-Erling Smørgrav * @param buf: buffer to store name in 289b7579f77SDag-Erling Smørgrav * @param max: size of buffer. 290b7579f77SDag-Erling Smørgrav * @return length of name on success. 0 on failure (buffer too short or 291b7579f77SDag-Erling Smørgrav * bad format nsec3 record). 292b7579f77SDag-Erling Smørgrav */ 293b7579f77SDag-Erling Smørgrav size_t nsec3_get_nextowner_b32(struct ub_packed_rrset_key* rrset, int r, 294b7579f77SDag-Erling Smørgrav uint8_t* buf, size_t max); 295b7579f77SDag-Erling Smørgrav 296b7579f77SDag-Erling Smørgrav /** 297b7579f77SDag-Erling Smørgrav * Convert hash into base32 encoding and with the 298b7579f77SDag-Erling Smørgrav * zone name appended. 299b7579f77SDag-Erling Smørgrav * @param hash: hashed buffer 300b7579f77SDag-Erling Smørgrav * @param hashlen: length of hash 301b7579f77SDag-Erling Smørgrav * @param zone: name of zone 302b7579f77SDag-Erling Smørgrav * @param zonelen: length of zonename. 303b7579f77SDag-Erling Smørgrav * @param buf: buffer to store name in 304b7579f77SDag-Erling Smørgrav * @param max: size of buffer. 305b7579f77SDag-Erling Smørgrav * @return length of name on success. 0 on failure (buffer too short or 306b7579f77SDag-Erling Smørgrav * bad format nsec3 record). 307b7579f77SDag-Erling Smørgrav */ 308b7579f77SDag-Erling Smørgrav size_t nsec3_hash_to_b32(uint8_t* hash, size_t hashlen, uint8_t* zone, 309b7579f77SDag-Erling Smørgrav size_t zonelen, uint8_t* buf, size_t max); 310b7579f77SDag-Erling Smørgrav 311b7579f77SDag-Erling Smørgrav /** 312b7579f77SDag-Erling Smørgrav * Get NSEC3 parameters out of rr. 313b7579f77SDag-Erling Smørgrav * @param rrset: the NSEC3 rrset. 314b7579f77SDag-Erling Smørgrav * @param r: the rr num of the nsec3 in the rrset. 315b7579f77SDag-Erling Smørgrav * @param algo: nsec3 hash algo. 316b7579f77SDag-Erling Smørgrav * @param iter: iteration count. 317b7579f77SDag-Erling Smørgrav * @param salt: ptr to salt inside rdata. 318b7579f77SDag-Erling Smørgrav * @param saltlen: length of salt. 319b7579f77SDag-Erling Smørgrav * @return 0 if bad formatted, unknown nsec3 hash algo, or unknown flags set. 320b7579f77SDag-Erling Smørgrav */ 321b7579f77SDag-Erling Smørgrav int nsec3_get_params(struct ub_packed_rrset_key* rrset, int r, 322b7579f77SDag-Erling Smørgrav int* algo, size_t* iter, uint8_t** salt, size_t* saltlen); 323b7579f77SDag-Erling Smørgrav 324b7579f77SDag-Erling Smørgrav /** 325b7579f77SDag-Erling Smørgrav * Get NSEC3 hashed in a buffer 326b7579f77SDag-Erling Smørgrav * @param buf: buffer for temp use. 327b7579f77SDag-Erling Smørgrav * @param nm: name to hash 328b7579f77SDag-Erling Smørgrav * @param nmlen: length of nm. 329b7579f77SDag-Erling Smørgrav * @param algo: algo to use, must be known. 330b7579f77SDag-Erling Smørgrav * @param iter: iterations 331b7579f77SDag-Erling Smørgrav * @param salt: salt for nsec3 332b7579f77SDag-Erling Smørgrav * @param saltlen: length of salt. 333b7579f77SDag-Erling Smørgrav * @param res: result of hash stored here. 334b7579f77SDag-Erling Smørgrav * @param max: maximum space for result. 335b7579f77SDag-Erling Smørgrav * @return 0 on failure, otherwise bytelength stored. 336b7579f77SDag-Erling Smørgrav */ 33717d15b25SDag-Erling Smørgrav size_t nsec3_get_hashed(struct sldns_buffer* buf, uint8_t* nm, size_t nmlen, 33817d15b25SDag-Erling Smørgrav int algo, size_t iter, uint8_t* salt, size_t saltlen, uint8_t* res, 33917d15b25SDag-Erling Smørgrav size_t max); 340b7579f77SDag-Erling Smørgrav 341b7579f77SDag-Erling Smørgrav /** 342b7579f77SDag-Erling Smørgrav * see if NSEC3 RR contains given type 343b7579f77SDag-Erling Smørgrav * @param rrset: NSEC3 rrset 344b7579f77SDag-Erling Smørgrav * @param r: RR in rrset 345b7579f77SDag-Erling Smørgrav * @param type: in host order to check bit for. 346b7579f77SDag-Erling Smørgrav * @return true if bit set, false if not or error. 347b7579f77SDag-Erling Smørgrav */ 348b7579f77SDag-Erling Smørgrav int nsec3_has_type(struct ub_packed_rrset_key* rrset, int r, uint16_t type); 349b7579f77SDag-Erling Smørgrav 350b7579f77SDag-Erling Smørgrav /** 351b7579f77SDag-Erling Smørgrav * return if nsec3 RR has the optout flag 352b7579f77SDag-Erling Smørgrav * @param rrset: NSEC3 rrset 353b7579f77SDag-Erling Smørgrav * @param r: RR in rrset 354b7579f77SDag-Erling Smørgrav * @return true if optout, false on error or not optout 355b7579f77SDag-Erling Smørgrav */ 356b7579f77SDag-Erling Smørgrav int nsec3_has_optout(struct ub_packed_rrset_key* rrset, int r); 357b7579f77SDag-Erling Smørgrav 358b7579f77SDag-Erling Smørgrav /** 359b7579f77SDag-Erling Smørgrav * Return nsec3 RR next hashed owner name 360b7579f77SDag-Erling Smørgrav * @param rrset: NSEC3 rrset 361b7579f77SDag-Erling Smørgrav * @param r: RR in rrset 362b7579f77SDag-Erling Smørgrav * @param next: ptr into rdata to next owner hash 363b7579f77SDag-Erling Smørgrav * @param nextlen: length of hash. 364b7579f77SDag-Erling Smørgrav * @return false on malformed 365b7579f77SDag-Erling Smørgrav */ 366b7579f77SDag-Erling Smørgrav int nsec3_get_nextowner(struct ub_packed_rrset_key* rrset, int r, 367b7579f77SDag-Erling Smørgrav uint8_t** next, size_t* nextlen); 368b7579f77SDag-Erling Smørgrav 369b7579f77SDag-Erling Smørgrav /** 370b7579f77SDag-Erling Smørgrav * nsec3Covers 371b7579f77SDag-Erling Smørgrav * Given a hash and a candidate NSEC3Record, determine if that NSEC3Record 372b7579f77SDag-Erling Smørgrav * covers the hash. Covers specifically means that the hash is in between 373b7579f77SDag-Erling Smørgrav * the owner and next hashes and does not equal either. 374b7579f77SDag-Erling Smørgrav * 375b7579f77SDag-Erling Smørgrav * @param zone: the zone name. 376b7579f77SDag-Erling Smørgrav * @param hash: the hash of the name 377b7579f77SDag-Erling Smørgrav * @param rrset: the rrset of the NSEC3. 378b7579f77SDag-Erling Smørgrav * @param rr: which rr in the rrset. 379b7579f77SDag-Erling Smørgrav * @param buf: temporary buffer. 380b7579f77SDag-Erling Smørgrav * @return true if covers, false if not. 381b7579f77SDag-Erling Smørgrav */ 382b7579f77SDag-Erling Smørgrav int nsec3_covers(uint8_t* zone, struct nsec3_cached_hash* hash, 38317d15b25SDag-Erling Smørgrav struct ub_packed_rrset_key* rrset, int rr, struct sldns_buffer* buf); 384b7579f77SDag-Erling Smørgrav 385b7579f77SDag-Erling Smørgrav #endif /* VALIDATOR_VAL_NSEC3_H */ 386