xref: /titanic_41/usr/src/lib/pkcs11/libpkcs11/common/pkcs11Object.c (revision 4496171313bed39e96f21bc2f9faf2868e267ae3)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <security/cryptoki.h>
30 #include "pkcs11Global.h"
31 #include "pkcs11Session.h"
32 #include "pkcs11Slot.h"
33 
34 /*
35  * C_CreateObject is a pure wrapper to the underlying provider.
36  * The only argument checked is whether or not hSession is valid.
37  */
38 CK_RV
39 C_CreateObject(CK_SESSION_HANDLE hSession,
40     CK_ATTRIBUTE_PTR pTemplate,
41     CK_ULONG ulCount,
42     CK_OBJECT_HANDLE_PTR phObject)
43 {
44 
45 	CK_RV rv;
46 	pkcs11_session_t *sessp;
47 
48 	/* Check for a fastpath */
49 	if (purefastpath || policyfastpath) {
50 		return (fast_funcs->C_CreateObject(hSession, pTemplate,
51 			    ulCount, phObject));
52 	}
53 
54 	if (!pkcs11_initialized) {
55 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
56 	}
57 
58 	/* Obtain the session pointer */
59 	HANDLE2SESSION(hSession, sessp, rv);
60 
61 	if (rv != CKR_OK) {
62 		return (rv);
63 	}
64 
65 	/* Pass data to the provider */
66 	rv = FUNCLIST(sessp->se_slotid)->C_CreateObject(sessp->se_handle,
67 	    pTemplate, ulCount, phObject);
68 
69 	/* Present consistent interface to the application */
70 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
71 		return (CKR_FUNCTION_FAILED);
72 	}
73 
74 	return (rv);
75 }
76 
77 /*
78  * C_CopyObject is a pure wrapper to the underlying provider.
79  * The only argument checked is whether or not hSession is valid.
80  */
81 CK_RV
82 C_CopyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
83     CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
84     CK_OBJECT_HANDLE_PTR phNewObject)
85 {
86 	CK_RV rv;
87 	pkcs11_session_t *sessp;
88 
89 	/* Check for a fastpath */
90 	if (purefastpath || policyfastpath) {
91 		return (fast_funcs->C_CopyObject(hSession, hObject,
92 			    pTemplate, ulCount, phNewObject));
93 	}
94 
95 	if (!pkcs11_initialized) {
96 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
97 	}
98 
99 	/* Obtain the session pointer */
100 	HANDLE2SESSION(hSession, sessp, rv);
101 
102 	if (rv != CKR_OK) {
103 		return (rv);
104 	}
105 
106 	/* Pass data to the provider */
107 	rv = FUNCLIST(sessp->se_slotid)->C_CopyObject(sessp->se_handle,
108 	    hObject, pTemplate, ulCount, phNewObject);
109 
110 	/* Present consistent interface to the application */
111 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
112 		return (CKR_FUNCTION_FAILED);
113 	}
114 
115 	return (rv);
116 }
117 
118 /*
119  * C_DestroyObject is a pure wrapper to the underlying provider.
120  * The only argument checked is whether or not hSession is valid.
121  */
122 CK_RV
123 C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject)
124 {
125 	CK_RV rv;
126 	pkcs11_session_t *sessp;
127 
128 	/* Check for a fastpath */
129 	if (purefastpath || policyfastpath) {
130 		return (fast_funcs->C_DestroyObject(hSession, hObject));
131 	}
132 
133 	if (!pkcs11_initialized) {
134 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
135 	}
136 
137 	/* Obtain the session pointer */
138 	HANDLE2SESSION(hSession, sessp, rv);
139 
140 	if (rv != CKR_OK) {
141 		return (rv);
142 	}
143 
144 	/* Pass data to the provider */
145 	rv = FUNCLIST(sessp->se_slotid)->C_DestroyObject(sessp->se_handle,
146 	    hObject);
147 
148 	/* Present consistent interface to the application */
149 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
150 		return (CKR_FUNCTION_FAILED);
151 	}
152 
153 	return (rv);
154 }
155 
156 /*
157  * C_GetAttributeValue is a pure wrapper to the underlying provider.
158  * The only argument checked is whether or not hSession is valid.
159  */
160 CK_RV
161 C_GetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
162     CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
163 {
164 	CK_RV rv;
165 	pkcs11_session_t *sessp;
166 
167 	/* Check for a fastpath */
168 	if (purefastpath || policyfastpath) {
169 		return (fast_funcs->C_GetAttributeValue(hSession, hObject,
170 			    pTemplate, ulCount));
171 	}
172 
173 	if (!pkcs11_initialized) {
174 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
175 	}
176 
177 	/* Obtain the session pointer */
178 	HANDLE2SESSION(hSession, sessp, rv);
179 
180 	if (rv != CKR_OK) {
181 		return (rv);
182 	}
183 
184 	/* Pass data to the provider */
185 	rv = FUNCLIST(sessp->se_slotid)->C_GetAttributeValue(sessp->se_handle,
186 	    hObject, pTemplate, ulCount);
187 
188 	/* Present consistent interface to the application */
189 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
190 		return (CKR_FUNCTION_FAILED);
191 	}
192 
193 	return (rv);
194 
195 }
196 
197 /*
198  * C_SetAttributeValue is a pure wrapper to the underlying provider.
199  * The only argument checked is whether or not hSession is valid.
200  */
201 CK_RV
202 C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
203     CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
204 {
205 	CK_RV rv;
206 	pkcs11_session_t *sessp;
207 
208 	/* Check for a fastpath */
209 	if (purefastpath || policyfastpath) {
210 		return (fast_funcs->C_SetAttributeValue(hSession, hObject,
211 			    pTemplate, ulCount));
212 	}
213 
214 	if (!pkcs11_initialized) {
215 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
216 	}
217 
218 	/* Obtain the session pointer */
219 	HANDLE2SESSION(hSession, sessp, rv);
220 
221 	if (rv != CKR_OK) {
222 		return (rv);
223 	}
224 
225 	/* Pass data to the provider */
226 	rv = FUNCLIST(sessp->se_slotid)->C_SetAttributeValue(sessp->se_handle,
227 	    hObject, pTemplate, ulCount);
228 
229 	/* Present consistent interface to the application */
230 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
231 		return (CKR_FUNCTION_FAILED);
232 	}
233 
234 	return (rv);
235 }
236 
237 /*
238  * C_GetObjectSize is a pure wrapper to the underlying provider.
239  * The only argument checked is whether or not hSession is valid.
240  */
241 CK_RV
242 C_GetObjectSize(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
243     CK_ULONG_PTR pulSize)
244 {
245 	CK_RV rv;
246 	pkcs11_session_t *sessp;
247 
248 	/* Check for a fastpath */
249 	if (purefastpath || policyfastpath) {
250 		return (fast_funcs->C_GetObjectSize(hSession, hObject,
251 			    pulSize));
252 	}
253 
254 	if (!pkcs11_initialized) {
255 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
256 	}
257 
258 	/* Obtain the session pointer */
259 	HANDLE2SESSION(hSession, sessp, rv);
260 
261 	if (rv != CKR_OK) {
262 		return (rv);
263 	}
264 
265 	/* Pass data to the provider */
266 	rv = FUNCLIST(sessp->se_slotid)->C_GetObjectSize(sessp->se_handle,
267 	    hObject, pulSize);
268 
269 	/* Present consistent interface to the application */
270 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
271 		return (CKR_FUNCTION_FAILED);
272 	}
273 
274 	return (rv);
275 }
276 
277 /*
278  * C_FindObjectsInit is a pure wrapper to the underlying provider.
279  * The only argument checked is whether or not hSession is valid.
280  */
281 CK_RV
282 C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate,
283     CK_ULONG ulCount)
284 {
285 	CK_RV rv;
286 	pkcs11_session_t *sessp;
287 
288 	/* Check for a fastpath */
289 	if (purefastpath || policyfastpath) {
290 		return (fast_funcs->C_FindObjectsInit(hSession, pTemplate,
291 			    ulCount));
292 	}
293 
294 	if (!pkcs11_initialized) {
295 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
296 	}
297 
298 	/* Obtain the session pointer */
299 	HANDLE2SESSION(hSession, sessp, rv);
300 
301 	if (rv != CKR_OK) {
302 		return (rv);
303 	}
304 
305 	/* Pass data to the provider */
306 	rv = FUNCLIST(sessp->se_slotid)->C_FindObjectsInit(sessp->se_handle,
307 	    pTemplate, ulCount);
308 
309 	/* Present consistent interface to the application */
310 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
311 		return (CKR_FUNCTION_FAILED);
312 	}
313 
314 	return (rv);
315 }
316 
317 /*
318  * C_FindObjects is a pure wrapper to the underlying provider.
319  * The only argument checked is whether or not hSession is valid.
320  */
321 CK_RV
322 C_FindObjects(CK_SESSION_HANDLE hSession,
323     CK_OBJECT_HANDLE_PTR phObject,
324     CK_ULONG ulMaxObjectCount,
325     CK_ULONG_PTR pulObjectCount)
326 {
327 	CK_RV rv;
328 	pkcs11_session_t *sessp;
329 
330 	/* Check for a fastpath */
331 	if (purefastpath || policyfastpath) {
332 		return (fast_funcs->C_FindObjects(hSession, phObject,
333 			    ulMaxObjectCount, pulObjectCount));
334 	}
335 
336 	if (!pkcs11_initialized) {
337 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
338 	}
339 
340 	/* Obtain the session pointer */
341 	HANDLE2SESSION(hSession, sessp, rv);
342 
343 	if (rv != CKR_OK) {
344 		return (rv);
345 	}
346 
347 	/* Pass data to the provider */
348 	rv = FUNCLIST(sessp->se_slotid)->C_FindObjects(sessp->se_handle,
349 	    phObject, ulMaxObjectCount, pulObjectCount);
350 
351 	/* Present consistent interface to the application */
352 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
353 		return (CKR_FUNCTION_FAILED);
354 	}
355 
356 	return (rv);
357 }
358 
359 /*
360  * C_FindObjectsFinal is a pure wrapper to the underlying provider.
361  * The only argument checked is whether or not hSession is valid.
362  */
363 CK_RV
364 C_FindObjectsFinal(CK_SESSION_HANDLE hSession)
365 {
366 	CK_RV rv;
367 	pkcs11_session_t *sessp;
368 
369 	/* Check for a fastpath */
370 	if (purefastpath || policyfastpath) {
371 		return (fast_funcs->C_FindObjectsFinal(hSession));
372 	}
373 
374 	if (!pkcs11_initialized) {
375 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
376 	}
377 
378 	/* Obtain the session pointer */
379 	HANDLE2SESSION(hSession, sessp, rv);
380 
381 	if (rv != CKR_OK) {
382 		return (rv);
383 	}
384 
385 	/* Pass data to the provider */
386 	rv = FUNCLIST(sessp->se_slotid)->C_FindObjectsFinal(sessp->se_handle);
387 
388 	/* Present consistent interface to the application */
389 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
390 		return (CKR_FUNCTION_FAILED);
391 	}
392 
393 	return (rv);
394 }
395