feature #959: cipher to encrypt/decrypt oneadmin pass is now set for the Zone classes. Now it does not require it to be set in OZONE_AUTH file

This commit is contained in:
Ruben S. Montero committed 2011-11-03 01:21:30 +01:00
1 parent 45e4923dc0
commit e2f5a07349
4 files changed
+48 -40

No files matched your search

+1 -35
View File
@@ -34,7 +34,6 @@ require 'base64'
module OZones
CIPHER="aes-256-cbc"
# -------------------------------------------------------------------------
# The Error Class represents a generic error in the OZones
# library. It contains a readable representation of the error.
@@ -72,37 +71,4 @@ module OZones
def self.str_to_json(str)
return JSON.pretty_generate({:message => str})
end
def self.readKey
begin
credentials = File.read(ENV['OZONES_AUTH']).strip
return Digest::SHA1.hexdigest(credentials);
rescue
return "";
end
end
def self.encrypt(plain_txt)
#prepare cipher object
cipher = OpenSSL::Cipher.new(CIPHER)
cipher.encrypt
cipher.key = OZones.readKey
enc_txt = cipher.update(plain_txt)
enc_txt << cipher.final
Base64::encode64(enc_txt).strip.delete("\n")
end
def self.decrypt(b64_txt)
#prepare cipher object
cipher = OpenSSL::Cipher.new(CIPHER)
cipher.decrypt
cipher.key = OZones.readKey
enc_txt = Base64::decode64(b64_txt)
plain_txt = cipher.update(enc_txt)
plain_txt << cipher.final
end
end
end
+40 -4
View File
@@ -68,10 +68,13 @@ module OZones
def ONEPASS
pw = super
OZones.decrypt(pw)
decrypt(pw)
end
def ONEPASS=(plain_pw)
super(encrypt(plain_pw))
end
#######################################################################
# Zone Data Management
#######################################################################
@@ -88,8 +91,6 @@ module OZones
name = zone_data[:ONENAME]
pass = zone_data[:ONEPASS]
zone_data[:ONEPASS] = OZones.encrypt(pass)
rc = OpenNebulaZone::check_oneadmin(name,
pass,
zone_data[:ENDPOINT])
@@ -113,6 +114,41 @@ module OZones
return zone
end
########################################################################
# Encryption functions for the class
########################################################################
CIPHER = "aes-256-cbc"
@@cipher = ""
def self.cipher=(cipher)
@@cipher = cipher
end
def encrypt(plain_txt)
#prepare cipher object
cipher = OpenSSL::Cipher.new(CIPHER)
cipher.encrypt
cipher.key = @@cipher
enc_txt = cipher.update(plain_txt)
enc_txt << cipher.final
Base64::encode64(enc_txt).strip.delete("\n")
end
def decrypt(b64_txt)
#prepare cipher object
cipher = OpenSSL::Cipher.new(CIPHER)
cipher.decrypt
cipher.key = @@cipher
enc_txt = Base64::decode64(b64_txt)
plain_txt = cipher.update(enc_txt)
plain_txt << cipher.final
end
end
###########################################################################
+5
View File
@@ -20,6 +20,11 @@ require 'JSONUtils'
class OzonesServer
include OpenNebulaJSON::JSONUtils
def initialize(cipher)
#Set cipher for Zone classes
OZones::Zones.cipher = cipher
end
############################################################################
# Get methods for the Zones and VDC interface
############################################################################
+2 -1
View File
@@ -96,6 +96,7 @@ end
ADMIN_NAME = @auth.name
ADMIN_PASS = @auth.password
ADMIN_KEY = Digest::SHA1.hexdigest("ADMIN_NAME:ADMIN_PASS")
begin
OZones::ProxyRules.new("apache",config[:htaccess])
@@ -171,7 +172,7 @@ before do
unless request.path=='/login' || request.path=='/'
halt 401 unless authorized?
@OzonesServer = OzonesServer.new
@OzonesServer = OzonesServer.new(ADMIN_KEY)
@pr = OZones::ProxyRules.new("apache",config[:htaccess])
end
end