Class: Xcode::Keychain
- Inherits:
-
Object
- Object
- Xcode::Keychain
- Defined in:
- lib/xcode/keychain.rb
Constant Summary collapse
- TEMP_PASSWORD =
"build_keychain_password"
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
-
.create(path, password) {|kc| ... } ⇒ Xcode::Keychain
Create a new keychain with the given name and password.
-
.login {|kc| ... } ⇒ Xcode::Keychain
Opens the default login.keychain for current user.
-
.temp ⇒ Object
Creates a keychain with the given name that lasts for the duration of the provided block.
Instance Method Summary collapse
-
#delete ⇒ Object
Remove the keychain from the filesystem.
-
#identities ⇒ Array<String>
Returns a list of identities in the keychain.
-
#import(cert, password) ⇒ Object
Import the .p12 certificate file into the keychain using the provided password.
-
#initialize(path) {|_self| ... } ⇒ Keychain
constructor
Open the keychain with the specified name.
-
#lock ⇒ Object
Secure the keychain.
-
#unlock(password) ⇒ Object
Unlock the keychain using the provided password.
Constructor Details
#initialize(path) {|_self| ... } ⇒ Keychain
Open the keychain with the specified name. It is assumed that keychains reside in the ~/Library/Keychains directory
58 59 60 61 62 63 |
# File 'lib/xcode/keychain.rb', line 58 def initialize(path) @path = File. path @name = File.basename path yield(self) if block_given? end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
48 49 50 |
# File 'lib/xcode/keychain.rb', line 48 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
48 49 50 |
# File 'lib/xcode/keychain.rb', line 48 def path @path end |
Class Method Details
.create(path, password) {|kc| ... } ⇒ Xcode::Keychain
Create a new keychain with the given name and password
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/xcode/keychain.rb', line 128 def self.create(path, password) cmd = Xcode::Shell::Command.new "security" cmd << "create-keychain" cmd << "-p #{password}" cmd << "\"#{path}\"" cmd.execute kc = Xcode::Keychain.new(path) yield(kc) if block_given? kc end |
.login {|kc| ... } ⇒ Xcode::Keychain
Opens the default login.keychain for current user
180 181 182 183 184 |
# File 'lib/xcode/keychain.rb', line 180 def self.login kc = Xcode::Keychain.new("~/Library/Keychains/login.keychain") yield(kc) if block_given? kc end |
.temp ⇒ Object
Creates a keychain with the given name that lasts for the duration of the provided block.
The keychain is deleted even if the block throws an exception.
If no block is provided, the temporary keychain is returned and it is deleted on system exit
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/xcode/keychain.rb', line 157 def self.temp kc = Xcode::Keychain.create("/tmp/xcoder#{Time.now.to_i}", TEMP_PASSWORD) kc.unlock(TEMP_PASSWORD) if !block_given? at_exit do kc.delete end kc else begin yield(kc) ensure kc.delete end end end |
Instance Method Details
#delete ⇒ Object
Remove the keychain from the filesystem
FIXME: dangerous
145 146 147 148 149 |
# File 'lib/xcode/keychain.rb', line 145 def delete cmd = Xcode::Shell::Command.new "security" cmd << "delete-keychain \"#{@path}\"" cmd.execute end |
#identities ⇒ Array<String>
Returns a list of identities in the keychain.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/xcode/keychain.rb', line 85 def identities names = [] cmd = Xcode::Shell::Command.new "security" cmd << "find-certificate" cmd << "-a" cmd << "\"#{@path}\"" data = cmd.execute(false).join("") data.scan /\s+"labl"<blob>="([^"]+)"/ do |m| names << m[0] end names end |
#import(cert, password) ⇒ Object
Import the .p12 certificate file into the keychain using the provided password
71 72 73 74 75 76 77 78 |
# File 'lib/xcode/keychain.rb', line 71 def import(cert, password) cmd = Xcode::Shell::Command.new "security" cmd << "import '#{cert}'" cmd << "-k \"#{@path}\"" cmd << "-P #{password}" cmd << "-T /usr/bin/codesign" cmd.execute end |