Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log encryption failures #127

Merged
merged 2 commits into from Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb
Expand Up @@ -545,7 +545,7 @@ def self.convert_value_based_on_datatype(value, datatype)
return value.to_i if datatype == 'integer' || datatype == 'Fixnum'
return value.to_f if datatype == 'float' || datatype == 'Float'
return value.gsub(/[\[\]]/, '').strip.split(/\s*,\s*/) if datatype == 'array' && value.class == String
return MiqAePassword.new(MiqAePassword.decrypt(value)) if datatype == 'password'
return decrypt_password(value) if datatype == 'password'

if datatype &&
(service_model = "MiqAeMethodService::MiqAeService#{SM_LOOKUP[datatype]}".safe_constantize)
Expand All @@ -558,6 +558,14 @@ def self.convert_value_based_on_datatype(value, datatype)
value
end

def self.decrypt_password(value)
MiqAePassword.new(MiqAePassword.decrypt(value))
rescue MiqPassword::MiqPasswordError => err
$miq_ae_logger.error("Error decrypting password #{err.message}. Possible cause: Password value was encrypted with a different encryption key")
raise
end
private_class_method :decrypt_password

def process_assertion(f, message, args)
Benchmark.current_realtime[:assertion_count] += 1
Benchmark.realtime_block(:assertion_time) do
Expand Down
Expand Up @@ -91,6 +91,7 @@ def instantiate(uri)
return nil if obj.nil?
MiqAeServiceObject.new(obj, self)
rescue => e
$miq_ae_logger.error("instantiate failed : #{e.message}")
return nil
end

Expand Down
17 changes: 17 additions & 0 deletions spec/miq_ae_object_spec.rb
Expand Up @@ -300,3 +300,20 @@ def value_match(value, xml_value)
end
end
end

describe MiqAeEngine::MiqAeObject do
context "password" do
let(:p45) { "Pneumonoultramicroscopicsilicovolcanoconiosis" }
let(:p45_encrypted) { MiqAePassword.encrypt(p45) }

it "can decrypt passwords" do
expect(described_class.convert_value_based_on_datatype(p45_encrypted, 'password').encStr).to eq(p45_encrypted)
end

it "raises exception for bogus passwords" do
expect do
described_class.convert_value_based_on_datatype('gobbledygook', 'password')
end.to raise_exception(MiqPassword::MiqPasswordError)
end
end
end