keyring-kwallet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 0.1.0 / 2011-05-28
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
@@ -0,0 +1,69 @@
1
+ keyring-kwallet
2
+ ===========
3
+
4
+ KWallet backend for keyring gem.
5
+
6
+ Features
7
+ --------
8
+
9
+ * Provides kwallet interface for the keyring framework
10
+
11
+ Examples
12
+ --------
13
+
14
+ You can use a KWallet keyring directly using an instance of Keyring::KWalletKeyring.
15
+
16
+ require "keyring-kwallet"
17
+ kr = Keyring::KWalletKeyring.new folder:"myfolder", app:"myapp"
18
+ raise "Not supported" unless kr.supported?
19
+ kr.get_password("service", "user")
20
+
21
+ or by putting the following in your user configuration file ~/.rbkeyringrc or the
22
+ path-local configuration ./.rbkeyringrc
23
+ ---
24
+ module: keyring-kwallet
25
+ params:
26
+ folder: myfolder
27
+ app: myapp
28
+
29
+ Requirements
30
+ ------------
31
+
32
+ * keyring
33
+ * ruby-dbus >= 0.6
34
+
35
+ Install
36
+ -------
37
+
38
+ * gem install keyring-kwallet
39
+
40
+ Author
41
+ ------
42
+
43
+ Original author: Frank Fischer
44
+
45
+ License
46
+ -------
47
+
48
+ (The MIT License) FIXME (different license?)
49
+
50
+ Copyright (c) 2011 FIXME (author's name)
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining
53
+ a copy of this software and associated documentation files (the
54
+ 'Software'), to deal in the Software without restriction, including
55
+ without limitation the rights to use, copy, modify, merge, publish,
56
+ distribute, sublicense, and/or sell copies of the Software, and to
57
+ permit persons to whom the Software is furnished to do so, subject to
58
+ the following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be
61
+ included in all copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
64
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
66
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
67
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
68
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
69
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+
2
+ begin
3
+ require 'bones'
4
+ rescue LoadError
5
+ abort '### Please install the "bones" gem ###'
6
+ end
7
+
8
+ task :default => 'spec:run'
9
+ task 'gem:release' => 'spec:run'
10
+
11
+ Bones {
12
+ name 'keyring-kwallet'
13
+ authors 'Frank Fischer'
14
+ email 'frank.fischer@mathematik.tu-chemnitz.de'
15
+ url 'http://darcsden.com/lyro/keyring-kwallet'
16
+ depend_on 'keyring'
17
+ depend_on 'ruby-dbus', '>= 0.6'
18
+ }
19
+
@@ -0,0 +1,60 @@
1
+
2
+ module KeyringKwallet
3
+
4
+ # :stopdoc:
5
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
+ VERSION = ::File.read(PATH + 'version.txt').strip
8
+ # :startdoc:
9
+
10
+ # Returns the library path for the module. If any arguments are given,
11
+ # they will be joined to the end of the libray path using
12
+ # <tt>File.join</tt>.
13
+ #
14
+ def self.libpath( *args )
15
+ rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
16
+ if block_given?
17
+ begin
18
+ $LOAD_PATH.unshift LIBPATH
19
+ rv = yield
20
+ ensure
21
+ $LOAD_PATH.shift
22
+ end
23
+ end
24
+ return rv
25
+ end
26
+
27
+ # Returns the lpath for the module. If any arguments are given,
28
+ # they will be joined to the end of the path using
29
+ # <tt>File.join</tt>.
30
+ #
31
+ def self.path( *args )
32
+ rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
33
+ if block_given?
34
+ begin
35
+ $LOAD_PATH.unshift PATH
36
+ rv = yield
37
+ ensure
38
+ $LOAD_PATH.shift
39
+ end
40
+ end
41
+ return rv
42
+ end
43
+
44
+ # Utility method used to require all files ending in .rb that lie in the
45
+ # directory below this file that has the same name as the filename passed
46
+ # in. Optionally, a specific _directory_ name can be passed in such that
47
+ # the _filename_ does not have to be equivalent to the directory.
48
+ #
49
+ def self.require_all_libs_relative_to( fname, dir = nil )
50
+ dir ||= ::File.basename(fname, '.*')
51
+ search_me = ::File.expand_path(
52
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
53
+
54
+ Dir.glob(search_me).sort.each {|rb| require rb}
55
+ end
56
+
57
+ end # module KeyringKwallet
58
+
59
+ KeyringKwallet.require_all_libs_relative_to(__FILE__)
60
+
@@ -0,0 +1,104 @@
1
+ require "dbus"
2
+ require "set"
3
+
4
+ module Keyring
5
+
6
+ # A keyring implementation using KDE's wallet.
7
+ class KWalletKeyring < Keyring
8
+ # A set of opened wallets, will be closed when the application exits.
9
+ @@open_wallets = Set.new
10
+
11
+ # Called when the application stops to close all wallets.
12
+ at_exit {
13
+ bus = DBus::SessionBus.instance
14
+ kw_service = bus.service("org.kde.kwalletd")
15
+ kwallet = kw_service.object("/modules/kwalletd")
16
+ kwallet.default_iface = "org.kde.KWallet"
17
+ kwallet.introspect
18
+ @@open_wallets.each do |wallet, app|
19
+ kwallet.disconnectApplication(wallet, app)
20
+ end
21
+ }
22
+
23
+ def initialize(params = {})
24
+ super()
25
+ params ||= {}
26
+ @folder = params[:folder] || params["folder"] || $0
27
+ @app_name = params[:app] || params["app"] || $0
28
+ @net_handle = nil
29
+
30
+ begin
31
+ bus = DBus::SessionBus.instance
32
+ kw_service = bus.service("org.kde.kwalletd")
33
+ @kwallet = kw_service.object("/modules/kwalletd")
34
+ @kwallet.default_iface = "org.kde.KWallet"
35
+ @kwallet.introspect
36
+ rescue => e
37
+ STDERR.puts "Warning: #{e}"
38
+ @kwallet = nil
39
+ end
40
+ end
41
+
42
+ def supported?
43
+ @kwallet != nil
44
+ end
45
+
46
+ def recommended?
47
+ supported?
48
+ end
49
+
50
+ def get_password(service, user)
51
+ open_wallet
52
+ entry = "#{user}@#{service}"
53
+ if @kwallet.hasEntry(@net_handle, @folder, entry, @app_name)[0]
54
+ @kwallet.readPassword(@net_handle, @folder, entry, @app_name)[0]
55
+ else
56
+ nil
57
+ end
58
+ end
59
+
60
+ def set_password(service, user, password)
61
+ open_wallet
62
+ if password
63
+ @kwallet.writePassword(@net_handle, @folder, "#{user}@#{service}", password, @app_name)
64
+ else
65
+ @kwallet.removeEntry(@net_handle, @folder, "#{user}@#{service}", @app_name)
66
+ end
67
+ end
68
+
69
+ # Deletes the folder associated with this wallet.
70
+ def delete_folder
71
+ open_wallet
72
+ @kwallet.removeFolder(@net_handle, @folder, @app_name)
73
+ end
74
+
75
+ private
76
+ def open_wallet
77
+ return if @net_handle
78
+ begin
79
+ @net_wallet, _ = @kwallet.networkWallet
80
+ @net_handle, _ = @kwallet.open(@net_wallet, 0, @app_name)
81
+
82
+ @@open_wallets.add [@net_wallet, @app_name]
83
+
84
+ unless @kwallet.hasFolder(@net_handle, @folder, @app_name)
85
+ unless @kwallet.createFolder(@net_handle, @folder, @app_name)
86
+ raise "Can't open kwallet folder #{@folder}"
87
+ end
88
+ end
89
+ rescue
90
+ @net_handle = nil
91
+ raise
92
+ end
93
+ end
94
+
95
+ def self.finalizer(kwallet, wallet_name, app_name)
96
+ Proc.new do |*args|
97
+ kwallet.disconnectApplication wallet_name, app_name
98
+ end
99
+ end
100
+ end
101
+
102
+ add_backend( "keyring-kwallet", KWalletKeyring )
103
+
104
+ end
@@ -0,0 +1,122 @@
1
+ require "keyring"
2
+
3
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
4
+
5
+ PARAMS = {
6
+ :folder => "rspec-test-keyring-kwallet",
7
+ :app => "rspec-test-keyring-kwallet"
8
+ }
9
+
10
+ describe Keyring::KWalletKeyring, "after creation" do
11
+ before do
12
+ @keyring = Keyring::KWalletKeyring.new PARAMS
13
+ end
14
+
15
+ after do
16
+ @keyring.delete_folder
17
+ end
18
+
19
+ it "should be supported" do
20
+ @keyring.supported?.should == true
21
+ end
22
+
23
+ it "should be recommended" do
24
+ @keyring.recommended?.should == true
25
+ end
26
+
27
+ it "should return nil when getting a password" do
28
+ @keyring.get_password("service", "user").should == nil
29
+ end
30
+
31
+ it "should not raise an error when setting a password" do
32
+ lambda{@keyring.set_password("service", "user", "pass")}.should_not raise_error
33
+ end
34
+
35
+ it "should not raise an error when deleting a password" do
36
+ lambda{@keyring.delete_password("service", "user")}.should_not raise_error
37
+ end
38
+ end
39
+
40
+
41
+ describe Keyring::KWalletKeyring, "with a single password" do
42
+ before do
43
+ @keyring = Keyring::KWalletKeyring.new PARAMS
44
+ @keyring.set_password "service", "user", "pass"
45
+ end
46
+
47
+ after do
48
+ @keyring.delete_folder
49
+ end
50
+
51
+ it "should contain the password" do
52
+ @keyring.get_password("service", "user").should == "pass"
53
+ end
54
+
55
+ it "should not contain a password for another user" do
56
+ @keyring.get_password("service", "user2").should == nil
57
+ end
58
+
59
+ it "should not contain a password for another service" do
60
+ @keyring.get_password("service2", "user").should == nil
61
+ end
62
+
63
+ it "should not contain a password after deletion" do
64
+ @keyring.delete_password("service", "user")
65
+ @keyring.get_password("service", "user").should == nil
66
+ end
67
+
68
+ it "should contain the password after deletion of another user" do
69
+ @keyring.delete_password("service", "user2")
70
+ @keyring.get_password("service", "user").should == "pass"
71
+ end
72
+
73
+ it "should contain the password after deletion of another service" do
74
+ @keyring.delete_password("service2", "user")
75
+ @keyring.get_password("service", "user").should == "pass"
76
+ end
77
+ end
78
+
79
+
80
+ describe Keyring::KWalletKeyring, "with a serveral passwords" do
81
+ before do
82
+ @keyring = Keyring::KWalletKeyring.new PARAMS
83
+ @keyring.set_password "service", "user", "pass"
84
+ @keyring.set_password "service", "user2", "pass2"
85
+ @keyring.set_password "service2", "user", "pass21"
86
+ @keyring.set_password "service2", "user3", "pass23"
87
+ end
88
+
89
+ after do
90
+ @keyring.delete_folder
91
+ end
92
+
93
+ it "should contain all passwords" do
94
+ @keyring.get_password("service", "user").should == "pass"
95
+ @keyring.get_password("service", "user2").should == "pass2"
96
+ @keyring.get_password("service2", "user").should == "pass21"
97
+ @keyring.get_password("service2", "user3").should == "pass23"
98
+ end
99
+
100
+ it "should not contain a password for another user" do
101
+ @keyring.get_password("service", "user3").should == nil
102
+ @keyring.get_password("service2", "user2").should == nil
103
+ end
104
+
105
+ it "should not contain a password after deletion" do
106
+ @keyring.delete_password("service", "user")
107
+ @keyring.get_password("service", "user").should == nil
108
+ end
109
+
110
+ it "should contain the password after deletion of another user" do
111
+ @keyring.delete_password("service", "user2")
112
+ @keyring.get_password("service", "user").should == "pass"
113
+ end
114
+
115
+ it "should contain the password after deletion of another service" do
116
+ @keyring.delete_password("service2", "user")
117
+ @keyring.get_password("service", "user").should == "pass"
118
+ end
119
+ end
120
+
121
+
122
+
@@ -0,0 +1,15 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. lib keyring-kwallet]))
4
+
5
+ RSpec.configure do |config|
6
+ # == Mock Framework
7
+ #
8
+ # RSpec uses it's own mocking framework by default. If you prefer to
9
+ # use mocha, flexmock or RR, uncomment the appropriate line:
10
+ #
11
+ # config.mock_with :mocha
12
+ # config.mock_with :flexmock
13
+ # config.mock_with :rr
14
+ end
15
+
File without changes
@@ -0,0 +1 @@
1
+ 0.1.0
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keyring-kwallet
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Frank Fischer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-28 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: keyring
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.1.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-dbus
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0.6"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bones
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.6.5
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: KWallet backend for keyring gem.
50
+ email: frank.fischer@mathematik.tu-chemnitz.de
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - History.txt
57
+ files:
58
+ - History.txt
59
+ - README.md
60
+ - Rakefile
61
+ - lib/keyring-kwallet.rb
62
+ - lib/keyring-kwallet/KWalletKeyring.rb
63
+ - spec/keyring-kwallet_spec.rb
64
+ - spec/spec_helper.rb
65
+ - test/test_keyring-kwallet.rb
66
+ - version.txt
67
+ has_rdoc: true
68
+ homepage: http://darcsden.com/lyro/keyring-kwallet
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --main
74
+ - README.md
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project: keyring-kwallet
92
+ rubygems_version: 1.6.2
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: KWallet backend for keyring gem.
96
+ test_files:
97
+ - test/test_keyring-kwallet.rb