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