-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Compare decrypted values to see if they are insync #221
Merged
bastelfreak
merged 1 commit into
voxpupuli:master
from
alexjfisher:compare_values_after_decrypting
Apr 9, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'openssl' | ||
require 'base64' | ||
|
||
module PuppetX | ||
module Voxpupuli | ||
module Splunk | ||
class Util | ||
def self.decrypt(secrets_file, value) | ||
return value unless value.start_with?('$7$') | ||
|
||
Puppet.debug "Decrypting splunk >= 7.2 data using secret from #{secrets_file}" | ||
value.slice!(0, 3) | ||
data = Base64.strict_decode64(value) | ||
splunk_secret = IO.binread(secrets_file).chomp | ||
|
||
iv = data.bytes[0, 16].pack('c*') | ||
tag = data.bytes[-16..-1].pack('c*') | ||
ciphertext = data.bytes[16..-17].pack('c*') | ||
|
||
decipher = OpenSSL::Cipher::AES.new(256, :GCM).decrypt | ||
decipher.key = OpenSSL::PKCS5.pbkdf2_hmac(splunk_secret, 'disk-encryption', 1, 32, OpenSSL::Digest::SHA256.new) | ||
decipher.iv_len = 16 | ||
decipher.iv = iv | ||
decipher.auth_tag = tag | ||
decipher.auth_data = '' | ||
|
||
decipher.update(ciphertext) + decipher.final | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
require 'puppet_x/voxpupuli/splunk/util' | ||
|
||
describe PuppetX::Voxpupuli::Splunk::Util do | ||
describe '.decrypt' do | ||
context 'when called with an unencrypted value' do | ||
it 'returns the value unmodified' do | ||
expect(described_class.decrypt('secrets_file', 'non_encrypted_value')).to eq 'non_encrypted_value' | ||
end | ||
end | ||
context 'when called with splunk 7.2 encrypted value' do | ||
let(:encrypted_value) { '$7$aTVkS01HYVNJUk5wSnR5NIu4GXLhj2Qd49n2B6Y8qmA/u1CdL9JYxQ==' } | ||
let(:splunk_secret) { 'JX7cQAnH6Nznmild8MvfN8/BLQnGr8C3UYg3mqvc3ArFkaxj4gUt1RUCaRBD/r0CNn8xOA2oKX8/0uyyChyGRiFKhp6h2FA+ydNIRnN46N8rZov8QGkchmebZa5GAM5U50GbCCgzJFObPyWi5yT8CrSCYmv9cpRtpKyiX+wkhJwltoJzAxWbBERiLp+oXZnN3lsRn6YkljmYBqN9tZLTVVpsLvqvkezPgpv727Fd//5dRoWsWBv2zRp0mwDv3tj' } | ||
|
||
it 'returns decrypted value' do | ||
allow(IO).to receive(:binread).with('secrets_file').and_return(splunk_secret) | ||
expect(described_class.decrypt('secrets_file', encrypted_value)).to eq 'temp1234' | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno if I should catch exceptions here, log a warning, and return something so that puppet can continue??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO things this deep shouldn't rescue exceptions because they're too deep to know what to do about them. That should be done higher up. IMHO only rescue exceptions here if you watch to toss your own customized exception like
Spunk::Util::DecodeException
blah blah blah IMHO YMMVThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thought was if decryption did fail, it could be because of something like the splunk.secrets file being replaced. If decryption does fail (for whatever reason), it's maybe better for
insync?
to return false instead of a hard error being thrown and not handled.I like your advice on rethrowing a custom exception and catching it higher up. I'll leave this as is in this PR, but might work on an enhancement in a separate PR later. Thanks for the tip.