1/* 2 * Copyright (c) 2002-2003 Apple Computer, Inc. All Rights Reserved. 3 * 4 * The contents of this file constitute Original Code as defined in and are 5 * subject to the Apple Public Source License Version 1.2 (the 'License'). 6 * You may not use this file except in compliance with the License. Please 7 * obtain a copy of the License at http://www.apple.com/publicsource and 8 * read it before using this file. 9 * 10 * This Original Code and all software distributed under the License are 11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 12 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 13 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 14 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 15 * Please see the License for the specific language governing rights and 16 * limitations under the License. 17 */ 18 19/* 20 File: CertUI.h 21 22 Description: stdio-based routines to get cert info from user. 23 24 Author: dmitch 25*/ 26 27#ifndef _CREATECERT_CERT_UI_H_ 28#define _CREATECERT_CERT_UI_H_ 29 30#include <Security/cssmtype.h> 31#include <Security/cssmapple.h> 32#include <MacTypes.h> 33 34#ifdef __cplusplus 35extern "C" { 36 37enum AbortException {kEOFException}; 38 39/* Dump error info. */ 40void showError( 41 OSStatus ortn, 42 const char *errStr); 43 44/* 45 * Safe gets(). 46 * -- guaranteed no buffer overflow 47 * -- guaranteed NULL-terminated string 48 * -- handles empty string (i.e., response is just CR) properly 49 */ 50void getString( 51 char *buf, 52 unsigned bufSize); 53 54/* 55 * Prompt and safe getString. 56 */ 57void getStringWithPrompt( 58 const char *prompt, // need not end in newline 59 char *buf, 60 unsigned bufSize); 61 62/* 63 * Used to interactively cook up an array of CSSM_APPLE_TP_NAME_OIDs, representing 64 * a cert's RDN. 65 */ 66typedef struct { 67 const CSSM_OID *oid; // e.g., CSSMOID_CommonName 68 const char *description; // e.g., "Common Name" 69 const char *example; // e.g., "www.apple.com" 70} NameOidInfo; 71 72#define MAX_NAMES 6 73 74/* Fill in a CSSM_APPLE_TP_NAME_OID array. */ 75void getNameOids( 76 CSSM_APPLE_TP_NAME_OID *subjectNames, // size MAX_NAMES mallocd by caller 77 uint32 *numNames); // RETURNED 78 79/* 80 * Free strings mallocd in getNameOids. 81 */ 82void freeNameOids( 83 CSSM_APPLE_TP_NAME_OID *subjectNames, 84 uint32 numNames); 85 86/* get key size and algorithm for subject key */ 87void getKeyParams( 88 CSSM_ALGORITHMS &keyAlg, 89 uint32 &keySizeInBits); 90 91/* given a signing key, obtain signing algorithm (int and oid format) */ 92OSStatus getSigAlg( 93 const CSSM_KEY *signingKey, 94 CSSM_ALGORITHMS &sigAlg, 95 const CSSM_OID * &sigOid); 96 97/* 98 * Obtain key usage. 99 */ 100 101/* these are OR-able bitfields */ 102typedef unsigned CU_KeyUsage; 103#define kKeyUseSigning 0x01 104#define kKeyUseEncrypting 0x02 105#define kKeyUseDerive 0x04 106 107CU_KeyUsage getKeyUsage(bool isRoot); 108 109#endif 110#ifdef __cplusplus 111} 112#endif 113 114#endif /* _CREATECERT_CERT_UI_H_ */ 115