pkcs11-helper
pkcs11-helper-1.0/pkcs11h-core.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005-2011 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 Alon Bar-Lev 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_CRYPTOAPI    (1<< 2)
00093 
00097 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_WIN32        (1<< 2)
00098 
00099 #define PKCS11H_FEATURE_MASK_DEBUG                      (1<< 3)
00100 
00101 #define PKCS11H_FEATURE_MASK_THREADING                  (1<< 4)
00102 
00103 #define PKCS11H_FEATURE_MASK_TOKEN                      (1<< 5)
00104 
00105 #define PKCS11H_FEATURE_MASK_DATA                       (1<< 6)
00106 
00107 #define PKCS11H_FEATURE_MASK_CERTIFICATE                (1<< 7)
00108 
00109 #define PKCS11H_FEATURE_MASK_SLOTEVENT                  (1<< 8)
00110 
00111 #define PKCS11H_FEATURE_MASK_OPENSSL                    (1<< 9)
00112 
00113 #define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_POLARSSL     (1<< 10)
00114 
00124 #define PKCS11H_LOG_DEBUG2      5
00125 
00126 #define PKCS11H_LOG_DEBUG1      4
00127 
00128 #define PKCS11H_LOG_INFO        3
00129 
00130 #define PKCS11H_LOG_WARN        2
00131 
00132 #define PKCS11H_LOG_ERROR       1
00133 
00134 #define PKCS11H_LOG_QUIET       0
00135 
00138 #define PKCS11H_PIN_CACHE_INFINITE      -1
00139 
00146 #define PKCS11H_PRIVATEMODE_MASK_AUTO           (0)
00147 
00148 #define PKCS11H_PRIVATEMODE_MASK_SIGN           (1<<0)
00149 
00150 #define PKCS11H_PRIVATEMODE_MASK_RECOVER        (1<<1)
00151 
00152 #define PKCS11H_PRIVATEMODE_MASK_DECRYPT        (1<<2)
00153 
00154 #define PKCS11H_PRIVATEMODE_MASK_UNWRAP         (1<<3)
00155 
00162 /* Auto select by provider information. */
00163 #define PKCS11H_SLOTEVENT_METHOD_AUTO           0
00164 
00165 #define PKCS11H_SLOTEVENT_METHOD_TRIGGER        1
00166 
00167 #define PKCS11H_SLOTEVENT_METHOD_POLL           2
00168 
00169 #define PKCS11H_SLOTEVENT_METHOD_FETCH          3
00170 
00178 #define PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT    (1<<0)
00179 
00180 #define PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT  (1<<1)
00181 
00182 #define PKCS11H_PROMPT_MASK_ALLOW_ALL ( \
00183                 PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT | \
00184                 PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT \
00185         )
00186 
00194 #define PKCS11H_ENUM_METHOD_CACHE               0
00195 
00196 #define PKCS11H_ENUM_METHOD_CACHE_EXIST         1
00197 
00198 #define PKCS11H_ENUM_METHOD_RELOAD              2
00199 
00201 struct pkcs11h_token_id_s;
00202 
00206 typedef struct pkcs11h_token_id_s *pkcs11h_token_id_t;
00207 
00215 typedef void (*pkcs11h_hook_log_t)(
00216         IN void * const global_data,
00217         IN const unsigned flags,
00218         IN const char * const format,
00219         IN va_list args
00220 );
00221 
00226 typedef void (*pkcs11h_hook_slotevent_t)(
00227         IN void * const global_data
00228 );
00229 
00238 typedef PKCS11H_BOOL (*pkcs11h_hook_token_prompt_t)(
00239         IN void * const global_data,
00240         IN void * const user_data,
00241         IN const pkcs11h_token_id_t token,
00242         IN const unsigned retry
00243 );
00244 
00255 typedef PKCS11H_BOOL (*pkcs11h_hook_pin_prompt_t)(
00256         IN void * const global_data,
00257         IN void * const user_data,
00258         IN const pkcs11h_token_id_t token,
00259         IN const unsigned retry,
00260         OUT char * const pin,
00261         IN const size_t pin_max
00262 );
00263 
00267 struct pkcs11h_token_id_s {
00269         char display[1024];
00271         char manufacturerID[sizeof (((CK_TOKEN_INFO *)NULL)->manufacturerID)+1];
00273         char model[sizeof (((CK_TOKEN_INFO *)NULL)->model)+1];
00275         char serialNumber[sizeof (((CK_TOKEN_INFO *)NULL)->serialNumber)+1];
00277         char label[sizeof (((CK_TOKEN_INFO *)NULL)->label)+1];
00278 };
00279 
00285 const char *
00286 pkcs11h_getMessage (
00287         IN const CK_RV rv
00288 );
00289 
00294 unsigned int
00295 pkcs11h_getVersion (void);
00296 
00301 unsigned int
00302 pkcs11h_getFeatures (void);
00303 
00310 CK_RV
00311 pkcs11h_initialize (void);
00312 
00318 CK_RV
00319 pkcs11h_terminate (void);
00320 
00325 void
00326 pkcs11h_setLogLevel (
00327         IN const unsigned flags
00328 );
00329 
00334 unsigned
00335 pkcs11h_getLogLevel (void);
00336 
00349 CK_RV
00350 pkcs11h_setForkMode (
00351         IN const PKCS11H_BOOL safe
00352 );
00353 
00360 CK_RV
00361 pkcs11h_setLogHook (
00362         IN const pkcs11h_hook_log_t hook,
00363         IN void * const global_data
00364 );
00365 
00377 CK_RV
00378 pkcs11h_setSlotEventHook (
00379         IN const pkcs11h_hook_slotevent_t hook,
00380         IN void * const global_data
00381 );
00382 
00391 CK_RV
00392 pkcs11h_setTokenPromptHook (
00393         IN const pkcs11h_hook_token_prompt_t hook,
00394         IN void * const global_data
00395 );
00396 
00405 CK_RV
00406 pkcs11h_setPINPromptHook (
00407         IN const pkcs11h_hook_pin_prompt_t hook,
00408         IN void * const global_data
00409 );
00410 
00417 CK_RV
00418 pkcs11h_setProtectedAuthentication (
00419         IN const PKCS11H_BOOL allow_protected_auth
00420 );
00421 
00428 CK_RV
00429 pkcs11h_setPINCachePeriod (
00430         IN const int pin_cache_period
00431 );
00432 
00439 CK_RV
00440 pkcs11h_setMaxLoginRetries (
00441         IN const unsigned max_retries
00442 );
00443 
00457 CK_RV
00458 pkcs11h_addProvider (
00459         IN const char * const reference,
00460         IN const char * const provider_location,
00461         IN const PKCS11H_BOOL allow_protected_auth,
00462         IN const unsigned mask_private_mode,
00463         IN const unsigned slot_event_method,
00464         IN const unsigned slot_poll_interval,
00465         IN const PKCS11H_BOOL cert_is_private
00466 );
00467 
00474 CK_RV
00475 pkcs11h_removeProvider (
00476         IN const char * const reference
00477 );
00478 
00490 CK_RV
00491 pkcs11h_forkFixup (void);
00492 
00504 CK_RV
00505 pkcs11h_plugAndPlay (void);
00506 
00511 CK_RV
00512 pkcs11h_logout (void);
00513 
00514 #ifdef __cplusplus
00515 }
00516 #endif
00517 
00520 #endif                          /* __PKCS11H_BASE_H */

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