gnome-keyring r1216 - in trunk: . daemon/data gp11



Author: nnielsen
Date: Sun Aug  3 20:35:04 2008
New Revision: 1216
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1216&view=rev

Log:
	* gp11/gp11-attribute.c:
	* gp11/gp11-call.c:
	* gp11/gp11-object.c:
	* gp11/gp11-private.h:
	* gp11/gp11-session.c:
	* gp11/gp11-slot.c:
	* gp11/gp11.h: Add concept of invalid attributes. Don't throw error
	when some attributes of a multi attribute retrieval are invalid.
	Call async ready callbacks with right object. 
	
	* daemon/data/gnome-keyring.schemas.in: Add gconf schema for 
	noting the PKCS#11 objects for the current user.

Modified:
   trunk/ChangeLog
   trunk/daemon/data/gnome-keyring.schemas.in
   trunk/gp11/gp11-attributes.c
   trunk/gp11/gp11-call.c
   trunk/gp11/gp11-object.c
   trunk/gp11/gp11-private.h
   trunk/gp11/gp11-session.c
   trunk/gp11/gp11-slot.c
   trunk/gp11/gp11.h

Modified: trunk/daemon/data/gnome-keyring.schemas.in
==============================================================================
--- trunk/daemon/data/gnome-keyring.schemas.in	(original)
+++ trunk/daemon/data/gnome-keyring.schemas.in	Sun Aug  3 20:35:04 2008
@@ -28,5 +28,21 @@
 				when certain command line arguments are passed to the daemon.</long>
 			</locale>
 		</schema>
+		<schema>
+			<key>/schemas/system/pkcs11/modules</key>
+			<applyto>/system/pkcs11/modules</applyto>
+			<owner>gnome-keyring</owner>
+			<type>list</type>
+			<list_type>string</list_type>
+			<default>[]</default>
+			<locale name="C">
+				<short>PKCS#11 Modules</short>
+				<long>A list of paths to PKCS#11 modules to load. No modules are 
+				currently listed by default, as this is still an experimental
+				feature. This is used by seahorse and other PKCS#11 aware 
+				applications.</long>
+			</locale>
+		</schema>
+			
 	</schemalist>
 </gconfschemafile>

Modified: trunk/gp11/gp11-attributes.c
==============================================================================
--- trunk/gp11/gp11-attributes.c	(original)
+++ trunk/gp11/gp11-attributes.c	Sun Aug  3 20:35:04 2008
@@ -19,6 +19,15 @@
 }
 
 void
+gp11_attribute_init_invalid (GP11Attribute *attr, guint attr_type)
+{
+	g_assert (sizeof (GP11Attribute) == sizeof (CK_ATTRIBUTE));
+	memset (attr, 0, sizeof (GP11Attribute));
+	attr->type = attr_type;
+	attr->length = (gulong)-1;
+}
+
+void
 _gp11_attribute_init_take (GP11Attribute *attr, guint attr_type,
                            gpointer value, gsize length)
 {
@@ -80,6 +89,14 @@
 }
 
 GP11Attribute*
+gp11_attribute_new_invalid (guint attr_type)
+{
+	GP11Attribute *attr = g_slice_new0 (GP11Attribute);
+	gp11_attribute_init_invalid (attr, attr_type);
+	return attr;
+}
+
+GP11Attribute*
 gp11_attribute_new_boolean (guint attr_type, gboolean value)
 {
 	GP11Attribute *attr = g_slice_new0 (GP11Attribute);
@@ -112,9 +129,18 @@
 }
 
 gboolean
+gp11_attribute_is_invalid (GP11Attribute *attr)
+{
+	g_return_val_if_fail (attr, TRUE);
+	return attr->length == (gulong)-1;
+}
+
+gboolean
 gp11_attribute_get_boolean (GP11Attribute *attr)
 {
 	g_return_val_if_fail (attr, FALSE);
+	if (gp11_attribute_is_invalid (attr))
+		return FALSE;
 	g_return_val_if_fail (attr->length == sizeof (CK_BBOOL), FALSE);
 	g_return_val_if_fail (attr->value, FALSE);
 	return *((CK_BBOOL*)attr->value) == CK_TRUE ? TRUE : FALSE;
@@ -124,6 +150,8 @@
 gp11_attribute_get_ulong (GP11Attribute *attr)
 {
 	g_return_val_if_fail (attr, FALSE);
+	if (gp11_attribute_is_invalid (attr))
+		return 0;
 	g_return_val_if_fail (attr->length == sizeof (CK_ULONG), (gulong)-1);
 	g_return_val_if_fail (attr->value, (gulong)-1);
 	return *((CK_ULONG*)attr->value);
@@ -134,6 +162,8 @@
 {
 	g_return_val_if_fail (attr, NULL);
 	
+	if (gp11_attribute_is_invalid (attr))
+		return NULL;
 	if (!attr->value)
 		return NULL;
 
@@ -149,6 +179,12 @@
 	gchar *end;
 	
 	g_return_if_fail (attr);
+	
+	if (gp11_attribute_is_invalid (attr)) {
+		g_date_clear (value, 1);
+		return;
+	}
+
 	g_return_if_fail (attr->length == sizeof (CK_DATE));
 	g_return_if_fail (attr->value);
 	date = (CK_DATE*)attr->value;
@@ -377,6 +413,16 @@
 }
 
 void
+gp11_attributes_add_invalid (GP11Attributes *attrs, guint attr_type)
+{
+	GP11Attribute *added;
+	g_return_if_fail (attrs);
+	g_return_if_fail (g_atomic_int_get (&attrs->immutable) == 0);
+	added = attributes_push (attrs);
+	gp11_attribute_init_invalid (added, attr_type);	
+}
+
+void
 gp11_attributes_add_boolean (GP11Attributes *attrs, guint attr_type, gboolean value)
 {
 	GP11Attribute *added;
@@ -448,7 +494,7 @@
 	g_return_val_if_fail (value, FALSE);
 
 	attr = gp11_attributes_find (attrs, attr_type);
-	if (!attr)
+	if (!attr || gp11_attribute_is_invalid (attr))
 		return FALSE;
 	*value = gp11_attribute_get_boolean (attr);
 	return TRUE;
@@ -461,7 +507,7 @@
 	g_return_val_if_fail (value, FALSE);
 
 	attr = gp11_attributes_find (attrs, attr_type);
-	if (!attr)
+	if (!attr || gp11_attribute_is_invalid (attr))
 		return FALSE;
 	*value = gp11_attribute_get_ulong (attr);
 	return TRUE;
@@ -474,7 +520,7 @@
 	g_return_val_if_fail (value, FALSE);
 
 	attr = gp11_attributes_find (attrs, attr_type);
-	if (!attr)
+	if (!attr || gp11_attribute_is_invalid (attr))
 		return FALSE;
 	*value = gp11_attribute_get_string (attr);
 	return TRUE;
@@ -487,7 +533,7 @@
 	g_return_val_if_fail (value, FALSE);
 
 	attr = gp11_attributes_find (attrs, attr_type);
-	if (!attr)
+	if (!attr || gp11_attribute_is_invalid (attr))
 		return FALSE;
 	gp11_attribute_get_date (attr, value);
 	return TRUE;

Modified: trunk/gp11/gp11-call.c
==============================================================================
--- trunk/gp11/gp11-call.c	(original)
+++ trunk/gp11/gp11-call.c	Sun Aug  3 20:35:04 2008
@@ -333,7 +333,8 @@
 }
 
 gpointer
-_gp11_call_async_prep (gpointer object, gpointer func, gsize args_size, gpointer destroy)
+_gp11_call_async_prep (gpointer object, gpointer cb_object, gpointer func, 
+                       gsize args_size, gpointer destroy)
 {
 	GP11Arguments *args;
 	GP11Module *module;
@@ -358,8 +359,8 @@
 	call = g_object_new (GP11_TYPE_CALL, NULL);
 	call->destroy = (GDestroyNotify)destroy;
 	call->func = (GP11CallFunc)func;
-	call->object = object;
-	g_object_ref (object);
+	call->object = cb_object;
+	g_object_ref (cb_object);
 
 	/* Hook the two together */
 	call->args = args;

Modified: trunk/gp11/gp11-object.c
==============================================================================
--- trunk/gp11/gp11-object.c	(original)
+++ trunk/gp11/gp11-object.c	Sun Aug  3 20:35:04 2008
@@ -195,7 +195,7 @@
 	g_return_if_fail (GP11_IS_OBJECT (object));
 	g_return_if_fail (GP11_IS_SESSION (object->session));
 
-	args = _gp11_call_async_prep (object->session, perform_destroy, sizeof (*args), NULL);
+	args = _gp11_call_async_prep (object->session, object, perform_destroy, sizeof (*args), NULL);
 	args->object = object->handle;
 	
 	_gp11_call_async_go (args, cancellable, callback, user_data);
@@ -268,7 +268,7 @@
 
 	g_return_if_fail (GP11_IS_OBJECT (object));
 
-	args = _gp11_call_async_prep (object->session, perform_set_attributes, 
+	args = _gp11_call_async_prep (object->session, object, perform_set_attributes, 
 	                              sizeof (*args), free_set_attributes);
 	args->attrs = attrs;
 	gp11_attributes_ref (attrs);
@@ -300,6 +300,24 @@
 	g_free (args);
 }
 
+/* 
+ * Certain failure return values only apply to individual attributes
+ * being retrieved. These are ignored, since the attribute should 
+ * already have -1 set as the length.
+ */
+static gboolean
+is_ok_get_attributes_rv (CK_RV rv) 
+{
+	switch (rv) {
+	case CKR_OK:
+	case CKR_ATTRIBUTE_SENSITIVE:
+	case CKR_ATTRIBUTE_TYPE_INVALID:
+		return TRUE;
+	default:
+		return FALSE;
+	}
+}
+
 static CK_RV
 perform_get_attributes (GetAttributes *args)
 {
@@ -320,7 +338,7 @@
 	/* Get the size of each value */
 	rv = (args->base.pkcs11->C_GetAttributeValue) (args->base.handle, args->object,
 	                                               attrs, n_attrs);
-	if (rv != CKR_OK) {
+	if (!is_ok_get_attributes_rv (rv)) {
 		g_free (attrs);
 		return rv;
 	}
@@ -336,7 +354,7 @@
 	                                               attrs, n_attrs);
 	
 	/* Transfer over the memory to the results */
-	if (rv == CKR_OK) {
+	if (is_ok_get_attributes_rv (rv)) {
 		g_assert (!args->results);
 		args->results = gp11_attributes_new ();
 		for (i = 0; i < n_attrs; ++i) {
@@ -350,6 +368,10 @@
 	for (i = 0; i < n_attrs; ++i)
 		g_free (attrs[i].pValue);
 	g_free (attrs);
+	
+	if (is_ok_get_attributes_rv (rv))
+		rv = CKR_OK;
+	
 	return rv;
 }
 
@@ -405,7 +427,7 @@
 
 	g_return_if_fail (GP11_IS_OBJECT (object));
 
-	args = _gp11_call_async_prep (object->session, perform_get_attributes, 
+	args = _gp11_call_async_prep (object->session, object, perform_get_attributes, 
 	                              sizeof (*args), free_get_attributes);
 	args->n_attr_types = n_attr_types;
 	if (n_attr_types)

Modified: trunk/gp11/gp11-private.h
==============================================================================
--- trunk/gp11/gp11-private.h	(original)
+++ trunk/gp11/gp11-private.h	Sun Aug  3 20:35:04 2008
@@ -98,6 +98,7 @@
                                                            GError **err);
 
 gpointer           _gp11_call_async_prep                  (gpointer object, 
+                                                           gpointer cb_object,
                                                            gpointer func, 
                                                            gsize args_size,
                                                            gpointer destroy_func);

Modified: trunk/gp11/gp11-session.c
==============================================================================
--- trunk/gp11/gp11-session.c	(original)
+++ trunk/gp11/gp11-session.c	Sun Aug  3 20:35:04 2008
@@ -252,7 +252,7 @@
                           gsize n_pin, GCancellable *cancellable, GAsyncReadyCallback callback,
                           gpointer user_data)
 {
-	Login* args = _gp11_call_async_prep (session, perform_login, sizeof (*args), free_login);
+	Login* args = _gp11_call_async_prep (session, session, perform_login, sizeof (*args), free_login);
 	
 	args->user_type = user_type;
 	args->pin = pin && n_pin ? g_memdup (pin, n_pin) : NULL;
@@ -296,7 +296,7 @@
 gp11_session_logout_async (GP11Session *session, GCancellable *cancellable,
                            GAsyncReadyCallback callback, gpointer user_data)
 {
-	GP11Arguments *args = _gp11_call_async_prep (session, perform_logout, 0, NULL);
+	GP11Arguments *args = _gp11_call_async_prep (session, session, perform_logout, 0, NULL);
 	_gp11_call_async_go (args, cancellable, callback, user_data);
 }
 
@@ -364,7 +364,7 @@
                                   GCancellable *cancellable, GAsyncReadyCallback callback, 
                                   gpointer user_data)
 {
-	CreateObject *args = _gp11_call_async_prep (session, perform_create_object, 
+	CreateObject *args = _gp11_call_async_prep (session, session, perform_create_object, 
 	                                            sizeof (*args), free_create_object);
 	args->attrs = attrs;
 	gp11_attributes_ref (attrs);
@@ -502,7 +502,7 @@
                                  GCancellable *cancellable, GAsyncReadyCallback callback, 
                                  gpointer user_data)
 {
-	FindObjects *args = _gp11_call_async_prep (session, perform_find_objects, 
+	FindObjects *args = _gp11_call_async_prep (session, session, perform_find_objects, 
 	                                           sizeof (*args), free_find_objects);
 	args->attrs = attrs;
 	gp11_attributes_ref (attrs);
@@ -618,7 +618,7 @@
              gsize n_input, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data,
              CK_C_EncryptInit init_func, CK_C_Encrypt complete_func)
 {
-	Crypt *args = _gp11_call_async_prep (session, perform_crypt, sizeof (*args), free_crypt);
+	Crypt *args = _gp11_call_async_prep (session, session, perform_crypt, sizeof (*args), free_crypt);
 
 	g_return_if_fail (GP11_IS_OBJECT (key));
 	g_return_if_fail (mech_args);
@@ -880,7 +880,7 @@
                            gsize n_signature, GCancellable *cancellable,
                            GAsyncReadyCallback callback, gpointer user_data)
 {
-	Verify *args = _gp11_call_async_prep (session, perform_verify, sizeof (*args), free_verify);
+	Verify *args = _gp11_call_async_prep (session, session, perform_verify, sizeof (*args), free_verify);
 
 	g_return_if_fail (GP11_IS_OBJECT (key));
 	g_return_if_fail (mech_args);

Modified: trunk/gp11/gp11-slot.c
==============================================================================
--- trunk/gp11/gp11-slot.c	(original)
+++ trunk/gp11/gp11-slot.c	Sun Aug  3 20:35:04 2008
@@ -638,7 +638,7 @@
                             const gchar *label, GCancellable *cancellable,
                             GAsyncReadyCallback callback, gpointer user_data)
 {
-	InitToken* args = _gp11_call_async_prep (slot, perform_init_token, 
+	InitToken* args = _gp11_call_async_prep (slot, slot, perform_init_token, 
 	                                         sizeof (*args));
 	
 	args->pin = pin;
@@ -698,7 +698,7 @@
 gp11_slot_open_session_async (GP11Slot *slot, guint flags, GCancellable *cancellable, 
                               GAsyncReadyCallback callback, gpointer user_data)
 {
-	OpenSession *args = _gp11_call_async_prep (slot, perform_open_session,
+	OpenSession *args = _gp11_call_async_prep (slot, slot, perform_open_session,
 	                                           sizeof (*args), NULL);
 	
 	/* Try to use a cached session */

Modified: trunk/gp11/gp11.h
==============================================================================
--- trunk/gp11/gp11.h	(original)
+++ trunk/gp11/gp11.h	Sun Aug  3 20:35:04 2008
@@ -52,6 +52,9 @@
                                                              gconstpointer value,
                                                              gsize length);
 
+void                gp11_attribute_init_invalid             (GP11Attribute *attr,
+                                                             guint attr_type);
+
 void                gp11_attribute_init_boolean             (GP11Attribute *attr,
                                                              guint attr_type,
                                                              gboolean value);
@@ -75,6 +78,8 @@
                                                              gpointer value,
                                                              gsize length);
 
+GP11Attribute*      gp11_attribute_new_invalid              (guint attr_type);
+
 GP11Attribute*      gp11_attribute_new_boolean              (guint attr_type,
                                                              gboolean value);
 
@@ -87,6 +92,8 @@
 GP11Attribute*      gp11_attribute_new_string               (guint attr_type,
                                                              const gchar *value);
 
+gboolean            gp11_attribute_is_invalid               (GP11Attribute *attr);
+
 gboolean            gp11_attribute_get_boolean              (GP11Attribute *attr);
 
 gulong              gp11_attribute_get_ulong                (GP11Attribute *attr);
@@ -130,6 +137,9 @@
                                                              gconstpointer value,
                                                              gsize length);
 
+void                gp11_attributes_add_invalid             (GP11Attributes *attrs,
+                                                             guint attr_type);
+
 void                gp11_attributes_add_boolean             (GP11Attributes *attrs,
                                                              guint attr_type,
                                                              gboolean value);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]