How about on-the-fly signing? In this example we add a signature
to any packet dealing with www.example.org. Again it is a
matter of defining the matching, action and setup functions.
Matching
We don’t have to match anything coming in, we only need to sign pkts on their way out. So the function becomes:
func match(m *dns.Msg, d int) (*dns.Msg, bool) {
// Matching criteria
switch d {
case IN:
// nothing
case OUT:
// nothing
}
// Packet Mangling
switch d {
case IN:
// nothing
case OUT:
if m.Question[0].Name == "www.example.org." {
// On the way out sign the packet
m = sign(m) // keys are global
}
}
return m, true
}
As you can see, it calls the sign() function where the actual signing
takes place. We just sign the first RR in the answer section —
if there is one.
(of course), see
