diff options
| author | Kasumi Hanazuki <kasumi@rollingapple.net> | 2024-02-28 06:48:40 +0000 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-02-29 20:55:26 +0000 |
| commit | 2508a7969977d1156a1e4772e80595b3fef2b559 (patch) | |
| tree | 39464f81763c26997aa3e510b013f08237e97438 /lib | |
| parent | d3ae5808bbeaba529449c0e0270658436e8699fd (diff) | |
[ruby/resolv] Implement CAA resource record
This patch implements handling of CAA resource records defined by [RFC8659].
- There are no known deployment of CAA records outside of IN (Internet),
but the RFC does not state that CAA records are class-specific.
Thus `CAA` class is defined as a class-independent RRType.
- `CAA` class stores `flags` field (a 1-octet bitset) as an Integer.
In this way it's easier to ensure the encoded RR is in the valid wire format.
[RFC8659]: https://datatracker.ietf.org/doc/html/rfc8659
https://github.com/ruby/resolv/commit/cfc4de75e3
Co-authored-by: aeris <aeris@imirhil.fr>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/resolv.rb | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/lib/resolv.rb b/lib/resolv.rb index 1363d49dc4..b585b10ca9 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -2537,8 +2537,70 @@ class Resolv TypeValue = 255 # :nodoc: end + ## + # CAA resource record defined in RFC 8659 + # + # These records identify certificate authority allowed to issue + # certificates for the given domain. + + class CAA < Resource + TypeValue = 257 + + ## + # Creates a new CAA for +flags+, +tag+ and +value+. + + def initialize(flags, tag, value) + unless (0..255) === flags + raise ArgumentError.new('flags must be an Integer between 0 and 255') + end + unless (1..15) === tag.bytesize + raise ArgumentError.new('length of tag must be between 1 and 15') + end + + @flags = flags + @tag = tag + @value = value + end + + ## + # Flags for this proprty: + # - Bit 0 : 0 = not critical, 1 = critical + + attr_reader :flags + + ## + # Property tag ("issue", "issuewild", "iodef"...). + + attr_reader :tag + + ## + # Property value. + + attr_reader :value + + ## + # Whether the critical flag is set on this property. + + def critical? + flags & 0x80 != 0 + end + + def encode_rdata(msg) # :nodoc: + msg.put_pack('C', @flags) + msg.put_string(@tag) + msg.put_bytes(@value) + end + + def self.decode_rdata(msg) # :nodoc: + flags, = msg.get_unpack('C') + tag = msg.get_string + value = msg.get_bytes + self.new flags, tag, value + end + end + ClassInsensitiveTypes = [ # :nodoc: - NS, CNAME, SOA, PTR, HINFO, MINFO, MX, TXT, LOC, ANY + NS, CNAME, SOA, PTR, HINFO, MINFO, MX, TXT, LOC, ANY, CAA ] ## |
