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
5*99ebb4caSwyllys  * Common Development and Distribution License (the "License").
6*99ebb4caSwyllys  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*99ebb4caSwyllys  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _PKTOOL_COMMON_H
277c478bd9Sstevel@tonic-gate #define	_PKTOOL_COMMON_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * This file contains data and functions shared between all the
337c478bd9Sstevel@tonic-gate  * modules that comprise this tool.
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef __cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <cryptoutil.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /* I18N helpers. */
437c478bd9Sstevel@tonic-gate #include <libintl.h>
447c478bd9Sstevel@tonic-gate #include <locale.h>
45*99ebb4caSwyllys #include <errno.h>
46*99ebb4caSwyllys #include <kmfapi.h>
477c478bd9Sstevel@tonic-gate 
487711facfSdinak /* Defines used throughout */
497711facfSdinak 
507c478bd9Sstevel@tonic-gate /* Error codes */
517c478bd9Sstevel@tonic-gate #define	PK_ERR_NONE		0
527c478bd9Sstevel@tonic-gate #define	PK_ERR_USAGE		1
537c478bd9Sstevel@tonic-gate #define	PK_ERR_QUIT		2
547711facfSdinak #define	PK_ERR_PK11		3
557711facfSdinak #define	PK_ERR_SYSTEM		4
567711facfSdinak #define	PK_ERR_OPENSSL		5
57*99ebb4caSwyllys #define	PK_ERR_NSS		6
587711facfSdinak 
597711facfSdinak /* Types of objects for searches. */
607711facfSdinak #define	PK_PRIVATE_OBJ		0x0001
617711facfSdinak #define	PK_PUBLIC_OBJ		0x0002
627711facfSdinak #define	PK_CERT_OBJ		0x0010
637711facfSdinak #define	PK_PRIKEY_OBJ		0x0020
647711facfSdinak #define	PK_PUBKEY_OBJ		0x0040
65*99ebb4caSwyllys #define	PK_SYMKEY_OBJ		0x0080
66*99ebb4caSwyllys #define	PK_CRL_OBJ		0x0100
677711facfSdinak 
68*99ebb4caSwyllys #define	PK_KEY_OBJ		(PK_PRIKEY_OBJ | PK_PUBKEY_OBJ | PK_SYMKEY_OBJ)
69*99ebb4caSwyllys #define	PK_ALL_OBJ		(PK_PRIVATE_OBJ | PK_PUBLIC_OBJ |\
70*99ebb4caSwyllys 				PK_CERT_OBJ| PK_CRL_OBJ | PK_KEY_OBJ)
71*99ebb4caSwyllys 
72*99ebb4caSwyllys #define	PK_DEFAULT_KEYTYPE	"rsa"
73*99ebb4caSwyllys #define	PK_DEFAULT_KEYLENGTH	1024
74*99ebb4caSwyllys #define	PK_DEFAULT_DIRECTORY	"."
75*99ebb4caSwyllys #define	PK_DEFAULT_SERIALNUM	1
76*99ebb4caSwyllys #define	PK_DEFAULT_PK11TOKEN	SOFT_TOKEN_LABEL
777711facfSdinak 
787711facfSdinak /* Constants for attribute templates. */
797711facfSdinak extern CK_BBOOL	pk_false;
807711facfSdinak extern CK_BBOOL	pk_true;
817711facfSdinak 
827711facfSdinak 
837711facfSdinak /* Common functions. */
847711facfSdinak extern CK_RV	init_pk11(void);
857711facfSdinak extern void	final_pk11(CK_SESSION_HANDLE sess);
867711facfSdinak 
877711facfSdinak extern CK_RV	login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin,
887711facfSdinak 		    CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess);
897711facfSdinak 
907711facfSdinak extern CK_RV	quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
917711facfSdinak 		    CK_UTF8CHAR_PTR pin, CK_ULONG pinlen,
927711facfSdinak 		    CK_SESSION_HANDLE_PTR sess);
937711facfSdinak 
947711facfSdinak extern CK_RV	get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin,
957711facfSdinak 		    CK_ULONG *pinlen);
967711facfSdinak extern boolean_t	yesno(char *prompt, char *invalid, boolean_t dflt);
977711facfSdinak 
987711facfSdinak extern CK_RV	get_token_slots(CK_SLOT_ID_PTR *slot_list,
997711facfSdinak 		    CK_ULONG *slot_count);
100*99ebb4caSwyllys 
101*99ebb4caSwyllys extern int get_subname(char **);
1027c478bd9Sstevel@tonic-gate 
10349e21299Sdinak extern int	getopt_av(int argc, char * const argv[], const char *optstring);
10449e21299Sdinak extern char	*optarg_av;
10549e21299Sdinak extern int	optind_av;
10649e21299Sdinak 
107*99ebb4caSwyllys int OT2Int(char *);
108*99ebb4caSwyllys int PK2Int(char *);
109*99ebb4caSwyllys KMF_KEYSTORE_TYPE KS2Int(char *);
110*99ebb4caSwyllys int Str2KeyType(char *, KMF_KEY_ALG *, KMF_ALGORITHM_INDEX *);
111*99ebb4caSwyllys int Str2SymKeyType(char *, KMF_KEY_ALG *);
112*99ebb4caSwyllys int Str2Lifetime(char *, uint32_t *);
113*99ebb4caSwyllys KMF_RETURN select_token(void *, char *, int);
114*99ebb4caSwyllys KMF_RETURN configure_nss(void *, char *, char *);
115*99ebb4caSwyllys 
116*99ebb4caSwyllys KMF_ENCODE_FORMAT Str2Format(char *);
117*99ebb4caSwyllys KMF_RETURN get_pk12_password(KMF_CREDENTIAL *);
118*99ebb4caSwyllys KMF_RETURN hexstring2bytes(uchar_t *, uchar_t **, size_t *);
119*99ebb4caSwyllys KMF_RETURN verify_altname(char *arg, KMF_GENERALNAMECHOICES *, int *);
120*99ebb4caSwyllys KMF_RETURN verify_keyusage(char *arg, uint16_t *, int *);
121*99ebb4caSwyllys KMF_RETURN verify_file(char *);
122*99ebb4caSwyllys int get_token_password(KMF_KEYSTORE_TYPE, char *, KMF_CREDENTIAL *);
123*99ebb4caSwyllys void display_error(void *, KMF_RETURN, char *);
124*99ebb4caSwyllys #define	DEFAULT_NSS_TOKEN	"internal"
125*99ebb4caSwyllys #define	DEFAULT_TOKEN_PROMPT	"Enter pin for %s: "
126*99ebb4caSwyllys 
127*99ebb4caSwyllys #define	EMPTYSTRING(s) (s == NULL || !strlen((char *)s))
128*99ebb4caSwyllys 
1297c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate #endif
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #endif /* _PKTOOL_COMMON_H */
134