Debian Codegraph @

src/proxy/scutils.h

raw
1 /**********************************************************************
2 scutils.h:
3
4 Description:
5 This header file used internally for smart card access via PKCS11
6 For windows we can dynamicly load, and so PKCS#11 support
7 can allways be compiled, as we now have the RSA header files
8 included from the PKCS#11 2.01 version
9
10
11 **********************************************************************/
12
13 #ifndef VOMS_SCUTILS_H
14 #define VOMS_SCUTILS_H
15
16 /**********************************************************************
17 Include header files
18 **********************************************************************/
19 #include <stdio.h>
20 #include "openssl/ssl.h"
21 #include "openssl/err.h"
22 #include "openssl/bio.h"
23 #include "openssl/pem.h"
24 #include "openssl/x509.h"
25 #include "openssl/stack.h"
26 #include "openssl/evp.h"
27 #include "openssl/rsa.h"
28
29 #include "pkcs11.h"
30
31 #ifdef USE_TYPEMAP
32 #include "typemap.h"
33 #endif
34
35 /**********************************************************************
36 Define constants
37 **********************************************************************/
38 /* RSA PKCS#11 says local strings donot include the null,
39 * but examples do. Litronics writes the null in their labels
40 * and expect them when formating.
41 * The following will be added when writing a label or
42 * other local string which might have this problem.
43 * If other cards dont require, or this gets fixed,
44 * set this to 0
45 *
46 * This was with Litronic before NetSign 2.0
47 *
48 * We have added code to try with and without the null,
49 * So set this to 0 for now.
50 */
51 #define HACK_PKCS11_LOCAL_STRING_NULL 0
52
53 /*
54 * We need to store the session and object handles with the key.
55 * In order to avoid changes to SSLeay, for the RSA structire,
56 * we will use two of the ex_data fields, by grabing 3 and 4.
57 * This may be a problem in future versions.
58 * These are used by the _get_ key routines when creating
59 * the key structure below, and by the sc_RSA_eay routines when
60 * they go to use the key.
61 */
62
63 #define SC_RSA_EX_DATA_INDEX_SESSION 3
64 #define SC_RSA_EX_DATA_INDEX_OBJECT 4
65
66
67 /* Location where the SCERR library will be stored */
68 #define ERR_USER_LIB_SCERR_NUMBER ((ERR_LIB_USER) + 1)
69
70 /*
71 * Use the SSLeay error facility with the ERR_LIB_USER
72 */
73
74 #define SCerr(f,r) ERR_PUT_error(ERR_USER_LIB_SCERR_NUMBER,(f),(r),__FILE__,__LINE__)
75
76 /*
77 * defines for function codes our minor error codes
78 */
79
80 #define SCERR_F_RSA_ENCRYPT 100
81 #define SCERR_F_RSA_DECRYPT 101
82 #define SCERR_F_SCINIT 102
83 #define SCERR_F_CREATE_DATA_OBJ 103
84 #define SCERR_F_CREATE_CERT_OBJ 104
85 #define SCERR_F_CREATE_RSA_PRIV_KEY_OBJ 105
86 #define SCERR_F_CREATE_PRIV_KEY_OBJ 106
87 #define SCERR_F_GET_RSA_PRIV_KEY_OBJ 107
88 #define SCERR_F_GET_PRIV_KEY_OBJ 108
89 #define SCERR_F_GET_PRIV_KEY_BY_LABEL 109
90 #define SCERR_F_GET_CERT_OBJ 110
91 #define SCERR_F_FIND_ONE_OBJ 111
92 #define SCERR_F_FIND_CERT_BY_LABEL 112
93 #define SCERR_F_LOAD_DLL 113
94
95 /*
96 * defines for reasons
97 */
98
99 #define SCERR_R_BASE 1500
100
101 #define SCERR_R_PKCS11_ERROR SCERR_R_BASE + 1
102 #define SCERR_R_SIGNINIT SCERR_R_BASE + 2
103 #define SCERR_R_SIGN SCERR_R_BASE + 3
104 #define SCERR_R_SIGNRECINIT SCERR_R_BASE + 4
105 #define SCERR_R_SIGNREC SCERR_R_BASE + 5
106 #define SCERR_R_INITIALIZE SCERR_R_BASE + 6
107 #define SCERR_R_GETSLOTLIST SCERR_R_BASE + 7
108 #define SCERR_R_OPENSESSION SCERR_R_BASE + 8
109 #define SCERR_R_LOGIN SCERR_R_BASE + 9
110 #define SCERR_R_CREATEOBJ SCERR_R_BASE + 10
111 #define SCERR_R_UNSUPPORTED SCERR_R_BASE + 11
112 #define SCERR_R_GETATTRVAL SCERR_R_BASE + 12
113 #define SCERR_R_FINDOBJINIT SCERR_R_BASE + 13
114 #define SCERR_R_FINDOBJ SCERR_R_BASE + 14
115 #define SCERR_R_FOUNDMANY SCERR_R_BASE + 15
116 #define SCERR_R_BAD_CERT_OBJ SCERR_R_BASE + 16
117 #define SCERR_R_FIND_FAILED SCERR_R_BASE + 17
118 #define SCERR_R_NO_PKCS11_DLL SCERR_R_BASE + 18
119 /* NOTE: Reason codes are limited to <4096 by openssl error handler */
120
121 /**********************************************************************
122 Type definitions
123 **********************************************************************/
124
125 /**********************************************************************
126 Global variables
127 *********************************************************************/
128
129 /* The pFunctionList is a pointer to the PKCS11 list
130 * of functions which is in the lib or DLL.
131 * It is initialized once on the first call to the
132 * sc_init() by sc_get_funct_list()
133 */
134
135 extern CK_FUNCTION_LIST_PTR pFunctionList;
136
137 /**********************************************************************
138 Function prototypes
139 **********************************************************************/
140 int
141 ERR_load_scerr_strings(int i);
142
143 char *
144 sc_ERR_code(CK_RV status);
145
146 CK_FUNCTION_LIST_PTR
147 sc_get_function_list();
148
149 int
150 sc_init(CK_SESSION_HANDLE_PTR PsessionHandle,
151 char *card,
152 CK_SLOT_ID_PTR pslot,
153 char * ppin,
154 CK_USER_TYPE userType,
155 int initialized);
156
157 int
158 sc_init_one(CK_SLOT_ID_PTR pslot);
159
160 int
161 sc_init_info(CK_SLOT_ID_PTR pslot,
162 CK_TOKEN_INFO_PTR ptokenInfo);
163
164 int
165 sc_init_open_login(CK_SESSION_HANDLE_PTR PsessionHandle,
166 CK_SLOT_ID_PTR pslot,
167 char * ppin,
168 CK_USER_TYPE userType);
169
170 int
171 sc_final(CK_SESSION_HANDLE sessionHandle);
172
173
174 int
175 sc_create_data_obj(CK_SESSION_HANDLE sessionHandle,
176 char *mylabel,
177 char *myvalue,
178 int mylen);
179
180 int
181 sc_create_rsa_priv_key_obj(CK_SESSION_HANDLE sessionHandle,
182 char *mylabel,
183 RSA *rkey);
184
185 int
186 sc_create_priv_key_obj(CK_SESSION_HANDLE sessionHandle,
187 char *mylabel,
188 EVP_PKEY *key);
189
190 int
191 sc_create_cert_obj(CK_SESSION_HANDLE sessionHandle,
192 char *mylabel,
193 X509 *ucert);
194
195 /**********************/
196 int
197 sc_get_rsa_priv_key_obj(CK_SESSION_HANDLE sessionHandle,
198 CK_OBJECT_HANDLE hPrivKey,
199 RSA ** nrkey);
200
201 int
202 sc_get_priv_key_obj(CK_SESSION_HANDLE sessionHandle,
203 CK_OBJECT_HANDLE hPrivKey,
204 EVP_PKEY ** nkey);
205
206 int
207 sc_get_priv_key_obj_by_label(CK_SESSION_HANDLE sessionHandle,
208 char *mylabel,
209 EVP_PKEY ** nkey);
210
211 int
212 sc_get_cert_obj_by_label(CK_SESSION_HANDLE sessionHandle,
213 char *mylabel,
214 X509 ** ncert);
215
216 int
217 sc_find_one_obj(CK_SESSION_HANDLE sessionHandle,
218 CK_ATTRIBUTE_PTR template,
219 int ai,
220 CK_OBJECT_HANDLE_PTR phObject);
221
222 int
223 sc_find_priv_key_obj_by_label(CK_SESSION_HANDLE sessionHandle,
224 char * mylabel,
225 CK_OBJECT_HANDLE_PTR phPrivKey);
226
227 int
228 sc_find_cert_obj_by_label(CK_SESSION_HANDLE hSession,
229 char * mylabel,
230 CK_OBJECT_HANDLE_PTR phCert);
231
232 int
233 sc_find_cert_obj_by_subject(CK_SESSION_HANDLE hSession,
234 X509_NAME * x509name,
235 CK_OBJECT_HANDLE_PTR phCert);
236
237
238 /************************************************************************/
239 /* replacement RSA_PKCS1_SSLeay routines which will use the key on the */
240 /* smart card We have our own method which will call PKCS11 */
241 /* These are in sc_rsa_ssleay.c */
242 /************************************************************************/
243
244 RSA_METHOD * sc_RSA_PKCS1_SSLeay();
245
246
247 #endif /* _SCUTILS_H */