dnsruby 1.55 → 1.56.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/test/tc_sshfp.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#Copyright 2007 Nominet UK
|
4
|
-
#
|
5
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
#you may not use this file except in compliance with the License.
|
7
|
-
#You may obtain a copy of the License at
|
8
|
-
#
|
1
|
+
|
2
|
+
# --
|
3
|
+
# Copyright 2007 Nominet UK
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
9
|
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
#Unless required by applicable law or agreed to in writing, software
|
12
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
#See the License for the specific language governing permissions and
|
15
|
-
#limitations under the License.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
require 'test/unit'
|
22
|
-
require 'dnsruby'
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
# ++
|
17
|
+
|
18
|
+
require_relative 'spec_helper'
|
19
|
+
|
23
20
|
include Dnsruby
|
24
|
-
class TestSSHFP < Test
|
21
|
+
class TestSSHFP < Minitest::Test
|
25
22
|
def test_sshfp
|
26
23
|
txt = "apt-blade6.nominet.org.uk. 85826 IN SSHFP 1 1 6D4CF7C68E3A959990855099E15D6E0D4DEA4FFF"
|
27
24
|
sshfp = RR.create(txt)
|
@@ -29,7 +26,7 @@ class TestSSHFP < Test::Unit::TestCase
|
|
29
26
|
assert(sshfp.alg == RR::SSHFP::Algorithms.RSA)
|
30
27
|
assert(sshfp.fptype == RR::SSHFP::FpTypes.SHA1)
|
31
28
|
assert(sshfp.fp.unpack("H*")[0].upcase == "6D4CF7C68E3A959990855099E15D6E0D4DEA4FFF")
|
32
|
-
|
29
|
+
|
33
30
|
m = Dnsruby::Message.new
|
34
31
|
m.add_additional(sshfp)
|
35
32
|
data = m.encode
|
data/test/tc_tcp.rb
CHANGED
@@ -1,26 +1,23 @@
|
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
require 'test/unit'
|
21
|
-
require 'dnsruby'
|
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
|
+
|
17
|
+
require_relative 'spec_helper'
|
18
|
+
|
22
19
|
require 'socket'
|
23
|
-
class TestTcp < Test
|
20
|
+
class TestTcp < Minitest::Test
|
24
21
|
def test_TCP
|
25
22
|
res = Dnsruby::Resolver.new()
|
26
23
|
res.use_tcp = true
|
@@ -28,7 +25,7 @@ class TestTcp < Test::Unit::TestCase
|
|
28
25
|
assert(ret.is_a?(Dnsruby::Message))
|
29
26
|
end
|
30
27
|
def test_TCP_port
|
31
|
-
#
|
28
|
+
# Need a test server so we can tell what port this message was actually sent on!
|
32
29
|
port = nil
|
33
30
|
src_port = 57923
|
34
31
|
Dnsruby::PacketSender.clear_caches
|
@@ -37,7 +34,7 @@ class TestTcp < Test::Unit::TestCase
|
|
37
34
|
ts = TCPServer.new(0)
|
38
35
|
port = ts.addr[1]
|
39
36
|
t = ts.accept
|
40
|
-
#
|
37
|
+
# Check that the source port was src_port
|
41
38
|
received_port = t.peeraddr()[1]
|
42
39
|
packet = t.recvfrom(2)[0]
|
43
40
|
|
@@ -69,7 +66,7 @@ class TestTcp < Test::Unit::TestCase
|
|
69
66
|
assert(received_port == src_port)
|
70
67
|
assert(ret.is_a?(Dnsruby::Message))
|
71
68
|
end
|
72
|
-
|
69
|
+
|
73
70
|
# def test_no_tcp
|
74
71
|
# # Try to get a long response (which is truncated) and check that we have
|
75
72
|
# @TODO@ FIX THIS TEST!!!
|
@@ -86,7 +83,7 @@ class TestTcp < Test::Unit::TestCase
|
|
86
83
|
@additional = Dnsruby::Message::Section.new(self)
|
87
84
|
end
|
88
85
|
|
89
|
-
#Decode the encoded message
|
86
|
+
# Decode the encoded message
|
90
87
|
def HackMessage.decode(m)
|
91
88
|
o = HackMessage.new()
|
92
89
|
begin
|
@@ -118,9 +115,9 @@ class TestTcp < Test::Unit::TestCase
|
|
118
115
|
}
|
119
116
|
}
|
120
117
|
rescue Dnsruby::DecodeError => e
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
118
|
+
# So we got a decode error
|
119
|
+
# However, we might have been able to fill in many parts of the message
|
120
|
+
# So let's raise the DecodeError, but add the partially completed message
|
124
121
|
e.partial_message = o
|
125
122
|
raise e
|
126
123
|
end
|
@@ -130,10 +127,10 @@ class TestTcp < Test::Unit::TestCase
|
|
130
127
|
end
|
131
128
|
|
132
129
|
def test_bad_truncation
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
130
|
+
# Some servers don't do truncation properly.
|
131
|
+
# Make a UDP server which returns large badly formatted packets (arcount > num_additional), with TC bit set
|
132
|
+
# And make a TCP server which returns large well formatted packets
|
133
|
+
# Then make sure that Dnsruby recieves response correctly.
|
137
134
|
Dnsruby::PacketSender.clear_caches
|
138
135
|
socket = UDPSocket.new
|
139
136
|
socket.bind("127.0.0.1", 0)
|
@@ -176,7 +173,7 @@ class TestTcp < Test::Unit::TestCase
|
|
176
173
|
|
177
174
|
|
178
175
|
|
179
|
-
#
|
176
|
+
# Now send query
|
180
177
|
res = Dnsruby::Resolver.new("127.0.0.1")
|
181
178
|
res.port = port
|
182
179
|
res.udp_size = 4096
|
@@ -190,5 +187,5 @@ class TestTcp < Test::Unit::TestCase
|
|
190
187
|
|
191
188
|
end
|
192
189
|
|
193
|
-
|
190
|
+
# @TODO@ Check stuff like persistent sockets
|
194
191
|
end
|
data/test/tc_tkey.rb
CHANGED
@@ -1,37 +1,34 @@
|
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
require 'test/unit'
|
21
|
-
require 'dnsruby'
|
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
|
+
|
17
|
+
require_relative 'spec_helper'
|
18
|
+
|
22
19
|
require "digest/md5"
|
23
|
-
class TestTKey < Test
|
20
|
+
class TestTKey < Minitest::Test
|
24
21
|
def is_empty(string)
|
25
22
|
return (string == "; no data" || string == "; rdlength = 0")
|
26
23
|
end
|
27
|
-
|
24
|
+
|
28
25
|
def test_tkey
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
|
26
|
+
|
27
|
+
|
28
|
+
# ------------------------------------------------------------------------------
|
29
|
+
# Canned data.
|
30
|
+
# ------------------------------------------------------------------------------
|
31
|
+
|
35
32
|
zone = "example.com"
|
36
33
|
name = "123456789-test"
|
37
34
|
klass = "IN"
|
@@ -39,15 +36,15 @@ class TestTKey < Test::Unit::TestCase
|
|
39
36
|
algorithm = "fake.algorithm.example.com"
|
40
37
|
key = "fake key"
|
41
38
|
inception = 100000 # use a strange fixed inception time to give a fixed
|
42
|
-
#
|
39
|
+
# checksum
|
43
40
|
expiration = inception + 24*60*60
|
44
|
-
|
41
|
+
|
45
42
|
rr = nil
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
|
43
|
+
|
44
|
+
# ------------------------------------------------------------------------------
|
45
|
+
# Packet creation.
|
46
|
+
# ------------------------------------------------------------------------------
|
47
|
+
|
51
48
|
rr = Dnsruby::RR.create(
|
52
49
|
:name => name,
|
53
50
|
:type => "TKEY",
|
@@ -60,20 +57,20 @@ class TestTKey < Test::Unit::TestCase
|
|
60
57
|
:key => "fake key",
|
61
58
|
:other_data => ""
|
62
59
|
)
|
63
|
-
|
60
|
+
|
64
61
|
packet = Dnsruby::Message.new(name, Dnsruby::Types.TKEY, "IN")
|
65
62
|
packet.add_answer(rr)
|
66
|
-
|
63
|
+
|
67
64
|
z = (packet.zone)[0]
|
68
|
-
|
65
|
+
|
69
66
|
assert(packet, 'new() returned packet') #2
|
70
|
-
assert_equal(Dnsruby::OpCode.QUERY, packet.header.opcode, 'header opcode correct') #3
|
67
|
+
assert_equal(Dnsruby::OpCode.QUERY, packet.header.opcode, 'header opcode correct') #3
|
71
68
|
assert_equal(name, z.zname.to_s, 'zname correct') #4
|
72
69
|
assert_equal(Dnsruby::Classes.IN, z.zclass, 'zclass correct') #5
|
73
|
-
assert_equal(Dnsruby::Types.TKEY, z.ztype, 'ztype correct') #6
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
assert_equal(Dnsruby::Types.TKEY, z.ztype, 'ztype correct') #6
|
71
|
+
|
72
|
+
# @TODO@ Test TKEY against server!
|
73
|
+
|
77
74
|
end
|
78
75
|
|
79
76
|
end
|
data/test/tc_tsig.rb
CHANGED
@@ -1,53 +1,50 @@
|
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
require 'test/unit'
|
21
|
-
require 'dnsruby'
|
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
|
+
|
17
|
+
require_relative 'spec_helper'
|
18
|
+
|
22
19
|
require "digest/md5"
|
23
20
|
include Dnsruby
|
24
|
-
class TestTSig < Test
|
21
|
+
class TestTSig < Minitest::Test
|
25
22
|
KEY_NAME="rubytsig"
|
26
23
|
KEY = "8n6gugn4aJ7MazyNlMccGKH1WxD2B3UvN/O/RA6iBupO2/03u9CTa3Ewz3gBWTSBCH3crY4Kk+tigNdeJBAvrw=="
|
27
24
|
def is_empty(string)
|
28
25
|
return (string == "; no data" || string == "; rdlength = 0")
|
29
26
|
end
|
30
27
|
def test_signed_update
|
31
|
-
#
|
28
|
+
# Dnsruby::Resolver::use_eventmachine(false)
|
32
29
|
run_test_client_signs
|
33
30
|
run_test_resolver_signs
|
34
31
|
end
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
|
32
|
+
# def test_signed_update_em
|
33
|
+
# begin
|
34
|
+
# Dnsruby::Resolver::use_eventmachine(true)
|
35
|
+
# rescue RuntimeError
|
36
|
+
# Dnsruby.log.error("EventMachine not installed - not running tsig EM tests")
|
37
|
+
# return
|
38
|
+
# end
|
39
|
+
# run_test_client_signs
|
40
|
+
# run_test_resolver_signs
|
41
|
+
# Dnsruby::Resolver::use_eventmachine(false)
|
42
|
+
# end
|
43
|
+
|
47
44
|
def run_test_client_signs
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
45
|
+
# NOTE - client signing is only appropriate if DNSSEC and EDNS are switched
|
46
|
+
# off. Otherwise, the resolver will attempt to alter the flags and add an
|
47
|
+
# EDNS OPT psuedo-record to the query message, invalidating the signing.
|
51
48
|
tsig = Dnsruby::RR.create({
|
52
49
|
:name => KEY_NAME,
|
53
50
|
:type => "TSIG",
|
@@ -58,30 +55,30 @@ class TestTSig < Test::Unit::TestCase
|
|
58
55
|
:key => KEY,
|
59
56
|
:error => 0
|
60
57
|
})
|
61
|
-
|
58
|
+
|
62
59
|
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
|
63
|
-
#
|
60
|
+
# Generate update record name, and test it has been made. Then delete it and check it has been deleted
|
64
61
|
update_name = generate_update_name
|
65
62
|
update.absent(update_name)
|
66
63
|
update.add(update_name, 'TXT', 100, "test signed update")
|
67
64
|
tsig.apply(update)
|
68
65
|
assert(update.signed?, "Update has not been signed")
|
69
|
-
|
66
|
+
|
70
67
|
res = Dnsruby::Resolver.new("ns0.validation-test-servers.nominet.org.uk")
|
71
68
|
res.udp_size=512 # Or else we needed to add OPT record already
|
72
69
|
res.dnssec=false
|
73
70
|
res.recurse=false
|
74
71
|
res.query_timeout = 20
|
75
72
|
response = res.send_message(update)
|
76
|
-
|
73
|
+
|
77
74
|
assert_equal( Dnsruby::RCode.NOERROR, response.rcode)
|
78
75
|
assert(response.verified?, "Response has not been verified")
|
79
|
-
|
80
|
-
#
|
76
|
+
|
77
|
+
# Now check the record exists
|
81
78
|
rr = res.query(update_name, 'TXT')
|
82
79
|
assert_equal("test signed update", rr.answer()[0].strings.join(" "), "TXT record has not been created in zone")
|
83
|
-
|
84
|
-
#
|
80
|
+
|
81
|
+
# Now delete the record
|
85
82
|
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
|
86
83
|
update.present(update_name, 'TXT')
|
87
84
|
update.delete(update_name)
|
@@ -90,17 +87,17 @@ class TestTSig < Test::Unit::TestCase
|
|
90
87
|
response = res.send_message(update)
|
91
88
|
assert_equal( Dnsruby::RCode.NOERROR, response.rcode)
|
92
89
|
assert(response.verified?, "Response has not been verified")
|
93
|
-
|
94
|
-
#
|
90
|
+
|
91
|
+
# Now check the record does not exist
|
95
92
|
Dnsruby::PacketSender.clear_caches
|
96
|
-
#
|
93
|
+
# Or else the cache will tell us it still deos!
|
97
94
|
begin
|
98
95
|
rr = res.query(update_name, 'TXT')
|
99
96
|
assert(false)
|
100
97
|
rescue Dnsruby::NXDomain
|
101
98
|
end
|
102
99
|
end
|
103
|
-
|
100
|
+
|
104
101
|
@@fudge = 0
|
105
102
|
def generate_update_name
|
106
103
|
update_name = Time.now.to_i.to_s + @@fudge.to_s
|
@@ -108,29 +105,29 @@ class TestTSig < Test::Unit::TestCase
|
|
108
105
|
update_name += ".update.validation-test-servers.nominet.org.uk"
|
109
106
|
return update_name
|
110
107
|
end
|
111
|
-
|
108
|
+
|
112
109
|
def run_test_resolver_signs
|
113
110
|
res = Dnsruby::Resolver.new("ns0.validation-test-servers.nominet.org.uk")
|
114
111
|
res.query_timeout=20
|
115
112
|
res.tsig=KEY_NAME, KEY
|
116
|
-
|
113
|
+
|
117
114
|
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
|
118
|
-
#
|
115
|
+
# Generate update record name, and test it has been made. Then delete it and check it has been deleted
|
119
116
|
update_name = generate_update_name
|
120
117
|
update.absent(update_name)
|
121
118
|
update.add(update_name, 'TXT', 100, "test signed update")
|
122
119
|
assert(!update.signed?, "Update has been signed")
|
123
|
-
|
120
|
+
|
124
121
|
response = res.send_message(update)
|
125
|
-
|
122
|
+
|
126
123
|
assert_equal( Dnsruby::RCode.NOERROR, response.rcode)
|
127
124
|
assert(response.verified?, "Response has not been verified")
|
128
|
-
|
129
|
-
#
|
125
|
+
|
126
|
+
# Now check the record exists
|
130
127
|
rr = res.query(update_name, 'TXT')
|
131
128
|
assert_equal("test signed update", rr.answer()[0].strings.join(" "), "TXT record has not been created in zone")
|
132
|
-
|
133
|
-
#
|
129
|
+
|
130
|
+
# Now delete the record
|
134
131
|
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
|
135
132
|
update.present(update_name, 'TXT')
|
136
133
|
update.delete(update_name)
|
@@ -146,42 +143,42 @@ class TestTSig < Test::Unit::TestCase
|
|
146
143
|
response = res.send_message(update)
|
147
144
|
assert_equal( Dnsruby::RCode.NOERROR, response.rcode)
|
148
145
|
assert(response.verified?, "Response has not been verified")
|
149
|
-
|
150
|
-
#
|
146
|
+
|
147
|
+
# Now check the record does not exist
|
151
148
|
Dnsruby::PacketSender.clear_caches
|
152
|
-
#
|
149
|
+
# Make sure the cache doesn't have an old copy!
|
153
150
|
begin
|
154
151
|
rr = res.query(update_name, 'TXT')
|
155
152
|
assert(false)
|
156
153
|
rescue Dnsruby::NXDomain
|
157
154
|
end
|
158
155
|
end
|
159
|
-
|
156
|
+
|
160
157
|
def test_message_signing
|
161
158
|
m = Dnsruby::Message.new("example.com")
|
162
159
|
m.set_tsig("name", "key")
|
163
160
|
assert(!m.signed?)
|
164
161
|
m.encode
|
165
162
|
assert(m.signed?)
|
166
|
-
|
163
|
+
|
167
164
|
m = Dnsruby::Message.new("example.com")
|
168
165
|
m.set_tsig("name", "key")
|
169
166
|
assert(!m.signed?)
|
170
|
-
m.sign!
|
167
|
+
m.sign!
|
171
168
|
assert(m.signed?)
|
172
|
-
|
169
|
+
|
173
170
|
m = Dnsruby::Message.new("example.com")
|
174
171
|
assert(!m.signed?)
|
175
172
|
m.sign!("name", "key")
|
176
173
|
assert(m.signed?)
|
177
174
|
end
|
178
|
-
|
175
|
+
|
179
176
|
def test_signed_zone_transfer
|
180
|
-
#
|
177
|
+
# test TSIG over TCP session
|
181
178
|
axfr
|
182
179
|
ixfr
|
183
180
|
end
|
184
|
-
|
181
|
+
|
185
182
|
def axfr
|
186
183
|
zt = Dnsruby::ZoneTransfer.new
|
187
184
|
zt.transfer_type = Dnsruby::Types.AXFR
|
@@ -191,31 +188,31 @@ class TestTSig < Test::Unit::TestCase
|
|
191
188
|
assert(zone.length > 0)
|
192
189
|
assert(zt.last_tsigstate==:Verified)
|
193
190
|
end
|
194
|
-
|
195
|
-
#
|
196
|
-
#
|
191
|
+
|
192
|
+
# We also test IXFR here - this is because we need to update a record (using
|
193
|
+
# TSIG) before we can test ixfr...
|
197
194
|
def ixfr
|
198
|
-
#
|
199
|
-
#
|
195
|
+
# Check the SOA serial, do an update, check that the IXFR for that soa serial gives us the update we did,
|
196
|
+
# then delete the updated record
|
200
197
|
start_soa_serial = get_soa_serial("validation-test-servers.nominet.org.uk")
|
201
|
-
|
202
|
-
#
|
198
|
+
|
199
|
+
# Now do an update
|
203
200
|
res = Dnsruby::Resolver.new("ns0.validation-test-servers.nominet.org.uk")
|
204
201
|
res.query_timeout=10
|
205
202
|
res.tsig=KEY_NAME, KEY
|
206
|
-
|
203
|
+
|
207
204
|
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
|
208
|
-
#
|
205
|
+
# Generate update record name, and test it has been made. Then delete it and check it has been deleted
|
209
206
|
update_name = Time.now.to_i.to_s + rand(100).to_s + ".update.validation-test-servers.nominet.org.uk"
|
210
207
|
update.absent(update_name)
|
211
208
|
update.add(update_name, 'TXT', 100, "test zone transfer")
|
212
209
|
assert(!update.signed?, "Update has been signed")
|
213
|
-
|
210
|
+
|
214
211
|
response = res.send_message(update)
|
215
212
|
assert(response.rcode == Dnsruby::RCode.NOERROR)
|
216
|
-
|
213
|
+
|
217
214
|
end_soa_serial = get_soa_serial("validation-test-servers.nominet.org.uk")
|
218
|
-
|
215
|
+
|
219
216
|
zt = Dnsruby::ZoneTransfer.new
|
220
217
|
zt.transfer_type = Dnsruby::Types.IXFR
|
221
218
|
zt.server = "ns0.validation-test-servers.nominet.org.uk"
|
@@ -225,15 +222,15 @@ class TestTSig < Test::Unit::TestCase
|
|
225
222
|
assert(deltas.last.class == Dnsruby::ZoneTransfer::Delta)
|
226
223
|
assert_equal("test zone transfer", deltas.last.adds.last.strings.join(" "))
|
227
224
|
assert(zt.last_tsigstate==nil)
|
228
|
-
|
229
|
-
#
|
225
|
+
|
226
|
+
# Now delete the updated record
|
230
227
|
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
|
231
228
|
update.present(update_name, 'TXT')
|
232
229
|
update.delete(update_name)
|
233
230
|
response = res.send_message(update)
|
234
231
|
assert_equal( Dnsruby::RCode.NOERROR, response.rcode)
|
235
232
|
end
|
236
|
-
|
233
|
+
|
237
234
|
def get_soa_serial(name)
|
238
235
|
soa_serial = nil
|
239
236
|
Dnsruby::DNS.open {|dns|
|