#include "lib/defines.h"
#include "lib/dnssec/ta.h"
+#include "lib/resolve.h"
#include "lib/utils.h"
knot_rrset_t *kr_ta_get(map_t *trust_anchors, const knot_dname_t *name)
return false;
}
+bool kr_ta_covers_qry(struct kr_context *ctx, const knot_dname_t *name,
+ const uint16_t type)
+{
+ assert(ctx && name);
+ if (type == KNOT_RRTYPE_DS && name[0] != '\0') {
+ /* DS is parent-side record, so the parent name needs to be covered. */
+ name = knot_wire_next_label(name, NULL);
+ if (!name) {
+ assert(false);
+ return kr_error(EINVAL);
+ }
+ }
+ return kr_ta_covers(&ctx->trust_anchors, name)
+ && !kr_ta_covers(&ctx->negative_anchors, name);
+}
+
/* Delete record data */
static int del_record(const char *k, void *v, void *ext)
{
if (query->flags & QUERY_DNSSEC_INSECURE) {
next->flags &= ~QUERY_DNSSEC_WANT;
next->flags |= QUERY_DNSSEC_INSECURE;
- } else if (kr_ta_covers(&req->ctx->trust_anchors, cname) &&
- !kr_ta_covers(&req->ctx->negative_anchors, cname)) {
+ } else if (kr_ta_covers_qry(req->ctx, cname, query->stype)) {
/* Want DNSSEC if it's posible to secure
* this name (e.g. is covered by any TA) */
next->flags |= QUERY_DNSSEC_WANT;
static int ns_fetch_cut(struct kr_query *qry, const knot_dname_t *requested_name,
struct kr_request *req, knot_pkt_t *pkt)
{
- map_t *trust_anchors = &req->ctx->trust_anchors;
- map_t *negative_anchors = &req->ctx->negative_anchors;
-
/* It can occur that here parent query already have
* provably insecured zonecut which not in the cache yet. */
const uint32_t insec_flags = QUERY_DNSSEC_INSECURE | QUERY_DNSSEC_NODS;
* even if cut name is covered by TA. */
qry->flags &= ~QUERY_DNSSEC_WANT;
qry->flags |= QUERY_DNSSEC_INSECURE;
- } else if (!kr_ta_covers(negative_anchors, qry->zone_cut.name) &&
- kr_ta_covers(trust_anchors, qry->zone_cut.name)) {
+ } else if (kr_ta_covers_qry(req->ctx, qry->zone_cut.name, KNOT_RRTYPE_NS)) {
qry->flags |= QUERY_DNSSEC_WANT;
} else {
qry->flags &= ~QUERY_DNSSEC_WANT;
/* Zonecut name can change, check it again
* to prevent unnecessary DS & DNSKEY queries */
if (!(qry->flags & QUERY_DNSSEC_INSECURE) &&
- !kr_ta_covers(negative_anchors, cut_found.name) &&
- kr_ta_covers(trust_anchors, cut_found.name)) {
+ kr_ta_covers_qry(req->ctx, cut_found.name, KNOT_RRTYPE_NS)) {
qry->flags |= QUERY_DNSSEC_WANT;
} else {
qry->flags &= ~QUERY_DNSSEC_WANT;
/* Deferred zone cut lookup for this query. */
qry->flags |= QUERY_AWAIT_CUT;
/* Want DNSSEC if it's posible to secure this name (e.g. is covered by any TA) */
- map_t *negative_anchors = &request->ctx->negative_anchors;
- map_t *trust_anchors = &request->ctx->trust_anchors;
if ((knot_wire_get_ad(packet->wire) || knot_pkt_has_dnssec(packet)) &&
- kr_ta_covers(trust_anchors, qname) && !kr_ta_covers(negative_anchors, qname)) {
+ kr_ta_covers_qry(request->ctx, qname, qtype)) {
qry->flags |= QUERY_DNSSEC_WANT;
}