4 * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id: unix.c,v 1.4 2009/10/26 23:47:35 tbox Exp */
25 /* dynamic loader (ifndef FORCE_STATIC_PROVIDER) */
29 /* load PKCS11 dynamic object */
31 #ifndef PK11_LIB_LOCATION
32 #error "PK11_LIB_LOCATION is not set"
35 const char *pk11_libname
= PK11_LIB_LOCATION
;
39 #define C_Initialize isc_C_Initialize
42 C_Initialize(CK_VOID_PTR pReserved
);
45 C_Initialize(CK_VOID_PTR pReserved
)
49 hPK11
= dlopen(pk11_libname
, RTLD_NOW
);
53 sym
= (CK_C_Initialize
)dlsym(hPK11
, "C_Initialize");
56 return (*sym
)(pReserved
);
59 #define C_Finalize isc_C_Finalize
62 C_Finalize(CK_VOID_PTR pReserved
);
65 C_Finalize(CK_VOID_PTR pReserved
)
71 sym
= (CK_C_Finalize
)dlsym(hPK11
, "C_Finalize");
74 return (*sym
)(pReserved
);
77 #define C_OpenSession isc_C_OpenSession
80 C_OpenSession(CK_SLOT_ID slotID
,
82 CK_VOID_PTR pApplication
,
83 CK_RV (*Notify
) (CK_SESSION_HANDLE hSession
,
84 CK_NOTIFICATION event
,
85 CK_VOID_PTR pApplication
),
86 CK_SESSION_HANDLE_PTR phSession
);
89 C_OpenSession(CK_SLOT_ID slotID
,
91 CK_VOID_PTR pApplication
,
92 CK_RV (*Notify
) (CK_SESSION_HANDLE hSession
,
93 CK_NOTIFICATION event
,
94 CK_VOID_PTR pApplication
),
95 CK_SESSION_HANDLE_PTR phSession
)
100 hPK11
= dlopen(pk11_libname
, RTLD_NOW
);
103 sym
= (CK_C_OpenSession
)dlsym(hPK11
, "C_OpenSession");
106 return (*sym
)(slotID
, flags
, pApplication
, Notify
, phSession
);
109 #define C_CloseSession isc_C_CloseSession
112 C_CloseSession(CK_SESSION_HANDLE hSession
);
115 C_CloseSession(CK_SESSION_HANDLE hSession
)
117 CK_C_CloseSession sym
;
121 sym
= (CK_C_CloseSession
)dlsym(hPK11
, "C_CloseSession");
124 return (*sym
)(hSession
);
127 #define C_Login isc_C_Login
130 C_Login(CK_SESSION_HANDLE hSession
,
131 CK_USER_TYPE userType
,
136 C_Login(CK_SESSION_HANDLE hSession
,
137 CK_USER_TYPE userType
,
145 sym
= (CK_C_Login
)dlsym(hPK11
, "C_Login");
148 return (*sym
)(hSession
, userType
, pPin
, usPinLen
);
151 #define C_CreateObject isc_C_CreateObject
154 C_CreateObject(CK_SESSION_HANDLE hSession
,
155 CK_ATTRIBUTE_PTR pTemplate
,
157 CK_OBJECT_HANDLE_PTR phObject
);
160 C_CreateObject(CK_SESSION_HANDLE hSession
,
161 CK_ATTRIBUTE_PTR pTemplate
,
163 CK_OBJECT_HANDLE_PTR phObject
)
165 CK_C_CreateObject sym
;
169 sym
= (CK_C_CreateObject
)dlsym(hPK11
, "C_CreateObject");
172 return (*sym
)(hSession
, pTemplate
, usCount
, phObject
);
175 #define C_DestroyObject isc_C_DestroyObject
178 C_DestroyObject(CK_SESSION_HANDLE hSession
, CK_OBJECT_HANDLE hObject
);
181 C_DestroyObject(CK_SESSION_HANDLE hSession
, CK_OBJECT_HANDLE hObject
)
183 CK_C_DestroyObject sym
;
187 sym
= (CK_C_DestroyObject
)dlsym(hPK11
, "C_DestroyObject");
190 return (*sym
)(hSession
, hObject
);
193 #define C_GetAttributeValue isc_C_GetAttributeValue
196 C_GetAttributeValue(CK_SESSION_HANDLE hSession
,
197 CK_OBJECT_HANDLE hObject
,
198 CK_ATTRIBUTE_PTR pTemplate
,
202 C_GetAttributeValue(CK_SESSION_HANDLE hSession
,
203 CK_OBJECT_HANDLE hObject
,
204 CK_ATTRIBUTE_PTR pTemplate
,
207 CK_C_GetAttributeValue sym
;
211 sym
= (CK_C_GetAttributeValue
)dlsym(hPK11
, "C_GetAttributeValue");
214 return (*sym
)(hSession
, hObject
, pTemplate
, usCount
);
217 #define C_SetAttributeValue isc_C_SetAttributeValue
220 C_SetAttributeValue(CK_SESSION_HANDLE hSession
,
221 CK_OBJECT_HANDLE hObject
,
222 CK_ATTRIBUTE_PTR pTemplate
,
226 C_SetAttributeValue(CK_SESSION_HANDLE hSession
,
227 CK_OBJECT_HANDLE hObject
,
228 CK_ATTRIBUTE_PTR pTemplate
,
231 CK_C_SetAttributeValue sym
;
235 sym
= (CK_C_SetAttributeValue
)dlsym(hPK11
, "C_SetAttributeValue");
238 return (*sym
)(hSession
, hObject
, pTemplate
, usCount
);
241 #define C_FindObjectsInit isc_C_FindObjectsInit
244 C_FindObjectsInit(CK_SESSION_HANDLE hSession
,
245 CK_ATTRIBUTE_PTR pTemplate
,
249 C_FindObjectsInit(CK_SESSION_HANDLE hSession
,
250 CK_ATTRIBUTE_PTR pTemplate
,
253 CK_C_FindObjectsInit sym
;
257 sym
= (CK_C_FindObjectsInit
)dlsym(hPK11
, "C_FindObjectsInit");
260 return (*sym
)(hSession
, pTemplate
, usCount
);
263 #define C_FindObjects isc_C_FindObjects
266 C_FindObjects(CK_SESSION_HANDLE hSession
,
267 CK_OBJECT_HANDLE_PTR phObject
,
268 CK_ULONG usMaxObjectCount
,
269 CK_ULONG_PTR pusObjectCount
);
272 C_FindObjects(CK_SESSION_HANDLE hSession
,
273 CK_OBJECT_HANDLE_PTR phObject
,
274 CK_ULONG usMaxObjectCount
,
275 CK_ULONG_PTR pusObjectCount
)
277 CK_C_FindObjects sym
;
281 sym
= (CK_C_FindObjects
)dlsym(hPK11
, "C_FindObjects");
284 return (*sym
)(hSession
, phObject
, usMaxObjectCount
, pusObjectCount
);
287 #define C_FindObjectsFinal isc_C_FindObjectsFinal
290 C_FindObjectsFinal(CK_SESSION_HANDLE hSession
);
293 C_FindObjectsFinal(CK_SESSION_HANDLE hSession
)
295 CK_C_FindObjectsFinal sym
;
299 sym
= (CK_C_FindObjectsFinal
)dlsym(hPK11
, "C_FindObjectsFinal");
302 return (*sym
)(hSession
);
305 #define C_GenerateKeyPair isc_C_GenerateKeyPair
308 C_GenerateKeyPair(CK_SESSION_HANDLE hSession
,
309 CK_MECHANISM_PTR pMechanism
,
310 CK_ATTRIBUTE_PTR pPublicKeyTemplate
,
311 CK_ULONG usPublicKeyAttributeCount
,
312 CK_ATTRIBUTE_PTR pPrivateKeyTemplate
,
313 CK_ULONG usPrivateKeyAttributeCount
,
314 CK_OBJECT_HANDLE_PTR phPrivateKey
,
315 CK_OBJECT_HANDLE_PTR phPublicKey
);
318 C_GenerateKeyPair(CK_SESSION_HANDLE hSession
,
319 CK_MECHANISM_PTR pMechanism
,
320 CK_ATTRIBUTE_PTR pPublicKeyTemplate
,
321 CK_ULONG usPublicKeyAttributeCount
,
322 CK_ATTRIBUTE_PTR pPrivateKeyTemplate
,
323 CK_ULONG usPrivateKeyAttributeCount
,
324 CK_OBJECT_HANDLE_PTR phPrivateKey
,
325 CK_OBJECT_HANDLE_PTR phPublicKey
)
327 CK_C_GenerateKeyPair sym
;
331 sym
= (CK_C_GenerateKeyPair
)dlsym(hPK11
, "C_GenerateKeyPair");
334 return (*sym
)(hSession
,
337 usPublicKeyAttributeCount
,
339 usPrivateKeyAttributeCount
,