Class: CICI::Decrypt

Inherits:
Object
  • Object
show all
Includes:
CICI
Defined in:
lib/cici/decrypt.rb

Constant Summary

Constants included from CICI

DECRYPT_IV_ENV_VAR, DECRYPT_KEY_ENV_VAR

Instance Method Summary collapse

Constructor Details

#initialize(ui, config) ⇒ Decrypt

Returns a new instance of Decrypt.



18
19
20
21
22
# File 'lib/cici/decrypt.rb', line 18

def initialize(ui, config)
  @ui = ui
  @config = config
  @util = CICI::Util.new(@ui)
end

Instance Method Details

#decrypt(key, iv) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cici/decrypt.rb', line 40

def decrypt(key, iv)
  @ui.verbose('Decrypting secrets encrypted file.')

  decipher = OpenSSL::Cipher.new('AES-256-CBC')
  decipher.decrypt
  decipher.key = key
  decipher.iv = iv

  plain = decipher.update(File.read(@config.output_file_encrypted)) + decipher.final

  plain
end

#start(set) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cici/decrypt.rb', line 24

def start(set)
  @set = set

  assert_encrypted_secret_exist
  plain = decrypt(Base64.decode64(@util.get_env(CICI::DECRYPT_KEY_ENV_VAR)), Base64.decode64(@util.get_env(CICI::DECRYPT_IV_ENV_VAR)))
  if !plain.empty?
    File.write(@config.output_file, plain)
  else
    @ui.fail('Wrong key/iv pair for decryption.')
  end
  decompress
  copy_files

  @ui.success('Files successfully decrypted and copied to their destination!')
end