Commits

Anonymous committed 4c26ad4

Password clearing

  • Participants
  • Parent commits 164b6e1

Comments (0)

Files changed (3)

experiments/kwallet_by_dbus.pl

 }
 
 {
-    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
+    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
     say "Read password for key $KEY2: ", $password || "(undef)";
 }
 
 {
-    # Po close przy ponownym otwieraniu będzie pytanie (cośtam prosi...), bez tego - nie, mimo końca programu
-    $kwallet->close($handle, 1, $APP_NAME); # drugi parametr: force
-    say "Closed $handle";
+    my $sth = $kwallet->removeEntry($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
+    say "Cleared password for key $KEY2, got $sth";
 }
 
 {
-    my $is_open = $kwallet->isOpen($handle);
-    say "is open($handle): $is_open";
+    my $sth = $kwallet->removeEntry($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
+    say "Cleared non-existing password for key $KEY2, got $sth";
 }
 
-eval {
-    my $sth = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
-    say "Read (non-exist) password for key $KEY1 from closed wallet, got $sth";
-}; if($@) {
-    say "Got error while reading password from closed wallet: $@";
+
+{
+    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
+    say "Read password for key $KEY2: ", $password || "(undef)";
 }
 
-eval {
-    my $sth = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
-    say "Read password for key $KEY2 from closed wallet, got $sth";
-}; if($@) {
-    say "Got error while reading password from closed wallet: $@";
-}
 
 say "Spawn  kwalletmanager  to check what is going on";

experiments/kwallet_by_dbus_with_closing.pl

+#!/usr/bin/perl -w
+
+# See http://stderr.org/doc/kde/HTML/en/kdelibs-apidocs/kwallet/html/classKWallet_1_1Wallet.html
+
+use strict;
+use Net::DBus;
+use Data::Dumper;
+use feature 'say';
+
+my $APP_NAME = "DBUStest";
+my $FOLDER_NAME = "DBUStestfolder";
+my $KEY1 = "Some key";
+my $KEY2 = "Yet another key";
+my $PWD1 = "Very secret";
+my $PWD2 = "Even more secret";
+my $PWD3 = "Uuuuuuuu";
+
+my $dbus = Net::DBus->session()
+  or die("KWallet not available (can't access DBus)");
+#print "dbus: ", Dumper($dbus);
+say "DBus connected"; 
+
+my $kwallet_svc = $dbus->get_service('org.kde.kwalletd')
+  or die("KWallet not available (can't access KWallet, likely kwalletd not running)");
+#print "kwalletd: ", Dumper($kwallet_svc);
+say "org.kde.kwalletd connected";
+
+my $kwallet = $kwallet_svc->get_object('/modules/kwalletd', 'org.kde.KWallet')
+  or die("Kwallet not available (can't find wallet)");
+#print "kwallet: ", Dumper($kwallet);
+say "/modules/kwalletd connected";
+# $kwallet = $kwallet->as_interface(...);
+
+# This is text name
+my $net_wallet = $kwallet->networkWallet()
+  or die "No net wallet";
+say "net_wallet id: $net_wallet";
+
+my $handle = $kwallet->open($net_wallet, 0, $APP_NAME); # 0 - window id
+$handle > 0 or die "No handle"; # decline means -1
+say "Opened, handle = $handle";
+
+{
+    my $is_open = $kwallet->isOpen($handle);
+    say "is open($handle): $is_open";
+}
+
+{
+    my $folders = $kwallet->folderList($handle, $APP_NAME);
+    say "Folders = ", join(", ", @$folders);
+}
+
+{
+    unless($kwallet->hasFolder($handle, $FOLDER_NAME, $APP_NAME)) {
+        say "Folder $FOLDER_NAME does not exists";
+        $kwallet->createFolder($handle, $FOLDER_NAME, $APP_NAME) or die "Failed to create";
+        say "Folder $FOLDER_NAME created";
+    } else {
+        say "Folder $FOLDER_NAME already exists";
+    }
+}
+
+{
+    my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, $KEY1, $PWD1, $APP_NAME);
+    say "Wrote password $PWD1 under key $KEY1, got $sth";
+    # NOn-zero output seems to mean failure
+}
+
+{
+    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
+    say "Read password for key $KEY1: ", $password || "(undef)";
+}
+
+{
+    # Po close przy ponownym otwieraniu będzie pytanie (cośtam prosi...), bez tego - nie, mimo końca programu
+    $kwallet->close($handle, 1, $APP_NAME); # drugi parametr: force
+    say "Closed $handle";
+}
+
+{
+    my $is_open = $kwallet->isOpen($handle);
+    say "is open($handle): $is_open";
+}
+
+eval {
+    my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, $KEY2, $PWD1, $APP_NAME);
+    say "Wrote password $PWD1 under key $KEY2 to closed wallet, got $sth";
+}; if($@) {
+    say "Got error while writing password to closed wallet: $@";
+}
+
+eval {
+    my $sth = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
+    say "Read password for key $KEY1 from closed wallet, got $sth";
+}; if($@) {
+    say "Got error while reading password from closed wallet: $@";
+}
+
+say "Spawn  kwalletmanager  to check what is going on";

lib/Passwd/Keyring/KDEWallet.pm

 
 sub clear_password {
     my ($self, $user_name, $domain) = @_;
+    $self->_open_if_not_open();
+    my $status = $self->{kwallet}->removeEntry(
+        $self->{handle}, $self->{group}, "$domain || $user_name", $self->{app});
+    if($status >= 0) {
+        return 1;
+    } else {
+        # TODO: classify failures
+        return 0;
+    }
 }
 
 =head2 is_persistent