Class: Dnsruby::Dnssec
- Inherits:
-
Object
- Object
- Dnsruby::Dnssec
- Defined in:
- lib/dnsruby/dnssec.rb
Overview
RFC4033, section 7 "There is one more step that a security-aware stub resolver can take if, for whatever reason, it is not able to establish a useful trust relationship with the recursive name servers that it uses: it can perform its own signature validation by setting the Checking Disabled (CD) bit in its query messages. A validating stub resolver is thus able to treat the DNSSEC signatures as trust relationships between the zone administrators and the stub resolver itself. "
Resolver queries do not validate responses by default; set Resolver#do_validation to true to enable validation. Root DS trust anchors are configured below. Applications may also use verify() to verify RRSets or Messages with given keys, or add their own trust anchors to this class.
Messages are tagged with the current security_level (Message::SecurityLevel). UNCHECKED means Dnsruby has not attempted to validate the response. BOGUS means the response has been checked, and is bogus. INSECURE means the response has been validated to be insecure (e.g. in an unsigned zone) SECURE means that the response has been verfied to be correct.
Several validators are provided, with each maintaining its own cache of trusted keys. If validators are added or removed, the caches of the other validators are not affected.
Defined Under Namespace
Classes: ValidationPolicy
Constant Summary collapse
- ROOT_TRUST_ANCHORS =
#NOTE# You may wish to import these via a secure channel yourself, if using Dnsruby for validation. KSK-2017 and KSK-2024, published at https://data.iana.org/root-anchors/root-anchors.xml
[ ". IN DS 20326 8 2 E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D".freeze, ". IN DS 38696 8 2 683D2D0ACB8C9B712A1948B27F741219298D0A450D612C483AF444A4C0FB2B16".freeze ].freeze
- @@validation_policy =
ValidationPolicy::LOCAL_ANCHORS_THEN_ROOT
- @@root_verifier =
SingleVerifier.new(SingleVerifier::VerifierType::ROOT)
- @@dlv_verifier =
SingleVerifier.new(SingleVerifier::VerifierType::DLV)
- @@anchor_verifier =
@TODO@ Could add a new one of these for each anchor.
SingleVerifier.new(SingleVerifier::VerifierType::ANCHOR)
- @@do_validation_with_recursor =
Many nameservers don't handle DNSSEC correctly yet
true- @@default_resolver =
Resolver.new
Class Method Summary collapse
-
.add_trust_anchor_with_expiration(k, expiration) ⇒ Object
Add the trusted key with the given expiration time.
- .anchor_verifier ⇒ Object
-
.clear_trust_anchors ⇒ Object
Remove all local trust anchors and keys learned from them.
-
.clear_trusted_keys ⇒ Object
Clear learned keys and all DS/DLV anchors, including the built-in root DS anchors.
- .default_resolver ⇒ Object
-
.default_resolver=(res) ⇒ Object
This method overrides the system default resolver configuration for validation If default_resolver is set, then it will be used to follow the chain of trust.
- .dlv_verifier ⇒ Object
-
.do_validation_with_recursor(on) ⇒ Object
This method defines the choice of Resolver or Recursor, when the validator is checking responses.
- .do_validation_with_recursor? ⇒ Boolean
- .no_keys? ⇒ Boolean
- .reset ⇒ Object
- .root_verifier ⇒ Object
- .set_hints(hints) ⇒ Object
- .trust_anchors ⇒ Object
-
.try_validation(last_level, last_error, last_error_level, proc, msg, query) ⇒ Object
:nodoc:.
-
.validate(msg) ⇒ Object
Returns true for secure/insecure, false otherwise This method will set the security_level on msg to the appropriate value.
- .validate_with_anchors(msg, query) ⇒ Object
- .validate_with_dlv(msg, query) ⇒ Object
- .validate_with_query(query, msg) ⇒ Object
- .validate_with_root(msg, query) ⇒ Object
- .validation_limits ⇒ Object
- .validation_limits=(limits) ⇒ Object
- .verify(msg, keys = nil) ⇒ Object
- .verify_rrset(rrset, keys = nil) ⇒ Object
Class Method Details
.add_trust_anchor_with_expiration(k, expiration) ⇒ Object
Add the trusted key with the given expiration time
120 121 122 123 |
# File 'lib/dnsruby/dnssec.rb', line 120 def self.add_trust_anchor_with_expiration(k, expiration) # Create a new verifier? @@anchor_verifier.add_trust_anchor_with_expiration(k, expiration) end |
.anchor_verifier ⇒ Object
391 392 393 |
# File 'lib/dnsruby/dnssec.rb', line 391 def self.anchor_verifier return @@anchor_verifier end |
.clear_trust_anchors ⇒ Object
Remove all local trust anchors and keys learned from them. Built-in root anchors are unaffected.
130 131 132 |
# File 'lib/dnsruby/dnssec.rb', line 130 def self.clear_trust_anchors @@anchor_verifier.clear_trust_anchors end |
.clear_trusted_keys ⇒ Object
Clear learned keys and all DS/DLV anchors, including the built-in root DS anchors. Configured DNSKEY anchors are retained.
140 141 142 143 144 |
# File 'lib/dnsruby/dnssec.rb', line 140 def self.clear_trusted_keys [@@anchor_verifier, @@root_verifier, @@dlv_verifier].each {|v| v.clear_trusted_keys } end |
.default_resolver ⇒ Object
194 195 196 |
# File 'lib/dnsruby/dnssec.rb', line 194 def self.default_resolver return @@default_resolver end |
.default_resolver=(res) ⇒ Object
This method overrides the system default resolver configuration for validation If default_resolver is set, then it will be used to follow the chain of trust. If it is not, then the default system resolver will be used (unless do_validation_with_recursor is set.
191 192 193 |
# File 'lib/dnsruby/dnssec.rb', line 191 def self.default_resolver=(res) @@default_resolver = res end |
.dlv_verifier ⇒ Object
394 395 396 |
# File 'lib/dnsruby/dnssec.rb', line 394 def self.dlv_verifier return @@dlv_verifier end |
.do_validation_with_recursor(on) ⇒ Object
This method defines the choice of Resolver or Recursor, when the validator is checking responses. If set to true, then a Recursor will be used to query for the DNSSEC records. Otherwise, the default system resolver will be used.
181 182 183 |
# File 'lib/dnsruby/dnssec.rb', line 181 def self.do_validation_with_recursor(on) @@do_validation_with_recursor = on end |
.do_validation_with_recursor? ⇒ Boolean
184 185 186 |
# File 'lib/dnsruby/dnssec.rb', line 184 def self.do_validation_with_recursor? return @@do_validation_with_recursor end |
.no_keys? ⇒ Boolean
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/dnsruby/dnssec.rb', line 164 def self.no_keys? no_keys = true [@@anchor_verifier, @@root_verifier, @@dlv_verifier].each {|v| if (v.trusted_keys.length() > 0 || v.trust_anchors.length() > 0) no_keys = false end } return no_keys end |
.reset ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/dnsruby/dnssec.rb', line 146 def self.reset SingleVerifier.set_recursor_hints(nil) @@validation_policy = ValidationPolicy::LOCAL_ANCHORS_THEN_ROOT @@root_verifier = SingleVerifier.new(SingleVerifier::VerifierType::ROOT) ROOT_TRUST_ANCHORS.each {|ds| @@root_verifier.add_root_ds(RR.create(ds))} @@dlv_verifier = SingleVerifier.new(SingleVerifier::VerifierType::DLV) # @TODO@ Could add a new one of these for each anchor. @@anchor_verifier = SingleVerifier.new(SingleVerifier::VerifierType::ANCHOR) @@do_validation_with_recursor = true # Many nameservers don't handle DNSSEC correctly yet @@default_resolver = Resolver.new end |
.root_verifier ⇒ Object
397 398 399 |
# File 'lib/dnsruby/dnssec.rb', line 397 def self.root_verifier return @@root_verifier end |
.set_hints(hints) ⇒ Object
160 161 162 |
# File 'lib/dnsruby/dnssec.rb', line 160 def self.set_hints(hints) SingleVerifier.set_recursor_hints(hints) end |
.trust_anchors ⇒ Object
134 135 136 |
# File 'lib/dnsruby/dnssec.rb', line 134 def self.trust_anchors return @@anchor_verifier.trust_anchors end |
.try_validation(last_level, last_error, last_error_level, proc, msg, query) ⇒ Object
:nodoc:
297 298 299 300 301 |
# File 'lib/dnsruby/dnssec.rb', line 297 def self.try_validation(last_level, last_error, last_error_level, proc, msg, query) # :nodoc: ValidationBudget.with do try_validation_internal(last_level, last_error, last_error_level, proc, msg, query) end end |
.validate(msg) ⇒ Object
Returns true for secure/insecure, false otherwise This method will set the security_level on msg to the appropriate value. Could be : secure, insecure, bogus or indeterminate If an error is encountered during verification, then the thrown exception will define the error.
203 204 205 206 207 |
# File 'lib/dnsruby/dnssec.rb', line 203 def self.validate(msg) query = Message.new() query.header.cd=true validate_with_query(query, msg) end |
.validate_with_anchors(msg, query) ⇒ Object
332 333 334 |
# File 'lib/dnsruby/dnssec.rb', line 332 def self.validate_with_anchors(msg, query) @@anchor_verifier.validate(msg, query) end |
.validate_with_dlv(msg, query) ⇒ Object
340 341 342 |
# File 'lib/dnsruby/dnssec.rb', line 340 def self.validate_with_dlv(msg, query) @@dlv_verifier.validate(msg, query) end |
.validate_with_query(query, msg) ⇒ Object
209 210 211 |
# File 'lib/dnsruby/dnssec.rb', line 209 def self.validate_with_query(query, msg) ValidationBudget.with { validate_with_query_internal(query, msg) } end |
.validate_with_root(msg, query) ⇒ Object
336 337 338 |
# File 'lib/dnsruby/dnssec.rb', line 336 def self.validate_with_root(msg, query) @@root_verifier.validate(msg, query) end |
.validation_limits ⇒ Object
48 49 50 |
# File 'lib/dnsruby/dnssec.rb', line 48 def self.validation_limits @validation_limits end |
.validation_limits=(limits) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dnsruby/dnssec.rb', line 52 def self.validation_limits=(limits) unknown = limits.keys - ValidationBudget::DEFAULT_LIMITS.keys raise ArgumentError, "Unknown DNSSEC validation limits: #{unknown.join(', ')}" unless unknown.empty? merged = ValidationBudget::DEFAULT_LIMITS.merge(limits) merged.each do |key, value| valid = key == :timeout ? value.is_a?(Numeric) && value.finite? && value > 0 : value.is_a?(Integer) && value > 0 raise ArgumentError, "Invalid DNSSEC validation limit #{key}" unless valid end @validation_limits = merged.freeze end |
.verify(msg, keys = nil) ⇒ Object
344 345 346 |
# File 'lib/dnsruby/dnssec.rb', line 344 def self.verify(msg, keys=nil) verify_result(msg, keys) == :secure end |
.verify_rrset(rrset, keys = nil) ⇒ Object
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/dnsruby/dnssec.rb', line 404 def self.verify_rrset(rrset, keys = nil) ValidationBudget.with do last_error = nil verified = [@@anchor_verifier, @@root_verifier, @@dlv_verifier].any? do |verifier| ValidationBudget.current.check! begin verifier.verify_rrset(rrset, keys) rescue ValidationLimitError raise rescue VerifyError => error last_error = error false end end raise last_error if !verified && last_error verified end end |