Class: Chef::EncryptedDataBagItem::Decryptor::Version0Decryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/encrypted_data_bag_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encrypted_data, key) ⇒ Version0Decryptor

Returns a new instance of Version0Decryptor.



227
228
229
230
# File 'lib/chef/encrypted_data_bag_item.rb', line 227

def initialize(encrypted_data, key)
  @encrypted_data = encrypted_data
  @key = key
end

Instance Attribute Details

#encrypted_dataObject (readonly)

Returns the value of attribute encrypted_data.



224
225
226
# File 'lib/chef/encrypted_data_bag_item.rb', line 224

def encrypted_data
  @encrypted_data
end

#keyObject (readonly)

Returns the value of attribute key.



225
226
227
# File 'lib/chef/encrypted_data_bag_item.rb', line 225

def key
  @key
end

Instance Method Details

#decrypted_dataObject



236
237
238
239
240
241
242
243
# File 'lib/chef/encrypted_data_bag_item.rb', line 236

def decrypted_data
  @decrypted_data ||= begin
    plaintext = openssl_decryptor.update(encrypted_bytes)
    plaintext << openssl_decryptor.final
  rescue OpenSSL::Cipher::CipherError => e
    raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect"
  end
end

#encrypted_bytesObject



245
246
247
# File 'lib/chef/encrypted_data_bag_item.rb', line 245

def encrypted_bytes
  Base64.decode64(@encrypted_data)
end

#for_decrypted_itemObject



232
233
234
# File 'lib/chef/encrypted_data_bag_item.rb', line 232

def for_decrypted_item
  YAML.load(decrypted_data)
end

#openssl_decryptorObject



249
250
251
252
253
254
255
256
# File 'lib/chef/encrypted_data_bag_item.rb', line 249

def openssl_decryptor
  @openssl_decryptor ||= begin
    d = OpenSSL::Cipher::Cipher.new(ALGORITHM)
    d.decrypt
    d.pkcs5_keyivgen(key)
    d
  end
end