Lines Matching +full:max +full:- +full:reason
2 * validator/val_nsec3.c - validator NSEC3 denial of existence functions.
63 * Max number of NSEC3 calculations at once, suspend query for later.
72 #define MAX_NSEC3_ERRORS -1
75 * This function we get from ldns-compat or from base system
81 * This function we get from ldns-compat or from base system
89 * Contains the ce and the next-closer (nc) proof.
128 rrset->entry.data;
130 return d->count;
138 rrset->entry.data;
139 log_assert(d && r < (int)d->count);
140 if(d->rr_len[r] < 2+2)
142 return (int)(d->rr_data[r][2+1] & NSEC3_UNKNOWN_FLAGS);
149 rrset->entry.data;
150 log_assert(d && r < (int)d->count);
151 if(d->rr_len[r] < 2+2)
153 return (int)(d->rr_data[r][2+1] & NSEC3_OPTOUT);
161 rrset->entry.data;
162 log_assert(d && r < (int)d->count);
163 if(d->rr_len[r] < 2+1)
165 return (int)(d->rr_data[r][2+0]);
173 rrset->entry.data;
174 log_assert(d && r < (int)d->count);
175 if(d->rr_len[r] < 2+1)
177 switch(d->rr_data[r][2+0]) {
190 rrset->entry.data;
191 log_assert(d && r < (int)d->count);
192 if(d->rr_len[r] < 2+4)
194 memmove(&i, d->rr_data[r]+2+2, sizeof(i));
205 rrset->entry.data;
206 log_assert(d && r < (int)d->count);
207 if(d->rr_len[r] < 2+5) {
212 *saltlen = (size_t)d->rr_data[r][2+4];
213 if(d->rr_len[r] < 2+5+(size_t)*saltlen) {
218 *salt = d->rr_data[r]+2+5;
240 rrset->entry.data;
241 log_assert(d && r < (int)d->count);
242 if(d->rr_len[r] < 2+5) {
247 saltlen = (size_t)d->rr_data[r][2+4];
248 if(d->rr_len[r] < 2+5+saltlen+1) {
253 *nextlen = (size_t)d->rr_data[r][2+5+saltlen];
254 if(d->rr_len[r] < 2+5+saltlen+1+*nextlen) {
259 *next = d->rr_data[r]+2+5+saltlen+1;
264 size_t zonelen, uint8_t* buf, size_t max)
268 if(max < hashlen*2+1) /* quick approx of b32, as if hexb16 */
270 ret = sldns_b32_ntop_extended_hex(hash, hashlen, (char*)buf+1, max-1);
275 if(max - ret < zonelen)
282 uint8_t* buf, size_t max)
289 zone = rrset->rk.dname;
290 zonelen = rrset->rk.dname_len;
292 return nsec3_hash_to_b32(nm, nmlen, zone, zonelen, buf, max);
301 rrset->entry.data;
302 log_assert(d && r < (int)d->count);
305 if(d->rr_len[r] < skiplen+1)
307 skiplen += 1+(size_t)d->rr_data[r][skiplen];
309 if(d->rr_len[r] < skiplen+1)
311 skiplen += 1+(size_t)d->rr_data[r][skiplen];
312 if(d->rr_len[r] < skiplen)
314 bitlen = d->rr_len[r] - skiplen;
315 bitmap = d->rr_data[r]+skiplen;
346 if(!filter->zone) /* empty list */
348 for(i=*rrsetnum; i<filter->num; i++) {
350 if(ntohs(filter->list[i]->rk.type) != LDNS_RR_TYPE_NSEC3 ||
351 ntohs(filter->list[i]->rk.rrset_class) !=
352 filter->fclass)
355 nm = filter->list[i]->rk.dname;
356 nmlen = filter->list[i]->rk.dname_len;
358 if(query_dname_compare(nm, filter->zone) != 0)
363 for(; r < (int)rrset_get_count(filter->list[i]); r++) {
365 if(nsec3_unknown_flags(filter->list[i], r) ||
366 !nsec3_known_algo(filter->list[i], r))
371 return filter->list[i];
379 * @param filter: the filter structure, must have been filter_init-ed.
389 *rrnum = -1;
425 filter->zone = NULL;
426 filter->zone_len = 0;
427 filter->list = list;
428 filter->num = num;
429 filter->fclass = qinfo->qclass;
432 if(ntohs(list[i]->rk.type) != LDNS_RR_TYPE_NSEC3 ||
433 ntohs(list[i]->rk.rrset_class) != qinfo->qclass)
441 nm = list[i]->rk.dname;
442 nmlen = list[i]->rk.dname_len;
446 if(dname_subdomain_c(qinfo->qname, nm) && (!filter->zone ||
447 dname_subdomain_c(nm, filter->zone))) {
449 if(qinfo->qtype == LDNS_RR_TYPE_DS &&
450 query_dname_compare(qinfo->qname, nm) == 0 &&
451 !dname_is_root(qinfo->qname))
453 filter->zone = nm;
454 filter->zone_len = nmlen;
460 * Find max iteration count using config settings and key size
463 * @return max iteration count
469 log_assert(ve->nsec3_keyiter_count > 0);
471 for(i=0; i<ve->nsec3_keyiter_count; i++) {
472 if(bits <= ve->nsec3_keysize[i])
473 return ve->nsec3_maxiter[i];
476 return ve->nsec3_maxiter[ve->nsec3_keyiter_count-1];
484 * @return 1 if some nsec3s are above the max iteration count.
493 /* first determine the max number of iterations */
496 verbose(VERB_ALGO, "nsec3: keysize %d bits, max iterations %d",
515 int c = query_dname_compare(h1->dname, h2->dname);
520 if(nsec3_get_algo(h1->nsec3, h1->rr) !=
521 nsec3_get_algo(h2->nsec3, h2->rr)) {
522 if(nsec3_get_algo(h1->nsec3, h1->rr) <
523 nsec3_get_algo(h2->nsec3, h2->rr))
524 return -1;
527 if(nsec3_get_iter(h1->nsec3, h1->rr) !=
528 nsec3_get_iter(h2->nsec3, h2->rr)) {
529 if(nsec3_get_iter(h1->nsec3, h1->rr) <
530 nsec3_get_iter(h2->nsec3, h2->rr))
531 return -1;
534 (void)nsec3_get_salt(h1->nsec3, h1->rr, &s1, &s1len);
535 (void)nsec3_get_salt(h2->nsec3, h2->rr, &s2, &s2len);
538 if(!s1) return -1;
542 return -1;
551 if(ct->ct) return 1;
552 ct->ct = (rbtree_type*)regional_alloc(region, sizeof(*ct->ct));
553 if(!ct->ct) return 0;
554 ct->region = region;
555 rbtree_init(ct->ct, &nsec3_hash_cmp);
561 size_t iter, uint8_t* salt, size_t saltlen, uint8_t* res, size_t max)
576 if(hash_len > max)
600 int algo = nsec3_get_algo(c->nsec3, c->rr);
601 size_t iter = nsec3_get_iter(c->nsec3, c->rr);
604 if(!nsec3_get_salt(c->nsec3, c->rr, &salt, &saltlen))
605 return -1;
608 sldns_buffer_write(buf, c->dname, c->dname_len);
612 c->hash_len = nsec3_hash_algo_size_supported(algo);
613 if(c->hash_len == 0) {
615 return -1;
617 c->hash = (uint8_t*)regional_alloc(region, c->hash_len);
618 if(!c->hash)
621 sldns_buffer_limit(buf), (unsigned char*)c->hash);
624 sldns_buffer_write(buf, c->hash, c->hash_len);
629 sldns_buffer_limit(buf), (unsigned char*)c->hash);
641 r = sldns_b32_ntop_extended_hex(c->hash, c->hash_len,
647 c->b32_len = (size_t)r;
648 c->b32 = regional_alloc_init(region, sldns_buffer_begin(buf),
649 c->b32_len);
650 if(!c->b32)
680 c->node.key = c;
681 c->nsec3 = nsec3;
682 c->rr = rr;
683 c->dname = dname;
684 c->dname_len = dname_len;
687 return r; /* returns -1 or 0 */
696 rbtree_insert(table, &c->node);
712 return -1;
732 uint8_t* nm = s->rk.dname;
742 if(hash->b32_len != 0 && (size_t)nm[0] == hash->b32_len &&
743 label_compare_lower(nm+1, hash->b32, hash->b32_len) == 0 &&
744 query_dname_compare(nm+(size_t)nm[0]+1, flt->zone) == 0) {
776 /* this loop skips other-zone and unknown NSEC3s, also non-NSEC3 RRs */
787 r = nsec3_hash_name(ct->ct, ct->region, env->scratch_buffer,
825 if(nextlen != hash->hash_len || hash->hash_len==0||hash->b32_len==0||
826 (size_t)*rrset->rk.dname != hash->b32_len ||
827 query_dname_compare(rrset->rk.dname+1+
828 (size_t)*rrset->rk.dname, zone) != 0)
832 if(label_compare_lower(rrset->rk.dname+1, hash->b32,
833 hash->b32_len) < 0 &&
834 memcmp(hash->hash, next, nextlen) < 0)
840 len = sldns_b32_pton_extended_hex((char*)rrset->rk.dname+1,
841 hash->b32_len, owner, sldns_buffer_limit(buf));
844 if((size_t)len != hash->hash_len || (size_t)len != nextlen)
849 * this also covers the only-apex case of next==owner.
852 ( memcmp(hash->hash, owner, nextlen) > 0 ||
853 memcmp(hash->hash, next, nextlen) < 0)) {
886 /* this loop skips other-zone and unknown NSEC3s, also non-NSEC3 RRs */
897 r = nsec3_hash_name(ct->ct, ct->region, env->scratch_buffer,
909 if(nsec3_covers(flt->zone, hash, s, i_rr,
910 env->scratch_buffer)) {
940 uint8_t* nm = qinfo->qname;
941 size_t nmlen = qinfo->qname_len;
952 while(dname_subdomain_c(nm, flt->zone)) {
958 &ce->ce_rrset, &ce->ce_rr, calculations)) {
959 ce->ce = nm;
960 ce->ce_len = nmlen;
983 int strip = dname_count_labels(qname) - dname_count_labels(ce) -1;
1005 * insecure if the closest-encloser candidate turns out to prove
1038 log_nametypeclass(VERB_ALGO, "ce candidate", ce->ce, 0, 0);
1040 if(query_dname_compare(ce->ce, qinfo->qname) == 0) {
1054 if(nsec3_has_type(ce->ce_rrset, ce->ce_rr, LDNS_RR_TYPE_NS) &&
1055 !nsec3_has_type(ce->ce_rrset, ce->ce_rr, LDNS_RR_TYPE_SOA)) {
1056 if(!nsec3_has_type(ce->ce_rrset, ce->ce_rr, LDNS_RR_TYPE_DS)) {
1065 if(nsec3_has_type(ce->ce_rrset, ce->ce_rr, LDNS_RR_TYPE_DNAME)) {
1072 next_closer(qinfo->qname, qinfo->qname_len, ce->ce, &nc, &nc_len);
1074 &ce->nc_rrset, &ce->nc_rr, calculations)) {
1102 if(celen > LDNS_MAX_DOMAINLEN - 2)
1149 wc = nsec3_ce_wildcard(ct->region, ce.ce, ce.ce_len, &wclen);
1204 * This existed in early drafts, but was later (-05) removed.
1220 if(find_matching_nsec3(env, flt, ct, qinfo->qname, qinfo->qname_len,
1223 if(nsec3_has_type(rrset, rr, qinfo->qtype)) {
1245 if(qinfo->qtype == LDNS_RR_TYPE_DS && qinfo->qname_len != 1
1247 !dname_is_root(qinfo->qname)) {
1251 } else if(qinfo->qtype != LDNS_RR_TYPE_DS &&
1278 /* For cases 3 - 5, we need the proven closest encloser, and it
1286 } else if(sec==sec_status_insecure && qinfo->qtype!=LDNS_RR_TYPE_DS){
1298 wc = nsec3_ce_wildcard(ct->region, ce.ce, ce.ce_len, &wclen);
1302 if(nsec3_has_type(rrset, rr, qinfo->qtype)) {
1311 if(qinfo->qtype == LDNS_RR_TYPE_DS && qinfo->qname_len != 1
1316 } else if(qinfo->qtype != LDNS_RR_TYPE_DS &&
1353 /* We need to make sure that the covering NSEC3 is opt-out. */
1356 if(qinfo->qtype == LDNS_RR_TYPE_DS)
1358 "opt-out in an opt-out DS NOERROR/NODATA case.");
1361 "-- no more options, bogus.");
1417 next_closer(qinfo->qname, qinfo->qname_len, ce.ce, &nc, &nc_len);
1449 struct key_entry_key* kkey, char** reason, sldns_ede_code *reason_bogus,
1456 d = (struct packed_rrset_data*)list[i]->entry.data;
1457 if(list[i]->rk.type != htons(LDNS_RR_TYPE_NSEC3))
1459 if(d->security == sec_status_secure)
1461 rrset_check_sec_status(env->rrset_cache, list[i], *env->now);
1462 if(d->security == sec_status_secure)
1464 d->security = val_verify_rrset_entry(env, ve, list[i], kkey,
1465 reason, reason_bogus, LDNS_SECTION_AUTHORITY, qstate,
1467 if(d->security != sec_status_secure) {
1471 rrset_update_sec_status(env->rrset_cache, list[i], *env->now);
1479 struct query_info* qinfo, struct key_entry_key* kkey, char** reason,
1490 log_assert(qinfo->qtype == LDNS_RR_TYPE_DS);
1493 *reason = "no valid NSEC3s";
1496 if(!list_is_secure(env, ve, list, num, kkey, reason, reason_bogus,
1498 *reason = "not all NSEC3 records secure";
1503 *reason = "no NSEC3 records";
1509 /* Look for a matching NSEC3 to qname -- this is the normal
1511 if(find_matching_nsec3(env, &flt, ct, qinfo->qname, qinfo->qname_len,
1517 qinfo->qname_len != 1) {
1520 *reason = "NSEC3 from child zone";
1525 *reason = "NSEC3 has DS in bitmap";
1548 /* Otherwise, we are probably in the opt-out case. */
1557 *reason = "no NSEC3 closest encloser";
1564 *reason = "no NSEC3 next closer";
1569 * covering NSEC3 was opt-out -- the proveClosestEncloser step already
1575 "opt-out in an opt-out DS NOERROR/NODATA case.");
1576 *reason = "covering NSEC3 was not opt-out in an opt-out "