mirror of
https://github.com/miekg/dns.git
synced 2025-08-12 04:26:58 +02:00
Fix tsig by making timeSigned a 64 bit int
only use the lower 48 bits to make it all work
This commit is contained in:
parent
42660c2a8e
commit
a6fee19f4c
46
msg.go
46
msg.go
@ -244,22 +244,6 @@ func packStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int, o
|
|||||||
BadType:
|
BadType:
|
||||||
fmt.Fprintf(os.Stderr, "dns: unknown packing type %v\n", f.Type)
|
fmt.Fprintf(os.Stderr, "dns: unknown packing type %v\n", f.Type)
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
case *reflect.ArrayValue:
|
|
||||||
switch f.Tag {
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(os.Stderr, "dns: unknown IP tag %v", f.Tag)
|
|
||||||
return len(msg), false
|
|
||||||
case "TSIG":
|
|
||||||
// has a 3 byte inception time (check len?)
|
|
||||||
// need to do some shifting here
|
|
||||||
msg[off] = byte(fv.Elem(0).(*reflect.UintValue).Get() >> 8)
|
|
||||||
msg[off+1] = byte(fv.Elem(0).(*reflect.UintValue).Get())
|
|
||||||
msg[off+2] = byte(fv.Elem(1).(*reflect.UintValue).Get() >> 8)
|
|
||||||
msg[off+3] = byte(fv.Elem(1).(*reflect.UintValue).Get())
|
|
||||||
msg[off+4] = byte(fv.Elem(2).(*reflect.UintValue).Get() >> 8)
|
|
||||||
msg[off+5] = byte(fv.Elem(2).(*reflect.UintValue).Get())
|
|
||||||
off += 6
|
|
||||||
}
|
|
||||||
case *reflect.SliceValue:
|
case *reflect.SliceValue:
|
||||||
switch f.Tag {
|
switch f.Tag {
|
||||||
default:
|
default:
|
||||||
@ -335,6 +319,18 @@ func packStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int, o
|
|||||||
msg[off+2] = byte(i >> 8)
|
msg[off+2] = byte(i >> 8)
|
||||||
msg[off+3] = byte(i)
|
msg[off+3] = byte(i)
|
||||||
off += 4
|
off += 4
|
||||||
|
case reflect.Uint64:
|
||||||
|
// Only used in TSIG, where it stops as 48 bits, discard the upper 16
|
||||||
|
if off+6 > len(msg) {
|
||||||
|
return len(msg), false
|
||||||
|
}
|
||||||
|
msg[off] = byte(i >> 40)
|
||||||
|
msg[off+1] = byte(i >> 32)
|
||||||
|
msg[off+2] = byte(i >> 24)
|
||||||
|
msg[off+3] = byte(i >> 16)
|
||||||
|
msg[off+4] = byte(i >> 8)
|
||||||
|
msg[off+5] = byte(i)
|
||||||
|
off += 6
|
||||||
}
|
}
|
||||||
case *reflect.StringValue:
|
case *reflect.StringValue:
|
||||||
// There are multiple string encodings.
|
// There are multiple string encodings.
|
||||||
@ -398,14 +394,6 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
|
|||||||
BadType:
|
BadType:
|
||||||
fmt.Fprintf(os.Stderr, "dns: unknown packing type %v", f.Type)
|
fmt.Fprintf(os.Stderr, "dns: unknown packing type %v", f.Type)
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
case *reflect.ArrayValue:
|
|
||||||
switch f.Tag {
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(os.Stderr, "dns: unknown IP tag %v", f.Tag)
|
|
||||||
return len(msg), false
|
|
||||||
case "TSIG":
|
|
||||||
println("TODO")
|
|
||||||
}
|
|
||||||
case *reflect.SliceValue:
|
case *reflect.SliceValue:
|
||||||
switch f.Tag {
|
switch f.Tag {
|
||||||
default:
|
default:
|
||||||
@ -469,6 +457,16 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
|
|||||||
i := uint32(msg[off])<<24 | uint32(msg[off+1])<<16 | uint32(msg[off+2])<<8 | uint32(msg[off+3])
|
i := uint32(msg[off])<<24 | uint32(msg[off+1])<<16 | uint32(msg[off+2])<<8 | uint32(msg[off+3])
|
||||||
fv.Set(uint64(i))
|
fv.Set(uint64(i))
|
||||||
off += 4
|
off += 4
|
||||||
|
case reflect.Uint64:
|
||||||
|
// This is *only* used in TSIG where the last 48 bits are occupied
|
||||||
|
// So for now, assume a uint48 (6 bytes)
|
||||||
|
if off+6 > len(msg) {
|
||||||
|
return len(msg), false
|
||||||
|
}
|
||||||
|
i := uint64(msg[off])<<40 | uint64(msg[off+1])<<32 | uint64(msg[off+2])<<24 | uint64(msg[off+3])<<16 |
|
||||||
|
uint64(msg[off+4])<<8 | uint64(msg[off+4])
|
||||||
|
fv.Set(uint64(i))
|
||||||
|
off += 6
|
||||||
}
|
}
|
||||||
case *reflect.StringValue:
|
case *reflect.StringValue:
|
||||||
var s string
|
var s string
|
||||||
|
19
tsig.go
19
tsig.go
@ -17,12 +17,12 @@ const (
|
|||||||
|
|
||||||
type RR_TSIG struct {
|
type RR_TSIG struct {
|
||||||
Hdr RR_Header
|
Hdr RR_Header
|
||||||
Algorithm string "domain-name"
|
Algorithm string "domain-name"
|
||||||
TimeSigned [3]uint16 "TSIG"
|
TimeSigned uint64
|
||||||
Fudge uint16
|
Fudge uint16
|
||||||
MACSize uint16
|
MACSize uint16
|
||||||
MAC string
|
MAC string
|
||||||
OrigId uint16 // msg id
|
OrigId uint16 // msg id
|
||||||
Error uint16
|
Error uint16
|
||||||
OtherLen uint16
|
OtherLen uint16
|
||||||
OtherData string
|
OtherData string
|
||||||
@ -33,12 +33,12 @@ func (rr *RR_TSIG) Header() *RR_Header {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_TSIG) String() string {
|
func (rr *RR_TSIG) String() string {
|
||||||
// It has no presentation format
|
// It has no presentation format
|
||||||
return rr.Hdr.String() +
|
return rr.Hdr.String() +
|
||||||
" " + rr.Algorithm +
|
" " + rr.Algorithm +
|
||||||
" " + "<timesigned>" +
|
" " + "<timesigned>" +
|
||||||
" " + strconv.Itoa(int(rr.Fudge)) +
|
" " + strconv.Itoa(int(rr.Fudge)) +
|
||||||
" " + "<MAC>" +
|
" " + "<MAC>" +
|
||||||
" " + strconv.Itoa(int(rr.OrigId)) +
|
" " + strconv.Itoa(int(rr.OrigId)) +
|
||||||
" " + strconv.Itoa(int(rr.Error)) +
|
" " + strconv.Itoa(int(rr.Error)) +
|
||||||
" " + rr.OtherData
|
" " + rr.OtherData
|
||||||
@ -53,8 +53,8 @@ type tsig_generation_fmt struct {
|
|||||||
Class uint16
|
Class uint16
|
||||||
Ttl uint32
|
Ttl uint32
|
||||||
// Rdata of the TSIG
|
// Rdata of the TSIG
|
||||||
Algorithm string "domain-name"
|
Algorithm string "domain-name"
|
||||||
TimeSigned [3]uint16 "TSIG"
|
TimeSigned uint64
|
||||||
Fudge uint16
|
Fudge uint16
|
||||||
// MACSize, MAC and OrigId excluded
|
// MACSize, MAC and OrigId excluded
|
||||||
Error uint16
|
Error uint16
|
||||||
@ -103,5 +103,8 @@ func (rr *RR_TSIG) Generate(msg *Msg, secret string) bool {
|
|||||||
// the TSIG record still attached (as the last rr in the Additional
|
// the TSIG record still attached (as the last rr in the Additional
|
||||||
// section)
|
// section)
|
||||||
func (rr *RR_TSIG) Verify(msg *Msg, secret string) bool {
|
func (rr *RR_TSIG) Verify(msg *Msg, secret string) bool {
|
||||||
|
// copy the mesg, strip (and check) the tsig rr
|
||||||
|
// perform the opposite of Generate() and then
|
||||||
|
// verify the mac
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
7
types.go
7
types.go
@ -535,6 +535,13 @@ func timeToDate(t uint32) string {
|
|||||||
return ti.Format("20060102030405")
|
return ti.Format("20060102030405")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Translate the TSIG time signed into a date. There is no
|
||||||
|
// need for RFC1982 calculations as this date is 48 bits
|
||||||
|
func tsigTimeToDate(t uint64) string {
|
||||||
|
// only use the lower 48 bits
|
||||||
|
return "TODO"
|
||||||
|
}
|
||||||
|
|
||||||
// Map of constructors for each RR wire type.
|
// Map of constructors for each RR wire type.
|
||||||
var rr_mk = map[int]func() RR{
|
var rr_mk = map[int]func() RR{
|
||||||
TypeCNAME: func() RR { return new(RR_CNAME) },
|
TypeCNAME: func() RR { return new(RR_CNAME) },
|
||||||
|
Loading…
Reference in New Issue
Block a user