Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #12 : Add support for dnssec validation #1

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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