Class: ChefKeepass::Certificate

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-keepass/certificate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_bag, name) ⇒ Certificate

Returns a new instance of Certificate.



5
6
7
8
# File 'lib/chef-keepass/certificate.rb', line 5

def initialize(data_bag, name)
  @name = name
  @data_bag = data_bag
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/chef-keepass/certificate.rb', line 3

def name
  @name
end

Instance Method Details

#decrypt_contentsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chef-keepass/certificate.rb', line 10

def decrypt_contents
  # use the private client_key file to create a decryptor
  private_key = open(Chef::Config[:client_key]).read
  private_key = OpenSSL::PKey::RSA.new(private_key)
  keys = Chef::DataBagItem.load(@data_bag, "#{name}_keys")

  unless keys[Chef::Config[:node_name]]
    throw "#{name} is not encrypted for you!  Rebuild the certificate data bag"
  end

  node_key = Base64.decode64(keys[Chef::Config[:node_name]])
  shared_secret = private_key.private_decrypt(node_key)
  certificate = Chef::EncryptedDataBagItem.load(@data_bag, @name, shared_secret)

  certificate["contents"]
end