xref: /illumos-gate/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.h (revision 2b24ab6b3865caeede9eeb9db6b83e1d89dcd1ea)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SOFTKEYSTOREUTIL_H
27 #define	_SOFTKEYSTOREUTIL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Structures and function prototypes for the keystore
33  */
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/types.h>
40 
41 /* Keystore State values */
42 #define	KEYSTORE_UNINITIALIZED	0
43 #define	KEYSTORE_PRESENT	1
44 #define	KEYSTORE_VERSION_OK	2
45 #define	KEYSTORE_INITIALIZED	3
46 #define	KEYSTORE_UNAVAILABLE	4
47 
48 typedef enum {
49 	ALL_TOKENOBJS = 0,
50 	PUB_TOKENOBJS = 1,
51 	PRI_TOKENOBJS = 2
52 } ks_search_type_t;
53 
54 typedef struct ks_obj_handle {
55 	unsigned char name[256]; /* obj[monotonic-counter] */
56 	boolean_t public;	/* true if public obj, false for private obj */
57 } ks_obj_handle_t;
58 
59 typedef struct ks_obj {
60 
61 	/* handle for accessing this object */
62 	ks_obj_handle_t ks_handle;
63 
64 	/* version number of object file */
65 	uint_t obj_version;
66 
67 	/* contains decrypted binary data for obj */
68 	uchar_t *buf;
69 
70 	/* size of binary data */
71 	size_t size;
72 
73 	/* pointer to next item in list */
74 	struct ks_obj *next;
75 } ks_obj_t;
76 
77 /*
78  * Prototype for functions in softKeystore.c
79  */
80 int soft_keystore_readlock(boolean_t set_lock);
81 int soft_keystore_writelock(boolean_t set_lock);
82 int soft_keystore_lock_object(ks_obj_handle_t *ks_handle, boolean_t read_lock);
83 int soft_keystore_unlock_object(int fd);
84 int soft_keystore_get_version(uint_t *version, boolean_t lock_held);
85 int soft_keystore_get_object_version(ks_obj_handle_t *ks_handle,
86     uint_t *version, boolean_t lock_held);
87 int soft_keystore_getpin(char **hashed_pin, boolean_t lock_held);
88 int soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held);
89 int soft_keystore_authpin(uchar_t *pin);
90 CK_RV soft_keystore_get_objs(ks_search_type_t search_type,
91     ks_obj_t **result_objs, boolean_t lock_held);
92 CK_RV soft_keystore_get_single_obj(ks_obj_handle_t *ks_handle,
93     ks_obj_t **result_obj, boolean_t lock_held);
94 int soft_keystore_put_new_obj(uchar_t *buf, size_t len, boolean_t public,
95     boolean_t lock_held, ks_obj_handle_t *keyhandle);
96 int soft_keystore_modify_obj(ks_obj_handle_t *ks_handle, uchar_t *buf,
97     size_t len, boolean_t lock_held);
98 int soft_keystore_del_obj(ks_obj_handle_t *ks_handle, boolean_t lock_held);
99 int soft_keystore_get_pin_salt(char **salt);
100 CK_RV soft_keystore_pin_initialized(boolean_t *initialized, char **hashed_pin,
101     boolean_t lock_held);
102 boolean_t soft_keystore_status(int desired_state);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* _SOFTKEYSTOREUTIL_H */
109