← Back to team overview

deja-dup-team team mailing list archive

[Merge] lp:~mterry/deja-dup/libsecret into lp:deja-dup

 

Michael Terry has proposed merging lp:~mterry/deja-dup/libsecret into lp:deja-dup.

Requested reviews:
  Robert Bruce Park (robru)

For more details, see:
https://code.launchpad.net/~mterry/deja-dup/libsecret/+merge/127627

Port from libgnome-keyring to libsecret.

We use keyrings in two places:
1) In non-gio backends, to save the network password
2) To save the encryption password

Both are relatively easy to port over.

I tested manually that it works (and finds old passwords saved with libgnome-keyring).  Didn't seem easy or worth it to add unit tests for an inherently integration-oriented branch like this.
-- 
https://code.launchpad.net/~mterry/deja-dup/libsecret/+merge/127627
Your team Déjà Dup Developers is subscribed to branch lp:deja-dup.
=== modified file 'common/BackendRackspace.vala'
--- common/BackendRackspace.vala	2012-03-21 03:01:36 +0000
+++ common/BackendRackspace.vala	2012-10-03 03:25:24 +0000
@@ -89,31 +89,27 @@
 
     if (id != "") {
       // First, try user's keyring
-      secret_key = null;
-      GnomeKeyring.find_network_password(id, null, RACKSPACE_SERVER, null, "https",
-                                         null, 0, found_password);
-    }
-    else
-      ask_password();
-  }
-
-  void found_password(GnomeKeyring.Result result,
-                      GLib.List<GnomeKeyring.NetworkPasswordData>? list)
-  {
-    if (result == GnomeKeyring.Result.OK && list != null) {
-      secret_key = list.data.password;
-      got_secret_key();
-    }
-    else {
-      ask_password();
-    }
-  }
-  
-  void save_password_callback(GnomeKeyring.Result result, uint32 val)
-  {
-  }
-  
-  void got_password_reply(MountOperation mount_op, MountOperationResult result)
+      try {
+        secret_key = yield Secret.password_lookup(Secret.SCHEMA_COMPAT_NETWORK,
+                                                  null, 
+                                                  "user", id,
+                                                  "server", RACKSPACE_SERVER,
+                                                  "protocol", "https");
+        if (secret_key != null) {
+          got_secret_key();
+          return;
+        }
+      }
+      catch (Error e) {
+        // fall through to ask_password below
+      }
+    }
+
+    // Didn't find it, so ask user
+    ask_password();
+  }
+
+  async void got_password_reply(MountOperation mount_op, MountOperationResult result)
   {
     if (result != MountOperationResult.HANDLED) {
       envp_ready(false, new List<string>(), _("Permission denied"));
@@ -127,10 +123,15 @@
     var remember = mount_op.password_save;
     if (remember != PasswordSave.NEVER) {
       string where = (remember == PasswordSave.FOR_SESSION) ?
-                     "session" : GnomeKeyring.DEFAULT;
-      GnomeKeyring.set_network_password(where, id, null, RACKSPACE_SERVER, null,
-                                        "https", null, 0, secret_key,
-                                        save_password_callback);
+                     Secret.COLLECTION_SESSION : Secret.COLLECTION_DEFAULT;
+      yield Secret.password_store(Secret.SCHEMA_COMPAT_NETWORK,
+                                  where,
+                                  "%s@%s".printf(id, RACKSPACE_SERVER),
+                                  secret_key,
+                                  null,
+                                  "user", id,
+                                  "server", RACKSPACE_SERVER,
+                                  "protocol", "https");
     }
 
     got_secret_key();

=== modified file 'common/BackendS3.vala'
--- common/BackendS3.vala	2012-04-30 00:18:18 +0000
+++ common/BackendS3.vala	2012-10-03 03:25:24 +0000
@@ -142,31 +142,27 @@
     
     if (id != "") {
       // First, try user's keyring
-      secret_key = null;
-      GnomeKeyring.find_network_password(id, null, S3_SERVER, null, "https",
-                                         null, 0, found_password);
-    }
-    else
-      ask_password();
-  }
-  
-  void found_password(GnomeKeyring.Result result,
-                      GLib.List<GnomeKeyring.NetworkPasswordData>? list)
-  {
-    if (result == GnomeKeyring.Result.OK && list != null) {
-      secret_key = list.data.password;
-      got_secret_key();
-    }
-    else {
-      ask_password();
-    }
-  }
-  
-  void save_password_callback(GnomeKeyring.Result result, uint32 val)
-  {
-  }
-  
-  void got_password_reply(MountOperation mount_op, MountOperationResult result)
+      try {
+        secret_key = yield Secret.password_lookup(Secret.SCHEMA_COMPAT_NETWORK,
+                                                  null, 
+                                                  "user", id,
+                                                  "server", S3_SERVER,
+                                                  "protocol", "https");
+        if (secret_key != null) {
+          got_secret_key();
+          return;
+        }
+      }
+      catch (Error e) {
+        // fall through to ask_password below
+      }
+    }
+
+    // Didn't find it, so ask user
+    ask_password();
+  }
+
+  async void got_password_reply(MountOperation mount_op, MountOperationResult result)
   {
     if (result != MountOperationResult.HANDLED) {
       envp_ready(false, new List<string>(), _("Permission denied"));
@@ -180,12 +176,17 @@
     var remember = mount_op.password_save;
     if (remember != PasswordSave.NEVER) {
       string where = (remember == PasswordSave.FOR_SESSION) ?
-                     "session" : GnomeKeyring.DEFAULT;
-      GnomeKeyring.set_network_password(where, id, null, S3_SERVER, null,
-                                        "https", null, 0, secret_key,
-                                        save_password_callback);
+                     Secret.COLLECTION_SESSION : Secret.COLLECTION_DEFAULT;
+      yield Secret.password_store(Secret.SCHEMA_COMPAT_NETWORK,
+                                  where,
+                                  "%s@%s".printf(id, S3_SERVER),
+                                  secret_key,
+                                  null,
+                                  "user", id,
+                                  "server", S3_SERVER,
+                                  "protocol", "https");
     }
-    
+
     got_secret_key();
   }
 

=== modified file 'common/CommonUtils.vala'
--- common/CommonUtils.vala	2012-08-20 01:16:15 +0000
+++ common/CommonUtils.vala	2012-10-03 03:25:24 +0000
@@ -582,5 +582,14 @@
   return date;
 }
 
+public Secret.Schema get_passphrase_schema()
+{
+  // Use freedesktop's schema id for historical reasons
+  return new Secret.Schema("org.freedesktop.Secret.Generic",
+                           Secret.SchemaFlags.NONE,
+                           "owner", Secret.SchemaAttributeType.STRING,
+                           "type", Secret.SchemaAttributeType.STRING);
+}
+
 } // end namespace
 

=== modified file 'common/Makefile.am'
--- common/Makefile.am	2012-08-10 18:33:29 +0000
+++ common/Makefile.am	2012-10-03 03:25:24 +0000
@@ -31,7 +31,6 @@
 	@INTLLIBS@
 
 noinst_HEADERS = \
-	chacks.h \
 	uriutils.h
 
 libcommon_la_VALASOURCES = \
@@ -60,7 +59,6 @@
 	ToolPlugin.vala
 
 libcommon_la_SOURCES = \
-	chacks.c \
 	uriutils.c \
 	$(libcommon_la_VALASOURCES)
 
@@ -72,7 +70,8 @@
 	$(NETWORKMONITOR_VALAFLAGS) \
 	--pkg gio-2.0 \
 	--pkg gio-unix-2.0 \
-	--pkg gnome-keyring-1 \
+	--pkg libsecret-1 \
+	--pkg secret \
 	--pkg libpeas-1.0 \
 	--pkg uriutils \
 	--pkg posix \

=== removed file 'common/chacks.c'
--- common/chacks.c	2011-06-28 15:48:17 +0000
+++ common/chacks.c	1970-01-01 00:00:00 +0000
@@ -1,31 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: nil; tab-width: 2 -*- */
-/*
-    This file is part of Déjà Dup.
-    For copyright information, see AUTHORS.
-
-    Déjà Dup is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    Déjà Dup is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "chacks.h"
-
-static const GnomeKeyringPasswordSchema PASSPHRASE_SCHEMA_DEF = {
-  GNOME_KEYRING_ITEM_GENERIC_SECRET,
-  {
-    {"owner", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING},
-    {"type", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING},
-    {NULL, 0}
-  }
-};
-
-const GnomeKeyringPasswordSchema *PASSPHRASE_SCHEMA = &PASSPHRASE_SCHEMA_DEF;

=== removed file 'common/chacks.h'
--- common/chacks.h	2011-06-28 15:48:17 +0000
+++ common/chacks.h	1970-01-01 00:00:00 +0000
@@ -1,29 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: nil; tab-width: 2 -*- */
-/*
-    This file is part of Déjà Dup.
-    For copyright information, see AUTHORS.
-
-    Déjà Dup is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    Déjà Dup is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* This file is for whatever we can't currently do in Vala. */
-#ifndef __CHACKS_H__
-#define __CHACKS_H__
-
-#include <gnome-keyring.h>
-
-extern const GnomeKeyringPasswordSchema *PASSPHRASE_SCHEMA;
-
-#endif
-

=== added file 'common/libcommon.deps'
--- common/libcommon.deps	1970-01-01 00:00:00 +0000
+++ common/libcommon.deps	2012-10-03 03:25:24 +0000
@@ -0,0 +1,2 @@
+libpeas-1.0
+libsecret-1

=== modified file 'configure.ac'
--- configure.ac	2012-09-24 16:45:39 +0000
+++ configure.ac	2012-10-03 03:25:24 +0000
@@ -76,7 +76,7 @@
                   $GTK_MODULE >= $GTK_REQ_VER
                   gio-2.0 >= $GIO_REQ_VER
                   gio-unix-2.0 >= $GIO_REQ_VER
-                  gnome-keyring-1
+                  libsecret-1
                   libpeas-1.0
                   gmodule-2.0 >= $GLIB_REQ_VER
                   libnotify >= $NOTIFY_REQ_VER)
@@ -84,23 +84,26 @@
 PKG_CHECK_MODULES(PREF,
                   $GTK_MODULE >= $GTK_REQ_VER
                   gio-2.0 >= $GIO_REQ_VER
+                  libsecret-1
                   libpeas-1.0)
 
 PKG_CHECK_MODULES(COMMON,
                   gio-2.0 >= $GIO_REQ_VER
                   gio-unix-2.0 >= $GIO_REQ_VER
-                  gnome-keyring-1
+                  libsecret-1
                   libpeas-1.0
                   gmodule-2.0 >= $GLIB_REQ_VER)
 
 PKG_CHECK_MODULES(WIDGETS,
                   gmodule-2.0 >= $GLIB_REQ_VER
                   $GTK_MODULE >= $GTK_REQ_VER
+                  libsecret-1
                   libpeas-1.0
                   libnotify >= $NOTIFY_REQ_VER)
 
 PKG_CHECK_MODULES(MONITOR,
                   gio-2.0 >= $GIO_REQ_VER
+                  libsecret-1
                   libpeas-1.0
                   libnotify >= $NOTIFY_REQ_VER)
 

=== modified file 'deja-dup/AssistantOperation.vala'
--- deja-dup/AssistantOperation.vala	2012-08-21 01:19:49 +0000
+++ deja-dup/AssistantOperation.vala	2012-10-03 03:25:24 +0000
@@ -55,7 +55,6 @@
   protected bool nagged;
   List<Gtk.Widget> first_password_widgets;
   MainLoop password_ask_loop;
-  MainLoop password_find_loop;
   DejaDup.ToggleGroup password_toggles;
 
   Gtk.Label question_label;
@@ -648,7 +647,7 @@
       timeout_id = Timeout.add(250, pulse);
       if (op != null && op.needs_password) {
         // Operation is waiting for password
-        provide_password();
+        provide_password.begin();
       }
       else if (op == null)
         do_apply.begin();
@@ -728,43 +727,47 @@
     }
   }
 
-  void found_passphrase(GnomeKeyring.Result result, string? str)
+  async string? lookup_keyring()
   {
-    if (str != null) {
-      op.set_passphrase(str);
-    }
-    else {
-      ask_passphrase();
-    }
-    password_find_loop.quit();
-    password_find_loop = null;
+      try {
+        return yield Secret.password_lookup(DejaDup.get_passphrase_schema(),
+                                            null,
+                                            "owner", Config.PACKAGE,
+                                            "type", "passphrase");
+      }
+      catch (Error e) {
+        warning("%s\n", e.message);
+        return null;
+      }
   }
 
   protected void get_passphrase()
   {
     if (!searched_for_passphrase && !DejaDup.in_testing_mode() &&
         op.use_cached_password) {
-      // First, try user's keyring
-      GnomeKeyring.find_password(PASSPHRASE_SCHEMA,
-                                 found_passphrase,
-                                 "owner", Config.PACKAGE,
-                                 "type", "passphrase");
       // If we get asked for passphrase again, it is because a
       // saved or entered passphrase didn't work.  So don't bother
       // searching a second time.
       searched_for_passphrase = true;
-      // block until found
-      password_find_loop = new MainLoop(null);
-      password_find_loop.run();
-    }
-    else {
-      // just jump straight to asking user
-      ask_passphrase();
-    }
-  }
-
-  void save_password_callback(GnomeKeyring.Result result)
-  {
+
+      string str = null;
+
+      // First, try user's keyring
+      var loop = new MainLoop(null);
+      lookup_keyring.begin((obj, res) => {
+        str = lookup_keyring.end(res);
+        loop.quit();
+      });
+      loop.run();
+
+      // Did we get anything?
+      if (str != null) {
+        op.set_passphrase(str);
+        return;
+      }
+    }
+
+    ask_passphrase();
   }
 
   void check_password_validity()
@@ -849,7 +852,7 @@
     password_ask_loop.run();
   }
 
-  protected void provide_password()
+  protected async void provide_password()
   {
     var passphrase = "";
 
@@ -863,12 +866,18 @@
       if (passphrase != "") {
         // Save it
         if (encrypt_remember.active) {
-          GnomeKeyring.store_password(PASSPHRASE_SCHEMA,
-                                      GnomeKeyring.DEFAULT,
-                                      _("Backup encryption password"),
-                                      passphrase, save_password_callback,
-                                      "owner", Config.PACKAGE,
-                                      "type", "passphrase");
+          try {
+            yield Secret.password_store(DejaDup.get_passphrase_schema(),
+                                        Secret.COLLECTION_DEFAULT,
+                                        _("Backup encryption password"),
+                                        passphrase,
+                                        null,
+                                        "owner", Config.PACKAGE,
+                                        "type", "passphrase");
+          }
+          catch (Error e) {
+            warning("%s\n", e.message);
+          }
         }
       }
     }

=== modified file 'deja-dup/AssistantRestore.vala'
--- deja-dup/AssistantRestore.vala	2012-08-06 22:41:13 +0000
+++ deja-dup/AssistantRestore.vala	2012-10-03 03:25:24 +0000
@@ -491,7 +491,7 @@
         query_timeout_id = Timeout.add(250, query_pulse);
         if (query_op != null && query_op.needs_password) {
           // Operation is waiting for password
-          provide_password();
+          provide_password.begin();
         }
         else if (query_op == null)
           do_query.begin();

=== modified file 'deja-dup/AssistantRestoreMissing.vala'
--- deja-dup/AssistantRestoreMissing.vala	2012-08-06 22:41:13 +0000
+++ deja-dup/AssistantRestoreMissing.vala	2012-10-03 03:25:24 +0000
@@ -234,10 +234,10 @@
       }
       else {
         if (query_op != null && query_op.needs_password) {
-          provide_password();
+          provide_password.begin();
         }
         else if (query_op_files != null && query_op_files.needs_password) {
-          provide_password();
+          provide_password.begin();
         }
         else if (!backups_queue_filled) {
           do_query.begin();

=== modified file 'deja-dup/Makefile.am'
--- deja-dup/Makefile.am	2012-08-08 01:12:17 +0000
+++ deja-dup/Makefile.am	2012-10-03 03:25:24 +0000
@@ -56,12 +56,10 @@
 	--pkg @GTK_MODULE@ \
 	--pkg gio-2.0 \
 	--pkg gio-unix-2.0 \
-	--pkg gnome-keyring-1 \
-	--pkg libpeas-1.0 \
+	--pkg libsecret-1 \
 	--pkg libnotify \
 	--pkg libcommon \
 	--pkg libwidgets \
-	--pkg keyring \
 	--pkg config
 
 deja_dup_vala.stamp: $(top_srcdir)/config.h

=== modified file 'vapi/Makefile.am'
--- vapi/Makefile.am	2012-03-22 14:44:44 +0000
+++ vapi/Makefile.am	2012-10-03 03:25:24 +0000
@@ -18,6 +18,6 @@
 
 EXTRA_DIST = \
 	config.vapi \
-	keyring.vapi \
+	secret.vapi \
 	uriutils.vapi
 

=== renamed file 'vapi/keyring.vapi' => 'vapi/secret.vapi'
--- vapi/keyring.vapi	2011-06-28 15:48:17 +0000
+++ vapi/secret.vapi	2012-10-03 03:25:24 +0000
@@ -17,5 +17,10 @@
     along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "chacks.h")]
-public GnomeKeyring.PasswordSchema PASSPHRASE_SCHEMA;
+/* TODO: libsecret-1.vapi does not have SECRET_SCHEMA_COMPAT_NETWORK yet */
+[CCode (cprefix = "Secret", gir_namespace = "Secret", gir_version = "1", lower_case_cprefix = "secret_")]
+namespace Secret {
+	[CCode (cheader_filename = "libsecret/secret.h", cname = "SECRET_SCHEMA_COMPAT_NETWORK")]
+	public Secret.Schema SCHEMA_COMPAT_NETWORK;
+}
+

=== modified file 'widgets/Makefile.am'
--- widgets/Makefile.am	2012-08-08 01:12:17 +0000
+++ widgets/Makefile.am	2012-10-03 03:25:24 +0000
@@ -80,7 +80,6 @@
 	$(UNITY_VALAFLAGS) \
 	--pkg libcommon \
 	--pkg @GTK_MODULE@ \
-	--pkg libpeas-1.0 \
 	--pkg uriutils \
 	--pkg libnotify \
 	--pkg config


Follow ups