mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-21 04:12:37 +09:00
crypt and decrypt complete
This commit is contained in:
1 parent
2b05cde92e
commit
c5dc6a3c2a
2 files changed
+66
-3
No files matched your search
@@ -37,8 +37,10 @@ EOT
|
||||
|
||||
if ONE_LOCATION
|
||||
TABLE_CONF_PATH=ONE_LOCATION+"/etc/cli"
|
||||
VAR_LOCATION=ONE_LOCATION+"/var" if !defined?(VAR_LOCATION)
|
||||
else
|
||||
TABLE_CONF_PATH="/etc/one/cli"
|
||||
VAR_LOCATION="/var/lib/one" if !defined?(VAR_LOCATION)
|
||||
end
|
||||
|
||||
EDITOR_PATH='/usr/bin/vi'
|
||||
@@ -489,6 +491,47 @@ EOT
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# receive a object key => value format
|
||||
# returns hashed values
|
||||
def encrypt(opts)
|
||||
|
||||
res = {}
|
||||
key_one= File.read(VAR_LOCATION+'/.one/one_key')
|
||||
|
||||
opts.each do |key, value|
|
||||
cipher = OpenSSL::Cipher::AES.new(256,:CBC)
|
||||
cipher.encrypt.key = key_one
|
||||
puts "cifrando #{key}"
|
||||
encrypted = cipher.update(value) + cipher.final
|
||||
#res.merge!({key => value})
|
||||
res[key] = Base64::encode64(encrypted)
|
||||
puts "encriptado es: "+encrypted
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
def decrypt(res)
|
||||
opts = {}
|
||||
key_one= File.read(VAR_LOCATION+'/.one/one_key')
|
||||
|
||||
res.each do |key, encrypted_value|
|
||||
decipher = OpenSSL::Cipher::AES.new(256,:CBC)
|
||||
decipher.decrypt
|
||||
decipher.key = key_one
|
||||
puts "desencriptando #{key}"
|
||||
plain = decipher.update(Base64::decode64(encrypted_value)) + decipher.final
|
||||
puts "una vez desencriptado es "+plain
|
||||
opts[key] = plain
|
||||
end
|
||||
|
||||
return opts
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
def list_pool(options, top=false, filter_flag=nil)
|
||||
if options[:describe]
|
||||
table = format_pool(options)
|
||||
|
||||
+23
-3
@@ -32,7 +32,6 @@ $: << RUBY_LIB_LOCATION+"/cli"
|
||||
require 'command_parser'
|
||||
require 'one_helper/onehost_helper'
|
||||
require 'one_helper/onecluster_helper'
|
||||
require 'ec2_driver'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onehost` <command> [<args>] [<options>]"
|
||||
@@ -124,16 +123,37 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
STDERR.puts "\t -v hypervisor driver"
|
||||
exit -1
|
||||
end
|
||||
|
||||
ec2_host = !options[:ec2access].nil? && !options[:ec2secret].nil?
|
||||
|
||||
encrypt(options)
|
||||
if ec2_host
|
||||
ec2_opts = {
|
||||
:access => options[:ec2access],
|
||||
:secret => options[:ec2secret]
|
||||
}
|
||||
|
||||
encrypt_opts = helper.encrypt(ec2_opts)
|
||||
helper.decrypt(encrypt_opts)
|
||||
|
||||
end
|
||||
|
||||
cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
|
||||
|
||||
helper.create_resource(options) do |host|
|
||||
host.allocate(args[0],
|
||||
options[:im],
|
||||
options[:vm],
|
||||
cid)
|
||||
#template=""
|
||||
#encrypt_opts.each do |key, value|
|
||||
# template << "#{key}=\"+value\"\n"\
|
||||
#end
|
||||
|
||||
template = "EC2_ACCESS=\"#{encrypt_opts[:access]}\"\n"\
|
||||
"EC2_SECRET=\"#{encrypt_opts[:secret]}\"\n"\
|
||||
|
||||
host.update(template, true)
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user