xref: /titanic_52/usr/src/lib/libcryptoutil/common/cryptoutil.h (revision 10db1377dafab8ba3feedef26db9c5d8539a5cd1)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _CRYPTOUTIL_H
28 #define	_CRYPTOUTIL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <syslog.h>
38 #include <security/cryptoki.h>
39 #include <sys/param.h>
40 
41 #define	LOG_STDERR	-1
42 #define	SUCCESS		0
43 #define	FAILURE		1
44 #define	MECH_ID_HEX_LEN	11	/* length of mechanism id in hex form */
45 
46 #define	_PATH_PKCS11_CONF	"/etc/crypto/pkcs11.conf"
47 #define	_PATH_KCFD_LOCK		"/var/run/kcfd.lock"
48 
49 /* $ISA substitution for parsing pkcs11.conf data */
50 #define	PKCS11_ISA	"/$ISA/"
51 #if defined(_LP64)
52 #define	PKCS11_ISA_DIR	"/64/"
53 #else	/* !_LP64 */
54 #define	PKCS11_ISA_DIR	"/"
55 #endif
56 
57 /* keywords and delimiters for parsing configuration files */
58 #define	SEP_COLON	":"
59 #define	SEP_SEMICOLON	";"
60 #define	SEP_EQUAL	"="
61 #define	SEP_COMMA	","
62 #define	METASLOT_KEYWORD	"metaslot"
63 #define	EF_DISABLED	"disabledlist="
64 #define	EF_ENABLED	"enabledlist="
65 #define	EF_NORANDOM	"NO_RANDOM"
66 #define	METASLOT_TOKEN	"metaslot_token="
67 #define	METASLOT_SLOT	"metaslot_slot="
68 #define	METASLOT_STATUS	"metaslot_status="
69 #define	METASLOT_AUTO_KEY_MIGRATE	"metaslot_auto_key_migrate="
70 #define	METASLOT_ENABLED	"enabled"
71 #define	METASLOT_DISABLED	"disabled"
72 #define	SLOT_DESCRIPTION_SIZE	64
73 #define	TOKEN_LABEL_SIZE	32
74 
75 /*
76  * Define the following softtoken values that are used by softtoken
77  * library, cryptoadm and pktool command.
78  */
79 #define	SOFT_SLOT_DESCRIPTION	\
80 			"Sun Crypto Softtoken            " \
81 			"                                "
82 #define	SOFT_TOKEN_LABEL	"Sun Software PKCS#11 softtoken  "
83 #define	SOFT_TOKEN_SERIAL	"                "
84 #define	SOFT_MANUFACTURER_ID	"Sun Microsystems, Inc.          "
85 #define	SOFT_DEFAULT_PIN	"changeme"
86 
87 typedef char libname_t[MAXPATHLEN];
88 typedef char midstr_t[MECH_ID_HEX_LEN];
89 
90 typedef struct umechlist {
91 	midstr_t		name;	/* mechanism name in hex form */
92 	struct umechlist	*next;
93 } umechlist_t;
94 
95 typedef struct uentry {
96 	libname_t	name;
97 	boolean_t	flag_norandom; /* TRUE if random is disabled */
98 	boolean_t	flag_enabledlist; /* TRUE if an enabledlist */
99 	umechlist_t	*policylist; /* disabledlist or enabledlist */
100 	boolean_t	flag_metaslot_enabled; /* TRUE if metaslot's enabled */
101 	boolean_t	flag_metaslot_auto_key_migrate;
102 	CK_UTF8CHAR	metaslot_ks_slot[SLOT_DESCRIPTION_SIZE + 1];
103 	CK_UTF8CHAR	metaslot_ks_token[TOKEN_LABEL_SIZE + 1];
104 	int 		count;
105 } uentry_t;
106 
107 typedef struct uentrylist {
108 	uentry_t	*puent;
109 	struct uentrylist	*next;
110 } uentrylist_t;
111 
112 extern void cryptodebug(const char *fmt, ...);
113 extern void cryptoerror(int priority, const char *fmt, ...);
114 extern void cryptodebug_init(const char *prefix);
115 
116 extern char *pkcs11_mech2str(CK_MECHANISM_TYPE mech);
117 extern CK_RV pkcs11_str2mech(char *mech_str, CK_MECHANISM_TYPE_PTR mech);
118 
119 extern int get_pkcs11conf_info(uentrylist_t **);
120 extern umechlist_t *create_umech(char *);
121 extern void free_umechlist(umechlist_t *);
122 extern void free_uentrylist(uentrylist_t *);
123 extern void free_uentry(uentry_t *);
124 
125 extern void tohexstr(uchar_t *bytes, size_t blen, char *hexstr, size_t hexlen);
126 extern CK_RV pkcs11_mech2keytype(CK_MECHANISM_TYPE mech_type,
127     CK_KEY_TYPE *ktype);
128 extern char *pkcs11_strerror(CK_RV rv);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* _CRYPTOUTIL_H */
135