xref: /onnv-gate/usr/src/cmd/cmd-crypto/pktool/common.h (revision 17:003a85e6a25c)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*17Sdinak  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef _PKTOOL_COMMON_H
280Sstevel@tonic-gate #define	_PKTOOL_COMMON_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * This file contains data and functions shared between all the
340Sstevel@tonic-gate  * modules that comprise this tool.
350Sstevel@tonic-gate  */
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #ifdef __cplusplus
380Sstevel@tonic-gate extern "C" {
390Sstevel@tonic-gate #endif
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include <cryptoutil.h>
42*17Sdinak #include <biginteger.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /* I18N helpers. */
450Sstevel@tonic-gate #include <libintl.h>
460Sstevel@tonic-gate #include <locale.h>
470Sstevel@tonic-gate 
48*17Sdinak /* Defines used throughout */
49*17Sdinak #define	FULL_NAME_LEN	91	/* See full_token_name() for this number. */
50*17Sdinak 
510Sstevel@tonic-gate /* Error codes */
520Sstevel@tonic-gate #define	PK_ERR_NONE		0
530Sstevel@tonic-gate #define	PK_ERR_USAGE		1
540Sstevel@tonic-gate #define	PK_ERR_QUIT		2
55*17Sdinak #define	PK_ERR_PK11		3
56*17Sdinak #define	PK_ERR_SYSTEM		4
57*17Sdinak #define	PK_ERR_OPENSSL		5
58*17Sdinak 
59*17Sdinak /* Types of objects for searches. */
60*17Sdinak #define	PK_PRIVATE_OBJ		0x0001
61*17Sdinak #define	PK_PUBLIC_OBJ		0x0002
62*17Sdinak #define	PK_CERT_OBJ		0x0010
63*17Sdinak #define	PK_PRIKEY_OBJ		0x0020
64*17Sdinak #define	PK_PUBKEY_OBJ		0x0040
65*17Sdinak #define	PK_SECKEY_OBJ		0x0080
66*17Sdinak 
67*17Sdinak #define	PK_KEY_OBJ		(PK_PRIKEY_OBJ|PK_PUBKEY_OBJ|PK_SECKEY_OBJ)
68*17Sdinak #define	PK_ALL_OBJ		(PK_PRIVATE_OBJ|PK_PUBLIC_OBJ|\
69*17Sdinak 				PK_CERT_OBJ|PK_KEY_OBJ)
70*17Sdinak 
71*17Sdinak /* Constants for attribute templates. */
72*17Sdinak extern CK_BBOOL	pk_false;
73*17Sdinak extern CK_BBOOL	pk_true;
74*17Sdinak 
75*17Sdinak 
76*17Sdinak /* Common functions. */
77*17Sdinak extern CK_RV	init_pk11(void);
78*17Sdinak extern void	final_pk11(CK_SESSION_HANDLE sess);
79*17Sdinak 
80*17Sdinak extern CK_RV	open_sess(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
81*17Sdinak 		    CK_SESSION_HANDLE_PTR sess);
82*17Sdinak extern void	close_sess(CK_SESSION_HANDLE sess);
83*17Sdinak 
84*17Sdinak extern CK_RV	login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin,
85*17Sdinak 		    CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess);
86*17Sdinak extern void	logout_token(CK_SESSION_HANDLE sess);
870Sstevel@tonic-gate 
88*17Sdinak extern CK_RV	quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
89*17Sdinak 		    CK_UTF8CHAR_PTR pin, CK_ULONG pinlen,
90*17Sdinak 		    CK_SESSION_HANDLE_PTR sess);
91*17Sdinak extern void	quick_finish(CK_SESSION_HANDLE sess);
92*17Sdinak 
93*17Sdinak extern CK_RV	get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin,
94*17Sdinak 		    CK_ULONG *pinlen);
95*17Sdinak extern boolean_t	yesno(char *prompt, char *invalid, boolean_t dflt);
96*17Sdinak 
97*17Sdinak extern CK_RV	get_token_slots(CK_SLOT_ID_PTR *slot_list,
98*17Sdinak 		    CK_ULONG *slot_count);
99*17Sdinak extern CK_RV	find_token_slot(char *token_name, char *manuf_id,
100*17Sdinak 		    char *serial_no, CK_SLOT_ID *slot_id, CK_FLAGS *pin_state);
101*17Sdinak 
102*17Sdinak extern CK_RV	find_obj_count(CK_SESSION_HANDLE sess, int obj_type,
103*17Sdinak 		    CK_BYTE *label, CK_ULONG *count);
104*17Sdinak extern CK_RV	find_objs(CK_SESSION_HANDLE sess, int obj_type,
105*17Sdinak 		    CK_BYTE *label, CK_OBJECT_HANDLE_PTR *obj, CK_ULONG *count);
1060Sstevel@tonic-gate 
107*17Sdinak extern void	full_token_name(char *token, char *manuf, char *serial,
108*17Sdinak 		    char *buf);
109*17Sdinak 
110*17Sdinak extern char	*class_str(CK_OBJECT_CLASS class);
111*17Sdinak extern char	*keytype_str(CK_KEY_TYPE keytype);
112*17Sdinak extern char	*attr_str(CK_ATTRIBUTE_TYPE attrtype);
113*17Sdinak 
114*17Sdinak extern void	octetify(CK_BYTE *str, CK_ULONG str_sz, char *oct, int oct_sz,
115*17Sdinak 		    boolean_t stop_on_nul, boolean_t do_ascii, int limit,
116*17Sdinak 		    char *indent, char *blank);
117*17Sdinak 
118*17Sdinak extern void	copy_bigint_to_attr(biginteger_t big, CK_ATTRIBUTE_PTR attr);
119*17Sdinak extern void	copy_string_to_attr(CK_BYTE *buf, CK_ULONG buflen,
120*17Sdinak 		    CK_ATTRIBUTE_PTR attr);
121*17Sdinak extern void	copy_attr_to_bigint(CK_ATTRIBUTE_PTR attr, biginteger_t *big);
122*17Sdinak extern void	copy_attr_to_string(CK_ATTRIBUTE_PTR attr, CK_BYTE **buf,
123*17Sdinak 		    CK_ULONG *buflen);
124*17Sdinak extern void	copy_attr_to_date(CK_ATTRIBUTE_PTR attr, CK_DATE **buf,
125*17Sdinak 		    CK_ULONG *buflen);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate #ifdef __cplusplus
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate #endif
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate #endif /* _PKTOOL_COMMON_H */
132