some minor tweaks

This commit is contained in:
Miek Gieben 2011-08-01 14:13:13 +02:00
parent 38d15b76e2
commit 9330f16c5c
5 changed files with 47 additions and 47 deletions

View File

@ -20,7 +20,7 @@ func NewFunkenSturm() *FunkenSturm {
f.Default = send f.Default = send
f.Funk = make([]*Funk, 1) // 1 Funk chain f.Funk = make([]*Funk, 1) // 1 Funk chain
f.Funk[0] = NewFunk() f.Funk[0] = new(Funk)
f.Funk[0].Match = func(m *dns.Msg) (*dns.Msg, bool) { return m, true } f.Funk[0].Match = func(m *dns.Msg) (*dns.Msg, bool) { return m, true }
f.Funk[0].Action = send f.Funk[0].Action = send
return f return f

View File

@ -52,7 +52,7 @@ func NewFunkenSturm() *FunkenSturm {
f.Setup = func() bool { previous = time.Nanoseconds(); return true } f.Setup = func() bool { previous = time.Nanoseconds(); return true }
f.Funk = make([]*Funk, 1) f.Funk = make([]*Funk, 1)
f.Funk[0] = NewFunk() f.Funk[0] = new(Funk)
f.Funk[0].Match = match f.Funk[0].Match = match
f.Funk[0].Action = delay f.Funk[0].Action = delay
return f return f

View File

@ -91,7 +91,7 @@ func NewFunkenSturm() *FunkenSturm {
f := new(FunkenSturm) f := new(FunkenSturm)
f.Funk = make([]*Funk, 1) f.Funk = make([]*Funk, 1)
f.Setup = func() bool { cache = NewCache(); return true } f.Setup = func() bool { cache = NewCache(); return true }
f.Funk[0] = NewFunk() f.Funk[0] = new(Funk)
f.Funk[0].Match = func(m *dns.Msg) (*dns.Msg, bool) { return m, true } f.Funk[0].Match = func(m *dns.Msg) (*dns.Msg, bool) { return m, true }
f.Funk[0].Action = checkcache f.Funk[0].Action = checkcache
return f return f

View File

@ -7,52 +7,52 @@ package main
// We could also use one 1 key for multiple domains. // We could also use one 1 key for multiple domains.
import ( import (
"dns" "dns"
"strings" "strings"
"crypto/rsa" "crypto/rsa"
) )
func sign(m *dns.Msg) *dns.Msg { func sign(m *dns.Msg) *dns.Msg {
sg := new(dns.RR_RRSIG) sg := new(dns.RR_RRSIG)
sg.Hdr = dns.RR_Header{"www.example.org.", dns.TypeRRSIG, dns.ClassINET, 14400, 0} sg.Hdr = dns.RR_Header{"www.example.org.", dns.TypeRRSIG, dns.ClassINET, 14400, 0}
sg.Expiration = 1296534305 // date -u '+%s' -d"2011-02-01 04:25:05" sg.Expiration = 1296534305 // date -u '+%s' -d"2011-02-01 04:25:05"
sg.Inception = 1293942305 // date -u '+%s' -d"2011-01-02 04:25:05" sg.Inception = 1293942305 // date -u '+%s' -d"2011-01-02 04:25:05"
sg.KeyTag = pubkey.KeyTag() // Get the keyfrom the Key sg.KeyTag = pubkey.KeyTag() // Get the keyfrom the Key
sg.SignerName = pubkey.Hdr.Name sg.SignerName = pubkey.Hdr.Name
sg.Algorithm = dns.RSASHA256 sg.Algorithm = dns.RSASHA256
if len(m.Answer) > 0 { if len(m.Answer) > 0 {
// sign the first record // sign the first record
an := m.Answer[0] an := m.Answer[0]
sg.TypeCovered = an.Header().Rrtype sg.TypeCovered = an.Header().Rrtype
sg.Labels = dns.Labels(an.Header().Name) sg.Labels = dns.Labels(an.Header().Name)
sg.OrigTtl = an.Header().Ttl sg.OrigTtl = an.Header().Ttl
switch p:=privkey.(type) { switch p := privkey.(type) {
case *rsa.PrivateKey: case *rsa.PrivateKey:
sg.Sign(p, []dns.RR{an}) sg.Sign(p, []dns.RR{an})
} }
} }
m.Answer = append(m.Answer, sg) m.Answer = append(m.Answer, sg)
return m return m
} }
func match(m *dns.Msg) (*dns.Msg, bool) { func match(m *dns.Msg) (*dns.Msg, bool) {
return m, m.Question[0].Name == "www.example.org." return m, m.Question[0].Name == "www.example.org."
} }
func send(m *dns.Msg) (o []byte) { func send(m *dns.Msg) (o []byte) {
var p *dns.Msg var p *dns.Msg
for _, c := range qr { for _, c := range qr {
p = c.Client.Exchange(m, c.Addr) p = c.Client.Exchange(m, c.Addr)
} }
o, _ = sign(p).Pack() o, _ = sign(p).Pack()
return return
} }
var pubkey *dns.RR_DNSKEY var pubkey *dns.RR_DNSKEY
var privkey dns.PrivateKey var privkey dns.PrivateKey
func setup() bool { func setup() bool {
privdata := `Private-key-format: v1.3 privdata := `Private-key-format: v1.3
Algorithm: 5 (RSASHA1) Algorithm: 5 (RSASHA1)
Modulus: AaTnz33zSgSIWzUBSJwerZiUdsTmfQNaB+AKpN8FnVlhGOfabJ6ZCi123hjOr3ucE/LWfPGtmEppuFf2dmuJW/yO6s8td5q5b81PUOt+uPMNBGJ1T4DUO8sOQQp4SXw76Q7KIgcrj2RSuNt9qv3JC4VlQB6j7bgVF8er2gbKxbvR Modulus: AaTnz33zSgSIWzUBSJwerZiUdsTmfQNaB+AKpN8FnVlhGOfabJ6ZCi123hjOr3ucE/LWfPGtmEppuFf2dmuJW/yO6s8td5q5b81PUOt+uPMNBGJ1T4DUO8sOQQp4SXw76Q7KIgcrj2RSuNt9qv3JC4VlQB6j7bgVF8er2gbKxbvR
PublicExponent: AQAB PublicExponent: AQAB
@ -65,22 +65,23 @@ Coefficient: AZX3xIGzo/3fw4ouA6nAjpiWGpTK+OdFRkZtvbmzwgqnFDQopB0SweVnd1shpKCXkPT
Created: 20110122104659 Created: 20110122104659
Publish: 20110122104659 Publish: 20110122104659
Activate: 20110122104659` Activate: 20110122104659`
pubkey = new(dns.RR_DNSKEY) pubkey = new(dns.RR_DNSKEY)
privkey, _ = pubkey.ReadPrivateKey(strings.NewReader(privdata)) privkey, _ = pubkey.ReadPrivateKey(strings.NewReader(privdata))
pubkey.Hdr = dns.RR_Header{"miek.nl.", dns.TypeDNSKEY, dns.ClassINET, 3600, 0} pubkey.Hdr = dns.RR_Header{"miek.nl.", dns.TypeDNSKEY, dns.ClassINET, 3600, 0}
pubkey.Protocol = 3 pubkey.Protocol = 3
pubkey.Flags = 256 pubkey.Flags = 256
return true return true
} }
// Return the configration // Return the configration
func NewFunkenSturm() *FunkenSturm { func NewFunkenSturm() *FunkenSturm {
f := new(FunkenSturm) f := new(FunkenSturm)
f.Funk = make([]*Funk, 1) // 1 Chain f.Funk = make([]*Funk, 1)
f.Setup = setup f.Setup = setup
f.Default = send
f.Funk[0] = NewFunk(1) f.Funk[0] = new(Funk)
f.Funk[0].Matches[0].Func = match f.Funk[0].Match = func(m *dns.Msg) (*dns.Msg, bool) { return m, m.Question[0].Name == "www.example.org." }
f.Funk[0].Action = send f.Funk[0].Action = send
return f return f
} }

View File

@ -35,11 +35,6 @@ type Funk struct {
Action func(*dns.Msg) []byte Action func(*dns.Msg) []byte
} }
func NewFunk() *Funk {
f := new(Funk)
return f
}
// Hold the information. // Hold the information.
type FunkenSturm struct { type FunkenSturm struct {
Setup func() bool // Inital setup (for extra resolvers, or loading keys, or ...) Setup func() bool // Inital setup (for extra resolvers, or loading keys, or ...)
@ -60,6 +55,10 @@ func doFunkenSturm(pkt *dns.Msg) (ret []byte) {
return return
} }
} }
if f.Default == nil {
println("No f.Default set!")
return
}
ret = f.Default(pkt) ret = f.Default(pkt)
return return
} }