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


61
62
63
# File 'match/lib/match/encryption/openssl.rb', line 61

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

#decrypt_filesObject


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'match/lib/match/encryption/openssl.rb', line 39

def decrypt_files
  iterate(self.working_directory) do |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")
end

#encrypt_filesObject


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

def encrypt_files
  iterate(self.working_directory) do |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")
end

#store_password(password) ⇒ Object


56
57
58
# File 'match/lib/match/encryption/openssl.rb', line 56

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