xref: /onnv-gate/usr/src/cmd/cmd-crypto/pktool/common.h (revision 3089:8ddeb2ace8aa)
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
5*3089Swyllys  * Common Development and Distribution License (the "License").
6*3089Swyllys  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*3089Swyllys  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _PKTOOL_COMMON_H
270Sstevel@tonic-gate #define	_PKTOOL_COMMON_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate  * This file contains data and functions shared between all the
330Sstevel@tonic-gate  * modules that comprise this tool.
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef __cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #include <cryptoutil.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /* I18N helpers. */
430Sstevel@tonic-gate #include <libintl.h>
440Sstevel@tonic-gate #include <locale.h>
45*3089Swyllys #include <errno.h>
46*3089Swyllys #include <kmfapi.h>
470Sstevel@tonic-gate 
4817Sdinak /* Defines used throughout */
4917Sdinak 
500Sstevel@tonic-gate /* Error codes */
510Sstevel@tonic-gate #define	PK_ERR_NONE		0
520Sstevel@tonic-gate #define	PK_ERR_USAGE		1
530Sstevel@tonic-gate #define	PK_ERR_QUIT		2
5417Sdinak #define	PK_ERR_PK11		3
5517Sdinak #define	PK_ERR_SYSTEM		4
5617Sdinak #define	PK_ERR_OPENSSL		5
57*3089Swyllys #define	PK_ERR_NSS		6
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
65*3089Swyllys #define	PK_SYMKEY_OBJ		0x0080
66*3089Swyllys #define	PK_CRL_OBJ		0x0100
6717Sdinak 
68*3089Swyllys #define	PK_KEY_OBJ		(PK_PRIKEY_OBJ | PK_PUBKEY_OBJ | PK_SYMKEY_OBJ)
69*3089Swyllys #define	PK_ALL_OBJ		(PK_PRIVATE_OBJ | PK_PUBLIC_OBJ |\
70*3089Swyllys 				PK_CERT_OBJ| PK_CRL_OBJ | PK_KEY_OBJ)
71*3089Swyllys 
72*3089Swyllys #define	PK_DEFAULT_KEYTYPE	"rsa"
73*3089Swyllys #define	PK_DEFAULT_KEYLENGTH	1024
74*3089Swyllys #define	PK_DEFAULT_DIRECTORY	"."
75*3089Swyllys #define	PK_DEFAULT_SERIALNUM	1
76*3089Swyllys #define	PK_DEFAULT_PK11TOKEN	SOFT_TOKEN_LABEL
7717Sdinak 
7817Sdinak /* Constants for attribute templates. */
7917Sdinak extern CK_BBOOL	pk_false;
8017Sdinak extern CK_BBOOL	pk_true;
8117Sdinak 
8217Sdinak 
8317Sdinak /* Common functions. */
8417Sdinak extern CK_RV	init_pk11(void);
8517Sdinak extern void	final_pk11(CK_SESSION_HANDLE sess);
8617Sdinak 
8717Sdinak extern CK_RV	login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin,
8817Sdinak 		    CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess);
890Sstevel@tonic-gate 
9017Sdinak extern CK_RV	quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags,
9117Sdinak 		    CK_UTF8CHAR_PTR pin, CK_ULONG pinlen,
9217Sdinak 		    CK_SESSION_HANDLE_PTR sess);
9317Sdinak 
9417Sdinak extern CK_RV	get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin,
9517Sdinak 		    CK_ULONG *pinlen);
9617Sdinak extern boolean_t	yesno(char *prompt, char *invalid, boolean_t dflt);
9717Sdinak 
9817Sdinak extern CK_RV	get_token_slots(CK_SLOT_ID_PTR *slot_list,
9917Sdinak 		    CK_ULONG *slot_count);
10017Sdinak 
101*3089Swyllys extern int get_subname(char **);
1020Sstevel@tonic-gate 
103864Sdinak extern int	getopt_av(int argc, char * const argv[], const char *optstring);
104864Sdinak extern char	*optarg_av;
105864Sdinak extern int	optind_av;
106864Sdinak 
107*3089Swyllys int OT2Int(char *);
108*3089Swyllys int PK2Int(char *);
109*3089Swyllys KMF_KEYSTORE_TYPE KS2Int(char *);
110*3089Swyllys int Str2KeyType(char *, KMF_KEY_ALG *, KMF_ALGORITHM_INDEX *);
111*3089Swyllys int Str2SymKeyType(char *, KMF_KEY_ALG *);
112*3089Swyllys int Str2Lifetime(char *, uint32_t *);
113*3089Swyllys KMF_RETURN select_token(void *, char *, int);
114*3089Swyllys KMF_RETURN configure_nss(void *, char *, char *);
115*3089Swyllys 
116*3089Swyllys KMF_ENCODE_FORMAT Str2Format(char *);
117*3089Swyllys KMF_RETURN get_pk12_password(KMF_CREDENTIAL *);
118*3089Swyllys KMF_RETURN hexstring2bytes(uchar_t *, uchar_t **, size_t *);
119*3089Swyllys KMF_RETURN verify_altname(char *arg, KMF_GENERALNAMECHOICES *, int *);
120*3089Swyllys KMF_RETURN verify_keyusage(char *arg, uint16_t *, int *);
121*3089Swyllys KMF_RETURN verify_file(char *);
122*3089Swyllys int get_token_password(KMF_KEYSTORE_TYPE, char *, KMF_CREDENTIAL *);
123*3089Swyllys void display_error(void *, KMF_RETURN, char *);
124*3089Swyllys #define	DEFAULT_NSS_TOKEN	"internal"
125*3089Swyllys #define	DEFAULT_TOKEN_PROMPT	"Enter pin for %s: "
126*3089Swyllys 
127*3089Swyllys #define	EMPTYSTRING(s) (s == NULL || !strlen((char *)s))
128*3089Swyllys 
1290Sstevel@tonic-gate #ifdef __cplusplus
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate #endif
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate #endif /* _PKTOOL_COMMON_H */
134