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-25 21:14:11 +11:00
|
|
|
year68 = 2 << (32 - 1)
|
2010-12-24 21:50:42 +11:00
|
|
|
)
|
|
|
|
|
2010-12-25 21:14:11 +11:00
|
|
|
// Translate the RRSIG's incep. and expir. time to the correct date.
|
|
|
|
// Taking into account serial arithmetic (RFC 1982)
|
2010-12-24 21:50:42 +11:00
|
|
|
func timeToDate(t uint32) string {
|
|
|
|
utc := time.UTC().Seconds()
|
2010-12-25 21:14:11 +11:00
|
|
|
mod := (int64(t) - utc) / year68
|
2010-12-24 21:50:42 +11:00
|
|
|
|
2010-12-25 21:14:11 +11:00
|
|
|
// If needed assume wrap around(s)
|
|
|
|
ti := time.SecondsToUTC(int64(t) + (mod * year68)) // abs()? TODO
|
2010-12-24 21:50:42 +11:00
|
|
|
return ti.Format("20060102030405")
|
|
|
|
}
|
|
|
|
|
2010-12-25 21:14:11 +11:00
|
|
|
// Using RFC1982 calculate if a signature is valid
|
2010-12-24 21:50:42 +11:00
|
|
|
func validSignaturePeriod(start, end uint32) bool {
|
2010-12-25 21:14:11 +11:00
|
|
|
utc := time.UTC().Seconds() // maybe as parameter?? TODO MG
|
|
|
|
return int64(start) <= utc && utc <= int64(end)
|
2010-12-24 21:50:42 +11:00
|
|
|
}
|
2010-12-25 21:43:12 +11:00
|
|
|
|
|
|
|
// Convert an DNSKEY record to a DS record.
|
|
|
|
func KeyToDS(k *RR_DNSKEY, hash int) *RR_DS {
|
|
|
|
switch hash {
|
|
|
|
case HashSHA1:
|
|
|
|
var _ = sha1.New()
|
|
|
|
|
|
|
|
case HashSHA256:
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the keytag of the DNSKEY
|
|
|
|
func KeyTag(k *RR_DNSKEY) int {
|
|
|
|
return 0
|
|
|
|
}
|