Class: Dnsruby::RR::NSEC3PARAM

Inherits:
Dnsruby::RR show all
Defined in:
lib/dnsruby/resource/NSEC3PARAM.rb

Overview

The NSEC3PARAM RR contains the NSEC3 parameters (hash algorithm, flags, iterations and salt) needed by authoritative servers to calculate hashed owner names. The presence of an NSEC3PARAM RR at a zone apex indicates that the specified parameters may be used by authoritative servers to choose an appropriate set of NSEC3 RRs for negative responses. The NSEC3PARAM RR is not used by validators or resolvers.

Constant Summary collapse

ClassValue =

:nodoc: all

nil
TypeValue =

:nodoc: all

Types::NSEC3PARAM

Constants inherited from Dnsruby::RR

ClassInsensitiveTypes

Instance Attribute Summary collapse

Attributes inherited from Dnsruby::RR

#klass, #name, #rdata, #ttl, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dnsruby::RR

#<=>, #==, #clone, create, #eql?, find_class, #from_hash, get_class, get_num, #hash, implemented_rrs, #init_defaults, new_from_data, new_from_hash, new_from_string, #rdlength, #sameRRset, #to_s

Instance Attribute Details

#flagsObject

The Flags field contains 8 one-bit flags that can be used to indicate different processing. All undefined flags must be zero. The only flag defined by the NSEC3 specification is the Opt-Out flag.



35
36
37
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 35

def flags
  @flags
end

#hash_algObject

The Hash Algorithm field identifies the cryptographic hash algorithm used to construct the hash-value.



31
32
33
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 31

def hash_alg
  @hash_alg
end

#iterationsObject

The Iterations field defines the number of additional times the hash function has been performed.



38
39
40
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 38

def iterations
  @iterations
end

#salt_lengthObject (readonly)

The Salt Length field defines the length of the Salt field in octets, ranging in value from 0 to 255.



41
42
43
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 41

def salt_length
  @salt_length
end

Class Method Details

.decode_rdata(msg) ⇒ Object

:nodoc: all



127
128
129
130
131
132
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 127

def self.decode_rdata(msg) #:nodoc: all
  hash_alg, flags, iterations, salt_length = msg.get_unpack("ccnc")
  salt = msg.get_bytes(salt_length)
  return self.new(
    [hash_alg, flags, iterations, salt_length, salt])
end

Instance Method Details

#encode_rdata(msg, canonical = false) ⇒ Object

:nodoc: all



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 113

def encode_rdata(msg, canonical=false) #:nodoc: all
#        s = salt()
  s = @salt
  sl = s.length()
  if (s == "-")
    sl == 0
  end
  msg.put_pack("ccnc", @hash_alg.code, @flags, @iterations, sl)

  if (sl > 0)
    msg.put_bytes(s)
  end
end

#from_data(data) ⇒ Object

def salt_length=(l) # :nodoc: all

  if ((l < 0) || (l > 255))
    raise DecodeError.new("NSEC3 salt length must be between 0 and 255")
  end
  @salt_length = l
end


87
88
89
90
91
92
93
94
95
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 87

def from_data(data) #:nodoc: all
  hash_alg, flags, iterations, _salt_length, salt = data
  self.hash_alg=(hash_alg)
  self.flags=(flags)
  self.iterations=(iterations)
  #         self.salt_length=(salt_length)
#        self.salt=(salt)
  @salt=salt
end

#from_string(input) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 97

def from_string(input)
  if (input.length > 0)
    data = input.split(" ")
    self.hash_alg=(data[0]).to_i
    self.flags=(data[1]).to_i
    self.iterations=(data[2]).to_i
    self.salt=(data[3])
    #           self.salt_length=(data[3].length)
  end
end

#rdata_to_stringObject

:nodoc: all



108
109
110
111
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 108

def rdata_to_string #:nodoc: all
    s = salt()
    return "#{@hash_alg.code} #{@flags} #{@iterations} #{s}"
end

#saltObject

The Salt field is appended to the original owner name before hashing in order to defend against pre-calculated dictionary attacks.



45
46
47
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 45

def salt
  return NSEC3.encode_salt(@salt)
end

#salt=(s) ⇒ Object



49
50
51
52
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 49

def salt=(s)
  @salt = NSEC3.decode_salt(s)
  @salt_length = @salt.length
end

#types=(t) ⇒ Object



68
69
70
# File 'lib/dnsruby/resource/NSEC3PARAM.rb', line 68

def types=(t)
  @types = NSEC.get_types(t)
end