17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5b8bf75cbSkrishna  * Common Development and Distribution License (the "License").
6b8bf75cbSkrishna  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2232e0ab73SMisaki Miyashita  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
24*6ea3c060SGarrett D'Amore /*
25*6ea3c060SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
26*6ea3c060SGarrett D'Amore  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef	_CRYPTOADM_H
297c478bd9Sstevel@tonic-gate #define	_CRYPTOADM_H
307c478bd9Sstevel@tonic-gate 
311b22764fSDaniel OpenSolaris Anderson #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/crypto/ioctladmin.h>
337c478bd9Sstevel@tonic-gate #include <cryptoutil.h>
347c478bd9Sstevel@tonic-gate #include <security/cryptoki.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef __cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	TMPFILE_TEMPLATE	"/etc/crypto/admXXXXXX"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	ERROR_USAGE	2
437c478bd9Sstevel@tonic-gate 
4432e0ab73SMisaki Miyashita #define	HW_PROVIDER_NCP		1
4532e0ab73SMisaki Miyashita #define	HW_PROVIDER_N2CP	2
4632e0ab73SMisaki Miyashita #define	HW_PROVIDER_N2RNG	3
4732e0ab73SMisaki Miyashita 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Common keywords and delimiters for pkcs11.conf and kcf.conf files are
507c478bd9Sstevel@tonic-gate  * defined in usr/lib/libcryptoutil/common/cryptoutil.h.  The following is
517c478bd9Sstevel@tonic-gate  * the extra keywords and delimiters used in kcf.conf file.
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate #define	SEP_SLASH		'/'
547c478bd9Sstevel@tonic-gate #define	EF_SUPPORTED		"supportedlist="
551b22764fSDaniel OpenSolaris Anderson #define	EF_UNLOAD		"unload"
567c478bd9Sstevel@tonic-gate #define	RANDOM			"random"
577c478bd9Sstevel@tonic-gate #define	UEF_FRAME_LIB		"/usr/lib/libpkcs11.so"
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #define	ADD_MODE	1
607c478bd9Sstevel@tonic-gate #define	DELETE_MODE	2
617c478bd9Sstevel@tonic-gate #define	MODIFY_MODE	3
627c478bd9Sstevel@tonic-gate 
63b5a2d845SHai-May Chao #define	REFRESH		1
64b5a2d845SHai-May Chao #define	NOT_REFRESH	0
65b5a2d845SHai-May Chao 
667c478bd9Sstevel@tonic-gate typedef char prov_name_t[MAXNAMELEN];
677c478bd9Sstevel@tonic-gate typedef char mech_name_t[CRYPTO_MAX_MECH_NAME];
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate typedef struct mechlist {
707c478bd9Sstevel@tonic-gate 	mech_name_t	name;
717c478bd9Sstevel@tonic-gate 	struct mechlist	*next;
727c478bd9Sstevel@tonic-gate } mechlist_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate typedef struct entry {
767c478bd9Sstevel@tonic-gate 	prov_name_t	name;
777c478bd9Sstevel@tonic-gate 	mechlist_t	*suplist; /* supported list */
781b22764fSDaniel OpenSolaris Anderson 	uint_t		sup_count;
797c478bd9Sstevel@tonic-gate 	mechlist_t	*dislist; /* disabled list */
801b22764fSDaniel OpenSolaris Anderson 	uint_t		dis_count;
811b22764fSDaniel OpenSolaris Anderson 	boolean_t	load; /* B_FALSE after cryptoadm unload */
827c478bd9Sstevel@tonic-gate } entry_t;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate typedef struct entrylist {
867c478bd9Sstevel@tonic-gate 	entry_t	*pent;
877c478bd9Sstevel@tonic-gate 	struct entrylist *next;
887c478bd9Sstevel@tonic-gate } entrylist_t;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate typedef enum {
917c478bd9Sstevel@tonic-gate 	NO_RNG,
927c478bd9Sstevel@tonic-gate 	HAS_RNG
937c478bd9Sstevel@tonic-gate } flag_val_t;
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate extern int errno;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /* adm_util */
987c478bd9Sstevel@tonic-gate extern boolean_t is_in_list(char *, mechlist_t *);
997c478bd9Sstevel@tonic-gate extern mechlist_t *create_mech(char *);
1007c478bd9Sstevel@tonic-gate extern void free_mechlist(mechlist_t *);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* adm_kef_util */
1037c478bd9Sstevel@tonic-gate extern boolean_t is_device(char *);
1047c478bd9Sstevel@tonic-gate extern char *ent2str(entry_t *);
1051b22764fSDaniel OpenSolaris Anderson extern entry_t *getent_kef(char *provname,
106d616ad8eSHai-May Chao 		entrylist_t *pdevlist, entrylist_t *psoftlist);
1071b22764fSDaniel OpenSolaris Anderson extern int check_kernel_for_soft(char *provname,
1081b22764fSDaniel OpenSolaris Anderson 		crypto_get_soft_list_t *psoftlist, boolean_t *in_kernel);
1091b22764fSDaniel OpenSolaris Anderson extern int check_kernel_for_hard(char *provname,
1101b22764fSDaniel OpenSolaris Anderson 		crypto_get_dev_list_t *pdevlist, boolean_t *in_kernel);
1117c478bd9Sstevel@tonic-gate extern int disable_mechs(entry_t **, mechlist_t *, boolean_t, mechlist_t *);
1127c478bd9Sstevel@tonic-gate extern int enable_mechs(entry_t **, boolean_t, mechlist_t *);
113d616ad8eSHai-May Chao extern int get_kcfconf_info(entrylist_t **, entrylist_t **);
1147c478bd9Sstevel@tonic-gate extern int get_admindev_info(entrylist_t **, entrylist_t **);
1157c478bd9Sstevel@tonic-gate extern int get_mech_count(mechlist_t *);
1161b22764fSDaniel OpenSolaris Anderson extern entry_t *create_entry(char *provname);
1177c478bd9Sstevel@tonic-gate extern int insert_kcfconf(entry_t *);
1187c478bd9Sstevel@tonic-gate extern int split_hw_provname(char *, char *, int *);
1197c478bd9Sstevel@tonic-gate extern int update_kcfconf(entry_t *, int);
1207c478bd9Sstevel@tonic-gate extern void free_entry(entry_t *);
1217c478bd9Sstevel@tonic-gate extern void free_entrylist(entrylist_t *);
1227c478bd9Sstevel@tonic-gate extern void print_mechlist(char *, mechlist_t *);
1231b22764fSDaniel OpenSolaris Anderson extern void print_kef_policy(char *provname, entry_t *pent,
1241b22764fSDaniel OpenSolaris Anderson 		boolean_t has_random, boolean_t has_mechs);
1257c478bd9Sstevel@tonic-gate extern boolean_t filter_mechlist(mechlist_t **, const char *);
1267c478bd9Sstevel@tonic-gate extern uentry_t *getent_uef(char *);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /* adm_uef */
1307c478bd9Sstevel@tonic-gate extern int list_mechlist_for_lib(char *, mechlist_t *, flag_val_t *,
1317c478bd9Sstevel@tonic-gate 		boolean_t, boolean_t, boolean_t);
1327c478bd9Sstevel@tonic-gate extern int list_policy_for_lib(char *);
1337c478bd9Sstevel@tonic-gate extern int disable_uef_lib(char *, boolean_t, boolean_t, mechlist_t *);
1347c478bd9Sstevel@tonic-gate extern int enable_uef_lib(char *, boolean_t, boolean_t, mechlist_t *);
1357c478bd9Sstevel@tonic-gate extern int install_uef_lib(char *);
1367c478bd9Sstevel@tonic-gate extern int uninstall_uef_lib(char *);
1377c478bd9Sstevel@tonic-gate extern int print_uef_policy(uentry_t *);
1387c478bd9Sstevel@tonic-gate extern void display_token_flags(CK_FLAGS flags);
1397c478bd9Sstevel@tonic-gate extern int convert_mechlist(CK_MECHANISM_TYPE **, CK_ULONG *, mechlist_t *);
1407c478bd9Sstevel@tonic-gate extern void display_verbose_mech_header();
1417c478bd9Sstevel@tonic-gate extern void display_mech_info(CK_MECHANISM_INFO *);
1427c478bd9Sstevel@tonic-gate extern int display_policy(uentry_t *);
1437c478bd9Sstevel@tonic-gate extern int update_pkcs11conf(uentry_t *);
1447c478bd9Sstevel@tonic-gate extern int update_policylist(uentry_t *, mechlist_t *, int);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /* adm_kef */
1471b22764fSDaniel OpenSolaris Anderson extern int list_mechlist_for_soft(char *provname,
148d616ad8eSHai-May Chao 		entrylist_t *phardlist, entrylist_t *psoftlist);
1497c478bd9Sstevel@tonic-gate extern int list_mechlist_for_hard(char *);
1501b22764fSDaniel OpenSolaris Anderson extern int list_policy_for_soft(char *provname,
151d616ad8eSHai-May Chao 		entrylist_t *phardlist, entrylist_t *psoftlist);
1521b22764fSDaniel OpenSolaris Anderson extern int list_policy_for_hard(char *provname,
1531b22764fSDaniel OpenSolaris Anderson 		entrylist_t *phardlist, entrylist_t *psoftlist,
1541b22764fSDaniel OpenSolaris Anderson 		crypto_get_dev_list_t *pdevlist);
1557c478bd9Sstevel@tonic-gate extern int disable_kef_software(char *, boolean_t, boolean_t, mechlist_t *);
1567c478bd9Sstevel@tonic-gate extern int disable_kef_hardware(char *, boolean_t, boolean_t, mechlist_t *);
1577c478bd9Sstevel@tonic-gate extern int enable_kef(char *, boolean_t, boolean_t, mechlist_t *);
1587c478bd9Sstevel@tonic-gate extern int install_kef(char *, mechlist_t *);
1597c478bd9Sstevel@tonic-gate extern int uninstall_kef(char *);
1601b22764fSDaniel OpenSolaris Anderson extern int unload_kef_soft(char *provname);
1617c478bd9Sstevel@tonic-gate extern int refresh(void);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /* adm_ioctl */
1647c478bd9Sstevel@tonic-gate extern crypto_load_soft_config_t *setup_soft_conf(entry_t *);
1657c478bd9Sstevel@tonic-gate extern crypto_load_soft_disabled_t *setup_soft_dis(entry_t *);
1667c478bd9Sstevel@tonic-gate extern crypto_load_dev_disabled_t *setup_dev_dis(entry_t *);
1677c478bd9Sstevel@tonic-gate extern crypto_unload_soft_module_t *setup_unload_soft(entry_t *);
1687c478bd9Sstevel@tonic-gate extern int get_dev_info(char *, int, int, mechlist_t **);
1697c478bd9Sstevel@tonic-gate extern int get_dev_list(crypto_get_dev_list_t **);
1701b22764fSDaniel OpenSolaris Anderson extern int get_soft_info(char *provname, mechlist_t **ppmechlist,
171d616ad8eSHai-May Chao 		entrylist_t *phardlist, entrylist_t *psoftlist);
1727c478bd9Sstevel@tonic-gate extern int get_soft_list(crypto_get_soft_list_t **);
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /* adm_metaslot */
1757c478bd9Sstevel@tonic-gate extern int list_metaslot_info(boolean_t, boolean_t, mechlist_t *);
1767c478bd9Sstevel@tonic-gate extern int list_metaslot_policy();
1777c478bd9Sstevel@tonic-gate extern int disable_metaslot(mechlist_t *, boolean_t, boolean_t);
1787c478bd9Sstevel@tonic-gate extern int enable_metaslot(char *, char *, boolean_t, mechlist_t *, boolean_t,
1797c478bd9Sstevel@tonic-gate     boolean_t);
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate #endif
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate #endif /* _CRYPTOADM_H */
186