From 7cc28a94e9e77a3b1bc65d576d601e02e0ebead1 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Wed, 6 Jul 2011 21:50:23 +0200 Subject: [PATCH] Fix funkensturm signing make LabelCount public account. --- _examples/funkensturm/config.go | 28 +++++++------- _examples/funkensturm/config_proxy.go | 55 --------------------------- _examples/funkensturm/config_sign.go | 17 ++++----- dns.go | 2 +- dnssec.go | 2 +- 5 files changed, 23 insertions(+), 81 deletions(-) delete mode 100644 _examples/funkensturm/config_proxy.go diff --git a/_examples/funkensturm/config.go b/_examples/funkensturm/config.go index 109183ac..c13262d2 100644 --- a/_examples/funkensturm/config.go +++ b/_examples/funkensturm/config.go @@ -6,14 +6,14 @@ import ( func match(m *dns.Msg, d int) (*dns.Msg, bool) { // Matching criteria - switch d { - case IN: - // nothing - case OUT: - // Note that when sending back only the mangling is important - // the actual return code of these function isn't checked by - // funkensturm - } + switch d { + case IN: + // nothing + case OUT: + // Note that when sending back only the mangling is important + // the actual return code of these function isn't checked by + // funkensturm + } // Packet Mangling switch d { @@ -26,23 +26,23 @@ func match(m *dns.Msg, d int) (*dns.Msg, bool) { } func send(m *dns.Msg, ok bool) (o *dns.Msg) { - for _, c := range qr { - o = c.Client.Exchange(m, c.Addr) - } + for _, c := range qr { + o = c.Client.Exchange(m, c.Addr) + } return } // Return the configration func funkensturm() *Funkensturm { f := new(Funkensturm) - f.Setup = func() bool { return true } // no setup + f.Setup = func() bool { return true } // no setup - // 1 match function, use AND as op (doesn't matter in this case) + // 1 match function, use AND as op (doesn't matter in this case) f.Matches = make([]Match, 1) f.Matches[0].Op = AND f.Matches[0].Func = match - // 1 action + // 1 action f.Actions = make([]Action, 1) f.Actions[0].Func = send return f diff --git a/_examples/funkensturm/config_proxy.go b/_examples/funkensturm/config_proxy.go deleted file mode 100644 index 81e1e1ee..00000000 --- a/_examples/funkensturm/config_proxy.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "dns" -) - -func match(m *dns.Msg, d int) (*dns.Msg, bool) { - // Matching criteria - switch d { - case IN: - // nothing - case OUT: - // Note that when sending back only the mangling is important - // the actual return code of these function isn't checked by - // funkensturm - } - - // Packet Mangling - switch d { - case IN: - // nothing - case OUT: - // nothing - } - return m, true -} - -func send(m *dns.Msg, ok bool) (out *dns.Msg) { - switch ok { - case true, false: - for _, r := range qr { - out, _ = r.Query(m) - } - return - } - return -} - -// Return the configration -func funkensturm() *Funkensturm { - f := new(Funkensturm) - - // Nothing to set up - f.Setup = func() bool { return true } - - // 1 match function, use AND as op (doesn't matter in this case) - f.Matches = make([]Match, 1) - f.Matches[0].Op = AND - f.Matches[0].Func = match - - // 1 action - f.Actions = make([]Action, 1) - f.Actions[0].Func = send - return f -} diff --git a/_examples/funkensturm/config_sign.go b/_examples/funkensturm/config_sign.go index 7009ad9b..c9054d81 100644 --- a/_examples/funkensturm/config_sign.go +++ b/_examples/funkensturm/config_sign.go @@ -7,6 +7,7 @@ package main // We could also use one 1 key for multiple domains. import ( "dns" + "strings" "crypto/rsa" ) @@ -58,15 +59,11 @@ func match(m *dns.Msg, d int) (*dns.Msg, bool) { return m, true } -func send(m *dns.Msg, ok bool) (out *dns.Msg) { - switch ok { - case true, false: - for _, r := range qr { - out, _ = r.Query(m) - } - return - } - return +func send(m *dns.Msg, ok bool) (o *dns.Msg) { + for _, c := range qr { + o = c.Client.Exchange(m, c.Addr) + } + return } var pubkey *dns.RR_DNSKEY @@ -87,7 +84,7 @@ Created: 20110122104659 Publish: 20110122104659 Activate: 20110122104659` pubkey = new(dns.RR_DNSKEY) - privkey, _ = pubkey.PrivateKeySetString(privdata) + privkey, _ = pubkey.ReadPrivateKey(strings.NewReader(privdata)) pubkey.Hdr = dns.RR_Header{"miek.nl.", dns.TypeDNSKEY, dns.ClassINET, 3600, 0} pubkey.Protocol = 3 pubkey.Flags = 256 diff --git a/dns.go b/dns.go index be5dd4bd..44a37766 100644 --- a/dns.go +++ b/dns.go @@ -143,7 +143,7 @@ func (h *RR_Header) String() string { // Return the number of labels in a domain name. // Need to add these kind of function in a structured way. TODO(mg) -func labelCount(a string) (c uint8) { +func LabelCount(a string) (c uint8) { // walk the string and count the dots // except when it is escaped esc := false diff --git a/dnssec.go b/dnssec.go index 4872ec68..928fc002 100644 --- a/dnssec.go +++ b/dnssec.go @@ -174,7 +174,7 @@ func (s *RR_RRSIG) Sign(k PrivateKey, rrset RRset) bool { s.OrigTtl = rrset[0].Header().Ttl s.TypeCovered = rrset[0].Header().Rrtype s.TypeCovered = rrset[0].Header().Rrtype - s.Labels = labelCount(rrset[0].Header().Name) + s.Labels = LabelCount(rrset[0].Header().Name) if strings.HasPrefix(rrset[0].Header().Name, "*") { s.Labels-- // wildcards, remove from label count }