mirror of
https://github.com/miekg/dns.git
synced 2025-10-10 17:31:01 +02:00
add a TsigStatus to the client as well
Bring server and client side more inline with each other. For a client we also use TsigStatus() to retrieve the tsig info.
This commit is contained in:
parent
49f41fb17b
commit
1744a80850
17
client.go
17
client.go
@ -24,11 +24,12 @@ type QueryHandler interface {
|
|||||||
// The RequestWriter interface is used by a DNS query handler to
|
// The RequestWriter interface is used by a DNS query handler to
|
||||||
// construct a DNS request.
|
// construct a DNS request.
|
||||||
type RequestWriter interface {
|
type RequestWriter interface {
|
||||||
Write(*Msg)
|
// Write ??
|
||||||
Send(*Msg) error
|
Send(*Msg) error
|
||||||
Receive() (*Msg, error)
|
Receive() (*Msg, error)
|
||||||
Close() error
|
Close() error
|
||||||
Dial() error
|
Dial() error
|
||||||
|
TsigStatus() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// hijacked connections...?
|
// hijacked connections...?
|
||||||
@ -39,7 +40,7 @@ type reply struct {
|
|||||||
conn net.Conn
|
conn net.Conn
|
||||||
tsigRequestMAC string
|
tsigRequestMAC string
|
||||||
tsigTimersOnly bool
|
tsigTimersOnly bool
|
||||||
tsigStatus int
|
tsigStatus error
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Request is a incoming message from a Client.
|
// A Request is a incoming message from a Client.
|
||||||
@ -281,6 +282,10 @@ func (w *reply) Request() *Msg {
|
|||||||
return w.req
|
return w.req
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *reply) TsigStatus() error {
|
||||||
|
return w.tsigStatus
|
||||||
|
}
|
||||||
|
|
||||||
func (w *reply) Receive() (*Msg, error) {
|
func (w *reply) Receive() (*Msg, error) {
|
||||||
var p []byte
|
var p []byte
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
@ -301,13 +306,11 @@ func (w *reply) Receive() (*Msg, error) {
|
|||||||
if m.IsTsig() {
|
if m.IsTsig() {
|
||||||
secret := m.Extra[len(m.Extra)-1].(*RR_TSIG).Hdr.Name
|
secret := m.Extra[len(m.Extra)-1].(*RR_TSIG).Hdr.Name
|
||||||
if _, ok := w.Client().TsigSecret[secret]; !ok {
|
if _, ok := w.Client().TsigSecret[secret]; !ok {
|
||||||
return m, ErrSecret
|
w.tsigStatus = ErrSecret
|
||||||
|
return m, nil
|
||||||
}
|
}
|
||||||
// Need to work on the original message p, as that was used to calculate the tsig.
|
// Need to work on the original message p, as that was used to calculate the tsig.
|
||||||
err := TsigVerify(p, w.Client().TsigSecret[secret], w.tsigRequestMAC, w.tsigTimersOnly)
|
w.tsigStatus = TsigVerify(p, w.Client().TsigSecret[secret], w.tsigRequestMAC, w.tsigTimersOnly)
|
||||||
if err != nil {
|
|
||||||
return m, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
@ -424,7 +424,8 @@ func (k *RR_DNSKEY) pubKeyRSA() *rsa.PublicKey {
|
|||||||
// Remainder
|
// Remainder
|
||||||
expo += uint64(keybuf[keyoff])
|
expo += uint64(keybuf[keyoff])
|
||||||
if expo > 2<<31 {
|
if expo > 2<<31 {
|
||||||
// Larger expo than supported
|
// Larger expo than supported.
|
||||||
|
// println("dns: F5 primes (or larger) are not supported")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
pubkey.E = int(expo)
|
pubkey.E = int(expo)
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
var dnskey *dns.RR_DNSKEY
|
var dnskey *dns.RR_DNSKEY
|
||||||
|
|
||||||
func q(w dns.RequestWriter, m *dns.Msg) {
|
func q(w dns.RequestWriter, m *dns.Msg) {
|
||||||
|
// Access this here, w.TsigStatus (for message m?)
|
||||||
if err := w.Send(m); err != nil {
|
if err := w.Send(m); err != nil {
|
||||||
fmt.Printf("%s\n", err.Error())
|
fmt.Printf("%s\n", err.Error())
|
||||||
w.Write(nil)
|
w.Write(nil)
|
||||||
|
@ -321,6 +321,7 @@ func (c *conn) serve() {
|
|||||||
if _, ok := w.conn.tsigSecret[secret]; !ok {
|
if _, ok := w.conn.tsigSecret[secret]; !ok {
|
||||||
w.tsigStatus = ErrKeyAlg
|
w.tsigStatus = ErrKeyAlg
|
||||||
}
|
}
|
||||||
|
// Do I *ever* need Tsig.Mac here? Or timersOnly? TODO(mg)
|
||||||
w.tsigStatus = TsigVerify(c.request, w.conn.tsigSecret[secret], "", false)
|
w.tsigStatus = TsigVerify(c.request, w.conn.tsigSecret[secret], "", false)
|
||||||
}
|
}
|
||||||
w.req = req
|
w.req = req
|
||||||
|
Loading…
x
Reference in New Issue
Block a user