0

I'm trying to use the Ruby library to lookup the CAA record for a domain. I was expecting it to look something like this:

Resolv::DNS.open do |dns|
  ress = dns.getresources "ruby-lang.org", Resolv::DNS::Resource::CAA
  p ress.map(&:inspect)
end

But the CAA record type isn't a defined Resolv::DNS::Resource. Does anyone know how to lookup the CAA record?

Tom Rossi
  • 11,604
  • 5
  • 65
  • 96

1 Answers1

1

There exists a gem with an MIT license which provides this functionality:

class Resolv::DNS::Resource::IN::CAA < Resolv::DNS::Resource
  TypeValue = 257
  ClassValue = IN::ClassValue
  ClassHash[[TypeValue, ClassValue]] = self

  def initialize(flags, tag, value)
    # https://tools.ietf.org/html/rfc8659#section-4.1
    #    +0-1-2-3-4-5-6-7-|0-1-2-3-4-5-6-7-|
    #    | Flags          | Tag Length = n |
    #    +----------------|----------------+...+---------------+
    #    | Tag char 0     | Tag char 1     |...| Tag char n-1  |
    #    +----------------|----------------+...+---------------+
    #    +----------------|----------------+.....+----------------+
    #    | Value byte 0   | Value byte 1   |.....| Value byte m-1 |
    #    +----------------|----------------+.....+----------------+
    @flags = flags
    @tag = tag
    @value = value
  end

  ##
  # Critical Flag

  attr_reader :flags

  ##
  # Property identifier

  attr_reader :tag

  ##
  # A sequence of octets representing the Property Value

  attr_reader :value

  def encode_rdata(msg)
    msg.put_bytes(@flags)
    msg.put_string(@tag)
    msg.put_bytes(@value)
  end

  def self.decode_rdata(msg)
    flags = msg.get_bytes(1)
    tag = msg.get_string
    value = msg.get_bytes
    new(flags, tag, value)
  end
end

Results in:

 Resolv::DNS.open do |dns|
 dns.getresources("google.com", Resolv::DNS::Resource::IN::CAA)
end
# => [#<Resolv::DNS::Resource::IN::CAA:0x00005580b4806738 
#      @flags="\x00", @tag="issue", @ttl=86400, @value="pki.goog">]
John Ledbetter
  • 13,557
  • 1
  • 61
  • 80