keychain_osx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a29289175bbb0064b44b0e51ab1d42569e3cf82a
4
+ data.tar.gz: 929558223113fcd97cb8b8001616814e6ab76e74
5
+ SHA512:
6
+ metadata.gz: 9680d174434d0c49d2259cd86c08af5bed0088d16ac34bafb17ca46f735f40b4d663a66e73d70c8de198a8df09e01c6c89d13e5df1931748709dc74c6e70053b
7
+ data.tar.gz: a3a0d36ae49e2de25517f7fcac61507534d7d2c6ac8e4c31f85ad402eb42d383b08e61b5462fe233ba06dc50ba3cb3e5a697c1a498f2495ed22bc0df74aa8e42
@@ -0,0 +1,15 @@
1
+ module OSX
2
+
3
+ module Command
4
+ def self.run(*cmd, &block)
5
+ unless block_given?
6
+ block = lambda { |ok, status|
7
+ ok or fail "Command failed with status (#{status.exitstatus}): [#{cmd.join(" ")}]"
8
+ }
9
+ end
10
+ puts cmd
11
+ res = system(*cmd)
12
+ block.call(res, $?)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,74 @@
1
+ KEYCHAIN_LOCATION = "/tmp/temp_keychain#{Time.now.to_i}.keychain"
2
+ TEMP_PASSWORD = "keychain_password"
3
+
4
+ module OSX
5
+
6
+ class Keychain
7
+
8
+ attr_accessor :keychain_path
9
+
10
+ def initialize(keychain_path, key_password)
11
+ @keychain_path = keychain_path
12
+ create(key_password)
13
+ unlock(key_password)
14
+ add_to_search_path
15
+ end
16
+
17
+ def unlock(password)
18
+ command = "security unlock-keychain -p #{password} \"#{@keychain_path}\""
19
+ OSX::Command::run(command)
20
+ end
21
+
22
+ def import(cert, password)
23
+ command = "security import '#{cert}' -k \"#{@keychain_path}\" -P #{password} -T /usr/bin/codesign"
24
+ OSX::Command::run(command)
25
+ end
26
+
27
+ def delete
28
+ command = "security delete-keychain #{@keychain_path}"
29
+ OSX::Command::run(command)
30
+ end
31
+
32
+ def set_default
33
+ command = "security default-keychain -s #{@keychain_path}"
34
+ OSX::Command::run(command)
35
+ end
36
+
37
+ def add_to_search_path
38
+ keychains = []
39
+
40
+ `security list-keychain`.split.map do |keychain|
41
+ keychains << keychain.strip.gsub(/\"/,'')
42
+ end
43
+
44
+ keychains << @keychain_path
45
+
46
+ command = "security list-keychain -s #{keychains.join(' ')}"
47
+ OSX::Command::run(command)
48
+ end
49
+
50
+ def self.temp(&block)
51
+ kc = OSX::Keychain.new(KEYCHAIN_LOCATION, TEMP_PASSWORD)
52
+ kc.unlock(TEMP_PASSWORD)
53
+
54
+ if block_given? # block is given
55
+ begin
56
+ yield(kc)
57
+ ensure
58
+ kc.delete
59
+ end
60
+ else
61
+ kc.delete
62
+ end
63
+ end
64
+
65
+ private
66
+ def create(key_password, timeout = 600)
67
+ command = "security create-keychain -p #{key_password} \"#{@keychain_path}\""
68
+ OSX::Command::run(command)
69
+
70
+ command = "security set-keychain-settings -u \"#{@keychain_path}\""
71
+ OSX::Command::run(command)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,108 @@
1
+ require 'fileutils'
2
+
3
+ module OSX
4
+
5
+ class ProvisioningProfile
6
+ attr_reader :path, :name, :uuid, :identifiers, :devices, :appstore
7
+
8
+ def initialize(path)
9
+
10
+ raise "Provisioning profile '#{path}' does not exist" unless File.exists? path
11
+
12
+ @path = path
13
+ @identifiers = []
14
+ @devices = []
15
+ @appstore = true
16
+ @enterprise = false
17
+
18
+ uuid = nil
19
+ find_profile_uuid(path)
20
+ end
21
+
22
+ def find_profile_uuid(path)
23
+ File.open(path, "rb") do |f|
24
+ input = f.read
25
+
26
+ if input=~/ProvisionedDevices/
27
+ @appstore = false
28
+ end
29
+
30
+ if input=~/<key>ProvisionsAllDevices<\/key>/
31
+ @enterprise = true
32
+ end
33
+
34
+ if input=~/<key>ProvisionedDevices<\/key>.*?<array>(.*?)<\/array>/im
35
+ $1.split(/<string>/).each do |id|
36
+ next if id.nil? or id.strip==""
37
+ @devices << id.gsub(/<\/string>/,'').strip
38
+ end
39
+ end
40
+
41
+ input=~/<key>UUID<\/key>.*?<string>(.*?)<\/string>/im
42
+ @uuid = $1.strip
43
+
44
+ input=~/<key>Name<\/key>.*?<string>(.*?)<\/string>/im
45
+ @name = $1.strip
46
+
47
+ input=~/<key>ApplicationIdentifierPrefix<\/key>.*?<array>(.*?)<\/array>/im
48
+ $1.split(/<string>/).each do |id|
49
+ next if id.nil? or id.strip==""
50
+ @identifiers << id.gsub(/<\/string>/,'').strip
51
+ end
52
+ end
53
+ end
54
+
55
+ def appstore?
56
+ @appstore
57
+ end
58
+
59
+ def enterprise?
60
+ @enterprise
61
+ end
62
+
63
+ def self.profiles_path
64
+ File.expand_path "~/Library/MobileDevice/Provisioning\ Profiles/"
65
+ end
66
+
67
+ def install_path
68
+ "#{ProvisioningProfile.profiles_path}/#{self.uuid}.mobileprovision"
69
+ end
70
+
71
+ def install
72
+ # Do not reinstall if profile is same and is already installed
73
+ return if (self.path == self.install_path.gsub(/\\ /, ' '))
74
+
75
+ ProvisioningProfile.installed_profiles.each do |installed|
76
+ if installed.identifiers==self.identifiers and installed.uuid==self.uuid
77
+ installed.uninstall
78
+ end
79
+ end
80
+
81
+ FileUtils.mkdir_p(File.dirname(self.install_path))
82
+ FileUtils.cp(self.path, self.install_path)
83
+ end
84
+
85
+ def uninstall
86
+ command = "rm -f #{self.install_path}"
87
+ OSX::Command::run(command)
88
+ end
89
+
90
+ def self.installed_profiles
91
+ Dir["#{self.profiles_path}/*.mobileprovision"].map do |file|
92
+ ProvisioningProfile.new(file)
93
+ end
94
+ end
95
+
96
+ def self.find_installed_by_uuid uuid
97
+ ProvisioningProfile.installed_profiles.each do |p|
98
+ return p if p.uuid == uuid
99
+ end
100
+ end
101
+
102
+ def self.installed_profile(name)
103
+ self.installed_profiles.select {|p| p.name == name.to_s}.first;
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,3 @@
1
+ require 'keychain_osx/keychain'
2
+ require 'keychain_osx/command'
3
+ require 'keychain_osx/provisioningprofile'
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keychain_osx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Griffiths
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - Christopher_Griffiths@hotmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/keychain_osx.rb
21
+ - lib/keychain_osx/command.rb
22
+ - lib/keychain_osx/keychain.rb
23
+ - lib/keychain_osx/provisioningprofile.rb
24
+ homepage: https://github.com/ChrisGriffiths/keychain_osx.git
25
+ licenses: []
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.2.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: A ruby wrapper to add Certificates to a temporary keychain
47
+ test_files: []