Class: KaseyaWS::Security

Inherits:
Object
  • Object
show all
Defined in:
lib/kaseyaws/security.rb

Class Method Summary collapse

Class Method Details

.client_ipObject

Utility method to return the client’s IP address, most but not all Kaseya VSA SOAP request require it.



23
24
25
26
# File 'lib/kaseyaws/security.rb', line 23

def self.client_ip
  r =  Net::HTTP.get( 'jsonip.com','/' )
  r = JSON::parse(r)['ip']
end

.compute_covered_password(username, password, rnd_number, hashing_algorithm) ⇒ Object

Computes the double hashed covered password to authenticate with the VSA server.



39
40
41
42
43
44
45
46
47
# File 'lib/kaseyaws/security.rb', line 39

def self.compute_covered_password(username, password, rnd_number, hashing_algorithm)
  if hashing_algorithm == "SHA-1"
    hash1 = Digest::SHA1.hexdigest(password + username)
    covered_password = Digest::SHA1.hexdigest(hash1 + rnd_number)
  else # Assume SHA-256
    hash1 = Digest::SHA256.hexdigest(password + username)
    covered_password = Digest::SHA256.hexdigest(hash1 + rnd_number)
  end
end

.secure_randomObject

Returns an eight digit secure random number, used to compute the second hash for the double hash sequence.



30
31
32
33
34
35
# File 'lib/kaseyaws/security.rb', line 30

def self.secure_random
  i = SecureRandom.random_bytes
  i = i.each_byte.map { |b| b.to_s }.join
  i = i.gsub("0","")
  i = i[1..8]
end