Estonian ID Card C-library
DigiDocPKCS11.h
1 #ifndef __DIGI_DOC_PKCS11_H__
2 #define __DIGI_DOC_PKCS11_H__
3 //==================================================
4 // FILE: DigiDocPKCS11.h
5 // PROJECT: Digi Doc
6 // DESCRIPTION: Digi Doc functions for signing using PKCS#11 API
7 // AUTHOR: Veiko Sinivee, S|E|B IT Partner Estonia
8 //==================================================
9 // Copyright (C) AS Sertifitseerimiskeskus
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 // GNU Lesser General Public Licence is available at
19 // http://www.gnu.org/copyleft/lesser.html
20 //==========< HISTORY >=============================
21 // 13.01.2004 Veiko Sinivee
22 // Creation
23 //==================================================
24 
25 #include <libdigidoc/DigiDocDefs.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #ifdef WIN32
32  #include <windows.h>
33  #define LIBHANDLE HANDLE
34  #include "pkcs11/cryptoki.h"
35 #else
36  #include <dlfcn.h> // Linux .so loading interface
37  #define LIBHANDLE void*
38  #include "pkcs11/pkcs11.h"
39 #endif
40 
41 
42 
43 #include <libdigidoc/DigiDocLib.h>
44 #include <openssl/ocsp.h>
45 
46 
47 EXP_OPTION LIBHANDLE initPKCS11Library(const char* libName);
48 EXP_OPTION void closePKCS11Library(LIBHANDLE pLibrary, CK_SESSION_HANDLE hSession);
49 EXP_OPTION int calculateSignatureWithEstID(SignedDoc* pSigDoc, SignatureInfo* pSigInfo,
50  int slot, const char* passwd);
51 
52 EXP_OPTION CK_RV GetSlotIds(CK_SLOT_ID_PTR pSlotids, CK_ULONG_PTR pLen);
53 EXP_OPTION CK_RV GetTokenInfo(CK_TOKEN_INFO_PTR pTokInfo, CK_SLOT_ID id);
54 int loadAndTestDriver(const char* driver, LIBHANDLE* pLibrary, CK_SLOT_ID* slotids,
55  int slots, CK_ULONG slot);
56 EXP_OPTION CK_RV getDriverInfo(CK_INFO_PTR pInfo);
57 EXP_OPTION CK_RV GetSlotInfo(CK_SLOT_INFO_PTR pSlotInfo, CK_SLOT_ID id);
58 
59 //============================================================
60 // Decrypts RSA encrypted data with the private key
61 // slot - number of the slot for decryption key. On ID card allways 0
62 // pin - corresponding pin for the key. On ID card - PIN1
63 // encData - encrypted data
64 // encLen - length of encrypted data
65 // decData - buffer for decrypted data
66 // encLen - length of buffer. Will be modified by amount of decrypted data
67 // return error code or ERR_OK
68 //============================================================
69 EXP_OPTION int decryptWithEstID(int slot, const char* pin,
70  const char* encData, int encLen,
71  char* decData, int *decLen);
72 
73 //============================================================
74 // Locates and reads users certificate from smartcard
75 // slot - number of the slot for decryption key. On ID card allways 0
76 // ppCert - address for newly allocated certificate pointer
77 // return error code or ERR_OK
78 //============================================================
79 EXP_OPTION int findUsersCertificate(int slot, X509** ppCert);
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif // __DIGI_DOC_PKCS11_H__
86 
Definition: DigiDocObj.h:154
Definition: DigiDocObj.h:177