Class: Dnsruby::SingleVerifier
- Inherits:
-
Object
- Object
- Dnsruby::SingleVerifier
- Defined in:
- lib/dnsruby/single_verifier.rb
Overview
:nodoc: all
Defined Under Namespace
Classes: VerifierType
Constant Summary collapse
- MAX_LEARNED_KEYS =
Configured anchors are separate; only learned trust is capacity-limited.
4096- MAX_LEARNED_DS_RECORDS =
4096
Class Method Summary collapse
Instance Method Summary collapse
- #add_dlv_key(key) ⇒ Object
-
#add_nameservers(ns_rrset, ns_additional, nameservers) ⇒ Object
:nodoc:.
- #add_root_ds(ds) ⇒ Object
- #add_trust_anchor(t) ⇒ Object
-
#add_trust_anchor_with_expiration(k, expiration) ⇒ Object
Add the.
-
#add_trusted_key(k, expiration = nil) ⇒ Object
Add the specified keys to the trusted key cache.
-
#check_ds(key, ds_rrset, expiration = nil) ⇒ Object
Check that the key fits a signed DS record key details A DS digest match identifies a candidate; only a verified DNSKEY RRset can publish that key and establish its authenticated cache lifetime.
-
#check_ds_stores(key_rrset, signatures = nil) ⇒ Object
:nodoc:.
-
#check_rr_data(rrset, sigrec) ⇒ Object
Check that the RRSet and RRSIG record are compatible.
-
#clear_trust_anchors ⇒ Object
Remove configured anchors and any keys learned from them.
-
#clear_trusted_keys ⇒ Object
Clear learned trust and configured DS/DLV anchors, retaining DNSKEY anchors.
-
#find_closest_anchor_for(name) ⇒ Object
:nodoc:.
-
#find_closest_dlv_anchor_for(name) ⇒ Object
:nodoc:.
-
#follow_chain(anchor, name) ⇒ Object
@TODO@ Handle REVOKED keys! (RFC 5011) Remember that revoked keys will have a different key_tag than pre-revoked.
-
#get_anchor_for(child, parent, current_anchor, parent_res = nil) ⇒ Object
:nodoc:.
-
#get_dlv_key(ksk) ⇒ Object
:nodoc:.
-
#get_dlv_resolver ⇒ Object
:nodoc:.
-
#get_keys_to_check(signatures = nil) ⇒ Object
:nodoc:.
-
#get_matching_key(keys, sigrecs) ⇒ Object
Find the first matching DNSKEY and RRSIG record in the two sets.
-
#get_nameservers_for(name, res = nil) ⇒ Object
:nodoc:.
-
#get_nameservers_from_message(name, ns_ret) ⇒ Object
:nodoc:.
- #get_recursor ⇒ Object
-
#get_zone_key_from_dlv_rrset(dlv_rrset, name) ⇒ Object
:nodoc:.
-
#initialize(vtype) ⇒ SingleVerifier
constructor
A new instance of SingleVerifier.
-
#query_dlv_for(name) ⇒ Object
:nodoc:.
- #remove_trust_anchor(t) ⇒ Object
- #set_hints(hints) ⇒ Object
- #trust_anchors ⇒ Object
- #trusted_keys ⇒ Object
-
#try_to_follow_from_anchor(closest_anchor, msg, qname) ⇒ Object
:nodoc:.
- #validate(msg, query) ⇒ Object
-
#validate_no_rrsigs(msg) ⇒ Object
:nodoc:.
-
#validation_cache_identity ⇒ Object
Response/failure caches need a stable, inexpensive identity for the current trust configuration.
-
#verify(msg, keys = nil) ⇒ Object
Verify the specified message (or RRSet) using the set of trusted keys.
-
#verify_ds_rrset(ds_rrset, keys = nil, msg = nil, context = {}) ⇒ Object
:nodoc:.
-
#verify_for_validation(msg) ⇒ Object
Cached-key verification for Dnssec's validation fast path uses the same algorithm policy and proof-lifetime accounting as chain discovery.
-
#verify_key_rrset(key_rrset, keys = nil, context = {}) ⇒ Object
:nodoc:.
-
#verify_nsecs(msg, context = nil) ⇒ Object
Check denial at the end of an alias chain, not at the original QNAME.
-
#verify_result(msg, keys = nil) ⇒ Object
:nodoc:.
-
#verify_rrset(rrset, keys = nil, context = {}) ⇒ Object
Verify the signature of an rrset encoded with the specified KeyCache or RRSet.
Constructor Details
#initialize(vtype) ⇒ SingleVerifier
Returns a new instance of SingleVerifier.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dnsruby/single_verifier.rb', line 75 def initialize(vtype) @trust_mutex = Mutex.new @trust_generation = 0 @trust_configuration_generation = 0 @trust_source_id = SingleVerifier.send(:register_trust_source, self) @verifier_type = vtype @added_dlv_key = false # The set of trust anchors. # If the root is unsigned, then these must be initialised with at least # one trusted key by the client application, if verification is to be performed. @trust_anchors = KeyCache.new # Track configured expiration independently of KeyCache pruning so an # expired anchor invalidates learned trust and in-flight publication. @configured_dnskey_identities = {} # The set of keys which are trusted. @trusted_keys = KeyCache.new(max_keys: MAX_LEARNED_KEYS) @trusted_key_provenance = {} # The set of keys which have been indicated by a DS RRSet which has been # signed by a trusted key. Although we have not yet located these keys, we # have the details (tag and digest) which can identify the keys when we # see them. At that point, they will be added to our trusted keys. @discovered_ds_store = DSCache.new(max_records: MAX_LEARNED_DS_RECORDS) # The configured_ds_store is the set of DS records which have been configured # by the client as trust anchors. Use Dnssec#add_trust_anchor to add these @configured_ds_store = [] @configured_ds_expirations = {} @configured_ds_index = DSCache.new(max_records: nil) end |
Class Method Details
.set_recursor_hints(hints) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/dnsruby/single_verifier.rb', line 127 def self.set_recursor_hints(hints) with_recursor_lock do @recursor_hints = if hints.is_a?(Array) hints.map { |hint| hint.dup.freeze }.freeze else hints&.dup&.freeze end @recursor = nil Recursor.reset_hints end end |
.shared_recursor ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/dnsruby/single_verifier.rb', line 143 def self.shared_recursor with_recursor_lock do unless @recursor if @recursor_hints bootstrap = Resolver.new begin Recursor.set_hints(@recursor_hints, bootstrap) ensure bootstrap.close end end @recursor = Recursor.new @recursor.dnssec = true end @recursor end end |
Instance Method Details
#add_dlv_key(key) ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/dnsruby/single_verifier.rb', line 179 def add_dlv_key(key) # Is this a ZSK or a KSK? # If it is a KSK, then get the ZSK from the zone if (key.sep_key?) get_dlv_key(key) end end |
#add_nameservers(ns_rrset, ns_additional, nameservers) ⇒ Object
:nodoc:
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 |
# File 'lib/dnsruby/single_verifier.rb', line 2149 def add_nameservers(ns_rrset, ns_additional, nameservers) # :nodoc: # Want to go through all of the ns_rrset NS records, # print "Checking #{ns_rrset.rrs.length} NS records against #{ns_additional.length} address records\n" ns_rrset.rrs.sort_by {rand}.each {|ns_rr| # and see if we can find any of the names in the A/AAAA records in ns_additional found_addr = false ns_additional.each {|addr_rr| if (ns_rr.nsdname.canonical == addr_rr.name.canonical) # print "Found address #{addr_rr.address} for #{ns_rr.nsdname}\n" nameservers.push(addr_rr.address.to_s) found_addr = true break # If we can, then we add the server A/AAAA address to nameservers end # If we can't, then we add the server NS name to nameservers } if (!found_addr) # print "Couldn't find address - adding #{ns_rr.nsdname}\n" nameservers.push(ns_rr.nsdname) end } end |
#add_root_ds(ds) ⇒ Object
434 435 436 437 438 439 440 441 442 |
# File 'lib/dnsruby/single_verifier.rb', line 434 def add_root_ds(ds) @trust_mutex.synchronize do @trust_configuration_generation += 1 identity = ds_identity(ds) @configured_ds_store.push(ds) unless @configured_ds_expirations.key?(identity) @configured_ds_expirations[identity] = Float::INFINITY index_configured_ds end end |
#add_trust_anchor(t) ⇒ Object
221 222 223 |
# File 'lib/dnsruby/single_verifier.rb', line 221 def add_trust_anchor(t) add_trust_anchor_with_expiration(t, Time.utc(2035,"jan",1,20,15,1).to_i) end |
#add_trust_anchor_with_expiration(k, expiration) ⇒ Object
Add the
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/dnsruby/single_verifier.rb', line 225 def add_trust_anchor_with_expiration(k, expiration) @trust_mutex.synchronize do @trust_configuration_generation += 1 if (k.type == Types.DNSKEY) @trust_anchors.add_key_with_expiration(k, expiration) identity = KeyCache.key_identity(k) @configured_dnskey_identities[identity] = [@configured_dnskey_identities[identity] || expiration, expiration].max TheLog.info("Adding trust anchor for #{k.name}") elsif ((k.type == Types.DS) || ((k.type == Types.DLV) && (@verifier_type == VerifierType::DLV))) identity = ds_identity(k) previous = @configured_ds_expirations[identity] @configured_ds_store.push(k) unless previous @configured_ds_expirations[identity] = [previous || expiration, expiration].max index_configured_ds end end end |
#add_trusted_key(k, expiration = nil) ⇒ Object
Add the specified keys to the trusted key cache. k can be a KeyCache, or an RRSet of DNSKEYs.
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/dnsruby/single_verifier.rb', line 393 def add_trusted_key(k, expiration = nil) provenance = learned_provenance(k) return false if provenance && !usable_provenance?(provenance) expiration ||= provenance&.expiration # Only an existing version of an incoming key can prevent its replacement. # Readers check other provenance before use; checking the whole cache here # makes each independent key discovery proportional to every cached zone. incoming = k.is_a?(RRSet) ? k.rrs : (k.is_a?(KeyCache) ? k.keys : []) identities = incoming.map { |key| KeyCache.key_identity(key) } previous = @trust_mutex.synchronize do identities.filter_map do |identity| trust = @trusted_key_provenance[identity] [identity, trust] if trust end.to_h end invalid = previous.reject { |_identity, trust| usable_provenance?(trust) } publish_trust do invalid.each do |identity, trust| next unless @trusted_key_provenance[identity].equal?(trust) @trusted_keys.delete_identity(identity) @trusted_key_provenance.delete(identity) end if provenance && (operation = trust_operation) k.rrs.each { |key| operation[:keys][KeyCache.key_identity(key)] = [key, provenance] } end result = @trusted_keys.add(k, expiration) if provenance && expiration && expiration > Time.now.to_i k.rrs.each do |key| identity = KeyCache.key_identity(key) previous = @trusted_key_provenance[identity] if !previous || (!previous.operational && provenance.operational) || (previous.operational == provenance.operational && previous.expiration < expiration) @trusted_key_provenance[identity] = provenance end end end @trusted_key_provenance.delete_if { |identity, _trust| !@trusted_keys.include_identity?(identity) } result end end |
#check_ds(key, ds_rrset, expiration = nil) ⇒ Object
Check that the key fits a signed DS record key details A DS digest match identifies a candidate; only a verified DNSKEY RRset can publish that key and establish its authenticated cache lifetime.
611 612 613 |
# File 'lib/dnsruby/single_verifier.rb', line 611 def check_ds(key, ds_rrset, expiration = nil)#:nodoc: all with_validation { check_ds_internal(key, ds_rrset, expiration) } end |
#check_ds_stores(key_rrset, signatures = nil) ⇒ Object
:nodoc:
1214 1215 1216 |
# File 'lib/dnsruby/single_verifier.rb', line 1214 def check_ds_stores(key_rrset, signatures = nil) # :nodoc: with_validation { check_ds_stores_internal(key_rrset, signatures) } end |
#check_rr_data(rrset, sigrec) ⇒ Object
Check that the RRSet and RRSIG record are compatible
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/dnsruby/single_verifier.rb', line 325 def check_rr_data(rrset, sigrec)#:nodoc: all # Each RR MUST have the same owner name as the RRSIG RR; if (rrset.name.canonical != sigrec.name.canonical) raise VerifyError.new("RRSET should have same owner name as RRSIG for verification (rrsert=#{rrset.name}, sigrec=#{sigrec.name}") end # Each RR MUST have the same class as the RRSIG RR; if (rrset.klass != sigrec.klass) raise VerifyError.new("RRSET should have same DNS class as RRSIG for verification") end # Each RR in the RRset MUST have the RR type listed in the # RRSIG RR's Type Covered field; if (rrset.type != sigrec.type_covered) raise VerifyError.new("RRSET should have same type as RRSIG for verification") end # RFC 4035 5.3.1: a signature is authoritative only within its zone. # DNSKEY is apex data; DS is parent-side data at a strict descendant. zone = sigrec.signers_name unless within_zone?(rrset.name, zone) raise VerifyError, 'RRSet owner is outside the signing zone' end if rrset.type == Types.DNSKEY && rrset.name != zone raise VerifyError, 'DNSKEY RRSet must be signed by its own zone' end if rrset.type == Types.DS && !rrset.name.subdomain_of?(zone) raise VerifyError, 'DS RRSet must be signed by a parent zone' end if sigrec.labels < zone.labels.length raise VerifyError, 'Wildcard source is outside the signing zone' end # #Each RR in the RRset MUST have the TTL listed in the # #RRSIG Original TTL Field; # if (rrset.ttl != sigrec.original_ttl) # raise VerifyError.new("RRSET should have same ttl as RRSIG original_ttl for verification (should be #{sigrec.original_ttl} but was #{rrset.ttl}") # end # Now check that we are in the validity period for the RRSIG now = Time.now.to_i unless SerialTime.valid?(sigrec.inception, sigrec.expiration, now) raise VerifyError.new("Signature record not in validity period") end end |
#clear_trust_anchors ⇒ Object
Remove configured anchors and any keys learned from them.
263 264 265 266 267 268 269 270 271 272 |
# File 'lib/dnsruby/single_verifier.rb', line 263 def clear_trust_anchors @trust_mutex.synchronize do @trust_anchors = KeyCache.new @configured_dnskey_identities = {} @configured_ds_store = [] @configured_ds_expirations = {} index_configured_ds clear_learned_keys end end |
#clear_trusted_keys ⇒ Object
Clear learned trust and configured DS/DLV anchors, retaining DNSKEY anchors.
445 446 447 448 449 450 451 452 |
# File 'lib/dnsruby/single_verifier.rb', line 445 def clear_trusted_keys @trust_mutex.synchronize do clear_learned_keys @configured_ds_store = [] @configured_ds_expirations = {} index_configured_ds end end |
#find_closest_anchor_for(name) ⇒ Object
:nodoc:
1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 |
# File 'lib/dnsruby/single_verifier.rb', line 1768 def find_closest_anchor_for(name) # :nodoc: n = Name.create(name == "" ? "." : name) names = [n] names << names.last.strip_label until names.last.labels.empty? # Lookup by owner before consulting provenance. A cache of unrelated # zones should not add work to every step down a delegation chain. candidates = @trust_mutex.synchronize do expire_trust_anchors names.map do |owner| [@trust_anchors.keys_for_name(owner) + @configured_ds_index.rrsets_for_name(owner), @trusted_keys.keys_for_name(owner), @discovered_ds_store.rrsets_for_name(owner)] end end operation = trust_operation names.zip(candidates).each do |owner, (configured, keys, discovered)| canonical = owner.canonical anchors = configured + keys.select { |key| usable_cached_key?(key) } + discovered.select { |rrset| usable_provenance?(learned_provenance(rrset)) } if operation operation[:keys].each_value do |key, trust| anchors << key if key.name.canonical == canonical && usable_provenance?(trust) end operation[:ds].each do |rrset, trust| anchors << rrset if rrset.name.canonical == canonical && usable_provenance?(trust) end end if operation&.fetch(:operational, false) anchors.reject! { |key| key.type == Types.DNSKEY && !algorithm_supported?(key.algorithm, operational: true) } end # Records remain mutable; an index entry must not grant trust under # the old owner after the caller changes the record's name. anchor = anchors.find { |key| key.name.canonical == canonical } return anchor if anchor end false end |
#find_closest_dlv_anchor_for(name) ⇒ Object
:nodoc:
1648 1649 1650 |
# File 'lib/dnsruby/single_verifier.rb', line 1648 def find_closest_dlv_anchor_for(name) # :nodoc: with_validation { find_closest_dlv_anchor_for_internal(name) } end |
#follow_chain(anchor, name) ⇒ Object
@TODO@ Handle REVOKED keys! (RFC 5011) Remember that revoked keys will have a different key_tag than pre-revoked. So, if we see a revoked key, we should go through our key store for that authority and remove any keys with the pre-revoked key_tag.
1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 |
# File 'lib/dnsruby/single_verifier.rb', line 1810 def follow_chain(anchor, name) # :nodoc: with_validation do operation = trust_operation operation[:last_insecure_expiration] = nil result = follow_chain_internal(anchor, name) if !result && operation[:insecurity_expirations] operation[:insecurity_expirations] << operation[:last_insecure_expiration] end result end end |
#get_anchor_for(child, parent, current_anchor, parent_res = nil) ⇒ Object
:nodoc:
1866 1867 1868 |
# File 'lib/dnsruby/single_verifier.rb', line 1866 def get_anchor_for(child, parent, current_anchor, parent_res = nil) # :nodoc: with_validation { get_anchor_for_internal(child, parent, current_anchor, parent_res) } end |
#get_dlv_key(ksk) ⇒ Object
:nodoc:
186 187 188 |
# File 'lib/dnsruby/single_verifier.rb', line 186 def get_dlv_key(ksk) # :nodoc: with_validation { get_dlv_key_internal(ksk) } end |
#get_dlv_resolver ⇒ Object
:nodoc:
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/dnsruby/single_verifier.rb', line 165 def get_dlv_resolver # :nodoc: # if (Dnssec.do_validation_with_recursor?) # return Recursor.new # else resolver = nil if (Dnssec.default_resolver) resolver = Dnssec.default_resolver else resolver = Resolver.new end # end resolver.dnssec = true return resolver end |
#get_keys_to_check(signatures = nil) ⇒ Object
:nodoc:
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 |
# File 'lib/dnsruby/single_verifier.rb', line 1279 def get_keys_to_check(signatures = nil) # :nodoc: anchors, keys = @trust_mutex.synchronize do expire_trust_anchors [signatures ? @trust_anchors.matching_keys(signatures) : @trust_anchors.keys, cached_trust_keys(signatures)] end local = (trust_operation&.fetch(:keys)&.values || []).filter_map do |key, provenance| key if usable_provenance?(provenance) end (anchors + keys.select { |key| usable_cached_key?(key) } + local).uniq { |key| KeyCache.key_identity(key) } end |
#get_matching_key(keys, sigrecs) ⇒ Object
Find the first matching DNSKEY and RRSIG record in the two sets.
1292 1293 1294 1295 |
# File 'lib/dnsruby/single_verifier.rb', line 1292 def get_matching_key(keys, sigrecs)#:nodoc: all each_matching_key(keys, sigrecs) { |key, sig| return key, sig } return nil, nil end |
#get_nameservers_for(name, res = nil) ⇒ Object
:nodoc:
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 |
# File 'lib/dnsruby/single_verifier.rb', line 2094 def get_nameservers_for(name, res = nil) # :nodoc: # @TODO@ !!! if (Dnssec.do_validation_with_recursor?) return get_recursor else resolver = nil if (Dnssec.default_resolver) resolver = Dnssec.default_resolver else resolver = Resolver.new end resolver.dnssec = true return resolver end end |
#get_nameservers_from_message(name, ns_ret) ⇒ Object
:nodoc:
2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 |
# File 'lib/dnsruby/single_verifier.rb', line 2110 def (name, ns_ret) # :nodoc: if (Dnssec.default_resolver) return Dnssec.default_resolver end ns_rrset = ns_ret.answer.rrset(name, Types.NS) if (!ns_rrset || ns_rrset.length == 0) ns_rrset = ns_ret..rrset(name, Types.NS) # @TODO@ Is ths OK? end if (!ns_rrset || ns_rrset.length == 0 || ns_rrset.name.canonical != name.canonical) return nil end if (ns_rrset.sigs.length > 0) # verify_rrset(ns_rrset) # @TODO@ ?? end # Cache.add(ns_ret) ns_additional = [] ns_ret.additional.each {|rr| ns_additional.push(rr) if (rr.type == Types.A) } nameservers = [] add_nameservers(ns_rrset, ns_additional, nameservers) # if (ns_additional.length > 0) ns_additional = [] ns_ret.additional.each {|rr| ns_additional.push(rr) if (rr.type == Types.AAAA) } add_nameservers(ns_rrset, ns_additional, nameservers) if (ns_additional.length > 0) # Make Resolver using all NSs if (nameservers.length == 0) # print "Can't find nameservers for #{ns_ret.question()[0].qname} from #{ns_rrset.rrs}\n" TheLog.info("Can't find nameservers for #{ns_ret.question()[0].qname} from #{ns_rrset.rrs}") return nil # @TODO@ Could return a recursor here? # return Recursor.new end res = Resolver.new() res.nameserver=(nameservers) # Set the retry_delay to be (at least) the number of nameservers # Otherwise, the queries will be sent at a rate of more than one a second! res.retry_delay = nameservers.length * 2 res.dnssec = true return res end |
#get_recursor ⇒ Object
161 162 163 |
# File 'lib/dnsruby/single_verifier.rb', line 161 def get_recursor SingleVerifier.shared_recursor end |
#get_zone_key_from_dlv_rrset(dlv_rrset, name) ⇒ Object
:nodoc:
1674 1675 1676 |
# File 'lib/dnsruby/single_verifier.rb', line 1674 def get_zone_key_from_dlv_rrset(dlv_rrset, name) # :nodoc: with_validation { get_zone_key_from_dlv_rrset_internal(dlv_rrset, name) } end |
#query_dlv_for(name) ⇒ Object
:nodoc:
1722 1723 1724 |
# File 'lib/dnsruby/single_verifier.rb', line 1722 def query_dlv_for(name) # :nodoc: with_validation { query_dlv_for_internal(name) } end |
#remove_trust_anchor(t) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/dnsruby/single_verifier.rb', line 243 def remove_trust_anchor(t) @trust_mutex.synchronize do configured = false removed = if (t.type == Types.DNSKEY) configured = @configured_dnskey_identities.delete(KeyCache.key_identity(t)) @trust_anchors.delete(t) elsif t.type == Types.DS || t.type == Types.DLV identity = ds_identity(t) configured = @configured_ds_expirations.delete(identity) found = @configured_ds_store.find { |record| ds_identity(record) == identity } @configured_ds_store.delete(found) if found index_configured_ds found end # Cached keys and in-flight discoveries may depend on this anchor. clear_learned_keys if removed || configured removed end end |
#set_hints(hints) ⇒ Object
139 140 141 |
# File 'lib/dnsruby/single_verifier.rb', line 139 def set_hints(hints) SingleVerifier.set_recursor_hints(hints) end |
#trust_anchors ⇒ Object
274 275 276 277 278 279 |
# File 'lib/dnsruby/single_verifier.rb', line 274 def trust_anchors @trust_mutex.synchronize do expire_trust_anchors @trust_anchors.keys + @configured_ds_store end end |
#trusted_keys ⇒ Object
464 465 466 467 468 469 470 471 |
# File 'lib/dnsruby/single_verifier.rb', line 464 def trusted_keys keys, configured, discovered = @trust_mutex.synchronize do expire_trust_anchors [cached_trust_keys, @configured_ds_store.dup, @discovered_ds_store.rrsets] end keys.select { |key| usable_cached_key?(key) } + configured + discovered.select { |rrset| usable_provenance?(learned_provenance(rrset)) }.flat_map(&:rrs) end |
#try_to_follow_from_anchor(closest_anchor, msg, qname) ⇒ Object
:nodoc:
2426 2427 2428 |
# File 'lib/dnsruby/single_verifier.rb', line 2426 def try_to_follow_from_anchor(closest_anchor, msg, qname) # :nodoc: with_validation { try_to_follow_from_anchor_internal(closest_anchor, msg, qname) } end |
#validate(msg, query) ⇒ Object
2202 2203 2204 |
# File 'lib/dnsruby/single_verifier.rb', line 2202 def validate(msg, query) with_operational_validation(msg) { validate_internal(msg, query) } end |
#validate_no_rrsigs(msg) ⇒ Object
:nodoc:
2174 2175 2176 |
# File 'lib/dnsruby/single_verifier.rb', line 2174 def validate_no_rrsigs(msg) # :nodoc: with_validation { validate_no_rrsigs_internal(msg) } end |
#validation_cache_identity ⇒ Object
Response/failure caches need a stable, inexpensive identity for the current trust configuration. Additions invalidate response caches without invalidating otherwise valid in-flight learned-trust publication.
284 285 286 287 288 289 |
# File 'lib/dnsruby/single_verifier.rb', line 284 def validation_cache_identity # :nodoc: @trust_mutex.synchronize do expire_trust_anchors [@trust_source_id, @trust_generation, @trust_configuration_generation].freeze end end |
#verify(msg, keys = nil) ⇒ Object
Verify the specified message (or RRSet) using the set of trusted keys. If keys is a DNSKEY, or an Array or RRSet of DNSKEYs, then keys is added to the set of trusted keys before the message (or RRSet) is verified.
If msg is a Dnsruby::Message, then any signed DNSKEY or DS RRSets are processed first, and any new keys are added to the trusted key set before the other RRSets are checked.
msg can be a Dnsruby::Message or Dnsruby::RRSet. keys may be nil, or a KeyCache or an RRSet of Dnsruby::RR::DNSKEY
Returns true if the message verifies OK, and false otherwise.
644 645 646 |
# File 'lib/dnsruby/single_verifier.rb', line 644 def verify(msg, keys = nil) verify_result(msg, keys) == :secure end |
#verify_ds_rrset(ds_rrset, keys = nil, msg = nil, context = {}) ⇒ Object
:nodoc:
1164 1165 1166 |
# File 'lib/dnsruby/single_verifier.rb', line 1164 def verify_ds_rrset(ds_rrset, keys = nil, msg = nil, context = {}) # :nodoc: with_validation { verify_ds_rrset_internal(ds_rrset, keys, msg, context) } end |
#verify_for_validation(msg) ⇒ Object
Cached-key verification for Dnssec's validation fast path uses the same algorithm policy and proof-lifetime accounting as chain discovery.
2208 2209 2210 |
# File 'lib/dnsruby/single_verifier.rb', line 2208 def verify_for_validation(msg) # :nodoc: with_operational_validation(msg) { verify_result(msg) } end |
#verify_key_rrset(key_rrset, keys = nil, context = {}) ⇒ Object
:nodoc:
1191 1192 1193 |
# File 'lib/dnsruby/single_verifier.rb', line 1191 def verify_key_rrset(key_rrset, keys = nil, context = {}) # :nodoc: with_validation { verify_key_rrset_internal(key_rrset, keys, context) } end |
#verify_nsecs(msg, context = nil) ⇒ Object
Check denial at the end of an alias chain, not at the original QNAME. A CNAME-only answer without a negative SOA can legitimately be partial. Positive wildcard proofs are checked when their signatures verify.
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
# File 'lib/dnsruby/single_verifier.rb', line 888 def verify_nsecs(msg, context = nil) # :nodoc: question = msg.question.first return unless question && [RCode.NOERROR, RCode.NXDOMAIN].include?(msg.rcode) name, answered = terminal_answer(msg, question) if trust_operation&.fetch(:insecure_names, {})&.key?([name.canonical, question.qclass.code]) context[:insecure] = true if context return end return if msg.rcode == RCode.NOERROR && answered raise VerifyError, 'NXDOMAIN response contains the requested answer' if answered = context ? context[:sections].fetch('authority') : msg..rrsets klass, qtype = question.qclass, question.qtype soa = .select do |set| set.type == Types.SOA && set.klass == klass && within_zone?(name, set.name) end.max_by { |set| set.name.labels.length } referral = if msg.rcode == RCode.NOERROR && !soa .select do |set| set.type == Types.NS && set.klass == klass && within_zone?(name, set.name) end.max_by { |set| set.name.labels.length } end if referral # A signed delegation with DS needs no denial. An unsigned referral # proves the absence of DS at the delegation, not absence of QTYPE. return if .any? { |set| set.type == Types.DS && set.name == referral.name && set.klass == klass } name, qtype = referral.name, Types.DS elsif msg.rcode == RCode.NOERROR && name != question.qname && !soa return end proofs = .select { |set| [Types.NSEC, Types.NSEC3].include?(set.type) && set.klass == klass } if proofs.empty? raise VerifyError, "Missing denial proof for #{name}" end zone = soa&.name if context && soa signature = context[:verified][soa]&.fetch(:signature) raise VerifyError, 'Negative SOA is not signed by its zone' unless signature && signature.signers_name == zone end groups = {} proofs.each do |set| ValidationBudget.current&.check!(1) signature = context && context[:verified][set]&.fetch(:signature) next if context && !signature signing_zone = signature&.signers_name || (set.type == Types.NSEC3 ? set.name.strip_label : zone) next unless signing_zone && within_zone?(name, signing_zone) next if zone && signing_zone != zone # DS denial at a non-root delegation must come from the parent. next if qtype == Types.DS && name == signing_zone && !name.labels.empty? next if signature && signature.labels != set.name.labels.length && !(set.name.wild? && signature.labels == set.name.labels.length - 1) (groups[[signing_zone, set.type]] ||= []).concat(set.rrs) end insecure = false groups.each do |(signing_zone, type), records| result = if type == Types.NSEC3 nsec3_denial(records, name, qtype, signing_zone, msg.rcode, !!referral) else nsec_denial(records, name, qtype, signing_zone, msg.rcode, !!referral) end if result == :secure return true elsif result == :insecure insecure = true end end if insecure context[:insecure] = true if context if context && (expirations = trust_operation&.fetch(:insecurity_expirations, nil)) expirations << context[:verified].values.map { |verified| verified[:expiration] }.min end return true end raise VerifyError, "No authenticated denial proof for #{name}, #{qtype}" end |
#verify_result(msg, keys = nil) ⇒ Object
:nodoc:
648 649 650 651 652 653 |
# File 'lib/dnsruby/single_verifier.rb', line 648 def verify_result(msg, keys = nil) # :nodoc: with_validation do result = verify_internal(msg, keys) result == true ? :secure : result end end |
#verify_rrset(rrset, keys = nil, context = {}) ⇒ Object
Verify the signature of an rrset encoded with the specified KeyCache or RRSet. If no signature is included, false is returned.
Returns true if the RRSet verified, false otherwise.
1333 1334 1335 |
# File 'lib/dnsruby/single_verifier.rb', line 1333 def verify_rrset(rrset, keys = nil, context = {}) with_validation { verify_rrset_internal(rrset, keys, context) } end |