pkcs11-helper-1.0/pkcs11h-core.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005-2007 Alon Bar-Lev <alon.barlev@gmail.com>
00003  * All rights reserved.
00004  *
00005  * This software is available to you under a choice of one of two
00006  * licenses.  You may choose to be licensed under the terms of the GNU
00007  * General Public License (GPL) Version 2, or the BSD license.
00008  *
00009  * GNU General Public License (GPL) Version 2
00010  * ===========================================
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License version 2
00013  * as published by the Free Software Foundation.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program (see the file COPYING.GPL included with this
00022  * distribution); if not, write to the Free Software Foundation, Inc.,
00023  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00024  *
00025  * BSD License
00026  * ============
00027  * Redistribution and use in source and binary forms, with or without
00028  * modification, are permitted provided that the following conditions are met:
00029  *
00030  *     o Redistributions of source code must retain the above copyright notice,
00031  *       this list of conditions and the following disclaimer.
00032  *     o Redistributions in binary form must reproduce the above copyright
00033  *       notice, this list of conditions and the following disclaimer in the
00034  *       documentation and/or other materials provided with the distribution.
00035  *     o Neither the name of the <ORGANIZATION> nor the names of its
00036  *       contributors may be used to endorse or promote products derived from
00037  *       this software without specific prior written permission.
00038  *
00039  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00040  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00041  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00042  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00043  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00044  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00045  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00046  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00047  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00048  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00049  * POSSIBILITY OF SUCH DAMAGE.
00050  */
00051 
00067 #ifndef __PKCS11H_BASE_H
00068 #define __PKCS11H_BASE_H
00069 
00070 #include <stdarg.h>
00071 #include <time.h>
00072 
00073 #include <pkcs11-helper-1.0/pkcs11h-version.h>
00074 #include <pkcs11-helper-1.0/pkcs11h-def.h>
00075 #include <pkcs11-helper-1.0/pkcs11h-engines.h>
00076 
00077 #if defined(__cplusplus)
00078 extern "C" {
00079 #endif
00080 
00088 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_OPENSSL      (1<< 0)
00089 
00090 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_GNUTLS       (1<< 1)
00091 
00092 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_WIN32        (1<< 2)
00093 
00094 #define PKCS11H_FEATURE_MASK_DEBUG                      (1<< 3)
00095 
00096 #define PKCS11H_FEATURE_MASK_THREADING                  (1<< 4)
00097 
00098 #define PKCS11H_FEATURE_MASK_TOKEN                      (1<< 5)
00099 
00100 #define PKCS11H_FEATURE_MASK_DATA                       (1<< 6)
00101 
00102 #define PKCS11H_FEATURE_MASK_CERTIFICATE                (1<< 7)
00103 
00104 #define PKCS11H_FEATURE_MASK_SLOTEVENT                  (1<< 8)
00105 
00106 #define PKCS11H_FEATURE_MASK_OPENSSL                    (1<< 9)
00107 
00117 #define PKCS11H_LOG_DEBUG2      5
00118 
00119 #define PKCS11H_LOG_DEBUG1      4
00120 
00121 #define PKCS11H_LOG_INFO        3
00122 
00123 #define PKCS11H_LOG_WARN        2
00124 
00125 #define PKCS11H_LOG_ERROR       1
00126 
00127 #define PKCS11H_LOG_QUIET       0
00128 
00131 #define PKCS11H_PIN_CACHE_INFINITE      -1
00132 
00139 #define PKCS11H_PRIVATEMODE_MASK_AUTO           (0)
00140 
00141 #define PKCS11H_PRIVATEMODE_MASK_SIGN           (1<<0)
00142 
00143 #define PKCS11H_PRIVATEMODE_MASK_RECOVER        (1<<1)
00144 
00145 #define PKCS11H_PRIVATEMODE_MASK_DECRYPT        (1<<2)
00146 
00147 #define PKCS11H_PRIVATEMODE_MASK_UNWRAP         (1<<3)
00148 
00155 /* Auto select by provider information. */
00156 #define PKCS11H_SLOTEVENT_METHOD_AUTO           0
00157 
00158 #define PKCS11H_SLOTEVENT_METHOD_TRIGGER        1
00159 
00160 #define PKCS11H_SLOTEVENT_METHOD_POLL           2
00161 
00162 #define PKCS11H_SLOTEVENT_METHOD_FETCH          3
00163 
00171 #define PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT    (1<<0)
00172 
00173 #define PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT  (1<<1)
00174 
00175 #define PKCS11H_PROMPT_MASK_ALLOW_ALL ( \
00176                 PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT | \
00177                 PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT \
00178         )
00179 
00187 #define PKCS11H_ENUM_METHOD_CACHE               0
00188 
00189 #define PKCS11H_ENUM_METHOD_CACHE_EXIST         1
00190 
00191 #define PKCS11H_ENUM_METHOD_RELOAD              2
00192 
00194 struct pkcs11h_token_id_s;
00195 
00199 typedef struct pkcs11h_token_id_s *pkcs11h_token_id_t;
00200 
00208 typedef void (*pkcs11h_hook_log_t)(
00209         IN void * const global_data,
00210         IN const unsigned flags,
00211         IN const char * const format,
00212         IN va_list args
00213 );
00214 
00219 typedef void (*pkcs11h_hook_slotevent_t)(
00220         IN void * const global_data
00221 );
00222 
00231 typedef PKCS11H_BOOL (*pkcs11h_hook_token_prompt_t)(
00232         IN void * const global_data,
00233         IN void * const user_data,
00234         IN const pkcs11h_token_id_t token,
00235         IN const unsigned retry
00236 );
00237 
00248 typedef PKCS11H_BOOL (*pkcs11h_hook_pin_prompt_t)(
00249         IN void * const global_data,
00250         IN void * const user_data,
00251         IN const pkcs11h_token_id_t token,
00252         IN const unsigned retry,
00253         OUT char * const pin,
00254         IN const size_t pin_max
00255 );
00256 
00260 struct pkcs11h_token_id_s {
00262         char display[1024];
00264         char manufacturerID[sizeof (((CK_TOKEN_INFO *)NULL)->manufacturerID)+1];
00266         char model[sizeof (((CK_TOKEN_INFO *)NULL)->model)+1];
00268         char serialNumber[sizeof (((CK_TOKEN_INFO *)NULL)->serialNumber)+1];
00270         char label[sizeof (((CK_TOKEN_INFO *)NULL)->label)+1];
00271 };
00272 
00278 const char *
00279 pkcs11h_getMessage (
00280         IN const CK_RV rv
00281 );
00282 
00287 unsigned int
00288 pkcs11h_getVersion (void);
00289 
00294 unsigned int
00295 pkcs11h_getFeatures (void);
00296 
00303 CK_RV
00304 pkcs11h_initialize (void);
00305 
00311 CK_RV
00312 pkcs11h_terminate (void);
00313 
00318 void
00319 pkcs11h_setLogLevel (
00320         IN const unsigned flags
00321 );
00322 
00327 unsigned
00328 pkcs11h_getLogLevel (void);
00329 
00342 CK_RV
00343 pkcs11h_setForkMode (
00344         IN const PKCS11H_BOOL safe
00345 );
00346 
00353 CK_RV
00354 pkcs11h_setLogHook (
00355         IN const pkcs11h_hook_log_t hook,
00356         IN void * const global_data
00357 );
00358 
00370 CK_RV
00371 pkcs11h_setSlotEventHook (
00372         IN const pkcs11h_hook_slotevent_t hook,
00373         IN void * const global_data
00374 );
00375 
00384 CK_RV
00385 pkcs11h_setTokenPromptHook (
00386         IN const pkcs11h_hook_token_prompt_t hook,
00387         IN void * const global_data
00388 );
00389 
00398 CK_RV
00399 pkcs11h_setPINPromptHook (
00400         IN const pkcs11h_hook_pin_prompt_t hook,
00401         IN void * const global_data
00402 );
00403 
00410 CK_RV
00411 pkcs11h_setProtectedAuthentication (
00412         IN const PKCS11H_BOOL allow_protected_auth
00413 );
00414 
00421 CK_RV
00422 pkcs11h_setPINCachePeriod (
00423         IN const int pin_cache_period
00424 );
00425 
00432 CK_RV
00433 pkcs11h_setMaxLoginRetries (
00434         IN const unsigned max_retries
00435 );
00436 
00450 CK_RV
00451 pkcs11h_addProvider (
00452         IN const char * const reference,
00453         IN const char * const provider_location,
00454         IN const PKCS11H_BOOL allow_protected_auth,
00455         IN const unsigned mask_private_mode,
00456         IN const unsigned slot_event_method,
00457         IN const unsigned slot_poll_interval,
00458         IN const PKCS11H_BOOL cert_is_private
00459 );
00460 
00467 CK_RV
00468 pkcs11h_removeProvider (
00469         IN const char * const reference
00470 );
00471 
00483 CK_RV
00484 pkcs11h_forkFixup (void);
00485 
00497 CK_RV
00498 pkcs11h_plugAndPlay (void);
00499 
00504 CK_RV
00505 pkcs11h_logout (void);
00506 
00507 #ifdef __cplusplus
00508 }
00509 #endif
00510 
00513 #endif                          /* __PKCS11H_BASE_H */

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