1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _PKTOOL_COMMON_H 27 #define _PKTOOL_COMMON_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 /* 32 * This file contains data and functions shared between all the 33 * modules that comprise this tool. 34 */ 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #include <cryptoutil.h> 41 42 /* I18N helpers. */ 43 #include <libintl.h> 44 #include <locale.h> 45 #include <errno.h> 46 #include <kmfapi.h> 47 48 /* Defines used throughout */ 49 50 /* Error codes */ 51 #define PK_ERR_NONE 0 52 #define PK_ERR_USAGE 1 53 #define PK_ERR_QUIT 2 54 #define PK_ERR_PK11 3 55 #define PK_ERR_SYSTEM 4 56 #define PK_ERR_OPENSSL 5 57 #define PK_ERR_NSS 6 58 59 /* Types of objects for searches. */ 60 #define PK_PRIVATE_OBJ 0x0001 61 #define PK_PUBLIC_OBJ 0x0002 62 #define PK_CERT_OBJ 0x0010 63 #define PK_PRIKEY_OBJ 0x0020 64 #define PK_PUBKEY_OBJ 0x0040 65 #define PK_SYMKEY_OBJ 0x0080 66 #define PK_CRL_OBJ 0x0100 67 68 #define PK_KEY_OBJ (PK_PRIKEY_OBJ | PK_PUBKEY_OBJ | PK_SYMKEY_OBJ) 69 #define PK_ALL_OBJ (PK_PRIVATE_OBJ | PK_PUBLIC_OBJ |\ 70 PK_CERT_OBJ| PK_CRL_OBJ | PK_KEY_OBJ) 71 72 #define PK_DEFAULT_KEYTYPE "rsa" 73 #define PK_DEFAULT_KEYLENGTH 1024 74 #define PK_DEFAULT_DIRECTORY "." 75 #define PK_DEFAULT_SERIALNUM 1 76 #define PK_DEFAULT_PK11TOKEN SOFT_TOKEN_LABEL 77 78 /* Constants for attribute templates. */ 79 extern CK_BBOOL pk_false; 80 extern CK_BBOOL pk_true; 81 82 83 /* Common functions. */ 84 extern CK_RV init_pk11(void); 85 extern void final_pk11(CK_SESSION_HANDLE sess); 86 87 extern CK_RV login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin, 88 CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess); 89 90 extern CK_RV quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags, 91 CK_UTF8CHAR_PTR pin, CK_ULONG pinlen, 92 CK_SESSION_HANDLE_PTR sess); 93 94 extern CK_RV get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin, 95 CK_ULONG *pinlen); 96 extern boolean_t yesno(char *prompt, char *invalid, boolean_t dflt); 97 98 extern CK_RV get_token_slots(CK_SLOT_ID_PTR *slot_list, 99 CK_ULONG *slot_count); 100 101 extern int get_subname(char **); 102 103 extern int getopt_av(int argc, char * const argv[], const char *optstring); 104 extern char *optarg_av; 105 extern int optind_av; 106 107 int OT2Int(char *); 108 int PK2Int(char *); 109 KMF_KEYSTORE_TYPE KS2Int(char *); 110 int Str2KeyType(char *, KMF_KEY_ALG *, KMF_ALGORITHM_INDEX *); 111 int Str2SymKeyType(char *, KMF_KEY_ALG *); 112 int Str2Lifetime(char *, uint32_t *); 113 KMF_RETURN select_token(void *, char *, int); 114 KMF_RETURN configure_nss(void *, char *, char *); 115 116 KMF_ENCODE_FORMAT Str2Format(char *); 117 KMF_RETURN get_pk12_password(KMF_CREDENTIAL *); 118 KMF_RETURN hexstring2bytes(uchar_t *, uchar_t **, size_t *); 119 KMF_RETURN verify_altname(char *arg, KMF_GENERALNAMECHOICES *, int *); 120 KMF_RETURN verify_keyusage(char *arg, uint16_t *, int *); 121 KMF_RETURN verify_file(char *); 122 int get_token_password(KMF_KEYSTORE_TYPE, char *, KMF_CREDENTIAL *); 123 void display_error(void *, KMF_RETURN, char *); 124 #define DEFAULT_NSS_TOKEN "internal" 125 #define DEFAULT_TOKEN_PROMPT "Enter PIN for %s: " 126 127 #define EMPTYSTRING(s) (s == NULL || !strlen((char *)s)) 128 129 #ifdef __cplusplus 130 } 131 #endif 132 133 #endif /* _PKTOOL_COMMON_H */ 134