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 587c478bd9Sstevel@tonic-gate 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 677c478bd9Sstevel@tonic-gate 6899ebb4caSwyllys #define PK_KEY_OBJ (PK_PRIKEY_OBJ | PK_PUBKEY_OBJ | PK_SYMKEY_OBJ) 697711facfSdinak #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 void final_pk11(CK_SESSION_HANDLE sess); 907711facfSdinak 917711facfSdinak extern CK_RV login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin, 927711facfSdinak CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess); 937711facfSdinak 947711facfSdinak extern CK_RV quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags, 957711facfSdinak CK_UTF8CHAR_PTR pin, CK_ULONG pinlen, 967711facfSdinak CK_SESSION_HANDLE_PTR sess); 977711facfSdinak 987711facfSdinak extern CK_RV get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin, 997711facfSdinak CK_ULONG *pinlen); 1007711facfSdinak extern boolean_t yesno(char *prompt, char *invalid, boolean_t dflt); 1017711facfSdinak 1027711facfSdinak extern CK_RV get_token_slots(CK_SLOT_ID_PTR *slot_list, 1037711facfSdinak CK_ULONG *slot_count); 1047711facfSdinak 10599ebb4caSwyllys extern int get_subname(char **); 1062cbed729Swyllys extern int get_serial(char **); 1072cbed729Swyllys extern int get_certlabel(char **); 1082cbed729Swyllys extern int get_filename(char *, char **); 1097c478bd9Sstevel@tonic-gate 11049e21299Sdinak extern int getopt_av(int argc, char * const argv[], const char *optstring); 11149e21299Sdinak extern char *optarg_av; 11249e21299Sdinak extern int optind_av; 11349e21299Sdinak 11499ebb4caSwyllys int OT2Int(char *); 11599ebb4caSwyllys int PK2Int(char *); 11699ebb4caSwyllys KMF_KEYSTORE_TYPE KS2Int(char *); 11799ebb4caSwyllys int Str2KeyType(char *, KMF_KEY_ALG *, KMF_ALGORITHM_INDEX *); 11899ebb4caSwyllys int Str2SymKeyType(char *, KMF_KEY_ALG *); 11999ebb4caSwyllys int Str2Lifetime(char *, uint32_t *); 12099ebb4caSwyllys KMF_RETURN select_token(void *, char *, int); 12199ebb4caSwyllys KMF_RETURN configure_nss(void *, char *, char *); 12299ebb4caSwyllys 12399ebb4caSwyllys KMF_ENCODE_FORMAT Str2Format(char *); 12499ebb4caSwyllys KMF_RETURN get_pk12_password(KMF_CREDENTIAL *); 12599ebb4caSwyllys KMF_RETURN hexstring2bytes(uchar_t *, uchar_t **, size_t *); 12699ebb4caSwyllys KMF_RETURN verify_altname(char *arg, KMF_GENERALNAMECHOICES *, int *); 12799ebb4caSwyllys KMF_RETURN verify_keyusage(char *arg, uint16_t *, int *); 12899ebb4caSwyllys KMF_RETURN verify_file(char *); 129d00756ccSwyllys KMF_RETURN verify_ekunames(char *, EKU_LIST **); 130fa60c371Swyllys KMF_RETURN token_auth_needed(KMF_HANDLE_T, char *, int *); 131d00756ccSwyllys 132d00756ccSwyllys void free_eku_list(EKU_LIST *); 133d00756ccSwyllys 134d00756ccSwyllys int yn_to_int(char *); 135d00756ccSwyllys 13699ebb4caSwyllys int get_token_password(KMF_KEYSTORE_TYPE, char *, KMF_CREDENTIAL *); 13799ebb4caSwyllys void display_error(void *, KMF_RETURN, char *); 138fa60c371Swyllys 13999ebb4caSwyllys #define DEFAULT_NSS_TOKEN "internal" 14069648175Shylee #define DEFAULT_TOKEN_PROMPT "Enter PIN for %s: " 14199ebb4caSwyllys 14299ebb4caSwyllys #define EMPTYSTRING(s) (s == NULL || !strlen((char *)s)) 143*577f4726Swyllys /* 144*577f4726Swyllys * The "dir" option is only valid with the NSS keystore. This check 145*577f4726Swyllys * forces PK_ERR_USAGE when it is used with non-NSS keystore. 146*577f4726Swyllys */ 147*577f4726Swyllys #define DIR_OPTION_CHECK(k, d) \ 148*577f4726Swyllys if (k != KMF_KEYSTORE_NSS && d != NULL) { \ 149*577f4726Swyllys cryptoerror(LOG_STDERR, gettext("The 'dir' option is " \ 150*577f4726Swyllys "not supported with the indicated keystore\n")); \ 151*577f4726Swyllys return (PK_ERR_USAGE); \ 152*577f4726Swyllys } 153*577f4726Swyllys 15499ebb4caSwyllys 1557c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate #endif 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate #endif /* _PKTOOL_COMMON_H */ 160