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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*7711facfSdinak  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _PKTOOL_COMMON_H
287c478bd9Sstevel@tonic-gate #define	_PKTOOL_COMMON_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * This file contains data and functions shared between all the
347c478bd9Sstevel@tonic-gate  * modules that comprise this tool.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef __cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <cryptoutil.h>
42*7711facfSdinak #include <biginteger.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /* I18N helpers. */
457c478bd9Sstevel@tonic-gate #include <libintl.h>
467c478bd9Sstevel@tonic-gate #include <locale.h>
477c478bd9Sstevel@tonic-gate 
48*7711facfSdinak /* Defines used throughout */
49*7711facfSdinak #define	FULL_NAME_LEN	91	/* See full_token_name() for this number. */
50*7711facfSdinak 
517c478bd9Sstevel@tonic-gate /* Error codes */
527c478bd9Sstevel@tonic-gate #define	PK_ERR_NONE		0
537c478bd9Sstevel@tonic-gate #define	PK_ERR_USAGE		1
547c478bd9Sstevel@tonic-gate #define	PK_ERR_QUIT		2
55*7711facfSdinak #define	PK_ERR_PK11		3
56*7711facfSdinak #define	PK_ERR_SYSTEM		4
57*7711facfSdinak #define	PK_ERR_OPENSSL		5
58*7711facfSdinak 
59*7711facfSdinak /* Types of objects for searches. */
60*7711facfSdinak #define	PK_PRIVATE_OBJ		0x0001
61*7711facfSdinak #define	PK_PUBLIC_OBJ		0x0002
62*7711facfSdinak #define	PK_CERT_OBJ		0x0010
63*7711facfSdinak #define	PK_PRIKEY_OBJ		0x0020
64*7711facfSdinak #define	PK_PUBKEY_OBJ		0x0040
65*7711facfSdinak #define	PK_SECKEY_OBJ		0x0080
66*7711facfSdinak 
67*7711facfSdinak #define	PK_KEY_OBJ		(PK_PRIKEY_OBJ|PK_PUBKEY_OBJ|PK_SECKEY_OBJ)
68*7711facfSdinak #define	PK_ALL_OBJ		(PK_PRIVATE_OBJ|PK_PUBLIC_OBJ|\
69*7711facfSdinak 				PK_CERT_OBJ|PK_KEY_OBJ)
70*7711facfSdinak 
71*7711facfSdinak /* Constants for attribute templates. */
72*7711facfSdinak extern CK_BBOOL	pk_false;
73*7711facfSdinak extern CK_BBOOL	pk_true;
74*7711facfSdinak 
75*7711facfSdinak 
76*7711facfSdinak /* Common functions. */
77*7711facfSdinak extern CK_RV	init_pk11(void);
78*7711facfSdinak extern void	final_pk11(CK_SESSION_HANDLE sess);
79*7711facfSdinak 
80*7711facfSdinak extern CK_RV	open_sess(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
81*7711facfSdinak 		    CK_SESSION_HANDLE_PTR sess);
82*7711facfSdinak extern void	close_sess(CK_SESSION_HANDLE sess);
83*7711facfSdinak 
84*7711facfSdinak extern CK_RV	login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin,
85*7711facfSdinak 		    CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess);
86*7711facfSdinak extern void	logout_token(CK_SESSION_HANDLE sess);
87*7711facfSdinak 
88*7711facfSdinak extern CK_RV	quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
89*7711facfSdinak 		    CK_UTF8CHAR_PTR pin, CK_ULONG pinlen,
90*7711facfSdinak 		    CK_SESSION_HANDLE_PTR sess);
91*7711facfSdinak extern void	quick_finish(CK_SESSION_HANDLE sess);
92*7711facfSdinak 
93*7711facfSdinak extern CK_RV	get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin,
94*7711facfSdinak 		    CK_ULONG *pinlen);
95*7711facfSdinak extern boolean_t	yesno(char *prompt, char *invalid, boolean_t dflt);
96*7711facfSdinak 
97*7711facfSdinak extern CK_RV	get_token_slots(CK_SLOT_ID_PTR *slot_list,
98*7711facfSdinak 		    CK_ULONG *slot_count);
99*7711facfSdinak extern CK_RV	find_token_slot(char *token_name, char *manuf_id,
1007c478bd9Sstevel@tonic-gate 		    char *serial_no, CK_SLOT_ID *slot_id, CK_FLAGS *pin_state);
101*7711facfSdinak 
102*7711facfSdinak extern CK_RV	find_obj_count(CK_SESSION_HANDLE sess, int obj_type,
103*7711facfSdinak 		    CK_BYTE *label, CK_ULONG *count);
104*7711facfSdinak extern CK_RV	find_objs(CK_SESSION_HANDLE sess, int obj_type,
105*7711facfSdinak 		    CK_BYTE *label, CK_OBJECT_HANDLE_PTR *obj, CK_ULONG *count);
106*7711facfSdinak 
107*7711facfSdinak extern void	full_token_name(char *token, char *manuf, char *serial,
108*7711facfSdinak 		    char *buf);
109*7711facfSdinak 
110*7711facfSdinak extern char	*class_str(CK_OBJECT_CLASS class);
111*7711facfSdinak extern char	*keytype_str(CK_KEY_TYPE keytype);
112*7711facfSdinak extern char	*attr_str(CK_ATTRIBUTE_TYPE attrtype);
113*7711facfSdinak 
114*7711facfSdinak extern void	octetify(CK_BYTE *str, CK_ULONG str_sz, char *oct, int oct_sz,
115*7711facfSdinak 		    boolean_t stop_on_nul, boolean_t do_ascii, int limit,
116*7711facfSdinak 		    char *indent, char *blank);
117*7711facfSdinak 
118*7711facfSdinak extern void	copy_bigint_to_attr(biginteger_t big, CK_ATTRIBUTE_PTR attr);
119*7711facfSdinak extern void	copy_string_to_attr(CK_BYTE *buf, CK_ULONG buflen,
120*7711facfSdinak 		    CK_ATTRIBUTE_PTR attr);
121*7711facfSdinak extern void	copy_attr_to_bigint(CK_ATTRIBUTE_PTR attr, biginteger_t *big);
122*7711facfSdinak extern void	copy_attr_to_string(CK_ATTRIBUTE_PTR attr, CK_BYTE **buf,
123*7711facfSdinak 		    CK_ULONG *buflen);
124*7711facfSdinak extern void	copy_attr_to_date(CK_ATTRIBUTE_PTR attr, CK_DATE **buf,
125*7711facfSdinak 		    CK_ULONG *buflen);
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate #endif
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #endif /* _PKTOOL_COMMON_H */
132