Skip to content

Commit

Permalink
Merge pull request dell-asm#140 from dmohanty09/asm-cipher
Browse files Browse the repository at this point in the history
Asm cipher
  • Loading branch information
gavin-scott committed Feb 19, 2014
2 parents d13848f + 12a5c8e commit 5ad6c89
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/asm/asm_cipher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "asm"
require "asm/util"
require "sequel"
require "aescrypt"
db_conf = YAML.load_file(ASM::Util::DATABASE_CONF)
if RUBY_PLATFORM == "java"
require 'jdbc/postgres'
Jdbc::Postgres.load_driver
DB = Sequel.connect("jdbc:postgresql://#{db_conf['host']}/encryptionmgr?user=#{db_conf['username']}&password=#{db_conf['password']}")
else
require "pg"
DB = Sequel.connect("postgres://#{db_conf['username']}:#{db_conf['password']}@#{db_conf['host']}:#{db_conf['port']}/encryptionmgr")
end

module ASM::Cipher
def self.decrypt_string(id)
e_string = get_string(id)
e_key = get_key(e_string[:encryptionmethodid])
d_string = AESCrypt.decrypt_data(Base64.decode64(e_string[:encrypteddata]),Base64.decode64(e_key[:bytes]),nil,"AES-128-CBC")
d_string.slice!(0,16)
d_string
end
def self.get_string(id)
DB["SELECT * FROM encryptedstring WHERE id = ?", id].first
end
def self.get_key(key_id)
DB["SELECT bytes FROM encryptionkey WHERE id = (SELECT key_id FROM encryptionmethod WHERE id = ?)", key_id].first
end
end
4 changes: 3 additions & 1 deletion lib/asm/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ module Util
NETWORKS_RA_URL='http://localhost:9080/VirtualServices/Network'
CHASSIS_RA_URL='http://localhost:9080/ChassisRA/Chassis'
# TODO: give razor user access to this directory
DEVICE_CONF_DIR='/etc/puppetlabs/puppet/devices'
PUPPET_CONF_DIR='/etc/puppetlabs/puppet'
DEVICE_CONF_DIR="#{PUPPET_CONF_DIR}/devices"
DATABASE_CONF="#{PUPPET_CONF_DIR}/database.yaml"
# See spec/fixtures/asm_server_m620.json for sample response
#
# cert_name is in format devicetype-servicetag
Expand Down

0 comments on commit 5ad6c89

Please sign in to comment.