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