1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
/* unit-test-file-store.c: Test file store functionality
4
Copyright (C) 2008 Stefan Walter
6
The Gnome Keyring Library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public License as
8
published by the Free Software Foundation; either version 2 of the
9
License, or (at your option) any later version.
11
The Gnome Keyring Library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public
17
License along with the Gnome Library; see the file COPYING.LIB. If not,
18
<http://www.gnu.org/licenses/>.
20
Author: Stef Walter <stef@memberwebs.com>
25
#include "egg/egg-testing.h"
27
#include "gkm/gkm-module.h"
28
#include "gkm/gkm-test.h"
30
#include "gnome2-store/gkm-gnome2-store.h"
33
#include <gcr/gcr-base.h>
35
#include <p11-kit/p11-kit.h>
37
#include <glib/gstdio.h>
42
CK_FUNCTION_LIST_PTR funcs;
51
CK_C_INITIALIZE_ARGS args;
52
CK_SESSION_HANDLE session;
57
test->directory = egg_tests_create_scratch_directory (NULL, NULL);
59
memset (&args, 0, sizeof (args));
60
args.flags = CKF_OS_LOCKING_OK;
61
args.pReserved = g_strdup_printf ("directory='%s'", test->directory);
63
test->funcs = gkm_gnome2_store_get_functions ();
64
rv = (test->funcs->C_Initialize) (&args);
65
gkm_assert_cmprv (rv, ==, CKR_OK);
67
/* And now need to log in */
68
rv = (test->funcs->C_OpenSession) (GKM_SLOT_ID, CKF_SERIAL_SESSION | CKF_RW_SESSION,
69
NULL, NULL, &session);
70
gkm_assert_cmprv (rv, ==, CKR_OK);
72
/* The directory is empty, so we need to initialize */
73
rv = (test->funcs->C_SetPIN) (session, NULL, 0, (CK_BYTE_PTR)"mypin", 5);
74
gkm_assert_cmprv (rv, ==, CKR_OK);
76
/* Login so the importer doesn't have to */
77
rv = (test->funcs->C_Login) (session, CKU_USER, (CK_BYTE_PTR)"mypin", 5);
78
gkm_assert_cmprv (rv, ==, CKR_OK);
80
module = gck_module_new (test->funcs);
81
modules = g_list_prepend (NULL, module);
82
gcr_pkcs11_set_modules (modules);
83
g_list_free (modules);
84
g_object_unref (module);
93
g_list_free_full (test->importers, g_object_unref);
95
gcr_pkcs11_set_modules (NULL);
97
rv = (test->funcs->C_Finalize) (NULL);
98
gkm_assert_cmprv (rv, ==, CKR_OK);
100
/* Cleanup the directory */
101
egg_tests_remove_scratch_directory (test->directory);
102
g_free (test->directory);
106
on_parser_parsed (GcrParser *parser,
109
Test *test = user_data;
113
parsed = gcr_parser_get_parsed (parser);
115
if (test->importers == NULL)
116
importers = gcr_importer_create_for_parsed (parsed);
118
importers = gcr_importer_queue_and_filter_for_parsed (test->importers, parsed);
120
g_list_free_full (test->importers, g_object_unref);
121
test->importers = importers;
125
test_pkcs12_import (Test *test,
126
gconstpointer unused)
134
g_file_get_contents (SRCDIR "/pkcs11/gnome2-store/fixtures/personal.p12", &contents, &length, &error);
135
g_assert_no_error (error);
137
/* Parse the pkcs12 file */
138
parser = gcr_parser_new ();
139
gcr_parser_add_password (parser, "booo");
140
gcr_parser_format_enable (parser, GCR_FORMAT_DER_PKCS12);
141
g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), test);
142
gcr_parser_parse_data (parser, (const guchar *)contents, length, &error);
143
g_assert_no_error (error);
144
g_object_unref (parser);
147
/* Should have found importers */
148
g_assert (test->importers != NULL);
150
for (l = test->importers; l != NULL; l = g_list_next (l)) {
151
gcr_importer_import (l->data, NULL, &error);
152
g_assert_no_error (error);
157
null_log_handler (const gchar *log_domain,
158
GLogLevelFlags log_level,
159
const gchar *message,
166
main (int argc, char **argv)
168
#if !GLIB_CHECK_VERSION(2,35,0)
171
g_test_init (&argc, &argv, NULL);
173
g_set_prgname ("test-import");
175
/* Suppress these messages in tests */
176
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE,
177
null_log_handler, NULL);
179
g_test_add ("/gnome2-store/import/pkcs12", Test, NULL,
180
setup, test_pkcs12_import, teardown);
182
return g_test_run ();