dnsruby 1.55 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +96 -0
- data/Rakefile +30 -29
- data/demo/axfr.rb +93 -93
- data/demo/check_soa.rb +99 -99
- data/demo/check_zone.rb +59 -59
- data/demo/digdlv.rb +43 -43
- data/demo/digroot.rb +34 -34
- data/demo/example_recurse.rb +14 -14
- data/demo/mresolv.rb +30 -30
- data/demo/mx.rb +31 -31
- data/demo/rubydig.rb +37 -37
- data/demo/to_resolve.txt +3088 -3088
- data/demo/trace_dns.rb +46 -46
- data/lib/dnsruby.rb +161 -526
- data/lib/dnsruby/DNS.rb +305 -0
- data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
- data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
- data/lib/dnsruby/code_mappers.rb +295 -0
- data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
- data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
- data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
- data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
- data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
- data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
- data/lib/dnsruby/message/decoder.rb +164 -0
- data/lib/dnsruby/message/encoder.rb +75 -0
- data/lib/dnsruby/message/header.rb +249 -0
- data/lib/dnsruby/message/message.rb +629 -0
- data/lib/dnsruby/message/question.rb +86 -0
- data/lib/dnsruby/message/section.rb +96 -0
- data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
- data/lib/dnsruby/packet_sender.rb +661 -0
- data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
- data/lib/dnsruby/resolv.rb +113 -0
- data/lib/dnsruby/resolver.rb +1192 -0
- data/lib/dnsruby/resource/A.rb +56 -0
- data/lib/dnsruby/resource/AAAA.rb +54 -0
- data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
- data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
- data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
- data/lib/dnsruby/resource/DLV.rb +27 -0
- data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
- data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
- data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
- data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
- data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
- data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
- data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
- data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
- data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
- data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
- data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
- data/lib/dnsruby/resource/NSEC.rb +275 -0
- data/lib/dnsruby/resource/NSEC3.rb +332 -0
- data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
- data/lib/dnsruby/resource/OPT.rb +272 -0
- data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
- data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
- data/lib/dnsruby/resource/RR.rb +421 -0
- data/lib/dnsruby/resource/RRSIG.rb +275 -0
- data/lib/dnsruby/resource/RRSet.rb +190 -0
- data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
- data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
- data/lib/dnsruby/resource/SPF.rb +29 -0
- data/lib/dnsruby/resource/SRV.rb +112 -0
- data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
- data/lib/dnsruby/resource/TKEY.rb +163 -0
- data/lib/dnsruby/resource/TSIG.rb +593 -0
- data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
- data/lib/dnsruby/resource/X25.rb +55 -0
- data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
- data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
- data/lib/dnsruby/resource/resource.rb +25 -0
- data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
- data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
- data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
- data/lib/dnsruby/the_log.rb +44 -0
- data/lib/dnsruby/update.rb +278 -0
- data/lib/dnsruby/validator_thread.rb +124 -0
- data/lib/dnsruby/version.rb +3 -0
- data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
- data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
- data/test/spec_helper.rb +16 -0
- data/test/tc_axfr.rb +31 -34
- data/test/tc_cache.rb +32 -32
- data/test/tc_dlv.rb +28 -28
- data/test/tc_dns.rb +73 -76
- data/test/tc_dnskey.rb +31 -32
- data/test/tc_dnsruby.rb +50 -44
- data/test/tc_ds.rb +36 -36
- data/test/tc_escapedchars.rb +252 -255
- data/test/tc_hash.rb +17 -21
- data/test/tc_header.rb +48 -57
- data/test/tc_hip.rb +19 -22
- data/test/tc_ipseckey.rb +18 -21
- data/test/tc_keith.rb +300 -0
- data/test/tc_message.rb +87 -0
- data/test/tc_misc.rb +83 -87
- data/test/tc_name.rb +81 -84
- data/test/tc_naptr.rb +18 -21
- data/test/tc_nsec.rb +55 -55
- data/test/tc_nsec3.rb +23 -24
- data/test/tc_nsec3param.rb +20 -21
- data/test/tc_packet.rb +90 -93
- data/test/tc_packet_unique_push.rb +48 -51
- data/test/tc_question.rb +30 -33
- data/test/tc_queue.rb +16 -17
- data/test/tc_recur.rb +16 -17
- data/test/tc_res_config.rb +38 -41
- data/test/tc_res_env.rb +29 -32
- data/test/tc_res_file.rb +26 -29
- data/test/tc_res_opt.rb +62 -65
- data/test/tc_resolver.rb +287 -242
- data/test/tc_rr-opt.rb +70 -63
- data/test/tc_rr-txt.rb +68 -71
- data/test/tc_rr-unknown.rb +45 -48
- data/test/tc_rr.rb +76 -70
- data/test/tc_rrset.rb +21 -22
- data/test/tc_rrsig.rb +19 -20
- data/test/tc_single_resolver.rb +294 -297
- data/test/tc_soak.rb +199 -202
- data/test/tc_soak_base.rb +29 -34
- data/test/tc_sshfp.rb +20 -23
- data/test/tc_tcp.rb +32 -35
- data/test/tc_tkey.rb +41 -44
- data/test/tc_tsig.rb +81 -84
- data/test/tc_update.rb +108 -111
- data/test/tc_validator.rb +29 -29
- data/test/tc_verifier.rb +81 -82
- data/test/ts_dnsruby.rb +16 -15
- data/test/ts_offline.rb +62 -63
- data/test/ts_online.rb +115 -115
- metadata +155 -90
- data/README +0 -59
- data/lib/Dnsruby/DNS.rb +0 -305
- data/lib/Dnsruby/PacketSender.rb +0 -656
- data/lib/Dnsruby/Resolver.rb +0 -1189
- data/lib/Dnsruby/TheLog.rb +0 -44
- data/lib/Dnsruby/message.rb +0 -1230
- data/lib/Dnsruby/resource/A.rb +0 -56
- data/lib/Dnsruby/resource/AAAA.rb +0 -54
- data/lib/Dnsruby/resource/DLV.rb +0 -27
- data/lib/Dnsruby/resource/NSEC.rb +0 -298
- data/lib/Dnsruby/resource/NSEC3.rb +0 -340
- data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
- data/lib/Dnsruby/resource/OPT.rb +0 -213
- data/lib/Dnsruby/resource/RRSIG.rb +0 -275
- data/lib/Dnsruby/resource/SPF.rb +0 -29
- data/lib/Dnsruby/resource/SRV.rb +0 -112
- data/lib/Dnsruby/resource/TKEY.rb +0 -163
- data/lib/Dnsruby/resource/TSIG.rb +0 -593
- data/lib/Dnsruby/resource/X25.rb +0 -55
- data/lib/Dnsruby/resource/resource.rb +0 -678
- data/lib/Dnsruby/update.rb +0 -278
- data/lib/Dnsruby/validator_thread.rb +0 -124
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
#Copyright 2007 Nominet UK
|
|
3
|
-
#
|
|
4
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
#you may not use this file except in compliance with the License.
|
|
6
|
-
#You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
#Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
#See the License f181or the specific language governing permissions and
|
|
14
|
-
#limitations under the License.
|
|
15
|
-
|
|
1
|
+
# --
|
|
2
|
+
# Copyright 2007 Nominet UK
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License f181or the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ++
|
|
16
16
|
require 'digest/sha2'
|
|
17
17
|
require 'net/ftp'
|
|
18
|
-
require '
|
|
19
|
-
require '
|
|
18
|
+
require 'dnsruby/key_cache'
|
|
19
|
+
require 'dnsruby/single_verifier'
|
|
20
20
|
module Dnsruby
|
|
21
21
|
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
22
|
+
# RFC4033, section 7
|
|
23
|
+
# "There is one more step that a security-aware stub resolver can take
|
|
24
|
+
# if, for whatever reason, it is not able to establish a useful trust
|
|
25
|
+
# relationship with the recursive name servers that it uses: it can
|
|
26
|
+
# perform its own signature validation by setting the Checking Disabled
|
|
27
|
+
# (CD) bit in its query messages. A validating stub resolver is thus
|
|
28
|
+
# able to treat the DNSSEC signatures as trust relationships between
|
|
29
|
+
# the zone administrators and the stub resolver itself. "
|
|
30
|
+
#
|
|
31
|
+
# Dnsruby is configured to validate responses by default. However, it is not
|
|
32
|
+
# configured with any trusted keys by default. Applications may use the
|
|
33
|
+
# verify() method to perform verification with of RRSets of Messages with
|
|
34
|
+
# given keys. Alternatively, trusted keys may be added to this class (either
|
|
35
|
+
# directly, or by loading the IANA TAR or the DLV ISC ZSK). Validation will then
|
|
36
|
+
# be performed from these keys (or the DLV registry, if configured). Negative
|
|
37
|
+
# and positive responses are validation.
|
|
38
|
+
#
|
|
39
|
+
# Messages are tagged with the current security_level (Message::SecurityLevel).
|
|
40
|
+
# UNCHECKED means Dnsruby has not attempted to validate the response.
|
|
41
|
+
# BOGUS means the response has been checked, and is bogus.
|
|
42
|
+
# INSECURE means the response has been validated to be insecure (e.g. in an unsigned zone)
|
|
43
|
+
# SECURE means that the response has been verfied to be correct.
|
|
44
|
+
#
|
|
45
|
+
# Several validators are provided, with each maintaining its own cache of trusted keys.
|
|
46
|
+
# If validators are added or removed, the caches of the other validators are not affected.
|
|
47
47
|
class Dnssec
|
|
48
|
-
#
|
|
48
|
+
# A class to cache trusted keys
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
class ValidationPolicy
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
# @TODO@ Could do this by getting client to add verifiers in the order they
|
|
53
|
+
# want them to be used. Could then dispense with all this logic
|
|
54
|
+
# Note that any DLV registries which have been configured will only be tried
|
|
55
|
+
# after both the root and any local trust anchors (RFC 5074 section 5)
|
|
56
|
+
|
|
57
|
+
# * Always use the root and ignore local trust anchors.
|
|
58
58
|
ALWAYS_ROOT_ONLY = 1
|
|
59
|
-
|
|
59
|
+
# * Use the root if successful, otherwise try local anchors.
|
|
60
60
|
ROOT_THEN_LOCAL_ANCHORS = 2
|
|
61
|
-
|
|
61
|
+
# * Use local trust anchors if available, otherwise use root.
|
|
62
62
|
LOCAL_ANCHORS_THEN_ROOT = 3
|
|
63
|
-
|
|
63
|
+
# * Always use local trust anchors and ignore the root.
|
|
64
64
|
ALWAYS_LOCAL_ANCHORS_ONLY = 4
|
|
65
65
|
end
|
|
66
66
|
@@validation_policy = ValidationPolicy::LOCAL_ANCHORS_THEN_ROOT
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
def Dnssec.validation_policy=(p)
|
|
69
69
|
if ((p >= ALWAYS_ROOT_ONY) && (p <= ALWAYS_LOCAL_ANCHORS))
|
|
70
70
|
@@validation_policy = p
|
|
71
|
-
#
|
|
71
|
+
# @TODO@ Should we be clearing the trusted keys now?
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
def Dnssec.validation_policy
|
|
@@ -77,40 +77,40 @@ module Dnsruby
|
|
|
77
77
|
|
|
78
78
|
@@root_verifier = SingleVerifier.new(SingleVerifier::VerifierType::ROOT)
|
|
79
79
|
|
|
80
|
-
#
|
|
81
|
-
#
|
|
80
|
+
# #NOTE# You may wish to import these via a secure channel yourself, if
|
|
81
|
+
# using Dnsruby for validation.
|
|
82
82
|
@@root_key = RR.create(". IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5")
|
|
83
83
|
@@root_verifier.add_root_ds(@@root_key)
|
|
84
84
|
|
|
85
85
|
@@dlv_verifier = SingleVerifier.new(SingleVerifier::VerifierType::DLV)
|
|
86
86
|
|
|
87
|
-
#
|
|
87
|
+
# @TODO@ Could add a new one of these for each anchor.
|
|
88
88
|
@@anchor_verifier = SingleVerifier.new(SingleVerifier::VerifierType::ANCHOR)
|
|
89
89
|
|
|
90
90
|
|
|
91
|
-
#
|
|
91
|
+
# Add a trusted Key Signing Key for the ISC DLV registry.
|
|
92
92
|
def Dnssec.add_dlv_key(dlv_key)
|
|
93
93
|
@@dlv_verifier.add_dlv_key(dlv_key)
|
|
94
94
|
end
|
|
95
|
-
#
|
|
95
|
+
# Add a new trust anchor
|
|
96
96
|
def Dnssec.add_trust_anchor(t)
|
|
97
|
-
#
|
|
97
|
+
# @TODO@ Create a new verifier?
|
|
98
98
|
@@anchor_verifier.add_trust_anchor(t)
|
|
99
99
|
end
|
|
100
|
-
#
|
|
100
|
+
# Add the trusted key with the given expiration time
|
|
101
101
|
def self.add_trust_anchor_with_expiration(k, expiration)
|
|
102
|
-
#
|
|
102
|
+
# Create a new verifier?
|
|
103
103
|
@@anchor_verifier.add_trust_anchor_with_expiration(k, expiration)
|
|
104
104
|
end
|
|
105
|
-
#
|
|
105
|
+
# Remove the trusted key
|
|
106
106
|
def Dnssec.remove_trust_anchor(t)
|
|
107
107
|
@@anchor_verifier.remove_trust_anchor(t)
|
|
108
108
|
end
|
|
109
|
-
#
|
|
109
|
+
# Wipes the cache of trusted keys
|
|
110
110
|
def self.clear_trust_anchors
|
|
111
111
|
@@anchor_verifier.clear_trust_anchors
|
|
112
112
|
end
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
def self.trust_anchors
|
|
115
115
|
return @@anchor_verifier.trust_anchors
|
|
116
116
|
end
|
|
@@ -128,7 +128,7 @@ module Dnsruby
|
|
|
128
128
|
|
|
129
129
|
@@dlv_verifier = SingleVerifier.new(SingleVerifier::VerifierType::DLV)
|
|
130
130
|
|
|
131
|
-
#
|
|
131
|
+
# @TODO@ Could add a new one of these for each anchor.
|
|
132
132
|
@@anchor_verifier = SingleVerifier.new(SingleVerifier::VerifierType::ANCHOR)
|
|
133
133
|
@@do_validation_with_recursor = true # Many nameservers don't handle DNSSEC correctly yet
|
|
134
134
|
@@default_resolver = Resolver.new
|
|
@@ -152,20 +152,20 @@ module Dnsruby
|
|
|
152
152
|
|
|
153
153
|
@@do_validation_with_recursor = true # Many nameservers don't handle DNSSEC correctly yet
|
|
154
154
|
@@default_resolver = Resolver.new
|
|
155
|
-
#
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
155
|
+
# This method defines the choice of Resolver or Recursor, when the validator
|
|
156
|
+
# is checking responses.
|
|
157
|
+
# If set to true, then a Recursor will be used to query for the DNSSEC records.
|
|
158
|
+
# Otherwise, the default system resolver will be used.
|
|
159
159
|
def self.do_validation_with_recursor(on)
|
|
160
160
|
@@do_validation_with_recursor = on
|
|
161
161
|
end
|
|
162
162
|
def self.do_validation_with_recursor?
|
|
163
163
|
return @@do_validation_with_recursor
|
|
164
164
|
end
|
|
165
|
-
#
|
|
166
|
-
#
|
|
167
|
-
#
|
|
168
|
-
#
|
|
165
|
+
# This method overrides the system default resolver configuration for validation
|
|
166
|
+
# If default_resolver is set, then it will be used to follow the chain of trust.
|
|
167
|
+
# If it is not, then the default system resolver will be used (unless do_validation_with_recursor
|
|
168
|
+
# is set.
|
|
169
169
|
def self.default_resolver=(res)
|
|
170
170
|
@@default_resolver = res
|
|
171
171
|
end
|
|
@@ -173,22 +173,22 @@ module Dnsruby
|
|
|
173
173
|
return @@default_resolver
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
-
#
|
|
177
|
-
#
|
|
178
|
-
#
|
|
179
|
-
#
|
|
180
|
-
#
|
|
176
|
+
# Returns true for secure/insecure, false otherwise
|
|
177
|
+
# This method will set the security_level on msg to the appropriate value.
|
|
178
|
+
# Could be : secure, insecure, bogus or indeterminate
|
|
179
|
+
# If an error is encountered during verification, then the thrown exception
|
|
180
|
+
# will define the error.
|
|
181
181
|
def self.validate(msg)
|
|
182
182
|
query = Message.new()
|
|
183
183
|
query.header.cd=true
|
|
184
184
|
return self.validate_with_query(query, msg)
|
|
185
185
|
end
|
|
186
|
-
|
|
186
|
+
|
|
187
187
|
def self.validate_with_query(query, msg)
|
|
188
188
|
if (!msg)
|
|
189
189
|
return false
|
|
190
190
|
end
|
|
191
|
-
#
|
|
191
|
+
# First, just check there is something to validate!
|
|
192
192
|
found_sigs = false
|
|
193
193
|
msg.each_resource {|rr|
|
|
194
194
|
if (rr.type == Types::RRSIG)
|
|
@@ -206,16 +206,16 @@ module Dnsruby
|
|
|
206
206
|
end
|
|
207
207
|
end
|
|
208
208
|
|
|
209
|
-
#
|
|
210
|
-
#
|
|
209
|
+
# SHOULD ALWAYS VERIFY DNSSEC-SIGNED RESPONSES?
|
|
210
|
+
# Yes - if a trust anchor is configured. Otherwise, act on CD bit (in query)
|
|
211
211
|
TheLog.debug("Checking whether to validate, query.cd = #{query.header.cd}")
|
|
212
212
|
if (((@@validation_policy > ValidationPolicy::ALWAYS_ROOT_ONLY) && (self.trust_anchors().length > 0)) ||
|
|
213
|
-
#
|
|
213
|
+
# Check query here, and validate if CD is true
|
|
214
214
|
((query.header.cd == true))) # && (query.do_validation)))
|
|
215
215
|
TheLog.debug("Starting validation")
|
|
216
216
|
|
|
217
|
-
#
|
|
218
|
-
#
|
|
217
|
+
# Validate!
|
|
218
|
+
# Need to think about trapping/storing exceptions and security_levels here
|
|
219
219
|
last_error = ""
|
|
220
220
|
last_level = Message::SecurityLevel.BOGUS
|
|
221
221
|
last_error_level = Message::SecurityLevel.BOGUS
|
|
@@ -226,7 +226,7 @@ module Dnsruby
|
|
|
226
226
|
last_level, last_error, last_error_level = try_validation(last_level, last_error, last_error_level,
|
|
227
227
|
Proc.new{|m, q| validate_with_root(m, q)}, msg, query)
|
|
228
228
|
elsif (@@validation_policy == ValidationPolicy::LOCAL_ANCHORS_THEN_ROOT)
|
|
229
|
-
last_level, last_error, last_error_level = try_validation(last_level, last_error, last_error_level,
|
|
229
|
+
last_level, last_error, last_error_level = try_validation(last_level, last_error, last_error_level,
|
|
230
230
|
Proc.new{|m, q| validate_with_anchors(m, q)}, msg, query)
|
|
231
231
|
if (last_level != Message::SecurityLevel.SECURE)
|
|
232
232
|
last_level, last_error, last_error_level = try_validation(last_level, last_error, last_error_level,
|
|
@@ -241,10 +241,10 @@ module Dnsruby
|
|
|
241
241
|
end
|
|
242
242
|
end
|
|
243
243
|
if (last_level != Message::SecurityLevel.SECURE)
|
|
244
|
-
last_level, last_error, last_error_level = try_validation(last_level, last_error, last_error_level,
|
|
244
|
+
last_level, last_error, last_error_level = try_validation(last_level, last_error, last_error_level,
|
|
245
245
|
Proc.new{|m, q| validate_with_dlv(m, q)}, msg, query)
|
|
246
246
|
end
|
|
247
|
-
#
|
|
247
|
+
# Set the message security level!
|
|
248
248
|
msg.security_level = last_level
|
|
249
249
|
msg.security_error = last_error
|
|
250
250
|
raise VerifyError.new(last_error) if (last_level < 0)
|
|
@@ -266,7 +266,7 @@ module Dnsruby
|
|
|
266
266
|
end
|
|
267
267
|
return last_level, last_error, last_error_level
|
|
268
268
|
end
|
|
269
|
-
|
|
269
|
+
|
|
270
270
|
def self.validate_with_anchors(msg, query)
|
|
271
271
|
return @@anchor_verifier.validate(msg, query)
|
|
272
272
|
end
|
|
@@ -310,4 +310,4 @@ module Dnsruby
|
|
|
310
310
|
@@dlv_verifier.verify_rrset(rrset, keys)))
|
|
311
311
|
end
|
|
312
312
|
end
|
|
313
|
-
end
|
|
313
|
+
end
|
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
#Copyright 2007 Nominet UK
|
|
3
|
-
#
|
|
4
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
#you may not use this file except in compliance with the License.
|
|
6
|
-
#You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
#Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
#See the License for the specific language governing permissions and
|
|
14
|
-
#limitations under the License.
|
|
15
|
-
|
|
16
|
-
module Dnsruby
|
|
17
|
-
|
|
18
|
-
#Dnsruby::Hosts is a hostname resolver that uses the system hosts file
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
#
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# address lookup methods.
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
# hostnames lookup methods.
|
|
33
|
-
#
|
|
34
|
-
class Hosts
|
|
35
|
-
if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
|
|
36
|
-
require 'win32/resolv'
|
|
37
|
-
DefaultFileName = Win32::Resolv.get_hosts_path
|
|
38
|
-
else
|
|
39
|
-
DefaultFileName = '/etc/hosts'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
#Creates a new Dnsruby::Hosts using +filename+ for its data source
|
|
43
|
-
def initialize(filename = DefaultFileName)
|
|
44
|
-
@filename = filename
|
|
45
|
-
@mutex = Mutex.new
|
|
46
|
-
@initialized = nil
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def lazy_initialize# :nodoc:
|
|
50
|
-
@mutex.synchronize {
|
|
51
|
-
unless @initialized
|
|
52
|
-
@name2addr = {}
|
|
53
|
-
@addr2name = {}
|
|
54
|
-
begin
|
|
55
|
-
open(@filename) {|f|
|
|
56
|
-
f.each {|line|
|
|
57
|
-
line.sub!(/#.*/, '')
|
|
58
|
-
addr, hostname, *aliases = line.split(/\s+/)
|
|
59
|
-
next unless addr
|
|
60
|
-
addr.untaint
|
|
61
|
-
hostname.untaint
|
|
62
|
-
@addr2name[addr] = [] unless @addr2name.include? addr
|
|
63
|
-
@addr2name[addr] << hostname
|
|
64
|
-
@addr2name[addr] += aliases
|
|
65
|
-
@name2addr[hostname] = [] unless @name2addr.include? hostname
|
|
66
|
-
@name2addr[hostname] << addr
|
|
67
|
-
aliases.each {|n|
|
|
68
|
-
n.untaint
|
|
69
|
-
@name2addr[n] = [] unless @name2addr.include? n
|
|
70
|
-
@name2addr[n] << addr
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
rescue Exception
|
|
75
|
-
#
|
|
76
|
-
end
|
|
77
|
-
@name2addr.each {|name, arr| arr.reverse!}
|
|
78
|
-
@initialized = true
|
|
79
|
-
end
|
|
80
|
-
}
|
|
81
|
-
self
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
#Gets the first IP address for +name+ from the hosts file
|
|
85
|
-
def getaddress(name)
|
|
86
|
-
each_address(name) {|address| return address}
|
|
87
|
-
raise ResolvError.new("#{@filename} has no name: #{name}")
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
#Gets all IP addresses for +name+ from the hosts file
|
|
91
|
-
def getaddresses(name)
|
|
92
|
-
ret = []
|
|
93
|
-
each_address(name) {|address| ret << address}
|
|
94
|
-
return ret
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
#Iterates over all IP addresses for +name+ retrieved from the hosts file
|
|
98
|
-
def each_address(name, &proc)
|
|
99
|
-
lazy_initialize
|
|
100
|
-
if @name2addr.include?(name)
|
|
101
|
-
@name2addr[name].each(&proc)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
#Gets the first hostname of +address+ from the hosts file
|
|
106
|
-
def getname(address)
|
|
107
|
-
each_name(address) {|name| return name}
|
|
108
|
-
raise ResolvError.new("#{@filename} has no address: #{address}")
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
#Gets all hostnames for +address+ from the hosts file
|
|
112
|
-
def getnames(address)
|
|
113
|
-
ret = []
|
|
114
|
-
each_name(address) {|name| ret << name}
|
|
115
|
-
return ret
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
#Iterates over all hostnames for +address+ retrieved from the hosts file
|
|
119
|
-
def each_name(address, &proc)
|
|
120
|
-
lazy_initialize
|
|
121
|
-
if @addr2name.include?(address)
|
|
122
|
-
@addr2name[address].each(&proc)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
1
|
+
# --
|
|
2
|
+
# Copyright 2007 Nominet UK
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ++
|
|
16
|
+
module Dnsruby
|
|
17
|
+
# == Dnsruby::Hosts class
|
|
18
|
+
# Dnsruby::Hosts is a hostname resolver that uses the system hosts file
|
|
19
|
+
#
|
|
20
|
+
# === class methods
|
|
21
|
+
# * Dnsruby::Hosts.new(hosts='/etc/hosts')
|
|
22
|
+
#
|
|
23
|
+
# === methods
|
|
24
|
+
# * Dnsruby::Hosts#getaddress(name)
|
|
25
|
+
# * Dnsruby::Hosts#getaddresses(name)
|
|
26
|
+
# * Dnsruby::Hosts#each_address(name) {|address| ...}
|
|
27
|
+
# address lookup methods.
|
|
28
|
+
#
|
|
29
|
+
# * Dnsruby::Hosts#getname(address)
|
|
30
|
+
# * Dnsruby::Hosts#getnames(address)
|
|
31
|
+
# * Dnsruby::Hosts#each_name(address) {|name| ...}
|
|
32
|
+
# hostnames lookup methods.
|
|
33
|
+
#
|
|
34
|
+
class Hosts
|
|
35
|
+
if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
|
|
36
|
+
require 'win32/resolv'
|
|
37
|
+
DefaultFileName = Win32::Resolv.get_hosts_path
|
|
38
|
+
else
|
|
39
|
+
DefaultFileName = '/etc/hosts'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Creates a new Dnsruby::Hosts using +filename+ for its data source
|
|
43
|
+
def initialize(filename = DefaultFileName)
|
|
44
|
+
@filename = filename
|
|
45
|
+
@mutex = Mutex.new
|
|
46
|
+
@initialized = nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def lazy_initialize# :nodoc:
|
|
50
|
+
@mutex.synchronize {
|
|
51
|
+
unless @initialized
|
|
52
|
+
@name2addr = {}
|
|
53
|
+
@addr2name = {}
|
|
54
|
+
begin
|
|
55
|
+
open(@filename) {|f|
|
|
56
|
+
f.each {|line|
|
|
57
|
+
line.sub!(/#.*/, '')
|
|
58
|
+
addr, hostname, *aliases = line.split(/\s+/)
|
|
59
|
+
next unless addr
|
|
60
|
+
addr.untaint
|
|
61
|
+
hostname.untaint
|
|
62
|
+
@addr2name[addr] = [] unless @addr2name.include? addr
|
|
63
|
+
@addr2name[addr] << hostname
|
|
64
|
+
@addr2name[addr] += aliases
|
|
65
|
+
@name2addr[hostname] = [] unless @name2addr.include? hostname
|
|
66
|
+
@name2addr[hostname] << addr
|
|
67
|
+
aliases.each {|n|
|
|
68
|
+
n.untaint
|
|
69
|
+
@name2addr[n] = [] unless @name2addr.include? n
|
|
70
|
+
@name2addr[n] << addr
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
rescue Exception
|
|
75
|
+
# Java won't find this file if running on Windows
|
|
76
|
+
end
|
|
77
|
+
@name2addr.each {|name, arr| arr.reverse!}
|
|
78
|
+
@initialized = true
|
|
79
|
+
end
|
|
80
|
+
}
|
|
81
|
+
self
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Gets the first IP address for +name+ from the hosts file
|
|
85
|
+
def getaddress(name)
|
|
86
|
+
each_address(name) {|address| return address}
|
|
87
|
+
raise ResolvError.new("#{@filename} has no name: #{name}")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Gets all IP addresses for +name+ from the hosts file
|
|
91
|
+
def getaddresses(name)
|
|
92
|
+
ret = []
|
|
93
|
+
each_address(name) {|address| ret << address}
|
|
94
|
+
return ret
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Iterates over all IP addresses for +name+ retrieved from the hosts file
|
|
98
|
+
def each_address(name, &proc)
|
|
99
|
+
lazy_initialize
|
|
100
|
+
if @name2addr.include?(name)
|
|
101
|
+
@name2addr[name].each(&proc)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Gets the first hostname of +address+ from the hosts file
|
|
106
|
+
def getname(address)
|
|
107
|
+
each_name(address) {|name| return name}
|
|
108
|
+
raise ResolvError.new("#{@filename} has no address: #{address}")
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Gets all hostnames for +address+ from the hosts file
|
|
112
|
+
def getnames(address)
|
|
113
|
+
ret = []
|
|
114
|
+
each_name(address) {|name| ret << name}
|
|
115
|
+
return ret
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Iterates over all hostnames for +address+ retrieved from the hosts file
|
|
119
|
+
def each_name(address, &proc)
|
|
120
|
+
lazy_initialize
|
|
121
|
+
if @addr2name.include?(address)
|
|
122
|
+
@addr2name[address].each(&proc)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
126
|
end
|