pkcs11h-core.h
Go to the documentation of this file.
/*
* Copyright (c) 2005-2018 Alon Bar-Lev <alon.barlev@gmail.com>
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, or the BSD license.
*
* GNU General Public License (GPL) Version 2
* ===========================================
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see the file COPYING.GPL included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* BSD License
* ============
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* o Neither the name of the Alon Bar-Lev nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PKCS11H_BASE_H
#define __PKCS11H_BASE_H
#include <stdarg.h>
#include <time.h>
#include <pkcs11-helper-1.0/pkcs11h-version.h>
#include <pkcs11-helper-1.0/pkcs11h-def.h>
#include <pkcs11-helper-1.0/pkcs11h-engines.h>
#if defined(__cplusplus)
extern "C" {
#endif
#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_OPENSSL (1<< 0)
#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_GNUTLS (1<< 1)
#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_CRYPTOAPI (1<< 2)
#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_WIN32 (1<< 2)
#define PKCS11H_FEATURE_MASK_DEBUG (1<< 3)
#define PKCS11H_FEATURE_MASK_THREADING (1<< 4)
#define PKCS11H_FEATURE_MASK_TOKEN (1<< 5)
#define PKCS11H_FEATURE_MASK_DATA (1<< 6)
#define PKCS11H_FEATURE_MASK_CERTIFICATE (1<< 7)
#define PKCS11H_FEATURE_MASK_SLOTEVENT (1<< 8)
#define PKCS11H_FEATURE_MASK_OPENSSL (1<< 9)
#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_POLARSSL (1<< 10)
#define PKCS11H_FEATURE_MASK_ENGINE_CRYPTO_MBEDTLS (1<< 10)
#define PKCS11H_LOG_DEBUG2 5
#define PKCS11H_LOG_DEBUG1 4
#define PKCS11H_LOG_INFO 3
#define PKCS11H_LOG_WARN 2
#define PKCS11H_LOG_ERROR 1
#define PKCS11H_LOG_QUIET 0
#define PKCS11H_PIN_CACHE_INFINITE -1
#define PKCS11H_PRIVATEMODE_MASK_AUTO (0)
#define PKCS11H_PRIVATEMODE_MASK_SIGN (1<<0)
#define PKCS11H_PRIVATEMODE_MASK_RECOVER (1<<1)
#define PKCS11H_PRIVATEMODE_MASK_DECRYPT (1<<2)
#define PKCS11H_PRIVATEMODE_MASK_UNWRAP (1<<3)
#define PKCS11H_SLOTEVENT_METHOD_AUTO 0
#define PKCS11H_SLOTEVENT_METHOD_TRIGGER 1
#define PKCS11H_SLOTEVENT_METHOD_POLL 2
#define PKCS11H_SLOTEVENT_METHOD_FETCH 3
#define PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT (1<<0)
#define PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT (1<<1)
#define PKCS11H_PROMPT_MASK_ALLOW_KEY_PROMPT (1<<2)
#define PKCS11H_PROMPT_MASK_ALLOW_ALL ( \
PKCS11H_PROMPT_MASK_ALLOW_PIN_PROMPT | \
PKCS11H_PROMPT_MASK_ALLOW_TOKEN_PROMPT | \
PKCS11H_PROMPT_MASK_ALLOW_KEY_PROMPT | \
0 \
)
#define PKCS11H_ENUM_METHOD_CACHE 0
#define PKCS11H_ENUM_METHOD_CACHE_EXIST 1
#define PKCS11H_ENUM_METHOD_RELOAD 2
/*
* @brief The current log level of the helper.
* Value type is @ref PKCS11H_LOG.
* Default is PKCS11H_LOG_INFO.
*/
#define PKCS11H_PROPERTY_LOG_LEVEL 0
#define PKCS11H_PROPERTY_FORK_MODE 1
#define PKCS11H_PROPERTY_LOG_HOOK 2
#define PKCS11H_PROPERTY_LOG_HOOK_DATA 3
#define PKCS11H_PROPERTY_SLOT_EVENT_HOOK 4
#define PKCS11H_PROPERTY_SLOT_EVENT_HOOK_DATA 5
#define PKCS11H_PROPERTY_TOKEN_PROMPT_HOOK 6
#define PKCS11H_PROPERTY_TOKEN_PROMPT_HOOK_DATA 7
#define PKCS11H_PROPERTY_PIN_PROMPT_HOOK 8
#define PKCS11H_PROPERTY_PIN_PROMPT_HOOK_DATA 9
#define PKCS11H_PROPERTY_ALLOW_PROTECTED_AUTHENTICATION 10
#define PKCS11H_PROPERTY_PIN_CACHE_PERIOD 11
#define PKCS11H_PROPERTY_MAX_LOGIN_RETRIES 12
#define PKCS11H_PROPERTY_KEY_PROMPT_HOOK 13
#define PKCS11H_PROPERTY_KEY_PROMPT_HOOK_DATA 14
#define PKCS11H_PROVIDER_PROPERTY_LOCATION 0
#define PKCS11H_PROVIDER_PROPERTY_ALLOW_PROTECTED_AUTH 1
#define PKCS11H_PROVIDER_PROPERTY_MASK_PRIVATE_MODE 2
#define PKCS11H_PROVIDER_PROPERTY_SLOT_EVENT_METHOD 3
#define PKCS11H_PROVIDER_PROPERTY_SLOT_POLL_INTERVAL 4
/*
* @brief Provider's certificate access should be done after login.
* Value type is @ref PKCS11H_BOOL.
* Default value is False.
*/
#define PKCS11H_PROVIDER_PROPERTY_CERT_IS_PRIVATE 5
#define PKCS11H_PROVIDER_PROPERTY_INIT_ARGS 6
#define PKCS11H_PROVIDER_PROPERTY_PROVIDER_DESTRUCT_HOOK 7
#define PKCS11H_PROVIDER_PROPERTY_PROVIDER_DESTRUCT_HOOK_DATA 8
#define PKCS11H_PROVIDER_PROPERTY_LOADER_FLAGS 9
#define _PKCS11H_PROVIDER_PROPERTY_LAST 10
struct pkcs11h_token_id_s;
typedef struct pkcs11h_token_id_s *pkcs11h_token_id_t;
typedef void (*pkcs11h_hook_log_t)(
IN void * const global_data,
IN const unsigned flags,
IN const char * const format,
IN va_list args
);
typedef void (*pkcs11h_hook_slotevent_t)(
IN void * const global_data
);
typedef 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
);
typedef 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
);
typedef PKCS11H_BOOL (*pkcs11h_hook_key_prompt_t)(
IN void * const global_data,
IN void * const user_data,
IN const pkcs11h_token_id_t token,
IN const char * const label,
IN const unsigned retry,
OUT char * const pin,
IN const size_t pin_max
);
typedef void (*pkcs11h_provider_destruct_hook_t)(
IN void * const global_data,
IN const char * const reference
);
struct pkcs11h_token_id_s {
char display[1024];
char manufacturerID[sizeof (((CK_TOKEN_INFO *)NULL)->manufacturerID)+1];
char model[sizeof (((CK_TOKEN_INFO *)NULL)->model)+1];
char serialNumber[sizeof (((CK_TOKEN_INFO *)NULL)->serialNumber)+1];
char label[sizeof (((CK_TOKEN_INFO *)NULL)->label)+1];
};
const char *
pkcs11h_getMessage (
IN const CK_RV rv
);
unsigned int
pkcs11h_getVersion (void);
unsigned int
pkcs11h_getFeatures (void);
CK_RV
pkcs11h_initialize (void);
CK_RV
pkcs11h_terminate (void);
CK_RV
pkcs11h_getProperty (
IN const unsigned property,
OUT void * const value,
IN OUT size_t * const value_size
);
CK_RV
pkcs11h_setProperty (
IN const unsigned property,
IN const void * const value,
IN const size_t value_size
);
void
pkcs11h_setLogLevel (
IN const unsigned flags
);
unsigned
pkcs11h_getLogLevel (void);
CK_RV
pkcs11h_setForkMode (
IN const PKCS11H_BOOL safe
);
CK_RV
pkcs11h_setLogHook (
IN const pkcs11h_hook_log_t hook,
IN void * const global_data
);
CK_RV
pkcs11h_setSlotEventHook (
IN const pkcs11h_hook_slotevent_t hook,
IN void * const global_data
);
CK_RV
pkcs11h_setTokenPromptHook (
IN const pkcs11h_hook_token_prompt_t hook,
IN void * const global_data
);
CK_RV
pkcs11h_setPINPromptHook (
IN const pkcs11h_hook_pin_prompt_t hook,
IN void * const global_data
);
CK_RV
pkcs11h_setProtectedAuthentication (
IN const PKCS11H_BOOL allow_protected_auth
);
CK_RV
pkcs11h_setPINCachePeriod (
IN const int pin_cache_period
);
CK_RV
pkcs11h_setMaxLoginRetries (
IN const unsigned max_retries
);
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
);
CK_RV
pkcs11h_registerProvider (
IN const char * const reference
);
CK_RV
pkcs11h_setProviderPropertyByName (
IN const char * const reference,
IN const char * const property_str,
IN const char * const value_str
);
CK_RV
pkcs11h_setProviderProperty (
IN const char * const reference,
IN const unsigned property,
IN const void * value,
IN const size_t value_size
);
CK_RV
pkcs11h_initializeProvider (
IN const char * const reference
);
CK_RV
pkcs11h_removeProvider (
IN const char * const reference
);
CK_RV
pkcs11h_forkFixup (void);
CK_RV
pkcs11h_plugAndPlay (void);
CK_RV
pkcs11h_logout (void);
#ifdef __cplusplus
}
#endif
#endif /* __PKCS11H_BASE_H */
pkcs11h_hook_key_prompt_t
PKCS11H_BOOL(* pkcs11h_hook_key_prompt_t)(IN void *const global_data, IN void *const user_data, IN const pkcs11h_token_id_t token, IN const char *const label, IN const unsigned retry, OUT char *const pin, IN const size_t pin_max)
Key prompt hook.
Definition pkcs11h-core.h:475
pkcs11h_setProtectedAuthentication
CK_RV pkcs11h_setProtectedAuthentication(IN const PKCS11H_BOOL allow_protected_auth)
Set global protected authentication mode.
pkcs11h_setForkMode
CK_RV pkcs11h_setForkMode(IN const PKCS11H_BOOL safe)
How does the foked process bahaves after POSIX fork()
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_token_id_t
struct pkcs11h_token_id_s * pkcs11h_token_id_t
Token identifier.
Definition pkcs11h-core.h:406
pkcs11h_getProperty
CK_RV pkcs11h_getProperty(IN const unsigned property, OUT void *const value, IN OUT size_t *const value_size)
Get library property.
pkcs11h_logout
CK_RV pkcs11h_logout(void)
Logout from all sessions.
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:455
pkcs11h_getMessage
const char * pkcs11h_getMessage(IN const CK_RV rv)
Get message by return value.
pkcs11h_setProviderProperty
CK_RV pkcs11h_setProviderProperty(IN const char *const reference, IN const unsigned property, IN const void *value, IN const size_t value_size)
Set PKCS#11 provider property.
pkcs11h_setSlotEventHook
CK_RV pkcs11h_setSlotEventHook(IN const pkcs11h_hook_slotevent_t hook, IN void *const global_data)
Set a slot event callback.
pkcs11h_setProviderPropertyByName
CK_RV pkcs11h_setProviderPropertyByName(IN const char *const reference, IN const char *const property_str, IN const char *const value_str)
Set PKCS#11 provider property by name.
pkcs11h_getFeatures
unsigned int pkcs11h_getFeatures(void)
Get features of library.
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:438
pkcs11h_forkFixup
CK_RV pkcs11h_forkFixup(void)
Handle special case of POSIX fork()
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:415
pkcs11h_terminate
CK_RV pkcs11h_terminate(void)
Terminate helper interface.
pkcs11h_setPINCachePeriod
CK_RV pkcs11h_setPINCachePeriod(IN const int pin_cache_period)
Set global PIN cache timeout.
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_setPINPromptHook
CK_RV pkcs11h_setPINPromptHook(IN const pkcs11h_hook_pin_prompt_t hook, IN void *const global_data)
Set a pin prompt callback.
pkcs11h_setMaxLoginRetries
CK_RV pkcs11h_setMaxLoginRetries(IN const unsigned max_retries)
Set global login retries attempts.
pkcs11h_removeProvider
CK_RV pkcs11h_removeProvider(IN const char *const reference)
Delete a PKCS#11 provider.
pkcs11h_initialize
CK_RV pkcs11h_initialize(void)
Initialize helper interface.
pkcs11h_registerProvider
CK_RV pkcs11h_registerProvider(IN const char *const reference)
Register a PKCS#11 provider.
pkcs11h_initializeProvider
CK_RV pkcs11h_initializeProvider(IN const char *const reference)
Initialize a PKCS#11 provider.
pkcs11h_hook_slotevent_t
void(* pkcs11h_hook_slotevent_t)(IN void *const global_data)
Slotevent hook.
Definition pkcs11h-core.h:426
pkcs11h_getVersion
unsigned int pkcs11h_getVersion(void)
Get version of library.
pkcs11h_setProperty
CK_RV pkcs11h_setProperty(IN const unsigned property, IN const void *const value, IN const size_t value_size)
Set library property.
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_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)
Register, configure and initialize a PKCS#11 provider.
pkcs11h-def.h
pkcs11-helper core definitions.
pkcs11h-engines.h
pkcs11-helper engines definitions.
pkcs11h-version.h
pkcs11-helper core.
pkcs11h_token_id_s
Token identifier.
Definition pkcs11h-core.h:493
pkcs11h_token_id_s::label
char label[sizeof(((CK_TOKEN_INFO *) NULL) ->label)+1]
Definition pkcs11h-core.h:503
pkcs11h_token_id_s::manufacturerID
char manufacturerID[sizeof(((CK_TOKEN_INFO *) NULL) ->manufacturerID)+1]
Definition pkcs11h-core.h:497
pkcs11h_token_id_s::model
char model[sizeof(((CK_TOKEN_INFO *) NULL) ->model)+1]
Definition pkcs11h-core.h:499
pkcs11h_token_id_s::serialNumber
char serialNumber[sizeof(((CK_TOKEN_INFO *) NULL) ->serialNumber)+1]
Definition pkcs11h-core.h:501
pkcs11h_token_id_s::display
char display[1024]
Definition pkcs11h-core.h:495

pkcs11-helper, Copyright (C) Alon Bar-Lev <alon.barlev@gmail.com> |