| 1 |
package tsig |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/base64" |
| 5 |
"fmt" |
| 6 |
|
| 7 |
"codeberg.org/miekg/dns" |
| 8 |
"codeberg.org/miekg/dns/cmd/atomdns/internal/dnsserver" |
| 9 |
"codeberg.org/miekg/dns/dnsutil" |
| 10 |
) |
| 11 |
|
| 12 |
func (t *Tsig) Setup(co *dnsserver.Controller) error { |
| 13 |
if co.Next() { |
| 14 |
args := co.RemainingArgs() |
| 15 |
if len(args) != 3 { |
| 16 |
return co.ArgErr() |
| 17 |
} |
| 18 |
name := dnsutil.Canonical(args[0]) |
| 19 |
algo := dnsutil.Canonical(args[1]) |
| 20 |
if !dnsutil.IsName(name) { |
| 21 |
return co.PropErr(fmt.Errorf("name %s is not a domain name", name)) |
| 22 |
} |
| 23 |
if !dnsutil.IsName(algo) { |
| 24 |
return co.PropErr(fmt.Errorf("algorithm %s is not a domain name", algo)) |
| 25 |
} |
| 26 |
if _, err := base64.StdEncoding.DecodeString(args[2]); err != nil { |
| 27 |
return co.PropErr(err) |
| 28 |
} |
| 29 |
t.TSIG = dns.NewTSIG(name, algo, 0) |
| 30 |
t.TSIGSecret = args[2] |
| 31 |
} |
| 32 |
return nil |
| 33 |
} |