Skip to content

Commit

Permalink
Merge pull request #1 from neeravkumar/master
Browse files Browse the repository at this point in the history
Resolve coredns#12 : Add support for dnssec validation
  • Loading branch information
neeravkumar authored Dec 7, 2020
2 parents 23331a6 + a59b975 commit 4c56997
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ func unboundParse(c *caddy.Controller) (*Unbound, error) {
if err = u.config(args[0]); err != nil {
return nil, err
}
case "anchor":
args = c.RemainingArgs()
if len(args) != 1 {
return nil, c.ArgErr()
}
if err = u.setAnchor(args[0]); err != nil {
return nil, err
}
u.strict = true
default:
return nil, c.ArgErr()
}
Expand Down
22 changes: 21 additions & 1 deletion unbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package unbound
import (
"context"
"fmt"
"errors"
"strconv"

"github.com/coredns/coredns/plugin"
Expand All @@ -23,6 +24,7 @@ type Unbound struct {

from []string
except []string
strict bool

Next plugin.Handler
}
Expand Down Expand Up @@ -86,6 +88,22 @@ func (u *Unbound) config(f string) error {
return nil
}

// anchor reads the file f and sets it as anchor
func (u *Unbound) setAnchor(f string) error {
var err error

err = u.u.AddTaFile(f)
if err != nil {
return fmt.Errorf("failed to read trust anchor file (%s) UDP context: %s", f, err)
}

err = u.t.AddTaFile(f)
if err != nil {
return fmt.Errorf("failed to read trust anchor file (%s) TCP context: %s", f, err)
}
return nil
}

// ServeDNS implements the plugin.Handler interface.
func (u *Unbound) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
state := request.Request{W: w, Req: r}
Expand Down Expand Up @@ -121,7 +139,9 @@ func (u *Unbound) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
if err != nil {
return dns.RcodeServerFailure, err
}

if u.strict && !res.Secure {
return dns.RcodeServerFailure, errors.New("dnssec validation failed")
}
// If the client *didn't* set the opt record, and specifically not the DO bit,
// strip this from the reply (unbound default to setting DO).
if !state.Do() {
Expand Down

0 comments on commit 4c56997

Please sign in to comment.