Module: Fog::Compute::HP::Utils

Included in:
Mock, Real
Defined in:
lib/fog/hp/compute.rb

Instance Method Summary collapse

Instance Method Details

#decrypt_using_private_key(encrypted_text, private_key_data) ⇒ Object



119
120
121
122
123
124
# File 'lib/fog/hp/compute.rb', line 119

def decrypt_using_private_key(encrypted_text, private_key_data)
  return if (encrypted_text.nil? || private_key_data.nil?)
  private_key = OpenSSL::PKey::RSA.new(private_key_data)
  from_base64 = Base64.decode64(encrypted_text)
  private_key.private_decrypt(from_base64).strip
end

#encrypt_using_public_key(text, public_key_data) ⇒ Object



112
113
114
115
116
117
# File 'lib/fog/hp/compute.rb', line 112

def encrypt_using_public_key(text, public_key_data)
  return if (text.nil? || public_key_data.nil?)
  public_key = OpenSSL::PKey::RSA.new(public_key_data)
  encrypted_text = public_key.public_encrypt(text).strip
  Base64.encode64(encrypted_text)
end

#extract_password_from_log(log_text) ⇒ Object

extract windows password from log



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fog/hp/compute.rb', line 89

def extract_password_from_log(log_text)
  encrypted_text = ""
  section        = []
  return if log_text.nil?
  log_text.each_line do |line|
    case line
      when /^-----BEGIN (\w+)/
        section.push $1
        next
      when /^-----END (\w+)/
        section.pop
        next
    end

    case section
      when ["BASE64"]
        encrypted_text << line
    end
  end
  # return the encrypted portion only
  encrypted_text
end