class Exportation::Keychain
Attributes
password[RW]
path[RW]
Public Class Methods
find_or_create_keychain(name, password, output_directory='./')
click to toggle source
# File lib/exportation.rb, line 127 def self.find_or_create_keychain(name, password, output_directory='./') path = chain_path(name, output_directory) unless File.exists? path `security create-keychain -p '#{password}' #{path}` end Keychain.new(path: path, password: password) end
list_keychains()
click to toggle source
# File lib/exportation.rb, line 142 def self.list_keychains # Gets a list of all the user's keychains in an array # The keychain are paths wrapped in double quotes (`security list-keychains -d user`).scan(/(?:\w|"[^"]*")+/) end
login_keychain(password)
click to toggle source
# File lib/exportation.rb, line 137 def self.login_keychain(password) path = `security login-keychain`.strip Keychain.new(path: path, password: password) end
new(options)
click to toggle source
# File lib/exportation.rb, line 122 def initialize(options) @path = options[:path] @password = options[:password] end
Private Class Methods
chain_path(name, output_directory='./')
click to toggle source
# File lib/exportation.rb, line 178 def self.chain_path(name, output_directory='./') output_directory = File.expand_path output_directory File.join(output_directory, "#{name}.keychain") end
Public Instance Methods
add_to_keychain_list!()
click to toggle source
# File lib/exportation.rb, line 164 def add_to_keychain_list! # Adds the keychain to the search list keychains = (Keychain.list_keychains - ["\"#{@path}\""]).join(' ') `security list-keychains -d user -s #{keychains} \"#{@path}\"` end
import_certificate(cer_path)
click to toggle source
# File lib/exportation.rb, line 148 def import_certificate(cer_path) # Imports a certificate into the keychain `security import #{cer_path} -k #{@path} -T /usr/bin/codesign` end
import_private_key(key_path, password)
click to toggle source
# File lib/exportation.rb, line 153 def import_private_key(key_path, password) # Imports a private key into the keychain `security import #{key_path} -k #{@path} -P '#{password}' -T /usr/bin/codesign` end
remove_keychain_from_list!()
click to toggle source
# File lib/exportation.rb, line 170 def remove_keychain_from_list! # Removes the keychain from the search list keychains = (Keychain.list_keychains - ["\"#{@path}\""]).join(' ') `security list-keychains -d user -s #{keychains}` end
unlock!()
click to toggle source
# File lib/exportation.rb, line 158 def unlock! # Unlocks the keychain `security unlock-keychain -p '#{@password}' #{@path}` `security -v set-keychain-settings #{@path}` end