2010-12-24 20:59:15 +11:00
|
|
|
package dns
|
|
|
|
|
2010-12-25 21:43:12 +11:00
|
|
|
import (
|
|
|
|
"crypto/sha1"
|
|
|
|
"time"
|
|
|
|
)
|
2010-12-24 21:50:42 +11:00
|
|
|
|
|
|
|
const (
|
2010-12-27 22:49:48 +11:00
|
|
|
// RFC1982 serial arithmetic
|
2010-12-25 21:14:11 +11:00
|
|
|
year68 = 2 << (32 - 1)
|
2010-12-24 21:50:42 +11:00
|
|
|
)
|
|
|
|
|
2010-12-25 21:43:12 +11:00
|
|
|
// Convert an DNSKEY record to a DS record.
|
2010-12-27 22:49:48 +11:00
|
|
|
func (k *RR_DNSKEY) ToDS(hash int) *RR_DS {
|
2010-12-25 21:43:12 +11:00
|
|
|
switch hash {
|
|
|
|
case HashSHA1:
|
|
|
|
var _ = sha1.New()
|
|
|
|
|
|
|
|
case HashSHA256:
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2010-12-27 22:49:48 +11:00
|
|
|
// Calculate the keytag of the DNSKEY
|
|
|
|
func (k *RR_DNSKEY) Tag() (keytag int) {
|
|
|
|
switch k.Algorithm {
|
|
|
|
case AlgRSAMD5:
|
|
|
|
println("Keytag RSAMD5. Todo")
|
|
|
|
keytag = 0
|
|
|
|
default:
|
|
|
|
// Might encode header length too, so that
|
|
|
|
// we dont need to pack/unpack all the time
|
|
|
|
buf := make([]byte, 4096)
|
|
|
|
off1, ok := packRR(k, buf, 0)
|
|
|
|
if !ok {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
start := off1 - int(k.Header().Rdlength)
|
|
|
|
end := start + int(k.Header().Rdlength)
|
|
|
|
for i, v := range buf[start:end] {
|
|
|
|
if i&1 != 0 {
|
|
|
|
keytag += int(v)
|
|
|
|
} else {
|
|
|
|
keytag += int(v) << 8
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keytag += (keytag >> 16) & 0xFFFF
|
|
|
|
keytag &= 0xFFFF
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2010-12-25 23:13:32 +11:00
|
|
|
// Validate an rrset with the signature and key. Note the
|
|
|
|
// signature validate period is NOT checked. Used
|
|
|
|
// ValidSignaturePeriod for that
|
2010-12-27 22:49:48 +11:00
|
|
|
func (s *RR_RRSIG) Valid(rrset []RR, key *RR_DNSKEY) bool {
|
|
|
|
return false
|
2010-12-25 23:13:32 +11:00
|
|
|
}
|
|
|
|
|
2010-12-27 22:49:48 +11:00
|
|
|
// Translate the RRSIG's incep. and expir. time to the correct date.
|
|
|
|
// Taking into account serial arithmetic (RFC 1982)
|
|
|
|
func timeToDate(t uint32) string {
|
|
|
|
utc := time.UTC().Seconds()
|
|
|
|
mod := (int64(t) - utc) / year68
|
|
|
|
|
|
|
|
// If needed assume wrap around(s)
|
|
|
|
ti := time.SecondsToUTC(int64(t) + (mod * year68)) // abs()? TODO
|
|
|
|
return ti.Format("20060102030405")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work on a signature RR_RRSIG
|
|
|
|
// Using RFC1982 calculate if a signature is valid
|
|
|
|
func ValidSignaturePeriod(start, end uint32) bool {
|
|
|
|
utc := time.UTC().Seconds() // maybe as parameter?? TODO MG
|
|
|
|
return int64(start) <= utc && utc <= int64(end)
|
2010-12-25 21:43:12 +11:00
|
|
|
}
|