gnome-keyring r1546 - in trunk: . pkcs11/user-store



Author: nnielsen
Date: Tue Feb 10 04:07:54 2009
New Revision: 1546
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1546&view=rev

Log:
Dynamically update the state which allows us to prompt for a password for a new token.

Modified:
   trunk/ChangeLog
   trunk/pkcs11/user-store/gck-user-module.c
   trunk/pkcs11/user-store/gck-user-storage.c
   trunk/pkcs11/user-store/gck-user-storage.h

Modified: trunk/pkcs11/user-store/gck-user-module.c
==============================================================================
--- trunk/pkcs11/user-store/gck-user-module.c	(original)
+++ trunk/pkcs11/user-store/gck-user-module.c	Tue Feb 10 04:07:54 2009
@@ -41,9 +41,10 @@
 	GckUserStorage *storage;
 	gchar *directory;
 	GHashTable *logged_in_apps;
+	CK_TOKEN_INFO token_info;
 };
 
-static const CK_SLOT_INFO gck_user_module_slot_info = {
+static const CK_SLOT_INFO user_module_slot_info = {
 	"User Keys",
 	"Gnome Keyring",
 	CKF_TOKEN_PRESENT,
@@ -51,7 +52,7 @@
 	{ 0, 0 }
 };
 
-static const CK_TOKEN_INFO gck_user_module_token_info = {
+static const CK_TOKEN_INFO user_module_token_info = {
 	"User Keys",
 	"Gnome Keyring",
 	"1.0",
@@ -93,15 +94,20 @@
  */
 
 static const CK_SLOT_INFO* 
-gck_user_module_real_get_slot_info (GckModule *self)
+gck_user_module_real_get_slot_info (GckModule *base)
 {
-	return &gck_user_module_slot_info;
+	return &user_module_slot_info;
 }
 
 static const CK_TOKEN_INFO*
-gck_user_module_real_get_token_info (GckModule *self)
+gck_user_module_real_get_token_info (GckModule *base)
 {
-	return &gck_user_module_token_info;
+	GckUserModule *self = GCK_USER_MODULE (base);
+	
+	/* Update the info with current info */
+	self->token_info.flags = gck_user_storage_token_flags (self->storage);
+	
+	return &self->token_info;
 }
 
 static void 
@@ -248,6 +254,9 @@
 {
 	self->logged_in_apps = g_hash_table_new_full (gck_util_ulong_hash, gck_util_ulong_equal, gck_util_ulong_free, NULL);
 	
+	/* Our default token info, updated as module runs */
+	memcpy (&self->token_info, &user_module_token_info, sizeof (CK_TOKEN_INFO));
+	
 	/* For creating stored keys */
 	gck_module_register_factory (GCK_MODULE (self), GCK_FACTORY_USER_PRIVATE_KEY);
 	gck_module_register_factory (GCK_MODULE (self), GCK_FACTORY_USER_PUBLIC_KEY);

Modified: trunk/pkcs11/user-store/gck-user-storage.c
==============================================================================
--- trunk/pkcs11/user-store/gck-user-storage.c	(original)
+++ trunk/pkcs11/user-store/gck-user-storage.c	Tue Feb 10 04:07:54 2009
@@ -1175,7 +1175,7 @@
 	args.new_login = new_login;
 	gck_data_file_foreach_entry (file, relock_each_object, &args);
 	
-	if (!gck_transaction_get_failed (transaction))
+	if (!gck_transaction_get_failed (transaction) && self->login)
 		set_storage_login (self, new_login);
 	
 	g_object_unref (file);
@@ -1239,3 +1239,28 @@
 	g_return_val_if_fail (GCK_IS_USER_STORAGE (self), NULL);
 	return self->login;
 }
+
+gulong
+gck_user_storage_token_flags (GckUserStorage *self)
+{
+	gulong flags = 0;
+	CK_RV rv;
+	
+	/* We don't support SO logins, so always initialized */
+	flags |= CKF_TOKEN_INITIALIZED | CKF_LOGIN_REQUIRED;
+	
+	/* No file has been loaded yet? */
+	if (self->last_mtime == 0) {
+		rv = gck_user_storage_refresh (self);
+		if (rv == CKR_USER_PIN_NOT_INITIALIZED)
+			flags |= CKF_USER_PIN_TO_BE_CHANGED;
+		else if (rv != CKR_OK)
+			g_return_val_if_reached (flags);
+	}
+	
+	/* No private stuff in the file? */
+	if (gck_data_file_have_section (self->file, GCK_DATA_FILE_SECTION_PRIVATE))
+		flags |= CKF_USER_PIN_INITIALIZED;
+	
+	return flags;
+}

Modified: trunk/pkcs11/user-store/gck-user-storage.h
==============================================================================
--- trunk/pkcs11/user-store/gck-user-storage.h	(original)
+++ trunk/pkcs11/user-store/gck-user-storage.h	Tue Feb 10 04:07:54 2009
@@ -54,6 +54,8 @@
 
 GckLogin*                   gck_user_storage_get_login              (GckUserStorage *self);
 
+gulong                      gck_user_storage_token_flags            (GckUserStorage *self);
+
 CK_RV                       gck_user_storage_refresh                (GckUserStorage *self);
 
 void                        gck_user_storage_create                 (GckUserStorage *self, 



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