Class: Net::DNS::RR::SSHFP

Inherits:
Net::DNS::RR show all
Defined in:
lib/Net/DNS/RR/SSHFP.rb

Overview

NAME

Net::DNS::RR::SSHFP - DNS SSHFP resource record

DESCRIPTION

Class for Delegation signer (SSHFP) resource records.

ACKNOWLEDGEMENT

Jakob Schlyter for code review and supplying patches.

COPYRIGHT

Copyright © 2004 RIPE NCC, Olaf Kolkman.

“All rights reserved, This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, draft-ietf-dnssext-delegation-signer

Constant Summary collapse

HasBabble =

BEGIN {

  eval {
    require Digest::BubbleBabble; 
    Digest::BubbleBabble->import(qw(bubblebabble))
  };

  $HasBabble = $@ ? 0 : 1;

}
@TODO Use BubbleBabble!!
false
@@algtype =
{
   'RSA' => 1,
'DSA' => 2}
@@fingerprinttype =
{'SHA-1' => 1}
@@fingerprinttypebyval =
@@fingerprinttype.reverse
@@algtypebyval =
@@algtype.reverse

Constants inherited from Net::DNS::RR

RRS

Instance Attribute Summary collapse

Attributes inherited from Net::DNS::RR

#name, #rdata, #rdlength, #rrclass, #ttl, #type

Instance Method Summary collapse

Methods inherited from Net::DNS::RR

#_canonicalRdata, #_canonicaldata, _get_subclass, _name2wire, #_name2wire, build_regex, create, #create_rrsort_func, #data, #get_rrsort_func, #init, #init_rrsort_func, #inspect, new_from_data, new_from_hash, new_from_string, #set_rrsort_func

Instance Attribute Details

#algorithmObject

Returns the RR’s algorithm field in decimal representation

1 = RSA
2 = DSS

print "algoritm" = ", rr.algorithm, "\n"


51
52
53
# File 'lib/Net/DNS/RR/SSHFP.rb', line 51

def algorithm
  @algorithm
end

#fingerprintObject

Returns the value of attribute fingerprint.



53
54
55
# File 'lib/Net/DNS/RR/SSHFP.rb', line 53

def fingerprint
  @fingerprint
end

#fpbinObject

Returns the SHA1 fingerprint over the label and key in hexadecimal representation.

Returns the fingerprint as binary material.



60
61
62
# File 'lib/Net/DNS/RR/SSHFP.rb', line 60

def fpbin
  @fpbin
end

#fptypeObject

Returns the fingerprint type of the SSHFP RR.

print "fingerprint type  = " + rr.fptype  + "\n"


66
67
68
# File 'lib/Net/DNS/RR/SSHFP.rb', line 66

def fptype
  @fptype
end

Instance Method Details

#babbleObject



175
176
177
178
179
180
181
# File 'lib/Net/DNS/RR/SSHFP.rb', line 175

def babble
  if (HasBabble)
    return bubblebabble(Digest => fpbin())
  else
    return ""
  end
end

#new_from_data(data, offset) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/Net/DNS/RR/SSHFP.rb', line 104

def new_from_data(data, offset)
  if (@rdlength > 0)
    offsettoalg    = offset
    offsettofptype = offset+1
    offsettofp     = offset+2
    fplength       = 20   # This will need to change if other fingerprint types
    # are being deployed.
    
    
    @algorithm = data[oggsettoalg, 1].unpack('C') # , substr($$data, $offsettoalg, 1))
    @fptype    = data[offsettofptype, 1].unpack('C') # , substr($$data, $offsettofptype, 1))
    
    raise NotImplementedError, "This fingerprint type #{@fptype} has not yet been implemented\n." +
			"Contact developer of Net::DNS::RR::SSHFP.\n"  unless fingerprinttypebyval[@fptype] != nil
    
    # All this is SHA-1 dependend
    @fpbin = data[offsettofp, fplength] # SHA1 digest 20 bytes long
    
    @fingerprint = @fpbin.unpack('H*').upcase!  # uc unpack('H*', $self->{:fpbin});
  end
end

#new_from_hash(values) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/Net/DNS/RR/SSHFP.rb', line 140

def new_from_hash(values)
  if values.has_key?(:fingerprint)
    @fingerprint = values[:fingerprint]
  end
  if values.has_key?(:fptype)
    @fptype = values[:fptype]
  end
  if values.has_key?(:fpbin)
    @fpbin = values[:fpbin]
  end
  if values.has_key?(:algorithm)
    @algorithm = values[:algorithm]
  end
end

#new_from_string(instring) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/Net/DNS/RR/SSHFP.rb', line 127

def new_from_string(instring)
  if (string)
    instring = string.tr("()", "") # /()//d
    string.gsub!(/;.*$/, "") # /mg
    string.gsub!(/\n/, "")
    
    @algorithm, @fptype, @fingerprint = string.split(/\s+/, 3)
    
    # We allow spaces in the fingerprint.
    @fingerprint.gsub!(/\s/, "")
  end
end

#rdatastrObject



156
157
158
159
160
161
162
163
164
# File 'lib/Net/DNS/RR/SSHFP.rb', line 156

def rdatastr
  rdatastr = ''
  
  if (@algorithm!=nil)
    rdatastr = [@algorithm, @fptype, @fingerprint].join('  ') + ' ; ' + babble()
  end
  
  return rdatastr
end

#rr_rdataObject



166
167
168
169
170
171
172
# File 'lib/Net/DNS/RR/SSHFP.rb', line 166

def rr_rdata
  if (@algorithm != nil)
    return [@algorithm, @fptype].pack('C2') + fpbin()
  end
  
  return ''
end