[gnome-keyring/dbus-api] [dbus] Initialize dbus service with pkcs11 slot.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-keyring/dbus-api] [dbus] Initialize dbus service with pkcs11 slot.
- Date: Sat, 22 Aug 2009 13:41:45 +0000 (UTC)
commit 17618f2595cc541f2c90b2639e23d34a631bb863
Author: Stef Walter <stef memberwebs com>
Date: Sat Aug 22 01:33:06 2009 +0000
[dbus] Initialize dbus service with pkcs11 slot.
Choose the correct pkcs11 slot, and initialize the dbus
service with it. The criteria is currently simplistic.
daemon/dbus/gkd-dbus-secrets.c | 42 ++++++++++++++++++++++++++++++++++++-
daemon/dbus/gkd-secrets-service.c | 29 +++++++++++++++++++++++++
daemon/dbus/gkd-secrets-service.h | 8 +++++-
daemon/pkcs11/gkr-pkcs11-daemon.c | 6 +++++
daemon/pkcs11/gkr-pkcs11-daemon.h | 4 +++
5 files changed, 86 insertions(+), 3 deletions(-)
---
diff --git a/daemon/dbus/gkd-dbus-secrets.c b/daemon/dbus/gkd-dbus-secrets.c
index 012ff8c..4fb1e97 100644
--- a/daemon/dbus/gkd-dbus-secrets.c
+++ b/daemon/dbus/gkd-dbus-secrets.c
@@ -26,13 +26,50 @@
#include "gkd-dbus-private.h"
#include "gkd-secrets-service.h"
+#include "daemon/pkcs11/gkr-pkcs11-daemon.h"
+
static GkdSecretsService *secrets_service = NULL;
+static GP11Slot*
+calculate_secrets_slot (void)
+{
+ GP11Slot *slot = NULL;
+ GP11Module *module;
+ GList *slots, *l;
+ GP11SlotInfo *info;
+
+ module = gp11_module_new (gkr_pkcs11_daemon_get_functions ());
+ g_return_val_if_fail (module, NULL);
+
+ /*
+ * Find the right slot.
+ *
+ * TODO: This isn't necessarily the best way to do this.
+ * A good function could be added to gp11 library.
+ * But needs more thought on how to do this.
+ */
+ slots = gp11_module_get_slots (module, TRUE);
+ for (l = slots; !slot && l; l = g_list_next (l)) {
+ info = gp11_slot_get_info (l->data);
+ if (g_ascii_strcasecmp ("Secret Store", info->slot_description) == 0)
+ slot = g_object_ref (l->data);
+ gp11_slot_info_free (info);
+ }
+ gp11_list_unref_free (slots);
+
+ return slot;
+}
+
void
gkd_dbus_secrets_init (DBusConnection *conn)
{
DBusError error = DBUS_ERROR_INIT;
dbus_uint32_t result = 0;
+ GP11Slot *slot;
+
+ /* Figure out which slot to use */
+ slot = calculate_secrets_slot ();
+ g_return_if_fail (slot);
/* Try and grab our name */
result = dbus_bus_request_name (conn, SECRETS_SERVICE, 0, &error);
@@ -66,7 +103,10 @@ gkd_dbus_secrets_init (DBusConnection *conn)
}
g_return_if_fail (!secrets_service);
- secrets_service = g_object_new (GKD_SECRETS_TYPE_SERVICE, "connection", conn, NULL);
+ secrets_service = g_object_new (GKD_SECRETS_TYPE_SERVICE,
+ "connection", conn, "pkcs11-slot", slot, NULL);
+
+ g_object_unref (slot);
}
void
diff --git a/daemon/dbus/gkd-secrets-service.c b/daemon/dbus/gkd-secrets-service.c
index eafeef8..4dbe243 100644
--- a/daemon/dbus/gkd-secrets-service.c
+++ b/daemon/dbus/gkd-secrets-service.c
@@ -28,9 +28,12 @@
#include "egg/egg-unix-credentials.h"
+#include "gp11/gp11.h"
+
enum {
PROP_0,
PROP_CONNECTION,
+ PROP_PKCS11_SLOT,
#if 0
/* Secrets Service Properties */
PROP_COLLECTIONS,
@@ -44,6 +47,7 @@ struct _GkdSecretsService {
DBusConnection *connection;
GHashTable *sessions;
gchar *match_rule;
+ GP11Slot *pkcs11_slot;
#if 0
gchar *default_collection;
#endif
@@ -361,6 +365,7 @@ gkd_secrets_service_constructor (GType type, guint n_props, GObjectConstructPara
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (self->connection, NULL);
+ g_return_val_if_fail (self->pkcs11_slot, NULL);
/* Now register the object */
if (!dbus_connection_register_object_path (self->connection, SECRETS_SERVICE_PATH,
@@ -412,6 +417,11 @@ gkd_secrets_service_dispose (GObject *obj)
self->connection = NULL;
}
+ if (self->pkcs11_slot) {
+ g_object_unref (self->pkcs11_slot);
+ self->pkcs11_slot = NULL;
+ }
+
G_OBJECT_CLASS (gkd_secrets_service_parent_class)->dispose (obj);
}
@@ -444,6 +454,11 @@ gkd_secrets_service_set_property (GObject *obj, guint prop_id, const GValue *val
self->connection = g_value_dup_boxed (value);
g_return_if_fail (self->connection);
break;
+ case PROP_PKCS11_SLOT:
+ g_return_if_fail (!self->pkcs11_slot);
+ self->pkcs11_slot = g_value_dup_object (value);
+ g_return_if_fail (self->pkcs11_slot);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
break;
@@ -460,6 +475,9 @@ gkd_secrets_service_get_property (GObject *obj, guint prop_id, GValue *value,
case PROP_CONNECTION:
g_value_set_boxed (value, gkd_secrets_service_get_connection (self));
break;
+ case PROP_PKCS11_SLOT:
+ g_value_set_object (value, gkd_secrets_service_get_pkcs11_slot (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
break;
@@ -482,6 +500,10 @@ gkd_secrets_service_class_init (GkdSecretsServiceClass *klass)
g_object_class_install_property (gobject_class, PROP_CONNECTION,
g_param_spec_boxed ("connection", "Connection", "DBus Connection",
GKD_DBUS_TYPE_CONNECTION, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (gobject_class, PROP_PKCS11_SLOT,
+ g_param_spec_object ("pkcs11-slot", "Pkcs11 Slot", "PKCS#11 slot that we use for secrets",
+ GP11_TYPE_SLOT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
/* -----------------------------------------------------------------------------
@@ -495,6 +517,13 @@ gkd_secrets_service_get_connection (GkdSecretsService *self)
return self->connection;
}
+GP11Slot*
+gkd_secrets_service_get_pkcs11_slot (GkdSecretsService *self)
+{
+ g_return_val_if_fail (GKD_SECRETS_IS_SERVICE (self), NULL);
+ return self->pkcs11_slot;
+}
+
void
gkd_secrets_service_close_session (GkdSecretsService *self, GkdSecretsSession *session)
{
diff --git a/daemon/dbus/gkd-secrets-service.h b/daemon/dbus/gkd-secrets-service.h
index cd9b99d..83c182d 100644
--- a/daemon/dbus/gkd-secrets-service.h
+++ b/daemon/dbus/gkd-secrets-service.h
@@ -22,12 +22,14 @@
#ifndef __GKD_SECRETS_SERVICE_H__
#define __GKD_SECRETS_SERVICE_H__
-#include <glib-object.h>
-
#include "gkd-secrets-types.h"
+#include "gp11/gp11.h"
+
#include <dbus/dbus.h>
+#include <glib-object.h>
+
#define GKD_SECRETS_TYPE_SERVICE (gkd_secrets_service_get_type ())
#define GKD_SECRETS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKD_SECRETS_TYPE_SERVICE, GkdSecretsService))
#define GKD_SECRETS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GKD_SECRETS_TYPE_SERVICE, GkdSecretsServiceClass))
@@ -51,6 +53,8 @@ GType gkd_secrets_service_get_type (void);
DBusConnection* gkd_secrets_service_get_connection (GkdSecretsService *self);
+GP11Slot* gkd_secrets_service_get_pkcs11_slot (GkdSecretsService *self);
+
#if 0
void gkd_secrets_service_refresh (GkdSecretsService *self);
#endif
diff --git a/daemon/pkcs11/gkr-pkcs11-daemon.c b/daemon/pkcs11/gkr-pkcs11-daemon.c
index d7bc067..b7f0e25 100644
--- a/daemon/pkcs11/gkr-pkcs11-daemon.c
+++ b/daemon/pkcs11/gkr-pkcs11-daemon.c
@@ -232,3 +232,9 @@ gkr_pkcs11_daemon_setup_ssh (void)
return TRUE;
}
+
+CK_FUNCTION_LIST_PTR
+gkr_pkcs11_daemon_get_functions (void)
+{
+ return pkcs11_roof;
+}
diff --git a/daemon/pkcs11/gkr-pkcs11-daemon.h b/daemon/pkcs11/gkr-pkcs11-daemon.h
index 2d4ef63..4790734 100644
--- a/daemon/pkcs11/gkr-pkcs11-daemon.h
+++ b/daemon/pkcs11/gkr-pkcs11-daemon.h
@@ -24,10 +24,14 @@
#include <glib.h>
+#include "pkcs11/pkcs11.h"
+
gboolean gkr_pkcs11_daemon_initialize (void);
gboolean gkr_pkcs11_daemon_setup_pkcs11 (void);
gboolean gkr_pkcs11_daemon_setup_ssh (void);
+CK_FUNCTION_LIST_PTR gkr_pkcs11_daemon_get_functions (void);
+
#endif /* GKRPKCS11DAEMON_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]