Eneboo - Documentación para desarrolladores
|
00001 #ifndef __DIGI_DOC_PKCS11_H__ 00002 #define __DIGI_DOC_PKCS11_H__ 00003 //================================================== 00004 // FILE: DigiDocPKCS11.h 00005 // PROJECT: Digi Doc 00006 // DESCRIPTION: Digi Doc functions for signing using PKCS#11 API 00007 // AUTHOR: Veiko Sinivee, S|E|B IT Partner Estonia 00008 //================================================== 00009 // Copyright (C) AS Sertifitseerimiskeskus 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // This library is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // GNU Lesser General Public Licence is available at 00019 // http://www.gnu.org/copyleft/lesser.html 00020 //==========< HISTORY >============================= 00021 // 13.01.2004 Veiko Sinivee 00022 // Creation 00023 //================================================== 00024 00025 #include <libdigidoc/DigiDocDefs.h> 00026 00027 #ifdef __cplusplus 00028 extern "C" { 00029 #endif 00030 00031 #ifdef WIN32 00032 #include <windows.h> 00033 #define LIBHANDLE HANDLE 00034 #include "pkcs11/cryptoki.h" 00035 #else 00036 #include <dlfcn.h> // Linux .so loading interface 00037 #define LIBHANDLE void* 00038 #include "pkcs11/pkcs11.h" 00039 #endif 00040 00041 00042 00043 #include <libdigidoc/DigiDocLib.h> 00044 #include <openssl/ocsp.h> 00045 00046 00047 EXP_OPTION LIBHANDLE initPKCS11Library(const char* libName); 00048 EXP_OPTION void closePKCS11Library(LIBHANDLE pLibrary, CK_SESSION_HANDLE hSession); 00049 EXP_OPTION int calculateSignatureWithEstID(SignedDoc* pSigDoc, SignatureInfo* pSigInfo, 00050 int slot, const char* passwd); 00051 00052 EXP_OPTION CK_RV GetSlotIds(CK_SLOT_ID_PTR pSlotids, CK_ULONG_PTR pLen); 00053 EXP_OPTION CK_RV GetTokenInfo(CK_TOKEN_INFO_PTR pTokInfo, CK_SLOT_ID id); 00054 int loadAndTestDriver(const char* driver, LIBHANDLE* pLibrary, CK_SLOT_ID* slotids, 00055 int slots, CK_ULONG slot); 00056 EXP_OPTION CK_RV getDriverInfo(CK_INFO_PTR pInfo); 00057 EXP_OPTION CK_RV GetSlotInfo(CK_SLOT_INFO_PTR pSlotInfo, CK_SLOT_ID id); 00058 00059 //============================================================ 00060 // Decrypts RSA encrypted data with the private key 00061 // slot - number of the slot for decryption key. On ID card allways 0 00062 // pin - corresponding pin for the key. On ID card - PIN1 00063 // encData - encrypted data 00064 // encLen - length of encrypted data 00065 // decData - buffer for decrypted data 00066 // encLen - length of buffer. Will be modified by amount of decrypted data 00067 // return error code or ERR_OK 00068 //============================================================ 00069 EXP_OPTION int decryptWithEstID(int slot, const char* pin, 00070 const char* encData, int encLen, 00071 char* decData, int *decLen); 00072 00073 //============================================================ 00074 // Locates and reads users certificate from smartcard 00075 // slot - number of the slot for decryption key. On ID card allways 0 00076 // ppCert - address for newly allocated certificate pointer 00077 // return error code or ERR_OK 00078 //============================================================ 00079 EXP_OPTION int findUsersCertificate(int slot, X509** ppCert); 00080 00081 #ifdef __cplusplus 00082 } 00083 #endif 00084 00085 #endif // __DIGI_DOC_PKCS11_H__ 00086