File: tc_ds.rb

package info (click to toggle)
dnsruby 1.61.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,520 kB
  • sloc: ruby: 17,811; makefile: 3
file content (107 lines) | stat: -rw-r--r-- 3,573 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
105
106
107
# --
# Copyright 2007 Nominet UK
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ++

require_relative 'spec_helper'

require 'openssl'
require 'digest/sha2'

class DsTest < Minitest::Test

  include Dnsruby

  DLVINPUT = "dskey.example.com. 86400 IN DLV 60485 5 1 ( 2BB183AF5F22588179A53B0A" +
    "98631FAD1A292118 )"
  INPUT = "dskey.example.com. 86400 IN DS 60485 5 1 ( 2BB183AF5F22588179A53B0A" +
    "98631FAD1A292118 )"
     DNSKEY = "dskey.example.com. 86400 IN DNSKEY 256 3 5 ( AQOeiiR0GOMYkDshWoSKz9Xz" +
                                                "fwJr1AYtsmx3TGkJaNXVbfi/" +
                                                "2pHm822aJ5iI9BMzNXxeYCmZ"+
                                                "DRD99WYwYqUSdjMmmAphXdvx"+
                                                "egXd/M5+X7OrzKBaMbCVdFLU"+
                                                "Uh6DhweJBjEVv5f2wwjM9Xzc"+
                                                "nOf+EPbtG9DMBmADjFDc2w/r"+
                                                "ljwvFw== )" #  key id = 60485
      DS1 = "dskey.example.com. 86400 IN DS 60485 5 1 ( 2BB183AF5F22588179A53B0A"+
                                              "98631FAD1A292118 )"
      DS2 = "dskey.example.com. 86400 IN DS 60485 5 2   ( D4B7D520E7BB5F0F67674A0C"+
                                                "CEB1E3E0614B93C4F9E99B83"+
                                                "83F6A1E4469DA50A )"

  def test_ds_from_string
    ds = Dnsruby::RR.create(INPUT)
    assert_equal(60485, ds.key_tag)
    assert_equal(Algorithms.RSASHA1, ds.algorithm)
    assert_equal(1, ds.digest_type)
    assert_equal("2BB183AF5F22588179A53B0A98631FAD1A292118", ds.digest)

    ds2 = Dnsruby::RR.create(ds.to_s)
    assert(ds2.to_s == ds.to_s)
  end

  def test_ds_from_data
    ds = Dnsruby::RR.create(INPUT)
    m = Dnsruby::Message.new
    m.add_additional(ds)
    data = m.encode
    m2 = Dnsruby::Message.decode(data)
    ds3 = m2.additional()[0]
    assert_equal(ds.to_s, ds3.to_s)
  end

  def test_ds_values
    ds = Dnsruby::RR.create(INPUT)
    ds.digest_type = 2
    #  Be liberal in what you accept...
#    begin
#      ds.digest_type = 3
#      fail
# 
#    rescue DecodeError
#    end
  end

  def test_ds_digest
     key = Dnsruby::RR.create(DNSKEY)

     #  and check it is the same as DS
     right_ds = Dnsruby::RR.create(DS1)
     ds = Dnsruby::RR::DS.from_key(key, 1);
     assert_equal(ds.to_s, right_ds.to_s)
  end

  def test_sha2
     #  Create a new DS from the DNSKEY,
     key = Dnsruby::RR.create(DNSKEY)

     #  and check it is the same as DS
     right_ds = Dnsruby::RR.create(DS2)
     ds = Dnsruby::RR::DS.from_key(key, 2);
     assert_equal(ds.to_s, right_ds.to_s)
  end

  def test_dlv_from_string
    dlv = Dnsruby::RR.create(DLVINPUT)
    assert_equal(60485, dlv.key_tag)
    assert_equal(Algorithms.RSASHA1, dlv.algorithm)
    assert_equal(1, dlv.digest_type)
    assert_equal("2BB183AF5F22588179A53B0A98631FAD1A292118", dlv.digest)

    dlv2 = Dnsruby::RR.create(dlv.to_s)
    assert(dlv2.to_s == dlv.to_s)
  end

end