DEVELOPMENT ENVIRONMENT

~liljamo/felu

ce7ae4399373bc2312a3cd66e4c3451667cc7805 — Jonni Liljamo 16 days ago 3cd37b5
feat: handle CAA queries (poorly)
1 files changed, 31 insertions(+), 0 deletions(-)

M internal/dns/query.go
M internal/dns/query.go => internal/dns/query.go +31 -0
@@ 31,6 31,8 @@ func parseQuery(m *dns.Msg, r *dns.Msg) {
		case dns.TypeAAAA:
			// NOTE: Stub
			m.SetRcode(r, dns.RcodeNameError)
		case dns.TypeCAA:
			handleCAARecord(&q, m, r)
		case dns.TypeCNAME:
			// NOTE: This is stubbed like this to make things like lego not shit themselves if they get NOTIMP.
			m.SetRcode(r, dns.RcodeNameError)


@@ 79,6 81,35 @@ func handleARecord(q *dns.Question, m *dns.Msg, r *dns.Msg) {
	}
}

func handleCAARecord(q *dns.Question, m *dns.Msg, r *dns.Msg) {
	qName := strings.ToLower(q.Name)

	// FIXME: Figure out how CAA actually works I guess, currently this is just
	//        a carbron copy of handleNSRecord
	ns := &dns.NS{
		Hdr: dns.RR_Header{Name: q.Name, Rrtype: dns.TypeNS, Class: dns.ClassINET, Ttl: 86400},
		Ns:  config.FeluConfig.Domain,
	}

	// "Root" Domain NS.
	if qName == config.FeluConfig.Domain {
		m.Answer = append(m.Answer, ns)
		return
	}

	if index := strings.IndexByte(qName, '.'); index >= 0 {
		// FIXME: other way of checking that the domain exists
		_, err := db.FetchDomainARecord(qName[:index])
		if err != nil {
			m.SetRcode(r, dns.RcodeNameError)
		} else {
			m.Answer = append(m.Answer, ns)
		}
	} else {
		m.SetRcode(r, dns.RcodeNameError)
	}
}

func handleNSRecord(q *dns.Question, m *dns.Msg, r *dns.Msg) {
	qName := strings.ToLower(q.Name)