Class: Match::Encryption::OpenSSL

Inherits:
Interface
  • Object
show all
Defined in:
match/lib/match/encryption/openssl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keychain_name: nil, working_directory: nil) ⇒ OpenSSL

Returns a new instance of OpenSSL.

Parameters:

  • keychain_name: (defaults to: nil)

    The identifier used to store the passphrase in the Keychain

  • working_directory: (defaults to: nil)

    The path to where the certificates are stored



26
27
28
29
# File 'match/lib/match/encryption/openssl.rb', line 26

def initialize(keychain_name: nil, working_directory: nil)
  self.keychain_name = keychain_name
  self.working_directory = working_directory
end

Instance Attribute Details

#keychain_nameObject

Returns the value of attribute keychain_name.



13
14
15
# File 'match/lib/match/encryption/openssl.rb', line 13

def keychain_name
  @keychain_name
end

#working_directoryObject

Returns the value of attribute working_directory.



15
16
17
# File 'match/lib/match/encryption/openssl.rb', line 15

def working_directory
  @working_directory
end

Class Method Details

.configure(params) ⇒ Object



17
18
19
20
21
22
# File 'match/lib/match/encryption/openssl.rb', line 17

def self.configure(params)
  return self.new(
    keychain_name: params[:keychain_name],
    working_directory: params[:working_directory]
  )
end

Instance Method Details

#clear_passwordObject

removes the password from the keychain again



69
70
71
# File 'match/lib/match/encryption/openssl.rb', line 69

def clear_password
  Security::InternetPassword.delete(server: server_name(self.keychain_name))
end

#decrypt_filesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'match/lib/match/encryption/openssl.rb', line 43

def decrypt_files
  files = []
  password = fetch_password!
  iterate(self.working_directory) do |current|
    files << current
    begin
      decrypt_specific_file(path: current, password: password)
    rescue => ex
      UI.verbose(ex.to_s)
      UI.error("Couldn't decrypt the repo, please make sure you enter the right password!")
      UI.user_error!("Invalid password passed via 'MATCH_PASSWORD'") if ENV["MATCH_PASSWORD"]
      clear_password
      self.decrypt_files # Call itself
      return
    end
    UI.success("🔓  Decrypted '#{File.basename(current)}'") if FastlaneCore::Globals.verbose?
  end
  UI.success("🔓  Successfully decrypted certificates repo")
  return files
end

#encrypt_files(password: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'match/lib/match/encryption/openssl.rb', line 31

def encrypt_files(password: nil)
  files = []
  password ||= fetch_password!
  iterate(self.working_directory) do |current|
    files << current
    encrypt_specific_file(path: current, password: password)
    UI.success("🔒  Encrypted '#{File.basename(current)}'") if FastlaneCore::Globals.verbose?
  end
  UI.success("🔒  Successfully encrypted certificates repo")
  return files
end

#store_password(password) ⇒ Object



64
65
66
# File 'match/lib/match/encryption/openssl.rb', line 64

def store_password(password)
  Security::InternetPassword.add(server_name(self.keychain_name), "", password)
end