pkcs11-helper
pkcs11h-core.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005-2018 Alon Bar-Lev <alon.barlev@gmail.com>
3  *
4  * This software is available to you under a choice of one of two
5  * licenses. You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, or the BSD license.
7  *
8  * GNU General Public License (GPL) Version 2
9  * ===========================================
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program (see the file COPYING.GPL included with this
21  * distribution); if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  *
24  * BSD License
25  * ============
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions are met:
28  *
29  * o Redistributions of source code must retain the above copyright notice,
30  * this list of conditions and the following disclaimer.
31  * o Redistributions in binary form must reproduce the above copyright
32  * notice, this list of conditions and the following disclaimer in the
33  * documentation and/or other materials provided with the distribution.
34  * o Neither the name of the Alon Bar-Lev nor the names of its
35  * contributors may be used to endorse or promote products derived from
36  * this software without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
42  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
43  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
44  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
46  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49  */
50 
66 #ifndef __PKCS11H_BASE_H
67 #define __PKCS11H_BASE_H
68 
69 #include <stdarg.h>
70 #include <time.h>
71 
75 
76 #if defined(__cplusplus)
77 extern "C" {
78 #endif
79 
87 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_OPENSSL (1<< 0)
88 
89 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_GNUTLS (1<< 1)
90 
91 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_CRYPTOAPI (1<< 2)
92 
96 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_WIN32 (1<< 2)
97 
98 #define PKCS11H_FEATURE_MASK_DEBUG (1<< 3)
99 
100 #define PKCS11H_FEATURE_MASK_THREADING (1<< 4)
101 
102 #define PKCS11H_FEATURE_MASK_TOKEN (1<< 5)
103 
104 #define PKCS11H_FEATURE_MASK_DATA (1<< 6)
105 
106 #define PKCS11H_FEATURE_MASK_CERTIFICATE (1<< 7)
107 
108 #define PKCS11H_FEATURE_MASK_SLOTEVENT (1<< 8)
109 
110 #define PKCS11H_FEATURE_MASK_OPENSSL (1<< 9)
111 
112 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_POLARSSL (1<< 10)
113 
114 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_MBEDTLS (1<< 10)
115 
125 #define PKCS11H_LOG_DEBUG2 5
126 
127 #define PKCS11H_LOG_DEBUG1 4
128 
129 #define PKCS11H_LOG_INFO 3
130 
131 #define PKCS11H_LOG_WARN 2
132 
133 #define PKCS11H_LOG_ERROR 1
134 
135 #define PKCS11H_LOG_QUIET 0
136 
139 #define PKCS11H_PIN_CACHE_INFINITE -1
140 
147 #define PKCS11H_PRIVATEMODE_MASK_AUTO (0)
148 
149 #define PKCS11H_PRIVATEMODE_MASK_SIGN (1<<0)
150 
151 #define PKCS11H_PRIVATEMODE_MASK_RECOVER (1<<1)
152 
153 #define PKCS11H_PRIVATEMODE_MASK_DECRYPT (1<<2)
154 
155 #define PKCS11H_PRIVATEMODE_MASK_UNWRAP (1<<3)
156 
163 /* Auto select by provider information. */
164 #define PKCS11H_SLOTEVENT_METHOD_AUTO 0
165 
166 #define PKCS11H_SLOTEVENT_METHOD_TRIGGER 1
167 
168 #define PKCS11H_SLOTEVENT_METHOD_POLL 2
169 
170 #define PKCS11H_SLOTEVENT_METHOD_FETCH 3
171 
179 #define PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT (1<<0)
180 
181 #define PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT (1<<1)
182 
183 #define PKCS11H_PROMPT_MASK_ALLOW_ALL ( \
184  PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT | \
185  PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT \
186  )
187 
195 #define PKCS11H_ENUM_METHOD_CACHE 0
196 
197 #define PKCS11H_ENUM_METHOD_CACHE_EXIST 1
198 
199 #define PKCS11H_ENUM_METHOD_RELOAD 2
200 
202 struct pkcs11h_token_id_s;
203 
208 
216 typedef void (*pkcs11h_hook_log_t)(
217  IN void * const global_data,
218  IN const unsigned flags,
219  IN const char * const format,
220  IN va_list args
221 );
222 
227 typedef void (*pkcs11h_hook_slotevent_t)(
228  IN void * const global_data
229 );
230 
239 typedef PKCS11H_BOOL (*pkcs11h_hook_token_prompt_t)(
240  IN void * const global_data,
241  IN void * const user_data,
242  IN const pkcs11h_token_id_t token,
243  IN const unsigned retry
244 );
245 
256 typedef PKCS11H_BOOL (*pkcs11h_hook_pin_prompt_t)(
257  IN void * const global_data,
258  IN void * const user_data,
259  IN const pkcs11h_token_id_t token,
260  IN const unsigned retry,
261  OUT char * const pin,
262  IN const size_t pin_max
263 );
264 
270  char display[1024];
272  char manufacturerID[sizeof (((CK_TOKEN_INFO *)NULL)->manufacturerID)+1];
274  char model[sizeof (((CK_TOKEN_INFO *)NULL)->model)+1];
276  char serialNumber[sizeof (((CK_TOKEN_INFO *)NULL)->serialNumber)+1];
278  char label[sizeof (((CK_TOKEN_INFO *)NULL)->label)+1];
279 };
280 
286 const char *
288  IN const CK_RV rv
289 );
290 
295 unsigned int
297 
302 unsigned int
304 
311 CK_RV
313 
319 CK_RV
321 
326 void
328  IN const unsigned flags
329 );
330 
335 unsigned
337 
350 CK_RV
352  IN const PKCS11H_BOOL safe
353 );
354 
361 CK_RV
363  IN const pkcs11h_hook_log_t hook,
364  IN void * const global_data
365 );
366 
378 CK_RV
380  IN const pkcs11h_hook_slotevent_t hook,
381  IN void * const global_data
382 );
383 
392 CK_RV
394  IN const pkcs11h_hook_token_prompt_t hook,
395  IN void * const global_data
396 );
397 
406 CK_RV
408  IN const pkcs11h_hook_pin_prompt_t hook,
409  IN void * const global_data
410 );
411 
418 CK_RV
420  IN const PKCS11H_BOOL allow_protected_auth
421 );
422 
429 CK_RV
431  IN const int pin_cache_period
432 );
433 
440 CK_RV
442  IN const unsigned max_retries
443 );
444 
458 CK_RV
460  IN const char * const reference,
461  IN const char * const provider_location,
462  IN const PKCS11H_BOOL allow_protected_auth,
463  IN const unsigned mask_private_mode,
464  IN const unsigned slot_event_method,
465  IN const unsigned slot_poll_interval,
466  IN const PKCS11H_BOOL cert_is_private
467 );
468 
475 CK_RV
477  IN const char * const reference
478 );
479 
491 CK_RV
493 
505 CK_RV
507 
512 CK_RV
514 
515 #ifdef __cplusplus
516 }
517 #endif
518 
521 #endif /* __PKCS11H_BASE_H */
pkcs11h_hook_slotevent_t
void(* pkcs11h_hook_slotevent_t)(IN void *const global_data)
Slotevent hook.
Definition: pkcs11h-core.h:227
pkcs11h_getVersion
unsigned int pkcs11h_getVersion(void)
Get version of library.
pkcs11h_forkFixup
CK_RV pkcs11h_forkFixup(void)
Handle special case of POSIX fork()
pkcs11h-version.h
pkcs11-helper core.
pkcs11h_addProvider
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.
pkcs11h_setTokenPromptHook
CK_RV pkcs11h_setTokenPromptHook(IN const pkcs11h_hook_token_prompt_t hook, IN void *const global_data)
Set a token prompt callback.
pkcs11h-def.h
pkcs11-helper core definitions.
pkcs11h_hook_token_prompt_t
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:239
pkcs11h_getFeatures
unsigned int pkcs11h_getFeatures(void)
Get features of library.
pkcs11h_setPINPromptHook
CK_RV pkcs11h_setPINPromptHook(IN const pkcs11h_hook_pin_prompt_t hook, IN void *const global_data)
Set a pin prompt callback.
pkcs11h_token_id_t
struct pkcs11h_token_id_s * pkcs11h_token_id_t
Token identifier.
Definition: pkcs11h-core.h:207
pkcs11h_setProtectedAuthentication
CK_RV pkcs11h_setProtectedAuthentication(IN const PKCS11H_BOOL allow_protected_auth)
Set global protected authentication mode.
pkcs11h_logout
CK_RV pkcs11h_logout(void)
Logout from all sessions.
pkcs11h-engines.h
pkcs11-helper engines definitions.
pkcs11h_setForkMode
CK_RV pkcs11h_setForkMode(IN const PKCS11H_BOOL safe)
How does the foked process bahaves after POSIX fork()
pkcs11h_getLogLevel
unsigned pkcs11h_getLogLevel(void)
Get current log level.
pkcs11h_setLogLevel
void pkcs11h_setLogLevel(IN const unsigned flags)
Set current log level of the helper.
pkcs11h_setLogHook
CK_RV pkcs11h_setLogHook(IN const pkcs11h_hook_log_t hook, IN void *const global_data)
Set a log callback.
pkcs11h_plugAndPlay
CK_RV pkcs11h_plugAndPlay(void)
Handle slot rescan.
pkcs11h_setMaxLoginRetries
CK_RV pkcs11h_setMaxLoginRetries(IN const unsigned max_retries)
Set global login retries attempts.
pkcs11h_hook_pin_prompt_t
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:256
pkcs11h_setPINCachePeriod
CK_RV pkcs11h_setPINCachePeriod(IN const int pin_cache_period)
Set global PIN cache timeout.
pkcs11h_token_id_s::label
char label[sizeof(((CK_TOKEN_INFO *) NULL) ->label)+1]
Definition: pkcs11h-core.h:278
pkcs11h_hook_log_t
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:216
pkcs11h_getMessage
const char * pkcs11h_getMessage(IN const CK_RV rv)
Get message by return value.
pkcs11h_token_id_s::serialNumber
char serialNumber[sizeof(((CK_TOKEN_INFO *) NULL) ->serialNumber)+1]
Definition: pkcs11h-core.h:276
pkcs11h_initialize
CK_RV pkcs11h_initialize(void)
Inititalize helper interface.
pkcs11h_token_id_s::model
char model[sizeof(((CK_TOKEN_INFO *) NULL) ->model)+1]
Definition: pkcs11h-core.h:274
pkcs11h_token_id_s
Token identifier.
Definition: pkcs11h-core.h:268
pkcs11h_setSlotEventHook
CK_RV pkcs11h_setSlotEventHook(IN const pkcs11h_hook_slotevent_t hook, IN void *const global_data)
Set a slot event callback.
pkcs11h_terminate
CK_RV pkcs11h_terminate(void)
Terminate helper interface.
pkcs11h_token_id_s::manufacturerID
char manufacturerID[sizeof(((CK_TOKEN_INFO *) NULL) ->manufacturerID)+1]
Definition: pkcs11h-core.h:272
pkcs11h_removeProvider
CK_RV pkcs11h_removeProvider(IN const char *const reference)
Delete a PKCS#11 provider.
pkcs11h_token_id_s::display
char display[1024]
Definition: pkcs11h-core.h:270

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