| 1 |
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
| 2 |
/* test-module.c: A test PKCS#11 module implementation |
| 3 |
|
| 4 |
Copyright (C) 2009 Stefan Walter |
| 5 |
|
| 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. |
| 10 |
|
| 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. |
| 15 |
|
| 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/>. |
| 19 |
|
| 20 |
Author: Stef Walter <[email protected]> |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
|
| 25 |
#include "mock-ssh-module.h" |
| 26 |
|
| 27 |
#include "egg/egg-secure-memory.h" |
| 28 |
|
| 29 |
#include "gkm/gkm-module.h" |
| 30 |
|
| 31 |
#include "ssh-store/gkm-ssh-store.h" |
| 32 |
|
| 33 |
EGG_SECURE_DEFINE_GLIB_GLOBALS (); |
| 34 |
|
| 35 |
static GMutex *mutex = NULL; |
| 36 |
|
| 37 |
GkmModule* _gkm_ssh_store_get_module_for_testing (void); |
| 38 |
GMutex* _gkm_module_get_scary_mutex_that_you_should_not_touch (GkmModule *module); |
| 39 |
|
| 40 |
GkmModule* |
| 41 |
test_ssh_module_initialize_and_enter (void) |
| 42 |
{ |
| 43 |
CK_FUNCTION_LIST_PTR funcs; |
| 44 |
GkmModule *module; |
| 45 |
CK_RV rv; |
| 46 |
|
| 47 |
funcs = gkm_ssh_store_get_functions (); |
| 48 |
rv = (funcs->C_Initialize) (NULL); |
| 49 |
g_return_val_if_fail (rv == CKR_OK, NULL); |
| 50 |
|
| 51 |
module = _gkm_ssh_store_get_module_for_testing (); |
| 52 |
g_return_val_if_fail (module, NULL); |
| 53 |
|
| 54 |
mutex = _gkm_module_get_scary_mutex_that_you_should_not_touch (module); |
| 55 |
test_ssh_module_enter (); |
| 56 |
|
| 57 |
return module; |
| 58 |
} |
| 59 |
|
| 60 |
void |
| 61 |
test_ssh_module_leave_and_finalize (void) |
| 62 |
{ |
| 63 |
CK_FUNCTION_LIST_PTR funcs; |
| 64 |
CK_RV rv; |
| 65 |
|
| 66 |
test_ssh_module_leave (); |
| 67 |
|
| 68 |
funcs = gkm_ssh_store_get_functions (); |
| 69 |
rv = (funcs->C_Finalize) (NULL); |
| 70 |
g_return_if_fail (rv == CKR_OK); |
| 71 |
} |
| 72 |
|
| 73 |
void |
| 74 |
test_ssh_module_leave (void) |
| 75 |
{ |
| 76 |
g_assert (mutex); |
| 77 |
g_mutex_unlock (mutex); |
| 78 |
} |
| 79 |
|
| 80 |
void |
| 81 |
test_ssh_module_enter (void) |
| 82 |
{ |
| 83 |
g_assert (mutex); |
| 84 |
g_mutex_lock (mutex); |
| 85 |
} |
| 86 |
|
| 87 |
GkmSession* |
| 88 |
test_ssh_module_open_session (gboolean writable) |
| 89 |
{ |
| 90 |
CK_ULONG flags = CKF_SERIAL_SESSION; |
| 91 |
CK_SESSION_HANDLE handle; |
| 92 |
GkmModule *module; |
| 93 |
GkmSession *session; |
| 94 |
CK_RV rv; |
| 95 |
|
| 96 |
module = _gkm_ssh_store_get_module_for_testing (); |
| 97 |
g_return_val_if_fail (module, NULL); |
| 98 |
|
| 99 |
if (writable) |
| 100 |
flags |= CKF_RW_SESSION; |
| 101 |
|
| 102 |
rv = gkm_module_C_OpenSession (module, 1, flags, NULL, NULL, &handle); |
| 103 |
g_assert (rv == CKR_OK); |
| 104 |
|
| 105 |
session = gkm_module_lookup_session (module, handle); |
| 106 |
g_assert (session); |
| 107 |
|
| 108 |
return session; |
| 109 |
} |