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 /* 22*69648175Shylee * Copyright 2007 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 827711facfSdinak 837711facfSdinak /* Common functions. */ 847711facfSdinak extern CK_RV init_pk11(void); 857711facfSdinak extern void final_pk11(CK_SESSION_HANDLE sess); 867711facfSdinak 877711facfSdinak extern CK_RV login_token(CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin, 887711facfSdinak CK_ULONG pinlen, CK_SESSION_HANDLE_PTR sess); 897711facfSdinak 907711facfSdinak extern CK_RV quick_start(CK_SLOT_ID slot_id, CK_FLAGS sess_flags, 917711facfSdinak CK_UTF8CHAR_PTR pin, CK_ULONG pinlen, 927711facfSdinak CK_SESSION_HANDLE_PTR sess); 937711facfSdinak 947711facfSdinak extern CK_RV get_pin(char *prompt1, char *prompt2, CK_UTF8CHAR_PTR *pin, 957711facfSdinak CK_ULONG *pinlen); 967711facfSdinak extern boolean_t yesno(char *prompt, char *invalid, boolean_t dflt); 977711facfSdinak 987711facfSdinak extern CK_RV get_token_slots(CK_SLOT_ID_PTR *slot_list, 997711facfSdinak CK_ULONG *slot_count); 1007711facfSdinak 10199ebb4caSwyllys extern int get_subname(char **); 1027c478bd9Sstevel@tonic-gate 10349e21299Sdinak extern int getopt_av(int argc, char * const argv[], const char *optstring); 10449e21299Sdinak extern char *optarg_av; 10549e21299Sdinak extern int optind_av; 10649e21299Sdinak 10799ebb4caSwyllys int OT2Int(char *); 10899ebb4caSwyllys int PK2Int(char *); 10999ebb4caSwyllys KMF_KEYSTORE_TYPE KS2Int(char *); 11099ebb4caSwyllys int Str2KeyType(char *, KMF_KEY_ALG *, KMF_ALGORITHM_INDEX *); 11199ebb4caSwyllys int Str2SymKeyType(char *, KMF_KEY_ALG *); 11299ebb4caSwyllys int Str2Lifetime(char *, uint32_t *); 11399ebb4caSwyllys KMF_RETURN select_token(void *, char *, int); 11499ebb4caSwyllys KMF_RETURN configure_nss(void *, char *, char *); 11599ebb4caSwyllys 11699ebb4caSwyllys KMF_ENCODE_FORMAT Str2Format(char *); 11799ebb4caSwyllys KMF_RETURN get_pk12_password(KMF_CREDENTIAL *); 11899ebb4caSwyllys KMF_RETURN hexstring2bytes(uchar_t *, uchar_t **, size_t *); 11999ebb4caSwyllys KMF_RETURN verify_altname(char *arg, KMF_GENERALNAMECHOICES *, int *); 12099ebb4caSwyllys KMF_RETURN verify_keyusage(char *arg, uint16_t *, int *); 12199ebb4caSwyllys KMF_RETURN verify_file(char *); 12299ebb4caSwyllys int get_token_password(KMF_KEYSTORE_TYPE, char *, KMF_CREDENTIAL *); 12399ebb4caSwyllys void display_error(void *, KMF_RETURN, char *); 12499ebb4caSwyllys #define DEFAULT_NSS_TOKEN "internal" 125*69648175Shylee #define DEFAULT_TOKEN_PROMPT "Enter PIN for %s: " 12699ebb4caSwyllys 12799ebb4caSwyllys #define EMPTYSTRING(s) (s == NULL || !strlen((char *)s)) 12899ebb4caSwyllys 1297c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate #endif 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate #endif /* _PKTOOL_COMMON_H */ 134