xref: /titanic_41/usr/src/cmd/cmd-crypto/cryptoadm/cryptoadm.h (revision 82629e3015252bf18319ba3815c773df23e21436)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_CRYPTOADM_H
27 #define	_CRYPTOADM_H
28 
29 #include <sys/types.h>
30 #include <sys/crypto/ioctladmin.h>
31 #include <cryptoutil.h>
32 #include <security/cryptoki.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #define	_PATH_KCFD		"/lib/crypto/kcfd"
39 #define	TMPFILE_TEMPLATE	"/etc/crypto/admXXXXXX"
40 
41 #define	ERROR_USAGE	2
42 
43 /*
44  * Common keywords and delimiters for pkcs11.conf and kcf.conf files are
45  * defined in usr/lib/libcryptoutil/common/cryptoutil.h.  The following is
46  * the extra keywords and delimiters used in kcf.conf file.
47  */
48 #define	SEP_SLASH		'/'
49 #define	EF_SUPPORTED		"supportedlist="
50 #define	EF_UNLOAD		"unload"
51 #define	RANDOM			"random"
52 #define	UEF_FRAME_LIB		"/usr/lib/libpkcs11.so"
53 
54 #define	ADD_MODE	1
55 #define	DELETE_MODE	2
56 #define	MODIFY_MODE	3
57 
58 #define	REFRESH		1
59 #define	NOT_REFRESH	0
60 
61 typedef char prov_name_t[MAXNAMELEN];
62 typedef char mech_name_t[CRYPTO_MAX_MECH_NAME];
63 
64 typedef struct mechlist {
65 	mech_name_t	name;
66 	struct mechlist	*next;
67 } mechlist_t;
68 
69 
70 typedef struct entry {
71 	prov_name_t	name;
72 	mechlist_t	*suplist; /* supported list */
73 	uint_t		sup_count;
74 	mechlist_t	*dislist; /* disabled list */
75 	uint_t		dis_count;
76 	boolean_t	load; /* B_FALSE after cryptoadm unload */
77 } entry_t;
78 
79 
80 typedef struct entrylist {
81 	entry_t	*pent;
82 	struct entrylist *next;
83 } entrylist_t;
84 
85 typedef enum {
86 	NO_RNG,
87 	HAS_RNG
88 } flag_val_t;
89 
90 extern int errno;
91 
92 /* adm_util */
93 extern boolean_t is_in_list(char *, mechlist_t *);
94 extern mechlist_t *create_mech(char *);
95 extern void free_mechlist(mechlist_t *);
96 
97 /* adm_kef_util */
98 extern boolean_t is_device(char *);
99 extern int fips_update_pkcs11conf(int);
100 extern void fips_status_pkcs11conf(int *);
101 extern char *ent2str(entry_t *);
102 extern entry_t *getent_kef(char *provname,
103 		entrylist_t *pdevlist, entrylist_t *psoftlist);
104 extern int check_kernel_for_soft(char *provname,
105 		crypto_get_soft_list_t *psoftlist, boolean_t *in_kernel);
106 extern int check_kernel_for_hard(char *provname,
107 		crypto_get_dev_list_t *pdevlist, boolean_t *in_kernel);
108 extern int disable_mechs(entry_t **, mechlist_t *, boolean_t, mechlist_t *);
109 extern int enable_mechs(entry_t **, boolean_t, mechlist_t *);
110 extern int get_kcfconf_info(entrylist_t **, entrylist_t **);
111 extern int get_admindev_info(entrylist_t **, entrylist_t **);
112 extern int get_mech_count(mechlist_t *);
113 extern entry_t *create_entry(char *provname);
114 extern int insert_kcfconf(entry_t *);
115 extern int split_hw_provname(char *, char *, int *);
116 extern int update_kcfconf(entry_t *, int);
117 extern void free_entry(entry_t *);
118 extern void free_entrylist(entrylist_t *);
119 extern void print_mechlist(char *, mechlist_t *);
120 extern void print_kef_policy(char *provname, entry_t *pent,
121 		boolean_t has_random, boolean_t has_mechs);
122 extern boolean_t filter_mechlist(mechlist_t **, const char *);
123 extern uentry_t *getent_uef(char *);
124 
125 
126 /* adm_uef */
127 extern int list_mechlist_for_lib(char *, mechlist_t *, flag_val_t *,
128 		boolean_t, boolean_t, boolean_t);
129 extern int list_policy_for_lib(char *);
130 extern int disable_uef_lib(char *, boolean_t, boolean_t, mechlist_t *);
131 extern int enable_uef_lib(char *, boolean_t, boolean_t, mechlist_t *);
132 extern int install_uef_lib(char *);
133 extern int uninstall_uef_lib(char *);
134 extern int print_uef_policy(uentry_t *);
135 extern void display_token_flags(CK_FLAGS flags);
136 extern int convert_mechlist(CK_MECHANISM_TYPE **, CK_ULONG *, mechlist_t *);
137 extern void display_verbose_mech_header();
138 extern void display_mech_info(CK_MECHANISM_INFO *);
139 extern int display_policy(uentry_t *);
140 extern int update_pkcs11conf(uentry_t *);
141 extern int update_policylist(uentry_t *, mechlist_t *, int);
142 
143 /* adm_kef */
144 extern int list_mechlist_for_soft(char *provname,
145 		entrylist_t *phardlist, entrylist_t *psoftlist);
146 extern int list_mechlist_for_hard(char *);
147 extern int list_policy_for_soft(char *provname,
148 		entrylist_t *phardlist, entrylist_t *psoftlist);
149 extern int list_policy_for_hard(char *provname,
150 		entrylist_t *phardlist, entrylist_t *psoftlist,
151 		crypto_get_dev_list_t *pdevlist);
152 extern int disable_kef_software(char *, boolean_t, boolean_t, mechlist_t *);
153 extern int disable_kef_hardware(char *, boolean_t, boolean_t, mechlist_t *);
154 extern int enable_kef(char *, boolean_t, boolean_t, mechlist_t *);
155 extern int install_kef(char *, mechlist_t *);
156 extern int uninstall_kef(char *);
157 extern int unload_kef_soft(char *provname);
158 extern int refresh(void);
159 extern int start_daemon(void);
160 extern int stop_daemon(void);
161 
162 /* adm_ioctl */
163 extern crypto_load_soft_config_t *setup_soft_conf(entry_t *);
164 extern crypto_load_soft_disabled_t *setup_soft_dis(entry_t *);
165 extern crypto_load_dev_disabled_t *setup_dev_dis(entry_t *);
166 extern crypto_unload_soft_module_t *setup_unload_soft(entry_t *);
167 extern int get_dev_info(char *, int, int, mechlist_t **);
168 extern int get_dev_list(crypto_get_dev_list_t **);
169 extern int get_soft_info(char *provname, mechlist_t **ppmechlist,
170 		entrylist_t *phardlist, entrylist_t *psoftlist);
171 extern int get_soft_list(crypto_get_soft_list_t **);
172 extern int do_fips_actions(int, int);
173 
174 /* adm_metaslot */
175 extern int list_metaslot_info(boolean_t, boolean_t, mechlist_t *);
176 extern int list_metaslot_policy();
177 extern int disable_metaslot(mechlist_t *, boolean_t, boolean_t);
178 extern int enable_metaslot(char *, char *, boolean_t, mechlist_t *, boolean_t,
179     boolean_t);
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 
185 #endif /* _CRYPTOADM_H */
186