Class: ThumbPrint

Inherits:
Object
  • Object
show all
Defined in:
lib/VMwareWebService/thumb_print.rb

Direct Known Subclasses

ESXThumbPrint, VcenterThumbPrint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ ThumbPrint

Returns a new instance of ThumbPrint.



8
9
10
11
12
13
14
# File 'lib/VMwareWebService/thumb_print.rb', line 8

def initialize(host)
  $log.info "ThumbPrint.initialize(#{host})" if $log
  @host = host
  @cert = nil
  uri
  http_request
end

Instance Attribute Details

#certObject

Returns the value of attribute cert.



6
7
8
# File 'lib/VMwareWebService/thumb_print.rb', line 6

def cert
  @cert
end

#der_thumb_printObject (readonly)

Returns the value of attribute der_thumb_print.



5
6
7
# File 'lib/VMwareWebService/thumb_print.rb', line 5

def der_thumb_print
  @der_thumb_print
end

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/VMwareWebService/thumb_print.rb', line 5

def host
  @host
end

#httpObject (readonly)

Returns the value of attribute http.



5
6
7
# File 'lib/VMwareWebService/thumb_print.rb', line 5

def http
  @http
end

#thumb_printObject (readonly)

Returns the value of attribute thumb_print.



5
6
7
# File 'lib/VMwareWebService/thumb_print.rb', line 5

def thumb_print
  @thumb_print
end

#x509_certObject (readonly)

Returns the value of attribute x509_cert.



5
6
7
# File 'lib/VMwareWebService/thumb_print.rb', line 5

def x509_cert
  @x509_cert
end

Instance Method Details

#http_requestObject



16
17
18
19
20
# File 'lib/VMwareWebService/thumb_print.rb', line 16

def http_request
  @http             = Net::HTTP.new(@uri.host, @uri.port)
  @http.use_ssl     = true
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

#to_sha1Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/VMwareWebService/thumb_print.rb', line 22

def to_sha1
  @cert = to_cert if @cert.nil?
  $log.info "ThumbPrint.to_sha1 for host #{@host}" if $log
  raise "Invalid Certificate" if @cert.nil?
  @x509_cert       = OpenSSL::X509::Certificate.new(@cert)
  @der_thumb_print = OpenSSL::Digest::SHA1.new(@x509_cert.to_der).to_s
  @thumb_print     = @der_thumb_print.scan(/../).collect(&:upcase).join(":")
  $log.info "ThumbPrint.to_sha1 for host #{@host} is #{@thumb_print}" if $log
  @thumb_print
end