[gnome-keyring] pkcs11: Complete a bunch more tests
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] pkcs11: Complete a bunch more tests
- Date: Sat, 7 Apr 2012 14:41:57 +0000 (UTC)
commit 46748de8fc812dbc384e47b5910d522f57bbc79c
Author: Stef Walter <stefw gnome org>
Date: Sat Apr 7 16:41:16 2012 +0200
pkcs11: Complete a bunch more tests
* Add tests for the 'egg' merge coming up
* Fix a few problems resulting from p11-tests tests
.gitignore | 2 +
Makefile.decl | 8 +-
pkcs11/gkm/tests/Makefile.am | 5 +
pkcs11/gkm/tests/test-certificate.c | 208 +++++++++++++++
pkcs11/gnome2-store/gkm-gnome2-private-key.c | 5 +-
pkcs11/gnome2-store/gkm-gnome2-storage.c | 1 +
pkcs11/gnome2-store/tests/Makefile.am | 24 ++-
pkcs11/gnome2-store/tests/files/der-key-v2-des3.p8 | Bin 0 -> 714 bytes
.../tests/{p11-tests.conf => p11-tests.conf.in} | 2 +-
.../gnome2-store/tests/test-gnome2-private-key.c | 268 ++++++++++++++++++++
pkcs11/gnome2-store/tests/test-gnome2-storage.c | 21 ++
pkcs11/roots-store/tests/Makefile.am | 17 +-
.../tests/{p11-tests.conf => p11-tests.conf.in} | 2 +-
pkcs11/ssh-store/tests/Makefile.am | 17 +-
pkcs11/ssh-store/tests/p11-tests.conf | 2 +-
pkcs11/ssh-store/tests/p11-tests.conf.in | 3 +
pkcs11/ssh-store/tests/test-private-key.c | 68 ++++--
17 files changed, 615 insertions(+), 38 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 8b02d20..0a6df42 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,6 +40,7 @@ run-tests
*.pc
*.gir
*.typelib
+p11-tests.conf
/compile
/ABOUT-NLS
@@ -103,6 +104,7 @@ run-tests
/daemon/control/tests/frob-control-unlock
/pkcs11/gkm/tests/test-attributes
+/pkcs11/gkm/tests/test-certificate
/pkcs11/gkm/tests/test-credential
/pkcs11/gkm/tests/test-data-asn1
/pkcs11/gkm/tests/test-data-der
diff --git a/Makefile.decl b/Makefile.decl
index ab3bcf9..96900ec 100644
--- a/Makefile.decl
+++ b/Makefile.decl
@@ -21,6 +21,8 @@ SED_SUBST = sed \
-e 's,[ ]bindir[@],$(bindir),g' \
-e 's,[ ]exec_prefix[@],$(exec_prefix),g' \
-e 's,[ ]prefix[@],$(prefix),g' \
+ -e 's,[ ]abs_srcdir[@],$(abs_srcdir),g' \
+ -e 's,[ ]srcdir[@],$(srcdir),g' \
-e 's,[ ]PACKAGE[@],$(PACKAGE),g' \
-e 's,[ ]VERSION[@],$(VERSION),g' \
-e 's,[ ]VALGRIND_RUN[@],$(VALGRIND_RUN),g' \
@@ -34,4 +36,8 @@ SED_SUBST = sed \
.service.in.service:
$(V_SED) $(SED_SUBST) $< > $@
-SUFFIXES = .asn .asn.h .desktop.in .desktop.in.in .service .service.in
\ No newline at end of file
+.conf.in.conf:
+ $(V_SED) $(SED_SUBST) $< > $@
+
+SUFFIXES = .asn .asn.h .conf .conf.in .desktop.in .desktop.in.in .service .service.in
+
diff --git a/pkcs11/gkm/tests/Makefile.am b/pkcs11/gkm/tests/Makefile.am
index e50ed08..034e147 100644
--- a/pkcs11/gkm/tests/Makefile.am
+++ b/pkcs11/gkm/tests/Makefile.am
@@ -32,6 +32,7 @@ TEST_PROGS = \
test-file-tracker \
test-memory-store \
test-object \
+ test-certificate \
test-secret \
test-sexp \
test-store \
@@ -50,6 +51,10 @@ test_object_LDADD = \
libgkm-mock.a \
$(LDADD)
+test_certificate_LDADD = \
+ libgkm-mock.a \
+ $(LDADD)
+
test_store_LDADD = \
libgkm-mock.a \
$(LDADD)
diff --git a/pkcs11/gkm/tests/test-certificate.c b/pkcs11/gkm/tests/test-certificate.c
new file mode 100644
index 0000000..7ad9a6d
--- /dev/null
+++ b/pkcs11/gkm/tests/test-certificate.c
@@ -0,0 +1,208 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* test-object.c: Test GkmObject
+
+ Copyright (C) 2012 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 <stefw gnome org>
+*/
+
+#include "config.h"
+
+#include "mock-module.h"
+
+#include "gkm/gkm-attributes.h"
+#include "gkm/gkm-certificate.h"
+#include "gkm/gkm-object.h"
+#include "gkm/gkm-module.h"
+#include "gkm/gkm-serializable.h"
+#include "gkm/gkm-session.h"
+#include "gkm/gkm-test.h"
+
+#include "egg/egg-testing.h"
+
+#include "pkcs11i.h"
+
+typedef struct {
+ GkmModule *module;
+ GkmSession *session;
+ gpointer certificate_data;
+ gsize n_certificate_data;
+ GkmCertificate *certificate;
+} Test;
+
+static void
+setup_basic (Test* test,
+ gconstpointer unused)
+{
+ gchar *data;
+ gsize length;
+
+ test->module = mock_module_initialize_and_enter ();
+ test->session = mock_module_open_session (TRUE);
+
+ if (!g_file_get_contents (SRCDIR "/files/test-certificate-1.der", &data, &length, NULL))
+ g_assert_not_reached ();
+
+ test->certificate_data = data;
+ test->n_certificate_data = length;
+}
+
+static void
+teardown_basic (Test* test,
+ gconstpointer unused)
+{
+ g_free (test->certificate_data);
+ mock_module_leave_and_finalize ();
+}
+
+static GkmCertificate *
+create_certificate_object (GkmSession *session,
+ gpointer data, gsize length)
+{
+ GkmCertificate *certificate;
+
+ certificate = g_object_new (GKM_TYPE_CERTIFICATE,
+ "unique", "test-certificate",
+ "module", gkm_session_get_module (session),
+ "manager", gkm_session_get_manager (session),
+ NULL);
+
+ if (!gkm_serializable_load (GKM_SERIALIZABLE (certificate), NULL, data, length))
+ g_assert_not_reached ();
+
+ return certificate;
+}
+
+static void
+setup (Test *test,
+ gconstpointer unused)
+{
+ setup_basic (test, unused);
+ test->certificate = create_certificate_object (test->session, test->certificate_data, test->n_certificate_data);
+}
+
+static void
+teardown (Test *test,
+ gconstpointer unused)
+{
+ g_clear_object (&test->certificate);
+ teardown_basic (test, unused);
+}
+
+static void
+test_attribute_check_value (Test* test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_CHECK_VALUE, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x36\x86\x35", 3);
+ g_free (data);
+}
+
+static void
+test_attribute_issuer (Test* test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_ISSUER, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x30\x81\xCF\x31\x0B\x30\x09\x06\x03\x55\x04\x06\x13\x02\x5A\x41\x31\x15\x30\x13\x06\x03\x55\x04\x08\x13\x0C\x57\x65\x73\x74\x65\x72\x6E\x20\x43\x61\x70\x65\x31\x12\x30\x10\x06\x03\x55\x04\x07\x13\x09\x43\x61\x70\x65\x20\x54\x6F\x77\x6E\x31\x1A\x30\x18\x06\x03\x55\x04\x0A\x13\x11\x54\x68\x61\x77\x74\x65\x20\x43\x6F\x6E\x73\x75\x6C\x74\x69\x6E\x67\x31\x28\x30\x26\x06\x03\x55\x04\x0B\x13\x1F\x43\x65\x72\x74\x69\x66\x69\x63\x61\x74\x69\x6F\x6E\x20\x53\x65\x72\x76\x69\x63\x65\x73\x20\x44\x69\x76\x69\x73\x69\x6F\x6E\x31\x23\x30\x21\x06\x03\x55\x04\x03\x13\x1A\x54\x68\x61\x77\x74\x65\x20\x50\x65\x72\x73\x6F\x6E\x61\x6C\x20\x50\x72\x65\x6D\x69\x75\x6D\x20\x43\x41\x31\x2A\x30\x28\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x09\x01\x16\x1B\x70\x65\x72\x73\x6F\x6E\x61\x6C\x2D\x70\x72\x65\x6D\x69\x75\x6D\x40\x74\x68\x61\x77\x74\x65\x2E\x63\x6F\x6D", 210);
+ g_free (data);
+}
+
+static void
+test_attribute_subject (Test* test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_SUBJECT, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x30\x81\xCF\x31\x0B\x30\x09\x06\x03\x55\x04\x06\x13\x02\x5A\x41\x31\x15\x30\x13\x06\x03\x55\x04\x08\x13\x0C\x57\x65\x73\x74\x65\x72\x6E\x20\x43\x61\x70\x65\x31\x12\x30\x10\x06\x03\x55\x04\x07\x13\x09\x43\x61\x70\x65\x20\x54\x6F\x77\x6E\x31\x1A\x30\x18\x06\x03\x55\x04\x0A\x13\x11\x54\x68\x61\x77\x74\x65\x20\x43\x6F\x6E\x73\x75\x6C\x74\x69\x6E\x67\x31\x28\x30\x26\x06\x03\x55\x04\x0B\x13\x1F\x43\x65\x72\x74\x69\x66\x69\x63\x61\x74\x69\x6F\x6E\x20\x53\x65\x72\x76\x69\x63\x65\x73\x20\x44\x69\x76\x69\x73\x69\x6F\x6E\x31\x23\x30\x21\x06\x03\x55\x04\x03\x13\x1A\x54\x68\x61\x77\x74\x65\x20\x50\x65\x72\x73\x6F\x6E\x61\x6C\x20\x50\x72\x65\x6D\x69\x75\x6D\x20\x43\x41\x31\x2A\x30\x28\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x09\x01\x16\x1B\x70\x65\x72\x73\x6F\x6E\x61\x6C\x2D\x70\x72\x65\x6D\x69\x75\x6D\x40\x74\x68\x61\x77\x74\x65\x2E\x63\x6F\x6D", 210);
+ g_free (data);
+}
+
+static void
+test_attribute_serial_number (Test* test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_SERIAL_NUMBER, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x02\x01\x00", 3);
+ g_free (data);
+}
+
+static void
+test_attribute_value (Test* test,
+ gconstpointer unused)
+{
+ gconstpointer raw;
+ gpointer data;
+ gsize n_data, n_raw;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_VALUE, &n_data);
+
+ raw = test->certificate_data;
+ n_raw = test->n_certificate_data
+ ;
+ egg_assert_cmpmem (data, n_data, ==, raw, n_raw);
+ g_free (data);
+}
+
+static void
+test_hash (Test* test,
+ gconstpointer unused)
+{
+ gpointer hash;
+ gsize n_hash;
+
+ hash = gkm_certificate_hash (test->certificate, GCRY_MD_SHA1, &n_hash);
+
+ egg_assert_cmpmem (hash, n_hash, ==, "\x36\x86\x35\x63\xFD\x51\x28\xC7\xBE\xA6\xF0\x05\xCF\xE9\xB4\x36\x68\x08\x6C\xCE", 20);
+ g_free (hash);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/gkm/certificate/issuer", Test, NULL, setup, test_attribute_issuer, teardown);
+ g_test_add ("/gkm/certificate/subject", Test, NULL, setup, test_attribute_subject, teardown);
+ g_test_add ("/gkm/certificate/check-value", Test, NULL, setup, test_attribute_check_value, teardown);
+ g_test_add ("/gkm/certificate/serial-number", Test, NULL, setup, test_attribute_serial_number, teardown);
+ g_test_add ("/gkm/certificate/value", Test, NULL, setup, test_attribute_value, teardown);
+ g_test_add ("/gkm/certificate/hash", Test, NULL, setup, test_hash, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/gnome2-store/gkm-gnome2-private-key.c b/pkcs11/gnome2-store/gkm-gnome2-private-key.c
index 357e7ce..a2bc738 100644
--- a/pkcs11/gnome2-store/gkm-gnome2-private-key.c
+++ b/pkcs11/gnome2-store/gkm-gnome2-private-key.c
@@ -293,7 +293,7 @@ static gboolean
gkm_gnome2_private_key_real_save (GkmSerializable *base, GkmSecret *login, gpointer *data, gsize *n_data)
{
GkmGnome2PrivateKey *self = GKM_GNOME2_PRIVATE_KEY (base);
- const gchar *password;
+ const gchar *password = NULL;
gsize n_password;
GkmSexp *sexp;
guchar *key;
@@ -305,7 +305,8 @@ gkm_gnome2_private_key_real_save (GkmSerializable *base, GkmSecret *login, gpoin
sexp = gkm_gnome2_private_key_real_acquire_crypto_sexp (GKM_SEXP_KEY (self), NULL);
g_return_val_if_fail (sexp, FALSE);
- password = gkm_secret_get_password (login, &n_password);
+ if (login != NULL)
+ password = gkm_secret_get_password (login, &n_password);
if (password == NULL) {
key = gkm_data_der_write_private_pkcs8_plain (gkm_sexp_get (sexp), n_data);
diff --git a/pkcs11/gnome2-store/gkm-gnome2-storage.c b/pkcs11/gnome2-store/gkm-gnome2-storage.c
index 0ca0e9f..ac52ccf 100644
--- a/pkcs11/gnome2-store/gkm-gnome2-storage.c
+++ b/pkcs11/gnome2-store/gkm-gnome2-storage.c
@@ -1234,6 +1234,7 @@ gkm_gnome2_storage_relock (GkmGnome2Storage *self, GkmTransaction *transaction,
args.transaction = transaction;
args.old_login = old_login;
args.new_login = new_login;
+ args.self = self;
gkm_gnome2_file_foreach_entry (file, relock_each_object, &args);
if (!gkm_transaction_get_failed (transaction) && self->login) {
diff --git a/pkcs11/gnome2-store/tests/Makefile.am b/pkcs11/gnome2-store/tests/Makefile.am
index 1d09dba..37017ae 100644
--- a/pkcs11/gnome2-store/tests/Makefile.am
+++ b/pkcs11/gnome2-store/tests/Makefile.am
@@ -1,3 +1,4 @@
+include $(top_srcdir)/Makefile.decl
INCLUDES = \
-I$(top_builddir) \
@@ -20,17 +21,25 @@ else
CHECK_PROGS =
endif
+CHECK_FILES = \
+ p11-tests.conf
+
TEST_PROGS = \
test-gnome2-file \
- test-gnome2-storage
+ test-gnome2-storage \
+ test-gnome2-private-key
test_gnome2_storage_SOURCES = \
test-gnome2-storage.c \
mock-gnome2-module.c mock-gnome2-module.h
+test_gnome2_private_key_SOURCES = \
+ test-gnome2-private-key.c \
+ mock-gnome2-module.c mock-gnome2-module.h
+
check_PROGRAMS = $(TEST_PROGS)
-test: $(TEST_PROGS) $(CHECK_PROGS)
+test: $(TEST_PROGS) $(CHECK_PROGS) $(CHECK_FILES)
gtester --verbose -m $(TEST_MODE) --g-fatal-warnings $(TEST_PROGS)
@for prog in $(CHECK_PROGS); do SRCDIR='.' ./$$prog || exit 1; done
@@ -38,13 +47,16 @@ check-local: test
all-local: $(check_PROGRAMS)
-EXTRA_DIST = \
- p11-tests.conf \
- files
-
noinst_PROGRAMS = \
frob-gnome2-file \
$(CHECK_PROGS)
check_gnome2_module_CFLAGS = $(P11_TESTS_CFLAGS)
check_gnome2_module_LDADD = $(P11_TESTS_LIBS) $(LDADD)
+
+EXTRA_DIST = \
+ p11-tests.conf.in \
+ files
+
+CLEAN_FILES = \
+ $(CHECK_FILES)
diff --git a/pkcs11/gnome2-store/tests/files/der-key-v2-des3.p8 b/pkcs11/gnome2-store/tests/files/der-key-v2-des3.p8
new file mode 100644
index 0000000..9e2999c
Binary files /dev/null and b/pkcs11/gnome2-store/tests/files/der-key-v2-des3.p8 differ
diff --git a/pkcs11/gnome2-store/tests/p11-tests.conf b/pkcs11/gnome2-store/tests/p11-tests.conf.in
similarity index 54%
rename from pkcs11/gnome2-store/tests/p11-tests.conf
rename to pkcs11/gnome2-store/tests/p11-tests.conf.in
index fda5f0d..4437c5c 100644
--- a/pkcs11/gnome2-store/tests/p11-tests.conf
+++ b/pkcs11/gnome2-store/tests/p11-tests.conf.in
@@ -1,2 +1,2 @@
# Configuration for running p11-tests on this module
-init-string = directory='test-data'
+init-string = directory='@abs_srcdir@/files'
diff --git a/pkcs11/gnome2-store/tests/test-gnome2-private-key.c b/pkcs11/gnome2-store/tests/test-gnome2-private-key.c
new file mode 100644
index 0000000..f7ca8c7
--- /dev/null
+++ b/pkcs11/gnome2-store/tests/test-gnome2-private-key.c
@@ -0,0 +1,268 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* test-object.c: Test GkmObject
+
+ Copyright (C) 2012 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 <stefw gnome org>
+*/
+
+#include "config.h"
+
+#include "mock-gnome2-module.h"
+
+#include "gnome2-store/gkm-gnome2-private-key.h"
+
+#if 0
+#include "gkm/gkm-attributes.h"
+#include "gkm/gkm-certificate.h"
+#include "gkm/gkm-object.h"
+#endif
+#include "gkm/gkm-data-der.h"
+#include "gkm/gkm-module.h"
+#include "gkm/gkm-serializable.h"
+#include "gkm/gkm-session.h"
+#include "gkm/gkm-test.h"
+
+#include "egg/egg-testing.h"
+
+#include "pkcs11i.h"
+
+typedef struct {
+ GkmModule *module;
+ GkmSession *session;
+ gpointer key_data;
+ gsize n_key_data;
+ GkmGnome2PrivateKey *key;
+} Test;
+
+static void
+setup_basic (Test* test,
+ gconstpointer unused)
+{
+ gchar *data;
+ gsize length;
+
+ test->module = mock_gnome2_module_initialize_and_enter ();
+ test->session = mock_gnome2_module_open_session (TRUE);
+
+ if (!g_file_get_contents (SRCDIR "/files/der-key-v2-des3.p8", &data, &length, NULL))
+ g_assert_not_reached ();
+
+ test->key_data = data;
+ test->n_key_data = length;
+}
+
+static void
+teardown_basic (Test* test,
+ gconstpointer unused)
+{
+ g_free (test->key_data);
+ mock_gnome2_module_leave_and_finalize ();
+}
+
+static void
+setup (Test *test,
+ gconstpointer unused)
+{
+ GkmSecret *login;
+
+ setup_basic (test, unused);
+
+ test->key = g_object_new (GKM_TYPE_GNOME2_PRIVATE_KEY,
+ "unique", "test-key",
+ "module", gkm_session_get_module (test->session),
+ "manager", gkm_session_get_manager (test->session),
+ NULL);
+
+ login = gkm_secret_new_from_password ("booo");
+ if (!gkm_serializable_load (GKM_SERIALIZABLE (test->key), login, test->key_data, test->n_key_data))
+ g_assert_not_reached ();
+ g_object_unref (login);
+}
+
+static void
+teardown (Test *test,
+ gconstpointer unused)
+{
+ g_clear_object (&test->key);
+ teardown_basic (test, unused);
+}
+
+static void
+test_load_private_key (Test *test,
+ gconstpointer unused)
+{
+ GkmGnome2PrivateKey *key;
+ GkmSecret *login;
+
+ key = g_object_new (GKM_TYPE_GNOME2_PRIVATE_KEY,
+ "unique", "test-key",
+ "module", gkm_session_get_module (test->session),
+ "manager", gkm_session_get_manager (test->session),
+ NULL);
+
+ /* It's encrypted, this should fail */
+ if (gkm_serializable_load (GKM_SERIALIZABLE (key), NULL, test->key_data, test->n_key_data))
+ g_assert_not_reached ();
+
+ login = gkm_secret_new_from_password ("booo");
+ if (!gkm_serializable_load (GKM_SERIALIZABLE (key), login, test->key_data, test->n_key_data))
+ g_assert_not_reached ();
+ g_object_unref (login);
+
+ g_object_unref (key);
+}
+
+static void
+test_save_private_key (Test *test,
+ gconstpointer unused)
+{
+ GkmSecret *login;
+ gpointer data;
+ gsize n_data;
+ gcry_sexp_t sexp;
+
+ /* Save unencrypted */
+ if (!gkm_serializable_save (GKM_SERIALIZABLE (test->key), NULL, &data, &n_data))
+ g_assert_not_reached ();
+ g_assert (data != NULL);
+ g_assert (gkm_data_der_read_private_pkcs8_plain (data, n_data, &sexp) == GKM_DATA_SUCCESS);
+ g_free (data);
+ gcry_sexp_release (sexp);
+
+ /* Save encrypted */
+ login = gkm_secret_new_from_password ("booo");
+ if (!gkm_serializable_save (GKM_SERIALIZABLE (test->key), login, &data, &n_data))
+ g_assert_not_reached ();
+ g_assert (data != NULL);
+ g_assert (gkm_data_der_read_private_pkcs8_crypted (data, n_data, "booo", 4, &sexp) == GKM_DATA_SUCCESS);
+ g_free (data);
+ gcry_sexp_release (sexp);
+ g_object_unref (login);
+}
+
+#if 0
+static void
+test_attribute_check_value (Test* test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_CHECK_VALUE, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x36\x86\x35", 3);
+ g_free (data);
+}
+
+static void
+test_attribute_issuer (Test* test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_ISSUER, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x30\x81\xCF\x31\x0B\x30\x09\x06\x03\x55\x04\x06\x13\x02\x5A\x41\x31\x15\x30\x13\x06\x03\x55\x04\x08\x13\x0C\x57\x65\x73\x74\x65\x72\x6E\x20\x43\x61\x70\x65\x31\x12\x30\x10\x06\x03\x55\x04\x07\x13\x09\x43\x61\x70\x65\x20\x54\x6F\x77\x6E\x31\x1A\x30\x18\x06\x03\x55\x04\x0A\x13\x11\x54\x68\x61\x77\x74\x65\x20\x43\x6F\x6E\x73\x75\x6C\x74\x69\x6E\x67\x31\x28\x30\x26\x06\x03\x55\x04\x0B\x13\x1F\x43\x65\x72\x74\x69\x66\x69\x63\x61\x74\x69\x6F\x6E\x20\x53\x65\x72\x76\x69\x63\x65\x73\x20\x44\x69\x76\x69\x73\x69\x6F\x6E\x31\x23\x30\x21\x06\x03\x55\x04\x03\x13\x1A\x54\x68\x61\x77\x74\x65\x20\x50\x65\x72\x73\x6F\x6E\x61\x6C\x20\x50\x72\x65\x6D\x69\x75\x6D\x20\x43\x41\x31\x2A\x30\x28\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x09\x01\x16\x1B\x70\x65\x72\x73\x6F\x6E\x61\x6C\x2D\x70\x72\x65\x6D\x69\x75\x6D\x40\x74\x68\x61\x77\x74\x65\x2E\x63\x6F\x6D", 210);
+ g_free (data);
+}
+
+static void
+test_attribute_subject (Test* test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_SUBJECT, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x30\x81\xCF\x31\x0B\x30\x09\x06\x03\x55\x04\x06\x13\x02\x5A\x41\x31\x15\x30\x13\x06\x03\x55\x04\x08\x13\x0C\x57\x65\x73\x74\x65\x72\x6E\x20\x43\x61\x70\x65\x31\x12\x30\x10\x06\x03\x55\x04\x07\x13\x09\x43\x61\x70\x65\x20\x54\x6F\x77\x6E\x31\x1A\x30\x18\x06\x03\x55\x04\x0A\x13\x11\x54\x68\x61\x77\x74\x65\x20\x43\x6F\x6E\x73\x75\x6C\x74\x69\x6E\x67\x31\x28\x30\x26\x06\x03\x55\x04\x0B\x13\x1F\x43\x65\x72\x74\x69\x66\x69\x63\x61\x74\x69\x6F\x6E\x20\x53\x65\x72\x76\x69\x63\x65\x73\x20\x44\x69\x76\x69\x73\x69\x6F\x6E\x31\x23\x30\x21\x06\x03\x55\x04\x03\x13\x1A\x54\x68\x61\x77\x74\x65\x20\x50\x65\x72\x73\x6F\x6E\x61\x6C\x20\x50\x72\x65\x6D\x69\x75\x6D\x20\x43\x41\x31\x2A\x30\x28\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x09\x01\x16\x1B\x70\x65\x72\x73\x6F\x6E\x61\x6C\x2D\x70\x72\x65\x6D\x69\x75\x6D\x40\x74\x68\x61\x77\x74\x65\x2E\x63\x6F\x6D", 210);
+ g_free (data);
+}
+
+static void
+test_attribute_serial_number (Test* test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_SERIAL_NUMBER, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x02\x01\x00", 3);
+ g_free (data);
+}
+
+static void
+test_attribute_value (Test* test,
+ gconstpointer unused)
+{
+ gconstpointer raw;
+ gpointer data;
+ gsize n_data, n_raw;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->certificate),
+ test->session, CKA_VALUE, &n_data);
+
+ raw = egg_bytes_get_data (test->certificate_data);
+ n_raw = egg_bytes_get_size (test->certificate_data);
+ egg_assert_cmpmem (data, n_data, ==, raw, n_raw);
+ g_free (data);
+}
+
+static void
+test_hash (Test* test,
+ gconstpointer unused)
+{
+ gpointer hash;
+ gsize n_hash;
+
+ hash = gkm_certificate_hash (test->certificate, GCRY_MD_SHA1, &n_hash);
+
+ egg_assert_cmpmem (hash, n_hash, ==, "\x36\x86\x35\x63\xFD\x51\x28\xC7\xBE\xA6\xF0\x05\xCF\xE9\xB4\x36\x68\x08\x6C\xCE", 20);
+ g_free (hash);
+}
+#endif
+
+static void
+null_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data)
+{
+
+}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ /* Suppress these messages in tests */
+ g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG,
+ null_log_handler, NULL);
+
+ g_test_add ("/gnome2-store/private-key/load", Test, NULL, setup_basic, test_load_private_key, teardown_basic);
+ g_test_add ("/gnome2-store/private-key/save", Test, NULL, setup, test_save_private_key, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/gnome2-store/tests/test-gnome2-storage.c b/pkcs11/gnome2-store/tests/test-gnome2-storage.c
index 18de3c2..ac489c8 100644
--- a/pkcs11/gnome2-store/tests/test-gnome2-storage.c
+++ b/pkcs11/gnome2-store/tests/test-gnome2-storage.c
@@ -469,6 +469,25 @@ test_lock_writes (Test *test,
}
static void
+test_relock (Test *test,
+ gconstpointer unused)
+{
+ GkmTransaction *transaction;
+ GkmSecret *old_login;
+ GkmSecret *new_login;
+
+ transaction = gkm_transaction_new ();
+
+ old_login = NULL;
+ new_login = gkm_secret_new_from_password ("blah");
+
+ gkm_gnome2_storage_relock (test->storage, transaction, old_login, new_login);
+ gkm_assert_cmprv (gkm_transaction_complete_and_unref (transaction), ==, CKR_OK);
+
+ g_object_unref (new_login);
+}
+
+static void
null_log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
@@ -495,6 +514,8 @@ main (int argc, char **argv)
setup_all, test_create_and_fail, teardown_all);
g_test_add ("/gnome2-store/storage/write_value", Test, NULL,
setup_all, test_write_value, teardown_all);
+ g_test_add ("/gnome2-store/storage/relock", Test, NULL,
+ setup_all, test_relock, teardown_all);
if (!g_test_quick ()) {
g_test_add ("/gnome2-store/storage/locking_transaction", Test, NULL,
diff --git a/pkcs11/roots-store/tests/Makefile.am b/pkcs11/roots-store/tests/Makefile.am
index 0e21a72..1a6b07c 100644
--- a/pkcs11/roots-store/tests/Makefile.am
+++ b/pkcs11/roots-store/tests/Makefile.am
@@ -1,3 +1,4 @@
+include $(top_srcdir)/Makefile.decl
INCLUDES = \
-I$(top_builddir) \
@@ -20,19 +21,25 @@ else
CHECK_PROGS =
endif
-test: $(TEST_PROGS) $(CHECK_PROGS)
+CHECK_FILES = \
+ p11-tests.conf
+
+test: $(TEST_PROGS) $(CHECK_PROGS) $(CHECK_FILES)
@for prog in $(CHECK_PROGS); do SRCDIR='.' ./$$prog || exit 1; done
check-local: test
all-local: $(check_PROGRAMS)
-EXTRA_DIST = \
- p11-tests.conf \
- files
-
noinst_PROGRAMS = \
$(CHECK_PROGS)
check_roots_module_CFLAGS = $(P11_TESTS_CFLAGS)
check_roots_module_LDADD = $(P11_TESTS_LIBS) $(LDADD)
+
+EXTRA_DIST = \
+ p11-tests.conf.in \
+ files
+
+CLEAN_FILES = \
+ $(CHECK_FILES)
diff --git a/pkcs11/roots-store/tests/p11-tests.conf b/pkcs11/roots-store/tests/p11-tests.conf.in
similarity index 54%
rename from pkcs11/roots-store/tests/p11-tests.conf
rename to pkcs11/roots-store/tests/p11-tests.conf.in
index fda5f0d..4437c5c 100644
--- a/pkcs11/roots-store/tests/p11-tests.conf
+++ b/pkcs11/roots-store/tests/p11-tests.conf.in
@@ -1,2 +1,2 @@
# Configuration for running p11-tests on this module
-init-string = directory='test-data'
+init-string = directory='@abs_srcdir@/files'
diff --git a/pkcs11/ssh-store/tests/Makefile.am b/pkcs11/ssh-store/tests/Makefile.am
index 5b670c6..b4cfab2 100644
--- a/pkcs11/ssh-store/tests/Makefile.am
+++ b/pkcs11/ssh-store/tests/Makefile.am
@@ -1,3 +1,4 @@
+include $(top_srcdir)/Makefile.decl
INCLUDES = \
-I$(top_builddir) \
@@ -21,13 +22,16 @@ else
CHECK_PROGS =
endif
+CHECK_FILES = \
+ p11-tests.conf
+
TEST_PROGS = \
test-ssh-openssh \
test-private-key
check_PROGRAMS = $(TEST_PROGS)
-test: $(TEST_PROGS) $(CHECK_PROGS)
+test: $(TEST_PROGS) $(CHECK_PROGS) $(CHECK_FILES)
gtester --verbose -m $(TEST_MODE) --g-fatal-warnings $(TEST_PROGS)
@for prog in $(CHECK_PROGS); do SRCDIR='.' ./$$prog || exit 1; done
@@ -35,10 +39,6 @@ check-local: test
all-local: $(check_PROGRAMS)
-EXTRA_DIST = \
- p11-tests.conf \
- files
-
noinst_PROGRAMS = \
$(CHECK_PROGS)
@@ -49,3 +49,10 @@ noinst_LIBRARIES = libgkm-mock-ssh-module.a
libgkm_mock_ssh_module_a_SOURCES = \
mock-ssh-module.c mock-ssh-module.h
+
+EXTRA_DIST = \
+ p11-tests.conf.in \
+ files
+
+CLEAN_FILES = \
+ $(CHECK_FILES)
diff --git a/pkcs11/ssh-store/tests/p11-tests.conf b/pkcs11/ssh-store/tests/p11-tests.conf
index 7179012..2488840 100644
--- a/pkcs11/ssh-store/tests/p11-tests.conf
+++ b/pkcs11/ssh-store/tests/p11-tests.conf
@@ -1,3 +1,3 @@
# Configuration for running p11-tests on this module
-init-string = directory='test-data'
+init-string = directory='/data/projects/gnome-keyring/pkcs11/ssh-store/tests/files'
login-context-pin = password
diff --git a/pkcs11/ssh-store/tests/p11-tests.conf.in b/pkcs11/ssh-store/tests/p11-tests.conf.in
new file mode 100644
index 0000000..df1b8d7
--- /dev/null
+++ b/pkcs11/ssh-store/tests/p11-tests.conf.in
@@ -0,0 +1,3 @@
+# Configuration for running p11-tests on this module
+init-string = directory='@abs_srcdir@/files'
+login-context-pin = password
diff --git a/pkcs11/ssh-store/tests/test-private-key.c b/pkcs11/ssh-store/tests/test-private-key.c
index 182f848..94833ec 100644
--- a/pkcs11/ssh-store/tests/test-private-key.c
+++ b/pkcs11/ssh-store/tests/test-private-key.c
@@ -31,27 +31,56 @@
#include "ssh-store/gkm-ssh-private-key.h"
+#include "egg/egg-testing.h"
+
#include "pkcs11i.h"
typedef struct {
GkmModule *module;
GkmSession *session;
+ GkmSshPrivateKey *key;
} Test;
static void
-setup (Test *test, gconstpointer unused)
+setup_basic (Test *test,
+ gconstpointer unused)
{
test->module = test_ssh_module_initialize_and_enter ();
test->session = test_ssh_module_open_session (TRUE);
}
static void
-teardown (Test *test, gconstpointer unused)
+teardown_basic (Test *test,
+ gconstpointer unused)
{
test_ssh_module_leave_and_finalize ();
}
static void
+setup (Test *test,
+ gconstpointer unused)
+{
+ gboolean ret;
+
+ setup_basic (test, unused);
+
+ test->key = gkm_ssh_private_key_new (test->module, "my-unique");
+ g_assert (GKM_IS_SSH_PRIVATE_KEY (test->key));
+
+ ret = gkm_ssh_private_key_parse (test->key, SRCDIR "/files/id_dsa_encrypted.pub",
+ SRCDIR "/files/id_dsa_encrypted", NULL);
+ g_assert (ret == TRUE);
+}
+
+static void
+teardown (Test *test,
+ gconstpointer unused)
+{
+ g_object_unref (test->key);
+ teardown_basic (test, unused);
+}
+
+static void
test_parse_plain (Test *test, gconstpointer unused)
{
GkmSshPrivateKey *key;
@@ -68,25 +97,31 @@ test_parse_plain (Test *test, gconstpointer unused)
}
static void
-test_parse_and_unlock (Test *test, gconstpointer unused)
+test_unlock (Test *test,
+ gconstpointer unused)
{
- GkmSshPrivateKey *key;
GkmCredential *cred;
- gboolean ret;
CK_RV rv;
- key = gkm_ssh_private_key_new (test->module, "my-unique");
- g_assert (GKM_IS_SSH_PRIVATE_KEY (key));
-
- ret = gkm_ssh_private_key_parse (key, SRCDIR "/files/id_dsa_encrypted.pub",
- SRCDIR "/files/id_dsa_encrypted", NULL);
- g_assert (ret == TRUE);
-
- rv = gkm_credential_create (test->module, NULL, GKM_OBJECT (key), (guchar*)"password", 8, &cred);
+ rv = gkm_credential_create (test->module, NULL, GKM_OBJECT (test->key),
+ (guchar*)"password", 8, &cred);
g_assert (rv == CKR_OK);
g_object_unref (cred);
- g_object_unref (key);
+}
+
+static void
+test_internal_sha1_compat (Test *test,
+ gconstpointer unused)
+{
+ gpointer data;
+ gsize n_data;
+
+ data = gkm_object_get_attribute_data (GKM_OBJECT (test->key), test->session,
+ CKA_GNOME_INTERNAL_SHA1, &n_data);
+
+ egg_assert_cmpmem (data, n_data, ==, "\x33\x37\x31\x31\x64\x33\x33\x65\x61\x34\x31\x31\x33\x61\x35\x64\x32\x35\x38\x37\x63\x36\x66\x32\x35\x66\x39\x35\x35\x36\x39\x66\x65\x65\x38\x31\x38\x35\x39\x34", 40);
+ g_free (data);
}
int
@@ -95,8 +130,9 @@ main (int argc, char **argv)
g_type_init ();
g_test_init (&argc, &argv, NULL);
- g_test_add ("/ssh-store/private-key/parse_plain", Test, NULL, setup, test_parse_plain, teardown);
- g_test_add ("/ssh-store/private-key/parse_and_unlock", Test, NULL, setup, test_parse_and_unlock, teardown);
+ g_test_add ("/ssh-store/private-key/parse_plain", Test, NULL, setup_basic, test_parse_plain, teardown_basic);
+ g_test_add ("/ssh-store/private-key/unlock", Test, NULL, setup, test_unlock, teardown);
+ g_test_add ("/ssh-store/private-key/internal-sha1-compat", Test, NULL, setup, test_internal_sha1_compat, teardown);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]