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
599ebb4caSwyllys  * Common Development and Distribution License (the "License").
699ebb4caSwyllys  * 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 /*
22d00756ccSwyllys  * Copyright 2008 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>
4599ebb4caSwyllys #include <errno.h>
4699ebb4caSwyllys #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
5799ebb4caSwyllys #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
6599ebb4caSwyllys #define	PK_SYMKEY_OBJ		0x0080
6699ebb4caSwyllys #define	PK_CRL_OBJ		0x0100
677711facfSdinak 
6899ebb4caSwyllys #define	PK_KEY_OBJ		(PK_PRIKEY_OBJ | PK_PUBKEY_OBJ | PK_SYMKEY_OBJ)
6999ebb4caSwyllys #define	PK_ALL_OBJ		(PK_PRIVATE_OBJ | PK_PUBLIC_OBJ |\
7099ebb4caSwyllys 				PK_CERT_OBJ| PK_CRL_OBJ | PK_KEY_OBJ)
7199ebb4caSwyllys 
7299ebb4caSwyllys #define	PK_DEFAULT_KEYTYPE	"rsa"
7399ebb4caSwyllys #define	PK_DEFAULT_KEYLENGTH	1024
7499ebb4caSwyllys #define	PK_DEFAULT_DIRECTORY	"."
7599ebb4caSwyllys #define	PK_DEFAULT_SERIALNUM	1
7699ebb4caSwyllys #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 
82d00756ccSwyllys typedef struct {
83d00756ccSwyllys 	int	eku_count;
84d00756ccSwyllys 	int	*critlist;
85d00756ccSwyllys 	KMF_OID	*ekulist;
86d00756ccSwyllys } EKU_LIST;
877711facfSdinak 
887711facfSdinak /* Common functions. */
897711facfSdinak extern CK_RV	init_pk11(void);
907711facfSdinak extern void	final_pk11(CK_SESSION_HANDLE sess);
917711facfSdinak 
927711facfSdinak extern CK_RV	login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin,
937711facfSdinak 		    CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess);
947711facfSdinak 
957711facfSdinak extern CK_RV	quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
967711facfSdinak 		    CK_UTF8CHAR_PTR pin, CK_ULONG pinlen,
977711facfSdinak 		    CK_SESSION_HANDLE_PTR sess);
987711facfSdinak 
997711facfSdinak extern CK_RV	get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin,
1007711facfSdinak 		    CK_ULONG *pinlen);
1017711facfSdinak extern boolean_t	yesno(char *prompt, char *invalid, boolean_t dflt);
1027711facfSdinak 
1037711facfSdinak extern CK_RV	get_token_slots(CK_SLOT_ID_PTR *slot_list,
1047711facfSdinak 		    CK_ULONG *slot_count);
10599ebb4caSwyllys 
10699ebb4caSwyllys extern int get_subname(char **);
1072cbed729Swyllys extern int get_serial(char **);
1082cbed729Swyllys extern int get_certlabel(char **);
1092cbed729Swyllys extern int get_filename(char *, char **);
1107c478bd9Sstevel@tonic-gate 
11149e21299Sdinak extern int	getopt_av(int argc, char * const argv[], const char *optstring);
11249e21299Sdinak extern char	*optarg_av;
11349e21299Sdinak extern int	optind_av;
11449e21299Sdinak 
11599ebb4caSwyllys int OT2Int(char *);
11699ebb4caSwyllys int PK2Int(char *);
11799ebb4caSwyllys KMF_KEYSTORE_TYPE KS2Int(char *);
11899ebb4caSwyllys int Str2KeyType(char *, KMF_KEY_ALG *, KMF_ALGORITHM_INDEX *);
11999ebb4caSwyllys int Str2SymKeyType(char *, KMF_KEY_ALG *);
12099ebb4caSwyllys int Str2Lifetime(char *, uint32_t *);
12199ebb4caSwyllys KMF_RETURN select_token(void *, char *, int);
12299ebb4caSwyllys KMF_RETURN configure_nss(void *, char *, char *);
12399ebb4caSwyllys 
12499ebb4caSwyllys KMF_ENCODE_FORMAT Str2Format(char *);
12599ebb4caSwyllys KMF_RETURN get_pk12_password(KMF_CREDENTIAL *);
12699ebb4caSwyllys KMF_RETURN hexstring2bytes(uchar_t *, uchar_t **, size_t *);
12799ebb4caSwyllys KMF_RETURN verify_altname(char *arg, KMF_GENERALNAMECHOICES *, int *);
12899ebb4caSwyllys KMF_RETURN verify_keyusage(char *arg, uint16_t *, int *);
12999ebb4caSwyllys KMF_RETURN verify_file(char *);
130d00756ccSwyllys KMF_RETURN verify_ekunames(char *, EKU_LIST **);
131*fa60c371Swyllys KMF_RETURN token_auth_needed(KMF_HANDLE_T, char *, int *);
132d00756ccSwyllys 
133d00756ccSwyllys void free_eku_list(EKU_LIST *);
134d00756ccSwyllys 
135d00756ccSwyllys int yn_to_int(char *);
136d00756ccSwyllys 
13799ebb4caSwyllys int get_token_password(KMF_KEYSTORE_TYPE, char *, KMF_CREDENTIAL *);
13899ebb4caSwyllys void display_error(void *, KMF_RETURN, char *);
139*fa60c371Swyllys 
14099ebb4caSwyllys #define	DEFAULT_NSS_TOKEN	"internal"
14169648175Shylee #define	DEFAULT_TOKEN_PROMPT	"Enter PIN for %s: "
14299ebb4caSwyllys 
14399ebb4caSwyllys #define	EMPTYSTRING(s) (s == NULL || !strlen((char *)s))
14499ebb4caSwyllys 
1457c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate #endif
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #endif /* _PKTOOL_COMMON_H */
150