osx_keychain 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
Binary file
data/.autotest ADDED
@@ -0,0 +1,24 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = "minitest/autorun"
7
+ # at.extra_files << "../some/external/dependency.rb"
8
+ #
9
+ # at.libs << ":../some/external"
10
+ #
11
+ # at.add_exception 'vendor'
12
+ #
13
+ # at.add_mapping(/dependency.rb/) do |f, _|
14
+ # at.files_matching(/test_.*rb$/)
15
+ # end
16
+ #
17
+ # %w(TestA TestB).each do |klass|
18
+ # at.extra_class_map[klass] = "test/test_misc.rb"
19
+ # end
20
+ end
21
+
22
+ # Autotest.add_hook :run_command do |at|
23
+ # system "rake build"
24
+ # end
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-10-16
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/osx_keychain
7
+ lib/osx_keychain.rb
8
+ test/test_osx_keychain.rb
data/README.txt ADDED
@@ -0,0 +1,52 @@
1
+ = osx_keychain
2
+
3
+ * http://rubyforge.org/projects/seattlerb
4
+
5
+ == DESCRIPTION:
6
+
7
+ Provides API and a command line tool to Access the OS X Keychain. The
8
+ command line tool isn't actually useful (use `security` instead), but
9
+ demonstrates the usage quite well.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ * Very simple hash-like access to the OS X keychain.
14
+
15
+ == SYNOPSIS:
16
+
17
+ keychain = OSXKeychain.new
18
+ keychain[service, username] = password
19
+ p keychain[service, username]
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * RubyInline
24
+
25
+ == INSTALL:
26
+
27
+ * sudo gem install osx_keychain
28
+
29
+ == LICENSE:
30
+
31
+ (The MIT License)
32
+
33
+ Copyright (c) Ryan Davis, seattle.rb
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining
36
+ a copy of this software and associated documentation files (the
37
+ 'Software'), to deal in the Software without restriction, including
38
+ without limitation the rights to use, copy, modify, merge, publish,
39
+ distribute, sublicense, and/or sell copies of the Software, and to
40
+ permit persons to whom the Software is furnished to do so, subject to
41
+ the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be
44
+ included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
47
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
49
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
50
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
51
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
52
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :seattlerb
7
+
8
+ Hoe.spec 'osx_keychain' do
9
+ developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
10
+
11
+ extra_deps << ['RubyInline', '~> 3']
12
+
13
+ self.rubyforge_name = 'seattlerb'
14
+ end
15
+
16
+ # vim: syntax=ruby
data/bin/osx_keychain ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'osx_keychain'
4
+
5
+ keychain = OSXKeychain.new
6
+
7
+ action = ARGV.shift
8
+
9
+ abort "usage: #{File.basename $0} (get|set) service [user] [pass]" unless action
10
+
11
+ case action
12
+ when "get" then
13
+ p keychain[ARGV.shift, ARGV.shift]
14
+ when "set" then
15
+ keychain[ARGV.shift, ARGV.shift] = ARGV.shift
16
+ else
17
+ warn "unknown command: #{action}"
18
+ end
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'inline'
5
+
6
+ class OSXKeychain
7
+ VERSION = '1.0.0'
8
+
9
+ def []= service, username, password
10
+ set(service, username, password)
11
+ end
12
+
13
+ def [] service, username = nil
14
+ get(service, username)
15
+ end
16
+
17
+ inline :C do |builder|
18
+ builder.include '<Security/Security.h>'
19
+
20
+ builder.add_link_flags %w[-lc]
21
+
22
+ builder.add_link_flags %w[-framework Security
23
+ -framework CoreFoundation
24
+ -framework CoreServices]
25
+
26
+ builder.c <<-EOC
27
+ VALUE get(char * service, VALUE _username) {
28
+ char *username = RTEST(_username) ? StringValueCStr(_username) : NULL;
29
+ OSStatus status;
30
+ UInt32 length;
31
+ CFArrayRef keychains = NULL;
32
+ void *data;
33
+ VALUE result = Qnil;
34
+
35
+ status = SecKeychainCopySearchList(&keychains);
36
+
37
+ if (status)
38
+ rb_raise(rb_eRuntimeError,
39
+ "can't access keychains, Authorization failed: %d", status);
40
+
41
+ status = SecKeychainFindGenericPassword(keychains,
42
+ strlen(service), service,
43
+ username ? strlen(username) : 0, username,
44
+ &length, &data, NULL);
45
+
46
+ if (status == errSecItemNotFound)
47
+ status = SecKeychainFindInternetPassword(keychains,
48
+ strlen(service), service,
49
+ 0, NULL,
50
+ username ? strlen(username) : 0, username,
51
+ 0, NULL, 0, kSecProtocolTypeAny, kSecAuthenticationTypeAny,
52
+ &length, &data, NULL);
53
+
54
+ switch (status) {
55
+ case 0:
56
+ result = rb_str_new(data, length);
57
+ SecKeychainItemFreeContent(NULL, data);
58
+ break;
59
+ case errSecItemNotFound:
60
+ // do nothing, return nil password
61
+ break;
62
+ default:
63
+ rb_raise(rb_eRuntimeError, "Can't fetch password from system");
64
+ break;
65
+ }
66
+
67
+ CFRelease(keychains);
68
+
69
+ return result;
70
+ }
71
+ EOC
72
+
73
+ builder.c <<-EOC
74
+ void set(char * service, char * username, char * password) {
75
+ OSStatus status;
76
+ SecKeychainRef keychain;
77
+ SecKeychainItemRef item;
78
+
79
+ status = SecKeychainOpen("login.keychain",&keychain);
80
+
81
+ if (status)
82
+ rb_raise(rb_eRuntimeError,
83
+ "can't access keychains, Authorization failed: %d", status);
84
+
85
+ status = SecKeychainFindGenericPassword(keychain,
86
+ strlen(service), service,
87
+ username == NULL ? 0 : strlen(username), username,
88
+ 0, NULL, &item);
89
+
90
+ switch (status) {
91
+ case 0:
92
+ status = SecKeychainItemModifyAttributesAndData(item, NULL,
93
+ strlen(password), password);
94
+ CFRelease(item);
95
+ break;
96
+ case errSecItemNotFound:
97
+ status = SecKeychainAddGenericPassword(keychain,
98
+ strlen(service), service,
99
+ username == NULL ? 0 : strlen(username), username,
100
+ strlen(password), password,
101
+ NULL);
102
+ break;
103
+ default:
104
+ rb_raise(rb_eRuntimeError, "Can't fetch password from system");
105
+ break;
106
+ }
107
+
108
+ if (status)
109
+ rb_raise(rb_eRuntimeError, "Can't store password in Keychain");
110
+ }
111
+ EOC
112
+ end
113
+ end
@@ -0,0 +1,15 @@
1
+ require "minitest/autorun"
2
+ require "osx_keychain"
3
+
4
+ class TestOsxKeychain < MiniTest::Unit::TestCase
5
+ def test_sanity
6
+ keychain = OSXKeychain.new
7
+
8
+ serv, user, pass = %w[osx_keychain_test username password]
9
+
10
+ keychain[serv, user] = pass
11
+
12
+ assert_equal pass, keychain[serv, user]
13
+ assert_equal pass, keychain[serv]
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osx_keychain
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDPjCCAiagAwIBAgIBADANBgkqhk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5peR8TP/PtmIg7Cyqz23sLM4mCOoTGIy5OcZ8TdyiyINUHtb5ej/T
30
+ FBHgymkyj/AOSqKRIpXPhjC6
31
+ -----END CERTIFICATE-----
32
+
33
+ date: 2009-10-16 00:00:00 -07:00
34
+ default_executable:
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: RubyInline
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: "3"
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: hoe
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.3
55
+ version:
56
+ description: |-
57
+ Provides API and a command line tool to Access the OS X Keychain. The
58
+ command line tool isn't actually useful (use `security` instead), but
59
+ demonstrates the usage quite well.
60
+ email:
61
+ - ryand-ruby@zenspider.com
62
+ executables:
63
+ - osx_keychain
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - History.txt
68
+ - Manifest.txt
69
+ - README.txt
70
+ files:
71
+ - .autotest
72
+ - History.txt
73
+ - Manifest.txt
74
+ - README.txt
75
+ - Rakefile
76
+ - bin/osx_keychain
77
+ - lib/osx_keychain.rb
78
+ - test/test_osx_keychain.rb
79
+ has_rdoc: true
80
+ homepage: http://rubyforge.org/projects/seattlerb
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --main
86
+ - README.txt
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ version:
101
+ requirements: []
102
+
103
+ rubyforge_project: seattlerb
104
+ rubygems_version: 1.3.5
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Provides API and a command line tool to Access the OS X Keychain
108
+ test_files:
109
+ - test/test_osx_keychain.rb
metadata.gz.sig ADDED
@@ -0,0 +1,4 @@
1
+
2
+ ��ŊP��Q8~44�ͨ&�9�o�ջ�:��y�^f�\��v�͟{V�1a{ �s�$ D!�ۘBb���]B�*yD_�p��-�*~d�</���S �8c�A.���_j���8�xu��s§nv�+iΥ���φ(D���ͺ��L�j�k�>�=
3
+ �Hge��c��1��v�/��/��B�t��'�,��
4
+ �7HՃ͂���(Hb�h���sN*��T �S��\����iy���h���-/}΂��m����ش���]���