00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef PKCS11_H
00019 #define PKCS11_H
00020
00021 #include <openssl/x509.h>
00022
00023
00024
00025 #define CK_PTR *
00026 #define CK_DEFINE_FUNCTION(returnType, name) \
00027 returnType name
00028 #define CK_DECLARE_FUNCTION(returnType, name) \
00029 returnType name
00030 #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
00031 returnType (* name)
00032 #define CK_CALLBACK_FUNCTION(returnType, name) \
00033 returnType (* name)
00034 #ifndef NULL_PTR
00035 #define NULL_PTR 0
00036 #endif
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include "pkcs11t.h"
00056
00057 #define __PASTE(x,y) x##y
00058
00059
00060
00061
00062
00063
00064
00065 #define CK_NEED_ARG_LIST 1
00066 #define CK_PKCS11_FUNCTION_INFO(name) \
00067 extern CK_DECLARE_FUNCTION(CK_RV, name)
00068
00069
00070
00071 #include "pkcs11f.h"
00072
00073 #undef CK_NEED_ARG_LIST
00074 #undef CK_PKCS11_FUNCTION_INFO
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #define CK_NEED_ARG_LIST 1
00085 #define CK_PKCS11_FUNCTION_INFO(name) \
00086 typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
00087
00088
00089
00090 #include "pkcs11f.h"
00091
00092 #undef CK_NEED_ARG_LIST
00093 #undef CK_PKCS11_FUNCTION_INFO
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 #define CK_PKCS11_FUNCTION_INFO(name) \
00106 __PASTE(CK_,name) name;
00107
00108 struct CK_FUNCTION_LIST {
00109
00110 CK_VERSION version;
00111
00112
00113
00114
00115 #include "pkcs11f.h"
00116
00117 };
00118
00119 #undef CK_PKCS11_FUNCTION_INFO
00120 #undef __PASTE
00121
00122 typedef struct {
00123 CK_KEY_TYPE type;
00124 CK_BYTE *id;
00125 CK_ULONG id_length;
00126 CK_OBJECT_HANDLE private_key;
00127 X509 *x509;
00128 } key_object_t;
00129
00130 typedef struct {
00131 CK_SLOT_ID id;
00132 CK_BBOOL token_present;
00133 CK_UTF8CHAR label[33];
00134 } slot_t;
00135
00136 typedef struct {
00137 void *module_handle;
00138 CK_FUNCTION_LIST_PTR fl;
00139 slot_t *slots;
00140 CK_ULONG slot_count;
00141 CK_SESSION_HANDLE session;
00142 key_object_t *keys;
00143 int key_count;
00144 key_object_t *choosen_key;
00145 } pkcs11_handle_t;
00146
00147 int load_pkcs11_module(char *module, pkcs11_handle_t *h);
00148
00149 int init_pkcs11_module(pkcs11_handle_t *h);
00150
00151 void release_pkcs11_module(pkcs11_handle_t *h);
00152
00153 int open_pkcs11_session(pkcs11_handle_t *h, unsigned int slot);
00154
00155 int pkcs11_login(pkcs11_handle_t *h, char *password);
00156
00157 int close_pkcs11_session(pkcs11_handle_t *h);
00158
00159 int get_certificates(pkcs11_handle_t *h);
00160
00161 int get_private_keys(pkcs11_handle_t *h);
00162
00163 int sign_value(pkcs11_handle_t *h, CK_BYTE *data, CK_ULONG length,
00164 CK_BYTE **signature, CK_ULONG *signature_length);
00165
00166 int get_random_value(unsigned char *data, int length);
00167
00168 #endif