1. Marcin Kasperski
  2. perl/keyring/kdewallet


perl/keyring/kdewallet / lib / Passwd / Keyring / KDEWallet.pm

package Passwd::Keyring::KDEWallet;

use warnings;
use strict;
#use parent 'Keyring';
use Net::DBus;

=head1 NAME

Passwd::Keyring::KDEWallet - Password storage implementation based on KDE Wallet.

=head1 VERSION

Version 0.21


our $VERSION = '0.21';

our $APP_NAME = "Passwd::Keyring";
our $FOLDER_NAME = "Perl-Passwd-Keyring";


KDE Wallet based implementation of L<Passwd::Keyring>.

    use Passwd::Keyring::KDEWallet;

    my $keyring = Passwd::Keyring::KDEWallet->new();

    $keyring->set_password("John", "verysecret", "my-pseudodomain");
    # And later, on next run maybe
    my $password = $keyring->get_password("John", "my-pseudodomain");
    # plus
    $keyring->clear_password("John", "my-pseudodomain");


=head2 new

Initializes the processing. Croaks if kwallet does not 
seem to be available.


sub new {
    my $self = {};
    bless $self;

    # TODO: maybe some of those objects should rather be
    # created on demand and thrown away immediately.

    #$self->{bus} = Net::DBus->find()
    $self->{bus} = Net::DBus->session()
      or croak("KWallet not available (can't access DBus)");
    $self->{kwallet_svc} = $self->{bus}->get_service('org.kde.kwalletd')
      or croak("KWallet not available (can't access KWallet, likely kwalletd not running)");
    my $kwallet = $self->{kwallet_svc}->get_object('/modules/kwalletd', 'org.kde.KWallet')
      or croak("Kwallet not available (can't find wallet)");

    use Data::Dumper;
    print Dumper($kwallet);

    $self->{kwallet} = $kwallet->networkWallet();
    print Dumper($self->{kwallet});
    print "Wallet = $self->{kwallet}\n";

    # TODO: later
    my $kwallet_handle = $self->{kwallet}->open($self->{kwallet}, 0, $APP_NAME);
    print "Opened = $kwallet_handle\n";

    my $folders = $self->{kwallet}->folderList($kwallet_handle, $APP_NAME);
    print "Folders = ", dump($folders);

    return $self;

=head2 set_password(username, password, domain)

Sets (stores) password identified by given domain for given user 


sub set_password {
    my ($self, $user_name, $user_password, $domain) = @_;

=head2 get_password($user_name, $domain)

Reads previously stored password for given user in given app.
If such password can not be found, returns undef.


sub get_password {
    my ($self, $user_name, $domain) = @_;
#    my $pwd = $KWallet->readPassword($kwallet_handle, 'MyFolder','Some_Userid_Key', $APP_NAME);
#    print "Password = ", dump($pwd), "\n";

=head2 clear_password($user_name, $domain)

Removes given password (if present)


sub clear_password {
    my ($self, $user_name, $domain) = @_;

=head1 AUTHOR

Marcin Kasperski, C<< <Marcin.Kasperski at mekk.waw.pl> >>

Code heavily inspired by L<http://www.perlmonks.org/?node_id=869620>
and partially by python keyring.

=head1 BUGS

Please report any bugs or feature requests to 
issue tracker at L<https://bitbucket.org/Mekk/perl-keyring-kdewallet>.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Passwd::Keyring::KDEWallet

You can also look for information at:



Copyright 2010-2012 Marcin Kasperski.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.


1; # End of Passwd::Keyring::KDEWallet