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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _PKTOOL_COMMON_H 28 #define _PKTOOL_COMMON_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * This file contains data and functions shared between all the 34 * modules that comprise this tool. 35 */ 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #include <cryptoutil.h> 42 #include <biginteger.h> 43 44 /* I18N helpers. */ 45 #include <libintl.h> 46 #include <locale.h> 47 48 /* Defines used throughout */ 49 #define FULL_NAME_LEN 91 /* See full_token_name() for this number. */ 50 51 /* Error codes */ 52 #define PK_ERR_NONE 0 53 #define PK_ERR_USAGE 1 54 #define PK_ERR_QUIT 2 55 #define PK_ERR_PK11 3 56 #define PK_ERR_SYSTEM 4 57 #define PK_ERR_OPENSSL 5 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_SECKEY_OBJ 0x0080 66 67 #define PK_KEY_OBJ (PK_PRIKEY_OBJ|PK_PUBKEY_OBJ|PK_SECKEY_OBJ) 68 #define PK_ALL_OBJ (PK_PRIVATE_OBJ|PK_PUBLIC_OBJ|\ 69 PK_CERT_OBJ|PK_KEY_OBJ) 70 71 /* Constants for attribute templates. */ 72 extern CK_BBOOL pk_false; 73 extern CK_BBOOL pk_true; 74 75 76 /* Common functions. */ 77 extern CK_RV init_pk11(void); 78 extern void final_pk11(CK_SESSION_HANDLE sess); 79 80 extern CK_RV open_sess(CK_SLOT_ID slot_id, CK_FLAGS sess_flags, 81 CK_SESSION_HANDLE_PTR sess); 82 extern void close_sess(CK_SESSION_HANDLE sess); 83 84 extern CK_RV login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin, 85 CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess); 86 extern void logout_token(CK_SESSION_HANDLE sess); 87 88 extern CK_RV quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags, 89 CK_UTF8CHAR_PTR pin, CK_ULONG pinlen, 90 CK_SESSION_HANDLE_PTR sess); 91 extern void quick_finish(CK_SESSION_HANDLE sess); 92 93 extern CK_RV get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin, 94 CK_ULONG *pinlen); 95 extern boolean_t yesno(char *prompt, char *invalid, boolean_t dflt); 96 97 extern CK_RV get_token_slots(CK_SLOT_ID_PTR *slot_list, 98 CK_ULONG *slot_count); 99 extern CK_RV find_token_slot(char *token_name, char *manuf_id, 100 char *serial_no, CK_SLOT_ID *slot_id, CK_FLAGS *pin_state); 101 102 extern CK_RV find_obj_count(CK_SESSION_HANDLE sess, int obj_type, 103 CK_BYTE *label, CK_ULONG *count); 104 extern CK_RV find_objs(CK_SESSION_HANDLE sess, int obj_type, 105 CK_BYTE *label, CK_OBJECT_HANDLE_PTR *obj, CK_ULONG *count); 106 107 extern void full_token_name(char *token, char *manuf, char *serial, 108 char *buf); 109 110 extern char *class_str(CK_OBJECT_CLASS class); 111 extern char *keytype_str(CK_KEY_TYPE keytype); 112 extern char *attr_str(CK_ATTRIBUTE_TYPE attrtype); 113 114 extern void octetify(CK_BYTE *str, CK_ULONG str_sz, char *oct, int oct_sz, 115 boolean_t stop_on_nul, boolean_t do_ascii, int limit, 116 char *indent, char *blank); 117 118 extern void copy_bigint_to_attr(biginteger_t big, CK_ATTRIBUTE_PTR attr); 119 extern void copy_string_to_attr(CK_BYTE *buf, CK_ULONG buflen, 120 CK_ATTRIBUTE_PTR attr); 121 extern void copy_attr_to_bigint(CK_ATTRIBUTE_PTR attr, biginteger_t *big); 122 extern void copy_attr_to_string(CK_ATTRIBUTE_PTR attr, CK_BYTE **buf, 123 CK_ULONG *buflen); 124 extern void copy_attr_to_date(CK_ATTRIBUTE_PTR attr, CK_DATE **buf, 125 CK_ULONG *buflen); 126 127 #ifdef __cplusplus 128 } 129 #endif 130 131 #endif /* _PKTOOL_COMMON_H */ 132