gnome-keyring r1621 - in trunk: . pkcs11/gck pkcs11/gck/tests



Author: nnielsen
Date: Thu Feb 26 22:11:53 2009
New Revision: 1621
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1621&view=rev

Log:
Implement a testing tool to dump gck data files such as the user key store.

Added:
   trunk/pkcs11/gck/tests/dump-data-file.c
Modified:
   trunk/ChangeLog
   trunk/pkcs11/gck/gck-data-file.c
   trunk/pkcs11/gck/gck-data-file.h
   trunk/pkcs11/gck/tests/.gitignore
   trunk/pkcs11/gck/tests/Makefile.am

Modified: trunk/pkcs11/gck/gck-data-file.c
==============================================================================
--- trunk/pkcs11/gck/gck-data-file.c	(original)
+++ trunk/pkcs11/gck/gck-data-file.c	Thu Feb 26 22:11:53 2009
@@ -29,6 +29,7 @@
 #include "gck-util.h"
 
 #include "egg/egg-buffer.h"
+#include "egg/egg-hex.h"
 #include "egg/egg-secure-memory.h"
 #include "egg/egg-symkey.h"
 
@@ -994,6 +995,46 @@
 	g_signal_emit (self, signals[ENTRY_ADDED], 0, key);
 }
 
+static void
+dump_attributes (gpointer key, gpointer value, gpointer user_data)
+{
+	CK_ATTRIBUTE_PTR attr = value;
+	gulong *type = key;
+	gchar *text;
+	
+	g_assert (type);
+	g_assert (value);
+	
+	if (attr->pValue == NULL)
+		text = g_strdup ("NULL");
+	else
+		text = egg_hex_encode_full (attr->pValue, attr->ulValueLen, TRUE, ' ', 1);
+	
+	g_print ("\t0x%08x: %s\n", (guint)*type, text);
+	g_free (text);
+}
+
+static void
+dump_identifier_and_attributes (GckDataFile *self, const gchar *identifier, gpointer user_data)
+{
+	GHashTable *attributes;
+	guint section;
+	
+	g_assert (GCK_IS_DATA_FILE (self));
+	
+	if (!gck_data_file_lookup_entry (self, identifier, &section))
+		g_assert_not_reached ();
+	
+	if (GPOINTER_TO_UINT (user_data) == section) {
+		g_print ("%s\n", identifier);
+		if (identifier_to_attributes (self, identifier, &attributes) != GCK_DATA_SUCCESS)
+			g_assert_not_reached ();
+		g_hash_table_foreach (attributes, dump_attributes, NULL);
+		g_print ("\n");
+	}
+}
+
+
 /* -----------------------------------------------------------------------------
  * OBJECT 
  */
@@ -1431,3 +1472,14 @@
 {
 	return (self->sections & section) ? TRUE : FALSE;
 }
+
+void
+gck_data_file_dump (GckDataFile *self)
+{
+	g_print ("PUBLIC:\n\n");
+	gck_data_file_foreach_entry (self, dump_identifier_and_attributes, 
+	                             GUINT_TO_POINTER (GCK_DATA_FILE_SECTION_PUBLIC));	
+	g_print ("PRIVATE:\n\n");
+	gck_data_file_foreach_entry (self, dump_identifier_and_attributes, 
+	                             GUINT_TO_POINTER (GCK_DATA_FILE_SECTION_PRIVATE));	
+}

Modified: trunk/pkcs11/gck/gck-data-file.h
==============================================================================
--- trunk/pkcs11/gck/gck-data-file.h	(original)
+++ trunk/pkcs11/gck/gck-data-file.h	Thu Feb 26 22:11:53 2009
@@ -100,5 +100,10 @@
                                                                 gulong type,
                                                                 gconstpointer *value,
                                                                 gsize *n_value);
+
+void                      gck_data_file_foreach_value          (GckDataFile *self,
+                                                                const gchar *identifier);
      
+void                      gck_data_file_dump                   (GckDataFile *self);
+
 #endif /* __GCK_DATA_FILE_H__ */

Modified: trunk/pkcs11/gck/tests/.gitignore
==============================================================================
--- trunk/pkcs11/gck/tests/.gitignore	(original)
+++ trunk/pkcs11/gck/tests/.gitignore	Thu Feb 26 22:11:53 2009
@@ -6,3 +6,4 @@
 /Makefile.in
 /run-auto-test
 /run-prompt-test
+/dump-data-file

Modified: trunk/pkcs11/gck/tests/Makefile.am
==============================================================================
--- trunk/pkcs11/gck/tests/Makefile.am	(original)
+++ trunk/pkcs11/gck/tests/Makefile.am	Thu Feb 26 22:11:53 2009
@@ -29,3 +29,17 @@
 	test-data
 
 include $(top_srcdir)/tests/gtest.make
+
+# ---------------------------------------------------------------------
+
+noinst_PROGRAMS += \
+	dump-data-file
+
+dump_data_file_SOURCES = \
+	dump-data-file.c
+	
+dump_data_file_LDADD = \
+	$(top_builddir)/pkcs11/gck/libgck.la \
+	$(top_builddir)/egg/libegg.la \
+	$(DAEMON_LIBS)
+	
\ No newline at end of file

Added: trunk/pkcs11/gck/tests/dump-data-file.c
==============================================================================
--- (empty file)
+++ trunk/pkcs11/gck/tests/dump-data-file.c	Thu Feb 26 22:11:53 2009
@@ -0,0 +1,100 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* dump-data-file.c: Dump a gck data file
+
+   Copyright (C) 2009 Stefan Walter
+
+   The Gnome Keyring Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Keyring Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+
+   Author: Stef Walter <stef memberwebs com>
+*/
+
+#include "gck-crypto.h"
+#include "gck-data-file.h"
+
+#include "egg/egg-secure-memory.h"
+
+#include <glib.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+void egg_memory_lock (void) 
+	{ }
+void egg_memory_unlock (void) 
+	{ }
+void* egg_memory_fallback (void *p, size_t sz) 
+	{ return g_realloc (p, sz); }
+
+static void G_GNUC_NORETURN
+failure (const gchar* message, ...)
+{
+	va_list va;
+	va_start (va, message);
+	vfprintf (stderr, message, va);
+	fputc ('\n', stderr);
+	va_end (va);
+	exit (1);
+}
+
+int 
+main(int argc, char* argv[])
+{
+	const gchar *password;
+	GckDataResult res;
+	GckDataFile *file;
+	GckLogin *login;
+	int fd;
+	
+	g_type_init ();
+	gck_crypto_initialize ();
+	
+	if (argc != 2) 
+		failure ("usage: dump-data-file filename");
+	
+	fd = open (argv[1], O_RDONLY, 0);
+	if (fd == -1)
+		failure ("dump-data-file: couldn't open file: %s: %s", argv[1], g_strerror (errno));
+	
+	password = getpass ("Password: ");
+	login = gck_login_new ((guchar*)password, strlen (password));
+	
+	file = gck_data_file_new ();
+	res = gck_data_file_read_fd (file, fd, login);
+	g_object_unref (login);
+
+	switch(res) {
+	case GCK_DATA_FAILURE:
+		failure ("dump-data-file: failed to read file: %s", argv[1]);
+	case GCK_DATA_LOCKED:
+		failure ("dump-data-file: invalid password for file: %s", argv[1]);
+	case GCK_DATA_UNRECOGNIZED:
+		failure ("dump-data-file: unparseable file format: %s", argv[1]);
+	case GCK_DATA_SUCCESS:
+		break;
+	default:
+		g_assert_not_reached ();
+	}
+	
+	gck_data_file_dump (file);
+	g_object_unref (file);
+	
+	return 0;
+}



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