keyring 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -4
- data/keyring.gemspec +4 -0
- data/lib/keyring/backend.rb +1 -1
- data/lib/keyring/backends/gnome_keyring.rb +64 -0
- data/lib/keyring/backends/macosx_keychain.rb +4 -0
- data/lib/keyring/version.rb +1 -1
- data/test/test_backend.rb +19 -2
- data/test/test_backend_gnome_keyring.rb +56 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce4f04bde155cc548222940ab51bf72adc2e6357
|
4
|
+
data.tar.gz: 050a04df00a9229f8125081a79f99f7e2b5c5a05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85f263a69ac38e96fca4ccba27afda79097d0f226e0fe93938c0fddfb5b703a507e995d3ba065ddc5daf7302083963033f715bfe91205cac2bead32fa0601aec
|
7
|
+
data.tar.gz: b4d625b3e639b98c9a8afed3a06c59ffd324271b7377f85da8593c284fdce8997788095ea9e57fab46fcae388dd344341debc82c138afad95487185277b6370c
|
data/README.md
CHANGED
@@ -6,14 +6,15 @@ This library provides a easy way to access the system keyring service from ruby.
|
|
6
6
|
It can be used in any application that needs safe password storage.
|
7
7
|
|
8
8
|
The keyring services supported by this library:
|
9
|
-
* Mac OS X Keychain: the Apple Keychain service in Mac OS X
|
9
|
+
* Mac OS X Keychain: the Apple Keychain service in Mac OS X
|
10
|
+
* GNOME 2 Keyring
|
10
11
|
* In-memory keychain
|
11
12
|
|
12
13
|
Additional keyring services we'd like to support:
|
13
14
|
* KDE KWallet
|
14
|
-
* GNOME
|
15
|
-
* SecretServiceKeyring: for newer GNOME and KDE environments.
|
15
|
+
* SecretServiceKeyring: for newer GNOME and KDE environments
|
16
16
|
* Windows Credential Manager
|
17
|
+
* Windows Credential Manager, aka Windows Vault
|
17
18
|
|
18
19
|
## Installation
|
19
20
|
|
@@ -42,9 +43,20 @@ Keyring#get_password:
|
|
42
43
|
|
43
44
|
'service' is an arbitrary string identifying your application.
|
44
45
|
|
46
|
+
By default keyring will attempt to pick the best backend supported on your system. You can specify a particular backend:
|
47
|
+
|
48
|
+
require 'keyring'
|
49
|
+
keyring = Keyring.new(Keyring::Backend::Memory.new)
|
50
|
+
|
51
|
+
## Platform notes
|
52
|
+
|
53
|
+
Gnome Keyring uses the [GirFFI](https://github.com/mvz/gir_ffi) bindings, which
|
54
|
+
requires the introspection bindings to be installed (as well as gnome-keyring).
|
55
|
+
`apt-get install gnome-keyring libgirepository1.0-dev` for Debian/Ubuntu.
|
56
|
+
|
45
57
|
## Credits
|
46
58
|
|
47
|
-
Copyright 2013, Jason Heiss
|
59
|
+
Copyright 2013-2014, Jason Heiss, wvengen
|
48
60
|
|
49
61
|
Inspired by the keyring library for Python:
|
50
62
|
https://bitbucket.org/kang/python-keyring-lib
|
data/keyring.gemspec
CHANGED
data/lib/keyring/backend.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
# keyring: System keyring abstraction library
|
2
|
+
# License: MIT (http://www.opensource.org/licenses/mit-license.php)
|
3
|
+
|
4
|
+
# This is a keyring backend for the Gnome Keyring
|
5
|
+
# https://wiki.gnome.org/GnomeKeyring
|
6
|
+
# http://en.wikipedia.org/wiki/GNOME_Keyring
|
7
|
+
|
8
|
+
class Keyring::Backend::GnomeKeyring < Keyring::Backend
|
9
|
+
register_implementation(self)
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
require 'gir_ffi-gnome_keyring'
|
13
|
+
rescue LoadError
|
14
|
+
end
|
15
|
+
def supported?
|
16
|
+
defined?(::GnomeKeyring) && true
|
17
|
+
end
|
18
|
+
def priority
|
19
|
+
1
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_password(service, username, password)
|
23
|
+
attrs = get_attrs_for(service, username)
|
24
|
+
name = "#{service} (#{username})"
|
25
|
+
status, item_id = ::GnomeKeyring.item_create_sync nil, :generic_secret, name, attrs, password, true
|
26
|
+
item_id if status == :ok
|
27
|
+
end
|
28
|
+
def get_password(service, username)
|
29
|
+
if item = find_first(service, username)
|
30
|
+
item.secret
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def delete_password(service, username)
|
36
|
+
if item = find_first(service, username)
|
37
|
+
status, info = ::GnomeKeyring.item_delete_sync nil, item.item_id
|
38
|
+
status == :ok
|
39
|
+
else
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def find_first(service, username)
|
47
|
+
if list = find(service, username)
|
48
|
+
list.first
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def find(service, username)
|
53
|
+
attrs = get_attrs_for(service, username)
|
54
|
+
status, keys = ::GnomeKeyring.find_items_sync :generic_secret, attrs
|
55
|
+
keys if status == :ok
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_attrs_for(service, username)
|
59
|
+
attrs = ::GnomeKeyring::AttributeList.new
|
60
|
+
attrs.append_string 'service', service.to_s
|
61
|
+
attrs.append_string 'username', username.to_s
|
62
|
+
attrs
|
63
|
+
end
|
64
|
+
end
|
@@ -4,6 +4,10 @@
|
|
4
4
|
# This is a keyring backend for the Apple Keychain
|
5
5
|
# http://en.wikipedia.org/wiki/Keychain_(Apple)
|
6
6
|
|
7
|
+
# Consider switching to ruby-keychain gem to avoid password in command line
|
8
|
+
# https://rubygems.org/gems/ruby-keychain
|
9
|
+
# https://github.com/fcheung/keychain
|
10
|
+
|
7
11
|
require 'open3'
|
8
12
|
|
9
13
|
class Keyring::Backend::MacosxKeychain < Keyring::Backend
|
data/lib/keyring/version.rb
CHANGED
data/test/test_backend.rb
CHANGED
@@ -8,18 +8,35 @@ class KeyringBackendTests < Test::Unit::TestCase
|
|
8
8
|
def setup
|
9
9
|
@backend = Keyring::Backend.new
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
class Keyring::Backend::Test < Keyring::Backend; end
|
13
|
+
class BackendHighPriority < Keyring::Backend
|
14
|
+
def priority; 100 end
|
15
|
+
def supported?; true end
|
16
|
+
end
|
17
|
+
class BackendLowPriority < Keyring::Backend
|
18
|
+
def priority; 10 end
|
19
|
+
def supported?; true end
|
20
|
+
end
|
21
|
+
|
13
22
|
def test_register_implementation
|
14
23
|
Keyring::Backend.register_implementation(Keyring::Backend::Test)
|
15
24
|
assert Keyring::Backend.implementations.include?(Keyring::Backend::Test)
|
16
25
|
Keyring::Backend.implementations.delete(Keyring::Backend::Test)
|
17
26
|
end
|
27
|
+
|
18
28
|
def test_create
|
19
29
|
# This should be a bit more thorough
|
20
30
|
assert_kind_of Keyring::Backend, Keyring::Backend.create
|
31
|
+
|
32
|
+
# check that backend with highest priority is selected
|
33
|
+
Keyring::Backend.register_implementation(BackendHighPriority)
|
34
|
+
Keyring::Backend.register_implementation(BackendLowPriority)
|
35
|
+
assert_kind_of BackendHighPriority, Keyring::Backend.create
|
36
|
+
Keyring::Backend.implementations.delete(BackendLowPriority)
|
37
|
+
Keyring::Backend.implementations.delete(BackendHighPriority)
|
21
38
|
end
|
22
|
-
|
39
|
+
|
23
40
|
def test_supported
|
24
41
|
refute @backend.supported?
|
25
42
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# keyring: System keyring abstraction library
|
2
|
+
# License: MIT (http://www.opensource.org/licenses/mit-license.php)
|
3
|
+
|
4
|
+
# These tests require Gnome Keyring to be installed and are skipped otherwise
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'mocha/setup'
|
8
|
+
require 'keyring'
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'gir_ffi-gnome_keyring'
|
12
|
+
|
13
|
+
class KeyringBackendGnomeKeyringTests < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@backend = Keyring::Backend::GnomeKeyring.new
|
17
|
+
@backend.delete_password('service', 'username')
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
@backend.delete_password('service', 'username')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_supported
|
25
|
+
assert @backend.supported?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_priority
|
29
|
+
assert_equal 1, @backend.priority
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_no_default_password
|
33
|
+
refute @backend.get_password('service', 'username')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_set_password
|
37
|
+
@backend.set_password('service', 'username', 'password')
|
38
|
+
assert_equal 'password', @backend.get_password('service', 'username')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_delete_nonexistent_password
|
42
|
+
refute @backend.delete_password('service', 'username')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_delete_existing_password
|
46
|
+
@backend.set_password('service', 'username', 'password')
|
47
|
+
@backend.delete_password('service', 'username')
|
48
|
+
refute @backend.get_password('service', 'username')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
rescue LoadError
|
55
|
+
puts "Skipping GnomeKeyring tests because the native bindings could not be loaded."
|
56
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keyring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Heiss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,12 +84,14 @@ files:
|
|
84
84
|
- keyring.gemspec
|
85
85
|
- lib/keyring.rb
|
86
86
|
- lib/keyring/backend.rb
|
87
|
+
- lib/keyring/backends/gnome_keyring.rb
|
87
88
|
- lib/keyring/backends/macosx_keychain.rb
|
88
89
|
- lib/keyring/backends/memory.rb
|
89
90
|
- lib/keyring/cli.rb
|
90
91
|
- lib/keyring/version.rb
|
91
92
|
- test/keyring_tests.rb
|
92
93
|
- test/test_backend.rb
|
94
|
+
- test/test_backend_gnome_keyring.rb
|
93
95
|
- test/test_backend_macosx_keychain.rb
|
94
96
|
- test/test_backend_memory.rb
|
95
97
|
- test/test_cli.rb
|
@@ -124,13 +126,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
126
|
version: '0'
|
125
127
|
requirements: []
|
126
128
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.2.
|
129
|
+
rubygems_version: 2.2.2
|
128
130
|
signing_key:
|
129
131
|
specification_version: 4
|
130
132
|
summary: Store and access your passwords safely
|
131
133
|
test_files:
|
132
134
|
- test/keyring_tests.rb
|
133
135
|
- test/test_backend.rb
|
136
|
+
- test/test_backend_gnome_keyring.rb
|
134
137
|
- test/test_backend_macosx_keychain.rb
|
135
138
|
- test/test_backend_memory.rb
|
136
139
|
- test/test_cli.rb
|
@@ -145,3 +148,4 @@ test_files:
|
|
145
148
|
- test/testcmds/macosx/security-notfound
|
146
149
|
- test/testcmds/macosx/security-righthelp
|
147
150
|
- test/testcmds/macosx/security-wronghelp
|
151
|
+
has_rdoc:
|