1 /* 2 * gnome-keyring 3 * 4 * Copyright (C) 2008 Stefan Walter 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as 8 * published by the Free Software Foundation; either version 2.1 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this program; if not, see 18 * <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef __GKM_MODULE_H__ 22 #define __GKM_MODULE_H__ 23 24 #include <glib-object.h> 25 26 #include "pkcs11/pkcs11.h" 27 28 #include "gkm-factory.h" 29 #include "gkm-types.h" 30 31 #define GKM_TYPE_MODULE (gkm_module_get_type ()) 32 #define GKM_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKM_TYPE_MODULE, GkmModule)) 33 #define GKM_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GKM_TYPE_MODULE, GkmModuleClass)) 34 #define GKM_IS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GKM_TYPE_MODULE)) 35 #define GKM_IS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GKM_TYPE_MODULE)) 36 #define GKM_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKM_TYPE_MODULE, GkmModuleClass)) 37 38 typedef struct _GkmModuleClass GkmModuleClass; 39 typedef struct _GkmModulePrivate GkmModulePrivate; 40 41 struct _GkmModule { 42 GObject parent; 43 CK_FUNCTION_LIST pkcs11_funcs; 44 GkmModulePrivate *pv; 45 }; 46 47 struct _GkmModuleClass { 48 GObjectClass parent_class; 49 50 /* virtual methods */ 51 52 void (*parse_argument) (GkmModule *self, const gchar *name, const gchar *value); 53 54 const CK_SLOT_INFO* (*get_slot_info) (GkmModule *self); 55 56 const CK_TOKEN_INFO* (*get_token_info) (GkmModule *self); 57 58 CK_RV (*refresh_token) (GkmModule *self); 59 60 void (*add_token_object) (GkmModule *self, GkmTransaction *transaction, GkmObject *object); 61 62 void (*store_token_object) (GkmModule *self, GkmTransaction *transaction, GkmObject *object); 63 64 void (*remove_token_object) (GkmModule *self, GkmTransaction *transaction, GkmObject *object); 65 66 CK_RV (*login_change) (GkmModule *self, CK_SLOT_ID slot_id, 67 CK_UTF8CHAR_PTR old_pin, CK_ULONG n_old_pin, 68 CK_UTF8CHAR_PTR new_pin, CK_ULONG n_new_pin); 69 70 CK_RV (*login_user) (GkmModule *self, CK_SLOT_ID slot_id, 71 CK_UTF8CHAR_PTR pin, CK_ULONG n_pin); 72 73 CK_RV (*logout_user) (GkmModule *self, CK_SLOT_ID slot_id); 74 75 CK_RV (*login_so) (GkmModule *self, CK_SLOT_ID slot_id, 76 CK_UTF8CHAR_PTR pin, CK_ULONG n_pin); 77 78 CK_RV (*logout_so) (GkmModule *self, CK_SLOT_ID slot_id); 79 }; 80 81 /* 82 * The PKCS#11 module is created by the following code in a header file: 83 * 84 * #include "gkm-module.h" 85 * GKM_DECLARE_MODULE(my_module); 86 * 87 * And the following code in a source file: 88 * 89 * #include "gkm-module-ep.h" 90 * GKM_DEFINE_MODULE(my_module, MY_TYPE_MODULE) 91 * 92 */ 93 94 #define GKM_DECLARE_MODULE(prefix) \ 95 extern const CK_FUNCTION_LIST_PTR prefix ## _function_list 96 97 #define GKM_DEFINE_MODULE(prefix, type) \ 98 static GkmModule* gkm_module_instantiate (CK_C_INITIALIZE_ARGS_PTR args, GMutex* mutex) \ 99 { return g_object_new ((type), "initialize-args", args, "mutex", mutex, NULL); } \ 100 const CK_FUNCTION_LIST_PTR prefix ## _function_list = &gkm_module_function_list; 101 102 /* Our slot identifier is 1 */ 103 #define GKM_SLOT_ID 1 104 105 GType gkm_module_get_type (void); 106 107 GkmManager* gkm_module_get_manager (GkmModule *self); 108 109 gboolean gkm_module_get_write_protected (GkmModule *self); 110 111 CK_ULONG gkm_module_next_handle (GkmModule *self); 112 113 GkmSession* gkm_module_lookup_session (GkmModule *self, 114 CK_SESSION_HANDLE handle); 115 116 CK_RV gkm_module_login_change (GkmModule *self, 117 CK_SLOT_ID slot_id, 118 CK_UTF8CHAR_PTR old_pin, 119 CK_ULONG n_old_pin, 120 CK_UTF8CHAR_PTR new_pin, 121 CK_ULONG n_new_pin); 122 123 CK_RV gkm_module_login_user (GkmModule *self, 124 CK_SLOT_ID slot_id, 125 CK_UTF8CHAR_PTR pin, 126 CK_ULONG n_pin); 127 128 CK_RV gkm_module_logout_user (GkmModule *self, 129 CK_SLOT_ID slot_id); 130 131 CK_RV gkm_module_login_so (GkmModule *self, 132 CK_SLOT_ID slot_id, 133 CK_UTF8CHAR_PTR pin, 134 CK_ULONG n_pin); 135 136 CK_RV gkm_module_logout_so (GkmModule *self, 137 CK_SLOT_ID slot_id); 138 139 CK_RV gkm_module_refresh_token (GkmModule *self); 140 141 void gkm_module_add_token_object (GkmModule *self, 142 GkmTransaction *transaction, 143 GkmObject *object); 144 145 void gkm_module_store_token_object (GkmModule *self, 146 GkmTransaction *transaction, 147 GkmObject *object); 148 149 void gkm_module_remove_token_object (GkmModule *self, 150 GkmTransaction *transaction, 151 GkmObject *object); 152 153 GkmFactory* gkm_module_find_factory (GkmModule *self, 154 CK_ATTRIBUTE_PTR attrs, 155 CK_ULONG n_attrs); 156 157 void gkm_module_register_factory (GkmModule *self, 158 GkmFactory *factory); 159 160 CK_RV gkm_module_C_GetInfo (GkmModule *self, 161 CK_INFO_PTR info); 162 163 CK_RV gkm_module_C_GetSlotList (GkmModule *self, 164 CK_BBOOL token_present, 165 CK_SLOT_ID_PTR slot_list, 166 CK_ULONG_PTR count); 167 168 CK_RV gkm_module_C_GetSlotInfo (GkmModule *self, 169 CK_SLOT_ID id, 170 CK_SLOT_INFO_PTR info); 171 172 CK_RV gkm_module_C_GetTokenInfo (GkmModule *self, 173 CK_SLOT_ID id, 174 CK_TOKEN_INFO_PTR info); 175 176 CK_RV gkm_module_C_GetMechanismList (GkmModule *self, 177 CK_SLOT_ID id, 178 CK_MECHANISM_TYPE_PTR mech_list, 179 CK_ULONG_PTR count); 180 181 CK_RV gkm_module_C_GetMechanismInfo (GkmModule *self, 182 CK_SLOT_ID id, 183 CK_MECHANISM_TYPE type, 184 CK_MECHANISM_INFO_PTR info); 185 186 CK_RV gkm_module_C_InitToken (GkmModule *self, 187 CK_SLOT_ID id, 188 CK_UTF8CHAR_PTR pin, 189 CK_ULONG pin_len, 190 CK_UTF8CHAR_PTR label); 191 192 CK_RV gkm_module_C_OpenSession (GkmModule *self, 193 CK_SLOT_ID id, 194 CK_FLAGS flags, 195 CK_VOID_PTR user_data, 196 CK_NOTIFY callback, 197 CK_SESSION_HANDLE_PTR session); 198 199 CK_RV gkm_module_C_CloseSession (GkmModule *self, 200 CK_SESSION_HANDLE session); 201 202 CK_RV gkm_module_C_CloseAllSessions (GkmModule *self, 203 CK_SLOT_ID id); 204 205 CK_RV gkm_module_C_InitPIN (GkmModule* self, 206 CK_SESSION_HANDLE session, 207 CK_UTF8CHAR_PTR pin, 208 CK_ULONG pin_len); 209 210 CK_RV gkm_module_C_SetPIN (GkmModule* self, 211 CK_SESSION_HANDLE session, 212 CK_UTF8CHAR_PTR old_pin, 213 CK_ULONG old_pin_len, 214 CK_UTF8CHAR_PTR new_pin, 215 CK_ULONG new_pin_len); 216 217 CK_RV gkm_module_C_Login (GkmModule *self, 218 CK_SESSION_HANDLE session, 219 CK_USER_TYPE user_type, 220 CK_UTF8CHAR_PTR pin, 221 CK_ULONG pin_len); 222 223 CK_RV gkm_module_C_Logout (GkmModule *self, 224 CK_SESSION_HANDLE session); 225 226 #endif /* __GKM_MODULE_H__ */ 227