[gnome-keyring/wip/dueno/secrets-helper] daemon: Allow on the fly creation of secret service [ci skip]
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring/wip/dueno/secrets-helper] daemon: Allow on the fly creation of secret service [ci skip]
- Date: Thu, 13 Sep 2018 16:41:08 +0000 (UTC)
commit 802830e9d40c91b8d5f2dc49c7ae61157f7d535c
Author: Daiki Ueno <dueno src gnome org>
Date: Fri Aug 31 15:45:43 2018 +0200
daemon: Allow on the fly creation of secret service [ci skip]
WIP
Makefile.am | 1 +
daemon/dbus/Makefile.am | 56 +++++++++++--
daemon/dbus/gkd-dbus.c | 17 ----
daemon/dbus/gkd-dbus.h | 4 -
daemon/dbus/gkd-secret-util.c | 17 ++++
daemon/dbus/gkd-secret-util.h | 7 +-
daemon/dbus/gkd-secrets-helper.c | 138 +++++++++++++++++++++++++++++++
daemon/dbus/org.gnome.keyring.Daemon.xml | 4 +
8 files changed, 214 insertions(+), 30 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 640c0e98..dd297dcd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -158,6 +158,7 @@ AM_CPPFLAGS = \
$(GLIB_CFLAGS)
bin_PROGRAMS =
+libexec_PROGRAMS =
BUILT_SOURCES =
check_PROGRAMS =
noinst_DATA =
diff --git a/daemon/dbus/Makefile.am b/daemon/dbus/Makefile.am
index 9d0b2e1a..4d3284ec 100644
--- a/daemon/dbus/Makefile.am
+++ b/daemon/dbus/Makefile.am
@@ -1,5 +1,5 @@
-noinst_LTLIBRARIES += libgkd-dbus.la
+noinst_LTLIBRARIES += libgkd-dbus.la libgkd-secrets.la
daemon/dbus/gkd-secrets-generated.h: daemon/dbus/org.freedesktop.Secrets.xml
$(AM_V_GEN) gdbus-codegen --interface-prefix org.freedesktop.Secrets. \
@@ -38,22 +38,44 @@ EXTRA_DIST += \
daemon/dbus/org.gnome.keyring.InternalUnsupportedGuiltRiddenInterface.xml \
$(NULL)
-BUILT_SOURCES += \
+daemon_generated = \
daemon/dbus/gkd-daemon-generated.c \
- daemon/dbus/gkd-daemon-generated.h \
+ daemon/dbus/gkd-daemon-generated.h
+
+secrets_generated = \
daemon/dbus/gkd-internal-generated.c \
daemon/dbus/gkd-internal-generated.h \
daemon/dbus/gkd-secrets-generated.c \
daemon/dbus/gkd-secrets-generated.h
+BUILT_SOURCES += \
+ $(daemon_generated) \
+ $(secrets_generated)
+
libgkd_dbus_la_SOURCES = \
- $(BUILT_SOURCES) \
+ $(daemon_generated) \
daemon/dbus/gkd-dbus.c \
daemon/dbus/gkd-dbus.h \
daemon/dbus/gkd-dbus-environment.c \
daemon/dbus/gkd-dbus-private.h \
daemon/dbus/gkd-dbus-secrets.c \
daemon/dbus/gkd-dbus-session.c \
+ $(NULL)
+
+libgkd_dbus_la_LIBADD = \
+ libgkd-secrets.la \
+ $(GIO_LIBS) \
+ $(GLIB_LIBS) \
+ $(GOBJECT_LIBS)
+
+libgkd_dbus_la_CFLAGS = \
+ $(DAEMON_CFLAGS) \
+ $(GCR_BASE_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(GOBJECT_CFLAGS)
+
+libgkd_secrets_la_SOURCES = \
+ $(secrets_generated) \
daemon/dbus/gkd-secret-change.c \
daemon/dbus/gkd-secret-change.h \
daemon/dbus/gkd-secret-create.c \
@@ -82,20 +104,38 @@ libgkd_dbus_la_SOURCES = \
daemon/dbus/gkd-secret-unlock.c \
daemon/dbus/gkd-secret-unlock.h \
daemon/dbus/gkd-secret-util.c \
- daemon/dbus/gkd-secret-util.h \
- $(NULL)
+ daemon/dbus/gkd-secret-util.h
-libgkd_dbus_la_LIBADD = \
+libgkd_secrets_la_LIBADD = \
$(GIO_LIBS) \
$(GLIB_LIBS) \
$(GOBJECT_LIBS)
-libgkd_dbus_la_CFLAGS = \
+libgkd_secrets_la_CFLAGS = \
+ $(DAEMON_CFLAGS) \
+ $(GCR_BASE_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(GOBJECT_CFLAGS)
+
+libexec_PROGRAMS += gkd-secrets-helper
+
+gkd_secrets_helper_SOURCES = daemon/dbus/gkd-secrets-helper.c
+
+gkd_secrets_helper_CFLAGS = \
$(DAEMON_CFLAGS) \
$(GCR_BASE_CFLAGS) \
$(GIO_CFLAGS) \
$(GOBJECT_CFLAGS)
+gkd_secrets_helper_LDADD = \
+ libgkd-secrets.la \
+ libgkm-secret-store.la \
+ libgkm-wrap-layer.la \
+ $(GCR_BASE_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB_LIBS) \
+ $(GOBJECT_LIBS)
+
# -------------------------------------------------------------------
# TESTS
diff --git a/daemon/dbus/gkd-dbus.c b/daemon/dbus/gkd-dbus.c
index 6644a790..4f7c1434 100644
--- a/daemon/dbus/gkd-dbus.c
+++ b/daemon/dbus/gkd-dbus.c
@@ -282,20 +282,3 @@ gkd_dbus_setup (void)
egg_cleanup_register (dbus_cleanup, NULL);
return TRUE;
}
-
-gboolean
-gkd_dbus_invocation_matches_caller (GDBusMethodInvocation *invocation,
- const char *caller)
-{
- const char *invocation_caller;
-
- invocation_caller = g_dbus_method_invocation_get_sender (invocation);
- if (!g_str_equal (invocation_caller, caller)) {
- g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Invalid caller");
- return FALSE;
- }
-
- return TRUE;
-}
diff --git a/daemon/dbus/gkd-dbus.h b/daemon/dbus/gkd-dbus.h
index 8a9ca450..0784a9a1 100644
--- a/daemon/dbus/gkd-dbus.h
+++ b/daemon/dbus/gkd-dbus.h
@@ -34,8 +34,4 @@ gboolean gkd_dbus_singleton_acquire (gboolean *acquired);
gchar* gkd_dbus_singleton_control (void);
-/* DBus utils */
-gboolean gkd_dbus_invocation_matches_caller (GDBusMethodInvocation *invocation,
- const char *caller);
-
#endif /* GKD_DBUS_H */
diff --git a/daemon/dbus/gkd-secret-util.c b/daemon/dbus/gkd-secret-util.c
index 29443f8c..a01635d5 100644
--- a/daemon/dbus/gkd-secret-util.c
+++ b/daemon/dbus/gkd-secret-util.c
@@ -146,3 +146,20 @@ gkd_secret_util_build_path (const gchar *base, gconstpointer identifier, gssize
return g_string_free (result, FALSE);
}
+
+gboolean
+gkd_dbus_invocation_matches_caller (GDBusMethodInvocation *invocation,
+ const char *caller)
+{
+ const char *invocation_caller;
+
+ invocation_caller = g_dbus_method_invocation_get_sender (invocation);
+ if (!g_str_equal (invocation_caller, caller)) {
+ g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_ACCESS_DENIED,
+ "Invalid caller");
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/daemon/dbus/gkd-secret-util.h b/daemon/dbus/gkd-secret-util.h
index 99e7814f..97abd7fd 100644
--- a/daemon/dbus/gkd-secret-util.h
+++ b/daemon/dbus/gkd-secret-util.h
@@ -23,7 +23,7 @@
#include "gkd-secret-types.h"
-#include <glib.h>
+#include <gio/gio.h>
gboolean gkd_secret_util_parse_path (const gchar *path,
gchar **collection,
@@ -33,4 +33,9 @@ gchar* gkd_secret_util_build_path (const g
gconstpointer identifier,
gssize n_identifier);
+
+/* DBus utils */
+gboolean gkd_dbus_invocation_matches_caller (GDBusMethodInvocation *invocation,
+ const char *caller);
+
#endif /* __GKD_SECRET_UTIL_H__ */
diff --git a/daemon/dbus/gkd-secrets-helper.c b/daemon/dbus/gkd-secrets-helper.c
new file mode 100644
index 00000000..d8a407a6
--- /dev/null
+++ b/daemon/dbus/gkd-secrets-helper.c
@@ -0,0 +1,138 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2008 Stefan Walter
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * License along with this program; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "egg/egg-cleanup.h"
+#include "egg/egg-error.h"
+
+#include "gkd-dbus.h"
+#include "gkd-secret-service.h"
+
+#include "pkcs11/wrap-layer/gkm-wrap-layer.h"
+#include "pkcs11/secret-store/gkm-secret-store.h"
+
+#include <string.h>
+#include <gck/gck.h>
+
+static void
+pkcs11_cleanup (gpointer data)
+{
+ CK_FUNCTION_LIST_PTR pkcs11_roof = data;
+ CK_RV rv;
+
+ g_assert (pkcs11_roof);
+
+ rv = (pkcs11_roof->C_Finalize) (NULL);
+
+ if (rv != CKR_OK)
+ g_warning ("couldn't finalize internal PKCS#11 stack (code: %d)", (gint)rv);
+}
+
+static gboolean
+pkcs11_initialize (const gchar *path)
+{
+ CK_FUNCTION_LIST_PTR secret_store;
+ CK_FUNCTION_LIST_PTR pkcs11_roof;
+ CK_C_INITIALIZE_ARGS init_args;
+ CK_RV rv;
+ GckSlot *slot = NULL;
+ GckModule *module;
+ GList *modules;
+ GkdSecretService *service;
+ GError *error = NULL;
+ GDBusConnection *connection;
+
+ /* Secrets */
+ secret_store = gkm_secret_store_get_functions ();
+
+ /* Add all of those into the wrapper layer */
+ gkm_wrap_layer_add_module (secret_store);
+
+ pkcs11_roof = gkm_wrap_layer_get_functions ();
+
+ memset (&init_args, 0, sizeof (init_args));
+ init_args.flags = CKF_OS_LOCKING_OK;
+ init_args.pReserved = g_strdup_printf ("directory=\"%s\"", path);
+
+ /* Initialize the whole caboodle */
+ rv = (pkcs11_roof->C_Initialize) (&init_args);
+ g_free (init_args.pReserved);
+
+ if (rv != CKR_OK) {
+ g_warning ("couldn't initialize internal PKCS#11 stack (code: %d)", (gint)rv);
+ return FALSE;
+ }
+
+ egg_cleanup_register (pkcs11_cleanup, NULL);
+
+ module = gck_module_new (pkcs11_roof);
+ g_return_val_if_fail (module, FALSE);
+
+ modules = g_list_prepend (NULL, module);
+ slot = gck_modules_token_for_uri (modules,
+ "pkcs11:token=Secret%20Store", &error);
+ gck_list_unref_free (modules);
+ if (!slot) {
+ g_warning ("couldn't find secret store: %s",
+ egg_error_message (error));
+ g_clear_error (&error);
+ return FALSE;
+ }
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (!connection) {
+ g_warning ("couldn't connect to session bus: %s",
+ egg_error_message (error));
+ g_clear_error (&error);
+ return FALSE;
+ }
+ g_print ("%s\n", g_dbus_connection_get_unique_name (connection));
+
+ service = g_object_new (GKD_SECRET_TYPE_SERVICE,
+ "connection", connection,
+ "pkcs11-slot", slot,
+ NULL);
+
+ egg_cleanup_register (g_object_unref, service);
+ egg_cleanup_register (g_object_unref, connection);
+
+ return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+ GMainLoop *loop;
+
+ if (argc != 2) {
+ g_printerr ("gkd-secrets-helper PATH\n");
+ return 1;
+ }
+
+ if (!pkcs11_initialize (argv[1]))
+ return 1;
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+ g_main_loop_unref (loop);
+
+ return 0;
+}
diff --git a/daemon/dbus/org.gnome.keyring.Daemon.xml b/daemon/dbus/org.gnome.keyring.Daemon.xml
index b4334d9b..d1791871 100644
--- a/daemon/dbus/org.gnome.keyring.Daemon.xml
+++ b/daemon/dbus/org.gnome.keyring.Daemon.xml
@@ -9,5 +9,9 @@
<method name="GetControlDirectory">
<arg name="ControlDirectory" type="s" direction="out"/>
</method>
+ <method name="GetSecretService">
+ <arg name="KeyringDirectory" type="s" direction="in"/>
+ <arg name="DBusName" type="s" direction="out"/>
+ </method>
</interface>
</node>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]