00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __PKCS11_LIB_H__
00018 #define __PKCS11_LIB_H__
00019
00020 #include <openssl/x509.h>
00021 #include "rsaref/pkcs11.h"
00022
00023 typedef struct {
00024 CK_KEY_TYPE type;
00025 CK_BYTE *id;
00026 CK_ULONG id_length;
00027 CK_OBJECT_HANDLE private_key;
00028 X509 *x509;
00029 } key_object_t;
00030
00031 typedef struct {
00032 CK_KEY_TYPE type;
00033 CK_BYTE *id;
00034 CK_ULONG id_length;
00035 X509 *x509;
00036 } cert_object_t;
00037
00038 typedef struct {
00039 CK_SLOT_ID id;
00040 CK_BBOOL token_present;
00041 CK_UTF8CHAR label[33];
00042 } slot_t;
00043
00044 typedef struct {
00045 void *module_handle;
00046 CK_FUNCTION_LIST_PTR fl;
00047 slot_t *slots;
00048 CK_ULONG slot_count;
00049 CK_SESSION_HANDLE session;
00050 cert_object_t *certs;
00051 int cert_count;
00052 cert_object_t *choosen_cert;
00053 key_object_t *choosen_key;
00054 } pkcs11_handle_t;
00055
00056 #ifndef __PKCS11_LIB_C__
00057 #define PKCS11_EXTERN extern
00058 #else
00059 #define PKCS11_EXTERN
00060 #endif
00061
00062 PKCS11_EXTERN int load_pkcs11_module(char *module, pkcs11_handle_t *h);
00063 PKCS11_EXTERN int init_pkcs11_module(pkcs11_handle_t *h,int flag);
00064 PKCS11_EXTERN void release_pkcs11_module(pkcs11_handle_t *h);
00065 PKCS11_EXTERN int open_pkcs11_session(pkcs11_handle_t *h, unsigned int slot);
00066 PKCS11_EXTERN int close_pkcs11_session(pkcs11_handle_t *h);
00067 PKCS11_EXTERN int pkcs11_login(pkcs11_handle_t *h, char *password);
00068 PKCS11_EXTERN int pkcs11_pass_login(pkcs11_handle_t *h, int nullok);
00069 PKCS11_EXTERN int get_certificates(pkcs11_handle_t *h);
00070 PKCS11_EXTERN int get_private_key(pkcs11_handle_t *h);
00071 PKCS11_EXTERN int sign_value(pkcs11_handle_t *h, CK_BYTE *data, CK_ULONG length,
00072 CK_BYTE **signature, CK_ULONG *signature_length);
00073 PKCS11_EXTERN int get_random_value(unsigned char *data, int length);
00074
00075 #undef PKCS11_EXTERN
00076
00077
00078 #endif