xref: /illumos-gate/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.h (revision b1d7ec75953cd517f5b7c3d9cb427ff8ec5d7d07)
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 (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _SOFTKEYSTOREUTIL_H
26 #define	_SOFTKEYSTOREUTIL_H
27 
28 /*
29  * Structures and function prototypes for the keystore
30  */
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 
38 /* Keystore State values */
39 #define	KEYSTORE_UNINITIALIZED	0
40 #define	KEYSTORE_PRESENT	1
41 #define	KEYSTORE_LOAD		2
42 #define	KEYSTORE_INITIALIZED	3
43 #define	KEYSTORE_UNAVAILABLE	4
44 
45 typedef enum {
46 	ALL_TOKENOBJS = 0,
47 	PUB_TOKENOBJS = 1,
48 	PRI_TOKENOBJS = 2
49 } ks_search_type_t;
50 
51 typedef struct ks_obj_handle {
52 	unsigned char name[256]; /* obj[monotonic-counter] */
53 	boolean_t public;	/* true if public obj, false for private obj */
54 } ks_obj_handle_t;
55 
56 typedef struct ks_obj {
57 
58 	/* handle for accessing this object */
59 	ks_obj_handle_t ks_handle;
60 
61 	/* version number of object file */
62 	uint_t obj_version;
63 
64 	/* contains decrypted binary data for obj */
65 	uchar_t *buf;
66 
67 	/* size of binary data */
68 	size_t size;
69 
70 	/* pointer to next item in list */
71 	struct ks_obj *next;
72 } ks_obj_t;
73 
74 /*
75  * Prototype for functions in softKeystore.c
76  */
77 int soft_keystore_readlock(boolean_t set_lock);
78 int soft_keystore_writelock(boolean_t set_lock);
79 int soft_keystore_lock_object(ks_obj_handle_t *ks_handle, boolean_t read_lock);
80 int soft_keystore_unlock_object(int fd);
81 int soft_keystore_get_version(uint_t *version, boolean_t lock_held);
82 int soft_keystore_get_object_version(ks_obj_handle_t *ks_handle,
83     uint_t *version, boolean_t lock_held);
84 int soft_keystore_getpin(char **hashed_pin, boolean_t lock_held);
85 int soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held);
86 int soft_keystore_authpin(uchar_t *pin);
87 CK_RV soft_keystore_get_objs(ks_search_type_t search_type,
88     ks_obj_t **result_objs, boolean_t lock_held);
89 CK_RV soft_keystore_get_single_obj(ks_obj_handle_t *ks_handle,
90     ks_obj_t **result_obj, boolean_t lock_held);
91 int soft_keystore_put_new_obj(uchar_t *buf, size_t len, boolean_t public,
92     boolean_t lock_held, ks_obj_handle_t *keyhandle);
93 int soft_keystore_modify_obj(ks_obj_handle_t *ks_handle, uchar_t *buf,
94     size_t len, boolean_t lock_held);
95 int soft_keystore_del_obj(ks_obj_handle_t *ks_handle, boolean_t lock_held);
96 int soft_keystore_get_pin_salt(char **salt);
97 CK_RV soft_keystore_pin_initialized(boolean_t *initialized, char **hashed_pin,
98     boolean_t lock_held);
99 boolean_t soft_keystore_status(int desired_state);
100 int soft_keystore_init(int desired_state);
101 int create_keystore();
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif /* _SOFTKEYSTOREUTIL_H */
108