From 6bbae6c6ead595391a96a1e1fb39aa72155f04f1 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Thu, 23 Oct 2014 22:18:23 +0100 Subject: [PATCH] Add CDNSKEY support --- msg.go | 1 + types.go | 24 ++++++++++++++++++++++++ zscan_rr.go | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/msg.go b/msg.go index 6ed21a07..152e3793 100644 --- a/msg.go +++ b/msg.go @@ -91,6 +91,7 @@ var TypeToString = map[uint16]string{ TypeATMA: "ATMA", TypeAXFR: "AXFR", // Meta RR TypeCAA: "CAA", + TypeCDNSKEY: "CDNSKEY", TypeCDS: "CDS", TypeCERT: "CERT", TypeCNAME: "CNAME", diff --git a/types.go b/types.go index d5b5be40..99193217 100644 --- a/types.go +++ b/types.go @@ -75,6 +75,7 @@ const ( TypeRKEY uint16 = 57 TypeTALINK uint16 = 58 TypeCDS uint16 = 59 + TypeCDNSKEY uint16 = 60 TypeOPENPGPKEY uint16 = 61 TypeSPF uint16 = 99 TypeUINFO uint16 = 100 @@ -1071,6 +1072,29 @@ func (rr *DNSKEY) String() string { " " + rr.PublicKey } +type CDNSKEY struct { + Hdr RR_Header + Flags uint16 + Protocol uint8 + Algorithm uint8 + PublicKey string `dns:"base64"` +} + +func (rr *CDNSKEY) Header() *RR_Header { return &rr.Hdr } +func (rr *CDNSKEY) len() int { + return rr.Hdr.len() + 4 + base64.StdEncoding.DecodedLen(len(rr.PublicKey)) +} +func (rr *CDNSKEY) copy() RR { + return &DNSKEY{*rr.Hdr.copyHeader(), rr.Flags, rr.Protocol, rr.Algorithm, rr.PublicKey} +} + +func (rr *CDNSKEY) String() string { + return rr.Hdr.String() + strconv.Itoa(int(rr.Flags)) + + " " + strconv.Itoa(int(rr.Protocol)) + + " " + strconv.Itoa(int(rr.Algorithm)) + + " " + rr.PublicKey +} + type RKEY struct { Hdr RR_Header Flags uint16 diff --git a/zscan_rr.go b/zscan_rr.go index 957b9e15..16c51c1b 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -1487,6 +1487,41 @@ func setDNSKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } +func setCDNSKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { + rr := new(CDNSKEY) + rr.Hdr = h + + l := <-c + if l.length == 0 { + return rr, nil, l.comment + } + if i, e := strconv.Atoi(l.token); e != nil { + return nil, &ParseError{f, "bad CDNSKEY Flags", l}, "" + } else { + rr.Flags = uint16(i) + } + <-c // _BLANK + l = <-c // _STRING + if i, e := strconv.Atoi(l.token); e != nil { + return nil, &ParseError{f, "bad CDNSKEY Protocol", l}, "" + } else { + rr.Protocol = uint8(i) + } + <-c // _BLANK + l = <-c // _STRING + if i, e := strconv.Atoi(l.token); e != nil { + return nil, &ParseError{f, "bad CDNSKEY Algorithm", l}, "" + } else { + rr.Algorithm = uint8(i) + } + s, e, c1 := endingToString(c, "bad CDNSKEY PublicKey", f) + if e != nil { + return nil, e, c1 + } + rr.PublicKey = s + return rr, nil, c1 +} + func setRKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr := new(RKEY) rr.Hdr = h @@ -2118,6 +2153,7 @@ var typeToparserFunc = map[uint16]parserFunc{ TypeAFSDB: parserFunc{setAFSDB, false}, TypeA: parserFunc{setA, false}, TypeCDS: parserFunc{setCDS, true}, + TypeCDNSKEY: parserFunc{setCDNSKEY, true}, TypeCERT: parserFunc{setCERT, true}, TypeCNAME: parserFunc{setCNAME, false}, TypeDHCID: parserFunc{setDHCID, true},