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

Work with newer cryptors #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion knife-crypt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = Knife::Crypt::VERSION

gem.add_runtime_dependency "chef", ">= 0.10.8", "< 12.0.0"
gem.add_runtime_dependency "chef", ">= 0.10.8", "~> 12.0"

gem.add_development_dependency "aruba", "~> 0.4.11"
gem.add_development_dependency "bundler", "~> 1.0"
Expand Down
25 changes: 24 additions & 1 deletion lib/chef/knife/decrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def run
exit 1
end

encrypted_value = @name_args[0]
encrypted_value = eval @name_args[0]
secret = Chef::EncryptedDataBagItem.load_secret
decrypted_value = if Chef::EncryptedDataBagItem.methods.include?(:decrypt_value)
Chef::EncryptedDataBagItem.decrypt_value encrypted_value, secret
Expand All @@ -24,3 +24,26 @@ def run
end
end
end

module Encryption
class PlainDecrypt < Chef::Knife
banner "knife plain_decrypt DATA (options)"

def run
if @name_args.empty?
show_usage
ui.fatal "You must specify data to decrypt"
exit 1
end

encrypted_value = eval @name_args[0]
secret = Chef::EncryptedDataBagItem.load_secret
decrypted_value = if Chef::EncryptedDataBagItem.methods.include?(:decrypt_value)
Chef::EncryptedDataBagItem.decrypt_value encrypted_value, secret
else
Chef::EncryptedDataBagItem::Decryptor.for(encrypted_value, secret).for_decrypted_item
end
puts decrypted_value.inspect
end
end
end
27 changes: 26 additions & 1 deletion lib/chef/knife/encrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,35 @@ def run
encrypted_value = if Chef::EncryptedDataBagItem.methods.include? :encrypt_value
Chef::EncryptedDataBagItem.encrypt_value(decrypted_value, secret)
else
Chef::EncryptedDataBagItem::Encryptor.new(decrypted_value, secret, initialization_vector).for_encrypted_item["encrypted_data"]
Chef::EncryptedDataBagItem::Encryptor.new(decrypted_value, secret, initialization_vector).for_encrypted_item
end
puts encrypted_value
end
end
end
end

module Encryption
class PlainEncrypt < Chef::Knife
banner "knife plain_encrypt DATA (options)"

def run
if @name_args.empty?
show_usage
ui.fatal "You must specify data to encrypt"
exit 1
end

secret = Chef::EncryptedDataBagItem.load_secret
decrypted_value = eval @name_args[0]

d = OpenSSL::Cipher.new(Chef::EncryptedDataBagItem::ALGORITHM)
d.encrypt
d.pkcs5_keyivgen(secret)

enc_data = d.update(decrypted_value)
enc_data << d.final
puts Base64.encode64(enc_data)
end
end
end