5
5
#pragma once
6
6
7
7
#include <libknot/packet/pkt.h>
8
+ #include <libknot/rrtype/nsec3.h>
9
+ #include <libdnssec/nsec.h>
8
10
9
11
/** High numbers in NSEC3 iterations don't really help security
10
12
*
13
15
*
14
16
https://datatracker.ietf.org/doc/html/rfc9276#name-recommendation-for-validati
15
17
*/
16
- #define KR_NSEC3_MAX_ITERATIONS 50
18
+ static inline bool kr_nsec3_limited (unsigned int iterations , unsigned int salt_len )
19
+ {
20
+ const int MAX_ITERATIONS = 50 ; // limit with short salt length
21
+ // SHA1 works on 64-byte chunks.
22
+ // On iterating we hash the salt + 20 bytes of the previous hash.
23
+ int chunks_per_iter = (20 + salt_len - 1 ) / 64 + 1 ;
24
+ return (iterations + 1 ) * chunks_per_iter > MAX_ITERATIONS + 1 ;
25
+ }
26
+ static inline bool kr_nsec3_limited_rdata (const knot_rdata_t * rd )
27
+ {
28
+ return kr_nsec3_limited (knot_nsec3_iters (rd ), knot_nsec3_salt_len (rd ));
29
+ }
30
+ static inline bool kr_nsec3_limited_params (const dnssec_nsec3_params_t * params )
31
+ {
32
+ return kr_nsec3_limited (params -> iterations , params -> salt .size );
33
+ }
17
34
18
35
/**
19
36
* Name error response check (RFC5155 7.2.2).
@@ -36,7 +53,7 @@ int kr_nsec3_name_error_response_check(const knot_pkt_t *pkt, knot_section_t sec
36
53
* KNOT_ERANGE - NSEC3 RR that covers a wildcard
37
54
* has been found, but has opt-out flag set;
38
55
* otherwise - error.
39
- * Records over KR_NSEC3_MAX_ITERATIONS are skipped, so you probably get kr_error(ENOENT).
56
+ * Too expensive NSEC3 records are skipped, so you probably get kr_error(ENOENT).
40
57
*/
41
58
int kr_nsec3_wildcard_answer_response_check (const knot_pkt_t * pkt , knot_section_t section_id ,
42
59
const knot_dname_t * sname , int trim_to_next );
0 commit comments