Skip to content

Commit

Permalink
Resolve coredns#12 : Add support for dnssec validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Neerav Kumar committed Nov 19, 2020
1 parent 23331a6 commit 4f6e4ce
Show file tree
Hide file tree
Showing 2 changed files with 29 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
21 changes: 20 additions & 1 deletion unbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Unbound struct {

from []string
except []string
strict bool

Next plugin.Handler
}
Expand Down Expand Up @@ -86,6 +87,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 +138,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, "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 4f6e4ce

Please sign in to comment.