xref: /onnv-gate/usr/src/cmd/cmd-crypto/pktool/common.h (revision 864:75df3e9f93de)
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 /*
2317Sdinak  * 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>
4217Sdinak #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 
4817Sdinak /* Defines used throughout */
4917Sdinak #define	FULL_NAME_LEN	91	/* See full_token_name() for this number. */
5017Sdinak 
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
5517Sdinak #define	PK_ERR_PK11		3
5617Sdinak #define	PK_ERR_SYSTEM		4
5717Sdinak #define	PK_ERR_OPENSSL		5
5817Sdinak 
5917Sdinak /* Types of objects for searches. */
6017Sdinak #define	PK_PRIVATE_OBJ		0x0001
6117Sdinak #define	PK_PUBLIC_OBJ		0x0002
6217Sdinak #define	PK_CERT_OBJ		0x0010
6317Sdinak #define	PK_PRIKEY_OBJ		0x0020
6417Sdinak #define	PK_PUBKEY_OBJ		0x0040
6517Sdinak #define	PK_SECKEY_OBJ		0x0080
6617Sdinak 
6717Sdinak #define	PK_KEY_OBJ		(PK_PRIKEY_OBJ|PK_PUBKEY_OBJ|PK_SECKEY_OBJ)
6817Sdinak #define	PK_ALL_OBJ		(PK_PRIVATE_OBJ|PK_PUBLIC_OBJ|\
6917Sdinak 				PK_CERT_OBJ|PK_KEY_OBJ)
7017Sdinak 
7117Sdinak /* Constants for attribute templates. */
7217Sdinak extern CK_BBOOL	pk_false;
7317Sdinak extern CK_BBOOL	pk_true;
7417Sdinak 
7517Sdinak 
7617Sdinak /* Common functions. */
7717Sdinak extern CK_RV	init_pk11(void);
7817Sdinak extern void	final_pk11(CK_SESSION_HANDLE sess);
7917Sdinak 
8017Sdinak extern CK_RV	open_sess(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
8117Sdinak 		    CK_SESSION_HANDLE_PTR sess);
8217Sdinak extern void	close_sess(CK_SESSION_HANDLE sess);
8317Sdinak 
8417Sdinak extern CK_RV	login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin,
8517Sdinak 		    CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess);
8617Sdinak extern void	logout_token(CK_SESSION_HANDLE sess);
870Sstevel@tonic-gate 
8817Sdinak extern CK_RV	quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
8917Sdinak 		    CK_UTF8CHAR_PTR pin, CK_ULONG pinlen,
9017Sdinak 		    CK_SESSION_HANDLE_PTR sess);
9117Sdinak extern void	quick_finish(CK_SESSION_HANDLE sess);
9217Sdinak 
9317Sdinak extern CK_RV	get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin,
9417Sdinak 		    CK_ULONG *pinlen);
9517Sdinak extern boolean_t	yesno(char *prompt, char *invalid, boolean_t dflt);
9617Sdinak 
9717Sdinak extern CK_RV	get_token_slots(CK_SLOT_ID_PTR *slot_list,
9817Sdinak 		    CK_ULONG *slot_count);
9917Sdinak extern CK_RV	find_token_slot(char *token_name, char *manuf_id,
10017Sdinak 		    char *serial_no, CK_SLOT_ID *slot_id, CK_FLAGS *pin_state);
10117Sdinak 
10217Sdinak extern CK_RV	find_obj_count(CK_SESSION_HANDLE sess, int obj_type,
10317Sdinak 		    CK_BYTE *label, CK_ULONG *count);
10417Sdinak extern CK_RV	find_objs(CK_SESSION_HANDLE sess, int obj_type,
10517Sdinak 		    CK_BYTE *label, CK_OBJECT_HANDLE_PTR *obj, CK_ULONG *count);
1060Sstevel@tonic-gate 
107*864Sdinak extern int	parse_token_spec(char *spec, char **label, char **manuf,
108*864Sdinak 		    char **buf);
10917Sdinak extern void	full_token_name(char *token, char *manuf, char *serial,
11017Sdinak 		    char *buf);
11117Sdinak 
11217Sdinak extern char	*class_str(CK_OBJECT_CLASS class);
11317Sdinak extern char	*keytype_str(CK_KEY_TYPE keytype);
11417Sdinak extern char	*attr_str(CK_ATTRIBUTE_TYPE attrtype);
11517Sdinak 
11617Sdinak extern void	octetify(CK_BYTE *str, CK_ULONG str_sz, char *oct, int oct_sz,
11717Sdinak 		    boolean_t stop_on_nul, boolean_t do_ascii, int limit,
11817Sdinak 		    char *indent, char *blank);
11917Sdinak 
12017Sdinak extern void	copy_bigint_to_attr(biginteger_t big, CK_ATTRIBUTE_PTR attr);
12117Sdinak extern void	copy_string_to_attr(CK_BYTE *buf, CK_ULONG buflen,
12217Sdinak 		    CK_ATTRIBUTE_PTR attr);
12317Sdinak extern void	copy_attr_to_bigint(CK_ATTRIBUTE_PTR attr, biginteger_t *big);
12417Sdinak extern void	copy_attr_to_string(CK_ATTRIBUTE_PTR attr, CK_BYTE **buf,
12517Sdinak 		    CK_ULONG *buflen);
12617Sdinak extern void	copy_attr_to_date(CK_ATTRIBUTE_PTR attr, CK_DATE **buf,
12717Sdinak 		    CK_ULONG *buflen);
1280Sstevel@tonic-gate 
129*864Sdinak extern int	getopt_av(int argc, char * const argv[], const char *optstring);
130*864Sdinak extern char	*optarg_av;
131*864Sdinak extern int	optind_av;
132*864Sdinak 
1330Sstevel@tonic-gate #ifdef __cplusplus
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate #endif
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate #endif /* _PKTOOL_COMMON_H */
138