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 2008 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 typedef struct { 83 int eku_count; 84 int *critlist; 85 KMF_OID *ekulist; 86 } EKU_LIST; 87 88 /* Common functions. */ 89 extern CK_RV init_pk11(void); 90 extern void final_pk11(CK_SESSION_HANDLE sess); 91 92 extern CK_RV login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin, 93 CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess); 94 95 extern CK_RV quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags, 96 CK_UTF8CHAR_PTR pin, CK_ULONG pinlen, 97 CK_SESSION_HANDLE_PTR sess); 98 99 extern CK_RV get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin, 100 CK_ULONG *pinlen); 101 extern boolean_t yesno(char *prompt, char *invalid, boolean_t dflt); 102 103 extern CK_RV get_token_slots(CK_SLOT_ID_PTR *slot_list, 104 CK_ULONG *slot_count); 105 106 extern int get_subname(char **); 107 extern int get_serial(char **); 108 extern int get_certlabel(char **); 109 extern int get_filename(char *, char **); 110 111 extern int getopt_av(int argc, char * const argv[], const char *optstring); 112 extern char *optarg_av; 113 extern int optind_av; 114 115 int OT2Int(char *); 116 int PK2Int(char *); 117 KMF_KEYSTORE_TYPE KS2Int(char *); 118 int Str2KeyType(char *, KMF_KEY_ALG *, KMF_ALGORITHM_INDEX *); 119 int Str2SymKeyType(char *, KMF_KEY_ALG *); 120 int Str2Lifetime(char *, uint32_t *); 121 KMF_RETURN select_token(void *, char *, int); 122 KMF_RETURN configure_nss(void *, char *, char *); 123 124 KMF_ENCODE_FORMAT Str2Format(char *); 125 KMF_RETURN get_pk12_password(KMF_CREDENTIAL *); 126 KMF_RETURN hexstring2bytes(uchar_t *, uchar_t **, size_t *); 127 KMF_RETURN verify_altname(char *arg, KMF_GENERALNAMECHOICES *, int *); 128 KMF_RETURN verify_keyusage(char *arg, uint16_t *, int *); 129 KMF_RETURN verify_file(char *); 130 KMF_RETURN verify_ekunames(char *, EKU_LIST **); 131 132 void free_eku_list(EKU_LIST *); 133 134 int yn_to_int(char *); 135 136 int get_token_password(KMF_KEYSTORE_TYPE, char *, KMF_CREDENTIAL *); 137 void display_error(void *, KMF_RETURN, char *); 138 #define DEFAULT_NSS_TOKEN "internal" 139 #define DEFAULT_TOKEN_PROMPT "Enter PIN for %s: " 140 141 #define EMPTYSTRING(s) (s == NULL || !strlen((char *)s)) 142 143 #ifdef __cplusplus 144 } 145 #endif 146 147 #endif /* _PKTOOL_COMMON_H */ 148