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 
00122 #ifndef __PKCS11H_BASE_H
00123 #define __PKCS11H_BASE_H
00124 
00125 #include <stdarg.h>
00126 #include <time.h>
00127 
00128 #include <pkcs11-helper-1.0/pkcs11h-version.h>
00129 #include <pkcs11-helper-1.0/pkcs11h-def.h>
00130 #include <pkcs11-helper-1.0/pkcs11h-engines.h>
00131 
00132 #if defined(__cplusplus)
00133 extern "C" {
00134 #endif
00135 
00143 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_OPENSSL      (1<< 0)
00144 
00145 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_GNUTLS       (1<< 1)
00146 
00147 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_WIN32        (1<< 2)
00148 
00149 #define PKCS11H_FEATURE_MASK_DEBUG                      (1<< 3)
00150 
00151 #define PKCS11H_FEATURE_MASK_THREADING                  (1<< 4)
00152 
00153 #define PKCS11H_FEATURE_MASK_TOKEN                      (1<< 5)
00154 
00155 #define PKCS11H_FEATURE_MASK_DATA                       (1<< 6)
00156 
00157 #define PKCS11H_FEATURE_MASK_CERTIFICATE                (1<< 7)
00158 
00159 #define PKCS11H_FEATURE_MASK_SLOTEVENT                  (1<< 8)
00160 
00161 #define PKCS11H_FEATURE_MASK_OPENSSL                    (1<< 9)
00162 
00172 #define PKCS11H_LOG_DEBUG2      5
00173 
00174 #define PKCS11H_LOG_DEBUG1      4
00175 
00176 #define PKCS11H_LOG_INFO        3
00177 
00178 #define PKCS11H_LOG_WARN        2
00179 
00180 #define PKCS11H_LOG_ERROR       1
00181 
00182 #define PKCS11H_LOG_QUIET       0
00183 
00186 #define PKCS11H_PIN_CACHE_INFINITE      -1
00187 
00194 #define PKCS11H_PRIVATEMODE_MASK_AUTO           (0)
00195 
00196 #define PKCS11H_PRIVATEMODE_MASK_SIGN           (1<<0)
00197 
00198 #define PKCS11H_PRIVATEMODE_MASK_RECOVER        (1<<1)
00199 
00200 #define PKCS11H_PRIVATEMODE_MASK_DECRYPT        (1<<2)
00201 
00202 #define PKCS11H_PRIVATEMODE_MASK_UNWRAP         (1<<3)
00203 
00210 /* Auto select by provider information. */
00211 #define PKCS11H_SLOTEVENT_METHOD_AUTO           0
00212 
00213 #define PKCS11H_SLOTEVENT_METHOD_TRIGGER        1
00214 
00215 #define PKCS11H_SLOTEVENT_METHOD_POLL           2
00216 
00224 #define PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT    (1<<0)
00225 
00226 #define PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT  (1<<1)
00227 
00228 #define PKCS11H_PROMPT_MASK_ALLOW_ALL ( \
00229                 PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT | \
00230                 PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT \
00231         )
00232 
00240 #define PKCS11H_ENUM_METHOD_CACHE               0
00241 
00242 #define PKCS11H_ENUM_METHOD_CACHE_EXIST         1
00243 
00244 #define PKCS11H_ENUM_METHOD_RELOAD              2
00245 
00247 struct pkcs11h_token_id_s;
00248 
00252 typedef struct pkcs11h_token_id_s *pkcs11h_token_id_t;
00253 
00261 typedef void (*pkcs11h_hook_log_t)(
00262         IN void * const global_data,
00263         IN const unsigned flags,
00264         IN const char * const format,
00265         IN va_list args
00266 );
00267 
00272 typedef void (*pkcs11h_hook_slotevent_t)(
00273         IN void * const global_data
00274 );
00275 
00284 typedef PKCS11H_BOOL (*pkcs11h_hook_token_prompt_t)(
00285         IN void * const global_data,
00286         IN void * const user_data,
00287         IN const pkcs11h_token_id_t token,
00288         IN const unsigned retry
00289 );
00290 
00301 typedef PKCS11H_BOOL (*pkcs11h_hook_pin_prompt_t)(
00302         IN void * const global_data,
00303         IN void * const user_data,
00304         IN const pkcs11h_token_id_t token,
00305         IN const unsigned retry,
00306         OUT char * const pin,
00307         IN const size_t pin_max
00308 );
00309 
00313 struct pkcs11h_token_id_s {
00315         char display[1024];
00317         char manufacturerID[sizeof (((CK_TOKEN_INFO *)NULL)->manufacturerID)+1];
00319         char model[sizeof (((CK_TOKEN_INFO *)NULL)->model)+1];
00321         char serialNumber[sizeof (((CK_TOKEN_INFO *)NULL)->serialNumber)+1];
00323         char label[sizeof (((CK_TOKEN_INFO *)NULL)->label)+1];
00324 };
00325 
00331 const char *
00332 pkcs11h_getMessage (
00333         IN const CK_RV rv
00334 );
00335 
00340 unsigned int
00341 pkcs11h_getVersion (void);
00342 
00347 unsigned int
00348 pkcs11h_getFeatures (void);
00349 
00356 CK_RV
00357 pkcs11h_initialize (void);
00358 
00364 CK_RV
00365 pkcs11h_terminate (void);
00366 
00371 void
00372 pkcs11h_setLogLevel (
00373         IN const unsigned flags
00374 );
00375 
00380 unsigned
00381 pkcs11h_getLogLevel (void);
00382 
00395 CK_RV
00396 pkcs11h_setForkMode (
00397         IN const PKCS11H_BOOL safe
00398 );
00399 
00406 CK_RV
00407 pkcs11h_setLogHook (
00408         IN const pkcs11h_hook_log_t hook,
00409         IN void * const global_data
00410 );
00411 
00423 CK_RV
00424 pkcs11h_setSlotEventHook (
00425         IN const pkcs11h_hook_slotevent_t hook,
00426         IN void * const global_data
00427 );
00428 
00437 CK_RV
00438 pkcs11h_setTokenPromptHook (
00439         IN const pkcs11h_hook_token_prompt_t hook,
00440         IN void * const global_data
00441 );
00442 
00451 CK_RV
00452 pkcs11h_setPINPromptHook (
00453         IN const pkcs11h_hook_pin_prompt_t hook,
00454         IN void * const global_data
00455 );
00456 
00463 CK_RV
00464 pkcs11h_setProtectedAuthentication (
00465         IN const PKCS11H_BOOL allow_protected_auth
00466 );
00467 
00474 CK_RV
00475 pkcs11h_setPINCachePeriod (
00476         IN const int pin_cache_period
00477 );
00478 
00485 CK_RV
00486 pkcs11h_setMaxLoginRetries (
00487         IN const unsigned max_retries
00488 );
00489 
00503 CK_RV
00504 pkcs11h_addProvider (
00505         IN const char * const reference,
00506         IN const char * const provider_location,
00507         IN const PKCS11H_BOOL allow_protected_auth,
00508         IN const unsigned mask_private_mode,
00509         IN const unsigned slot_event_method,
00510         IN const unsigned slot_poll_interval,
00511         IN const PKCS11H_BOOL cert_is_private
00512 );
00513 
00520 CK_RV
00521 pkcs11h_removeProvider (
00522         IN const char * const reference
00523 );
00524 
00536 CK_RV
00537 pkcs11h_forkFixup (void);
00538 
00550 CK_RV
00551 pkcs11h_plugAndPlay (void);
00552 
00557 CK_RV
00558 pkcs11h_logout (void);
00559 
00560 #ifdef __cplusplus
00561 }
00562 #endif
00563 
00566 #endif                          /* __PKCS11H_BASE_H */

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