fix key2ds.go
This commit is contained in:
parent
70ab2eadb5
commit
7b4a5eca06
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
// Print the DNSKEY records of a domain as DS records
|
||||
// Twist with all the other tools that can do this. Do
|
||||
// this directly from the internet.
|
||||
// (c) Miek Gieben - 2011
|
||||
import (
|
||||
"dns"
|
||||
|
@ -9,37 +11,43 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
c, err := dns.ClientConfigFromFile("/etc/resolv.conf")
|
||||
conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
|
||||
if len(os.Args) != 2 || err != nil {
|
||||
fmt.Printf("%s DOMAIN\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
m := new(dns.Msg)
|
||||
m.MsgHdr.RecursionDesired = true //only set this bit
|
||||
m.Question = make([]dns.Question, 1)
|
||||
m.Question[0] = dns.Question{os.Args[1], dns.TypeDNSKEY, dns.ClassINET}
|
||||
m.SetQuestion(os.Args[1], dns.TypeDNSKEY)
|
||||
|
||||
d := new(dns.Conn)
|
||||
d.RemoteAddr = c.Servers[0]
|
||||
in, err := dns.SimpleQuery("udp", d, m)
|
||||
if in != nil {
|
||||
if in.Rcode != dns.RcodeSuccess {
|
||||
fmt.Printf(" *** invalid answer name %s after DNSKEY query for %s\n", os.Args[1], os.Args[1])
|
||||
os.Exit(1)
|
||||
// Set EDNS0's Do bit
|
||||
e := new(dns.RR_OPT)
|
||||
e.Hdr.Name = "."
|
||||
e.Hdr.Rrtype = dns.TypeOPT
|
||||
e.SetUDPSize(2048)
|
||||
e.SetDo()
|
||||
m.Extra = append(m.Extra, e)
|
||||
|
||||
c := dns.NewClient()
|
||||
r := c.Exchange(m, conf.Servers[0])
|
||||
if r == nil {
|
||||
fmt.Printf("*** no answer received for %s\n", os.Args[1])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if r.Rcode != dns.RcodeSuccess {
|
||||
fmt.Printf(" *** invalid answer name %s after DNSKEY query for %s\n", os.Args[1], os.Args[1])
|
||||
os.Exit(1)
|
||||
}
|
||||
// Stuff must be in the answer section, check len(r.Answer)
|
||||
for _, k := range r.Answer {
|
||||
// Foreach key would need to provide a DS records, both sha1 and sha256
|
||||
if key, ok := k.(*dns.RR_DNSKEY); ok {
|
||||
ds := key.ToDS(dns.HashSHA1)
|
||||
ds.Hdr.Ttl = 0
|
||||
fmt.Printf("%v\n", ds)
|
||||
ds = key.ToDS(dns.HashSHA256)
|
||||
ds.Hdr.Ttl = 0
|
||||
fmt.Printf("%v\n", ds)
|
||||
}
|
||||
// Stuff must be in the answer section
|
||||
for _, k := range in.Answer {
|
||||
// Foreach key would need to provide a DS records, both sha1 and sha256
|
||||
if key, ok := k.(*dns.RR_DNSKEY); ok {
|
||||
ds := key.ToDS(dns.HashSHA1)
|
||||
ds.Hdr.Ttl = 0
|
||||
fmt.Printf("%v\n", ds)
|
||||
ds = key.ToDS(dns.HashSHA256)
|
||||
ds.Hdr.Ttl = 0
|
||||
fmt.Printf("%v\n", ds)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("*** error: %s\n", err.String())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,7 @@ func TestClientSync(t *testing.T) {
|
|||
|
||||
/*
|
||||
func TestResolverEdns(t *testing.T) {
|
||||
res := new(Resolver)
|
||||
res.Servers = []string{"127.0.0.1"}
|
||||
res.Timeout = 2
|
||||
res.Attempts = 1
|
||||
|
||||
m := new(Msg)
|
||||
m.MsgHdr.RecursionDesired = true //only set this bit
|
||||
m.Question = make([]Question, 1)
|
||||
|
||||
// Add EDNS rr
|
||||
edns := new(RR_OPT)
|
||||
|
|
|
@ -38,6 +38,7 @@ func ClientConfigFromFile(conf string) (*ClientConfig, os.Error) {
|
|||
b := bufio.NewReader(file)
|
||||
c.Servers = make([]string, 3)[0:0] // small, but the standard limit
|
||||
c.Search = make([]string, 0)
|
||||
c.Port = "53"
|
||||
c.Ndots = 1
|
||||
c.Timeout = 5
|
||||
c.Attempts = 2
|
||||
|
|
Loading…
Reference in New Issue