10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51971Skrishna  * Common Development and Distribution License (the "License").
61971Skrishna  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
2210500SHai-May.Chao@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_CRYPTOADM_H
270Sstevel@tonic-gate #define	_CRYPTOADM_H
280Sstevel@tonic-gate 
297968Sopensolaris@drydog.com #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/crypto/ioctladmin.h>
310Sstevel@tonic-gate #include <cryptoutil.h>
320Sstevel@tonic-gate #include <security/cryptoki.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifdef __cplusplus
350Sstevel@tonic-gate extern "C" {
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
388192SJohn.Zolnowsky@Sun.COM #define	_PATH_KCFD		"/lib/crypto/kcfd"
390Sstevel@tonic-gate #define	TMPFILE_TEMPLATE	"/etc/crypto/admXXXXXX"
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #define	ERROR_USAGE	2
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * Common keywords and delimiters for pkcs11.conf and kcf.conf files are
450Sstevel@tonic-gate  * defined in usr/lib/libcryptoutil/common/cryptoutil.h.  The following is
460Sstevel@tonic-gate  * the extra keywords and delimiters used in kcf.conf file.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate #define	SEP_SLASH		'/'
490Sstevel@tonic-gate #define	EF_SUPPORTED		"supportedlist="
507968Sopensolaris@drydog.com #define	EF_UNLOAD		"unload"
510Sstevel@tonic-gate #define	RANDOM			"random"
520Sstevel@tonic-gate #define	UEF_FRAME_LIB		"/usr/lib/libpkcs11.so"
530Sstevel@tonic-gate 
540Sstevel@tonic-gate #define	ADD_MODE	1
550Sstevel@tonic-gate #define	DELETE_MODE	2
560Sstevel@tonic-gate #define	MODIFY_MODE	3
570Sstevel@tonic-gate 
5810500SHai-May.Chao@Sun.COM #define	REFRESH		1
5910500SHai-May.Chao@Sun.COM #define	NOT_REFRESH	0
6010500SHai-May.Chao@Sun.COM 
610Sstevel@tonic-gate typedef char prov_name_t[MAXNAMELEN];
620Sstevel@tonic-gate typedef char mech_name_t[CRYPTO_MAX_MECH_NAME];
630Sstevel@tonic-gate 
640Sstevel@tonic-gate typedef struct mechlist {
650Sstevel@tonic-gate 	mech_name_t	name;
660Sstevel@tonic-gate 	struct mechlist	*next;
670Sstevel@tonic-gate } mechlist_t;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 
700Sstevel@tonic-gate typedef struct entry {
710Sstevel@tonic-gate 	prov_name_t	name;
720Sstevel@tonic-gate 	mechlist_t	*suplist; /* supported list */
737968Sopensolaris@drydog.com 	uint_t		sup_count;
740Sstevel@tonic-gate 	mechlist_t	*dislist; /* disabled list */
757968Sopensolaris@drydog.com 	uint_t		dis_count;
767968Sopensolaris@drydog.com 	boolean_t	load; /* B_FALSE after cryptoadm unload */
770Sstevel@tonic-gate } entry_t;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 
800Sstevel@tonic-gate typedef struct entrylist {
810Sstevel@tonic-gate 	entry_t	*pent;
820Sstevel@tonic-gate 	struct entrylist *next;
830Sstevel@tonic-gate } entrylist_t;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate typedef enum {
860Sstevel@tonic-gate 	NO_RNG,
870Sstevel@tonic-gate 	HAS_RNG
880Sstevel@tonic-gate } flag_val_t;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate extern int errno;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate /* adm_util */
930Sstevel@tonic-gate extern boolean_t is_in_list(char *, mechlist_t *);
940Sstevel@tonic-gate extern mechlist_t *create_mech(char *);
950Sstevel@tonic-gate extern void free_mechlist(mechlist_t *);
960Sstevel@tonic-gate 
970Sstevel@tonic-gate /* adm_kef_util */
980Sstevel@tonic-gate extern boolean_t is_device(char *);
99*10979SHai-May.Chao@Sun.COM extern int fips_update_pkcs11conf(int);
100*10979SHai-May.Chao@Sun.COM extern void fips_status_pkcs11conf(int *);
1010Sstevel@tonic-gate extern char *ent2str(entry_t *);
1027968Sopensolaris@drydog.com extern entry_t *getent_kef(char *provname,
103*10979SHai-May.Chao@Sun.COM 		entrylist_t *pdevlist, entrylist_t *psoftlist);
1047968Sopensolaris@drydog.com extern int check_kernel_for_soft(char *provname,
1057968Sopensolaris@drydog.com 		crypto_get_soft_list_t *psoftlist, boolean_t *in_kernel);
1067968Sopensolaris@drydog.com extern int check_kernel_for_hard(char *provname,
1077968Sopensolaris@drydog.com 		crypto_get_dev_list_t *pdevlist, boolean_t *in_kernel);
1080Sstevel@tonic-gate extern int disable_mechs(entry_t **, mechlist_t *, boolean_t, mechlist_t *);
1090Sstevel@tonic-gate extern int enable_mechs(entry_t **, boolean_t, mechlist_t *);
110*10979SHai-May.Chao@Sun.COM extern int get_kcfconf_info(entrylist_t **, entrylist_t **);
1110Sstevel@tonic-gate extern int get_admindev_info(entrylist_t **, entrylist_t **);
1120Sstevel@tonic-gate extern int get_mech_count(mechlist_t *);
1137968Sopensolaris@drydog.com extern entry_t *create_entry(char *provname);
1140Sstevel@tonic-gate extern int insert_kcfconf(entry_t *);
1150Sstevel@tonic-gate extern int split_hw_provname(char *, char *, int *);
1160Sstevel@tonic-gate extern int update_kcfconf(entry_t *, int);
1170Sstevel@tonic-gate extern void free_entry(entry_t *);
1180Sstevel@tonic-gate extern void free_entrylist(entrylist_t *);
1190Sstevel@tonic-gate extern void print_mechlist(char *, mechlist_t *);
1207968Sopensolaris@drydog.com extern void print_kef_policy(char *provname, entry_t *pent,
1217968Sopensolaris@drydog.com 		boolean_t has_random, boolean_t has_mechs);
1220Sstevel@tonic-gate extern boolean_t filter_mechlist(mechlist_t **, const char *);
1230Sstevel@tonic-gate extern uentry_t *getent_uef(char *);
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /* adm_uef */
1270Sstevel@tonic-gate extern int list_mechlist_for_lib(char *, mechlist_t *, flag_val_t *,
1280Sstevel@tonic-gate 		boolean_t, boolean_t, boolean_t);
1290Sstevel@tonic-gate extern int list_policy_for_lib(char *);
1300Sstevel@tonic-gate extern int disable_uef_lib(char *, boolean_t, boolean_t, mechlist_t *);
1310Sstevel@tonic-gate extern int enable_uef_lib(char *, boolean_t, boolean_t, mechlist_t *);
1320Sstevel@tonic-gate extern int install_uef_lib(char *);
1330Sstevel@tonic-gate extern int uninstall_uef_lib(char *);
1340Sstevel@tonic-gate extern int print_uef_policy(uentry_t *);
1350Sstevel@tonic-gate extern void display_token_flags(CK_FLAGS flags);
1360Sstevel@tonic-gate extern int convert_mechlist(CK_MECHANISM_TYPE **, CK_ULONG *, mechlist_t *);
1370Sstevel@tonic-gate extern void display_verbose_mech_header();
1380Sstevel@tonic-gate extern void display_mech_info(CK_MECHANISM_INFO *);
1390Sstevel@tonic-gate extern int display_policy(uentry_t *);
1400Sstevel@tonic-gate extern int update_pkcs11conf(uentry_t *);
1410Sstevel@tonic-gate extern int update_policylist(uentry_t *, mechlist_t *, int);
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate /* adm_kef */
1447968Sopensolaris@drydog.com extern int list_mechlist_for_soft(char *provname,
145*10979SHai-May.Chao@Sun.COM 		entrylist_t *phardlist, entrylist_t *psoftlist);
1460Sstevel@tonic-gate extern int list_mechlist_for_hard(char *);
1477968Sopensolaris@drydog.com extern int list_policy_for_soft(char *provname,
148*10979SHai-May.Chao@Sun.COM 		entrylist_t *phardlist, entrylist_t *psoftlist);
1497968Sopensolaris@drydog.com extern int list_policy_for_hard(char *provname,
1507968Sopensolaris@drydog.com 		entrylist_t *phardlist, entrylist_t *psoftlist,
1517968Sopensolaris@drydog.com 		crypto_get_dev_list_t *pdevlist);
1520Sstevel@tonic-gate extern int disable_kef_software(char *, boolean_t, boolean_t, mechlist_t *);
1530Sstevel@tonic-gate extern int disable_kef_hardware(char *, boolean_t, boolean_t, mechlist_t *);
1540Sstevel@tonic-gate extern int enable_kef(char *, boolean_t, boolean_t, mechlist_t *);
1550Sstevel@tonic-gate extern int install_kef(char *, mechlist_t *);
1560Sstevel@tonic-gate extern int uninstall_kef(char *);
1577968Sopensolaris@drydog.com extern int unload_kef_soft(char *provname);
1580Sstevel@tonic-gate extern int refresh(void);
1590Sstevel@tonic-gate extern int start_daemon(void);
1600Sstevel@tonic-gate extern int stop_daemon(void);
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate /* adm_ioctl */
1630Sstevel@tonic-gate extern crypto_load_soft_config_t *setup_soft_conf(entry_t *);
1640Sstevel@tonic-gate extern crypto_load_soft_disabled_t *setup_soft_dis(entry_t *);
1650Sstevel@tonic-gate extern crypto_load_dev_disabled_t *setup_dev_dis(entry_t *);
1660Sstevel@tonic-gate extern crypto_unload_soft_module_t *setup_unload_soft(entry_t *);
1670Sstevel@tonic-gate extern int get_dev_info(char *, int, int, mechlist_t **);
1680Sstevel@tonic-gate extern int get_dev_list(crypto_get_dev_list_t **);
1697968Sopensolaris@drydog.com extern int get_soft_info(char *provname, mechlist_t **ppmechlist,
170*10979SHai-May.Chao@Sun.COM 		entrylist_t *phardlist, entrylist_t *psoftlist);
1710Sstevel@tonic-gate extern int get_soft_list(crypto_get_soft_list_t **);
17210500SHai-May.Chao@Sun.COM extern int do_fips_actions(int, int);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate /* adm_metaslot */
1750Sstevel@tonic-gate extern int list_metaslot_info(boolean_t, boolean_t, mechlist_t *);
1760Sstevel@tonic-gate extern int list_metaslot_policy();
1770Sstevel@tonic-gate extern int disable_metaslot(mechlist_t *, boolean_t, boolean_t);
1780Sstevel@tonic-gate extern int enable_metaslot(char *, char *, boolean_t, mechlist_t *, boolean_t,
1790Sstevel@tonic-gate     boolean_t);
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate #ifdef __cplusplus
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate #endif
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate #endif /* _CRYPTOADM_H */
186