pkcs11-helper
pkcs11h-core.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005-2011 Alon Bar-Lev <alon.barlev@gmail.com>
3 * All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, or the BSD license.
8 *
9 * GNU General Public License (GPL) Version 2
10 * ===========================================
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program (see the file COPYING.GPL included with this
22 * distribution); if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 *
25 * BSD License
26 * ============
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions are met:
29 *
30 * o Redistributions of source code must retain the above copyright notice,
31 * this list of conditions and the following disclaimer.
32 * o Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * o Neither the name of the Alon Bar-Lev nor the names of its
36 * contributors may be used to endorse or promote products derived from
37 * this software without specific prior written permission.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 * POSSIBILITY OF SUCH DAMAGE.
50 */
51
67#ifndef __PKCS11H_BASE_H
68#define __PKCS11H_BASE_H
69
70#include <stdarg.h>
71#include <time.h>
72
76
77#if defined(__cplusplus)
78extern "C" {
79#endif
80
88#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_OPENSSL (1<< 0)
90#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_GNUTLS (1<< 1)
92#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_CRYPTOAPI (1<< 2)
97#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_WIN32 (1<< 2)
99#define PKCS11H_FEATURE_MASK_DEBUG (1<< 3)
101#define PKCS11H_FEATURE_MASK_THREADING (1<< 4)
103#define PKCS11H_FEATURE_MASK_TOKEN (1<< 5)
105#define PKCS11H_FEATURE_MASK_DATA (1<< 6)
107#define PKCS11H_FEATURE_MASK_CERTIFICATE (1<< 7)
109#define PKCS11H_FEATURE_MASK_SLOTEVENT (1<< 8)
111#define PKCS11H_FEATURE_MASK_OPENSSL (1<< 9)
113#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_POLARSSL (1<< 10)
115#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_MBEDTLS (1<< 10)
126#define PKCS11H_LOG_DEBUG2 5
128#define PKCS11H_LOG_DEBUG1 4
130#define PKCS11H_LOG_INFO 3
132#define PKCS11H_LOG_WARN 2
134#define PKCS11H_LOG_ERROR 1
136#define PKCS11H_LOG_QUIET 0
140#define PKCS11H_PIN_CACHE_INFINITE -1
141
148#define PKCS11H_PRIVATEMODE_MASK_AUTO (0)
150#define PKCS11H_PRIVATEMODE_MASK_SIGN (1<<0)
152#define PKCS11H_PRIVATEMODE_MASK_RECOVER (1<<1)
154#define PKCS11H_PRIVATEMODE_MASK_DECRYPT (1<<2)
156#define PKCS11H_PRIVATEMODE_MASK_UNWRAP (1<<3)
164/* Auto select by provider information. */
165#define PKCS11H_SLOTEVENT_METHOD_AUTO 0
167#define PKCS11H_SLOTEVENT_METHOD_TRIGGER 1
169#define PKCS11H_SLOTEVENT_METHOD_POLL 2
171#define PKCS11H_SLOTEVENT_METHOD_FETCH 3
180#define PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT (1<<0)
182#define PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT (1<<1)
184#define PKCS11H_PROMPT_MASK_ALLOW_ALL ( \
185 PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT | \
186 PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT \
187 )
196#define PKCS11H_ENUM_METHOD_CACHE 0
198#define PKCS11H_ENUM_METHOD_CACHE_EXIST 1
200#define PKCS11H_ENUM_METHOD_RELOAD 2
203struct pkcs11h_token_id_s;
204
209
217typedef void (*pkcs11h_hook_log_t)(
218 IN void * const global_data,
219 IN const unsigned flags,
220 IN const char * const format,
221 IN va_list args
222);
223
229 IN void * const global_data
230);
231
240typedef PKCS11H_BOOL (*pkcs11h_hook_token_prompt_t)(
241 IN void * const global_data,
242 IN void * const user_data,
243 IN const pkcs11h_token_id_t token,
244 IN const unsigned retry
245);
246
257typedef PKCS11H_BOOL (*pkcs11h_hook_pin_prompt_t)(
258 IN void * const global_data,
259 IN void * const user_data,
260 IN const pkcs11h_token_id_t token,
261 IN const unsigned retry,
262 OUT char * const pin,
263 IN const size_t pin_max
264);
265
271 char display[1024];
273 char manufacturerID[sizeof (((CK_TOKEN_INFO *)NULL)->manufacturerID)+1];
275 char model[sizeof (((CK_TOKEN_INFO *)NULL)->model)+1];
277 char serialNumber[sizeof (((CK_TOKEN_INFO *)NULL)->serialNumber)+1];
279 char label[sizeof (((CK_TOKEN_INFO *)NULL)->label)+1];
280};
281
287const char *
289 IN const CK_RV rv
290);
291
296unsigned int
298
303unsigned int
305
312CK_RV
314
320CK_RV
322
327void
329 IN const unsigned flags
330);
331
336unsigned
338
351CK_RV
353 IN const PKCS11H_BOOL safe
354);
355
362CK_RV
364 IN const pkcs11h_hook_log_t hook,
365 IN void * const global_data
366);
367
379CK_RV
381 IN const pkcs11h_hook_slotevent_t hook,
382 IN void * const global_data
383);
384
393CK_RV
395 IN const pkcs11h_hook_token_prompt_t hook,
396 IN void * const global_data
397);
398
407CK_RV
409 IN const pkcs11h_hook_pin_prompt_t hook,
410 IN void * const global_data
411);
412
419CK_RV
421 IN const PKCS11H_BOOL allow_protected_auth
422);
423
430CK_RV
432 IN const int pin_cache_period
433);
434
441CK_RV
443 IN const unsigned max_retries
444);
445
459CK_RV
461 IN const char * const reference,
462 IN const char * const provider_location,
463 IN const PKCS11H_BOOL allow_protected_auth,
464 IN const unsigned mask_private_mode,
465 IN const unsigned slot_event_method,
466 IN const unsigned slot_poll_interval,
467 IN const PKCS11H_BOOL cert_is_private
468);
469
476CK_RV
478 IN const char * const reference
479);
480
492CK_RV
494
506CK_RV
508
513CK_RV
515
516#ifdef __cplusplus
517}
518#endif
519
522#endif /* __PKCS11H_BASE_H */
CK_RV pkcs11h_setProtectedAuthentication(IN const PKCS11H_BOOL allow_protected_auth)
Set global protected authentication mode.
CK_RV pkcs11h_setForkMode(IN const PKCS11H_BOOL safe)
How does the foked process bahaves after POSIX fork()
CK_RV pkcs11h_setTokenPromptHook(IN const pkcs11h_hook_token_prompt_t hook, IN void *const global_data)
Set a token prompt callback.
struct pkcs11h_token_id_s * pkcs11h_token_id_t
Token identifier.
Definition: pkcs11h-core.h:208
CK_RV pkcs11h_logout(void)
Logout from all sessions.
PKCS11H_BOOL(* pkcs11h_hook_pin_prompt_t)(IN void *const global_data, IN void *const user_data, IN const pkcs11h_token_id_t token, IN const unsigned retry, OUT char *const pin, IN const size_t pin_max)
PIN prompt hook.
Definition: pkcs11h-core.h:257
const char * pkcs11h_getMessage(IN const CK_RV rv)
Get message by return value.
CK_RV pkcs11h_setSlotEventHook(IN const pkcs11h_hook_slotevent_t hook, IN void *const global_data)
Set a slot event callback.
unsigned int pkcs11h_getFeatures(void)
Get features of library.
PKCS11H_BOOL(* pkcs11h_hook_token_prompt_t)(IN void *const global_data, IN void *const user_data, IN const pkcs11h_token_id_t token, IN const unsigned retry)
Token prompt hook.
Definition: pkcs11h-core.h:240
CK_RV pkcs11h_forkFixup(void)
Handle special case of POSIX fork()
void(* pkcs11h_hook_log_t)(IN void *const global_data, IN const unsigned flags, IN const char *const format, IN va_list args)
Log hook.
Definition: pkcs11h-core.h:217
CK_RV pkcs11h_terminate(void)
Terminate helper interface.
CK_RV pkcs11h_setPINCachePeriod(IN const int pin_cache_period)
Set global PIN cache timeout.
unsigned pkcs11h_getLogLevel(void)
Get current log level.
void pkcs11h_setLogLevel(IN const unsigned flags)
Set current log level of the helper.
CK_RV pkcs11h_setPINPromptHook(IN const pkcs11h_hook_pin_prompt_t hook, IN void *const global_data)
Set a pin prompt callback.
CK_RV pkcs11h_setMaxLoginRetries(IN const unsigned max_retries)
Set global login retries attempts.
CK_RV pkcs11h_removeProvider(IN const char *const reference)
Delete a PKCS#11 provider.
CK_RV pkcs11h_initialize(void)
Inititalize helper interface.
void(* pkcs11h_hook_slotevent_t)(IN void *const global_data)
Slotevent hook.
Definition: pkcs11h-core.h:228
unsigned int pkcs11h_getVersion(void)
Get version of library.
CK_RV pkcs11h_setLogHook(IN const pkcs11h_hook_log_t hook, IN void *const global_data)
Set a log callback.
CK_RV pkcs11h_plugAndPlay(void)
Handle slot rescan.
CK_RV pkcs11h_addProvider(IN const char *const reference, IN const char *const provider_location, IN const PKCS11H_BOOL allow_protected_auth, IN const unsigned mask_private_mode, IN const unsigned slot_event_method, IN const unsigned slot_poll_interval, IN const PKCS11H_BOOL cert_is_private)
Add a PKCS#11 provider.
pkcs11-helper core definitions.
pkcs11-helper engines definitions.
pkcs11-helper core.
Token identifier.
Definition: pkcs11h-core.h:269
char label[sizeof(((CK_TOKEN_INFO *) NULL) ->label)+1]
Definition: pkcs11h-core.h:279
char manufacturerID[sizeof(((CK_TOKEN_INFO *) NULL) ->manufacturerID)+1]
Definition: pkcs11h-core.h:273
char model[sizeof(((CK_TOKEN_INFO *) NULL) ->model)+1]
Definition: pkcs11h-core.h:275
char serialNumber[sizeof(((CK_TOKEN_INFO *) NULL) ->serialNumber)+1]
Definition: pkcs11h-core.h:277
char display[1024]
Definition: pkcs11h-core.h:271

pkcs11-helper, Copyright (C) Alon Bar-Lev <alon.barlev@gmail.com>OpenSC-Project.org Logo