]> git.saurik.com Git - apple/security.git/blob - CertTool/CertUI.h
Security-164.1.tar.gz
[apple/security.git] / CertTool / CertUI.h
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
33 #ifdef __cplusplus
34 extern "C" {
35
36 enum AbortException {kEOFException};
37
38 /* Dump error info. */
39 void showError(
40 OSStatus ortn,
41 const char *errStr);
42
43 /*
44 * Safe gets().
45 * -- guaranteed no buffer overflow
46 * -- guaranteed NULL-terminated string
47 * -- handles empty string (i.e., response is just CR) properly
48 */
49 void getString(
50 char *buf,
51 unsigned bufSize);
52
53 /*
54 * Prompt and safe getString.
55 */
56 void getStringWithPrompt(
57 const char *prompt, // need not end in newline
58 char *buf,
59 unsigned bufSize);
60
61 /*
62 * Used to interactively cook up an array of CSSM_APPLE_TP_NAME_OIDs, representing
63 * a cert's RDN.
64 */
65 typedef struct {
66 const CSSM_OID *oid; // e.g., CSSMOID_CommonName
67 const char *description; // e.g., "Common Name"
68 const char *example; // e.g., "www.apple.com"
69 } NameOidInfo;
70
71 #define MAX_NAMES 5
72
73 /* Fill in a CSSM_APPLE_TP_NAME_OID array. */
74 void getNameOids(
75 CSSM_APPLE_TP_NAME_OID *subjectNames, // size MAX_NAMES mallocd by caller
76 uint32 *numNames); // RETURNED
77
78 /*
79 * Free strings mallocd in getNameOids.
80 */
81 void freeNameOids(
82 CSSM_APPLE_TP_NAME_OID *subjectNames,
83 uint32 numNames);
84
85 /* get key size and algorithm for subject key */
86 void getKeyParams(
87 CSSM_ALGORITHMS &keyAlg,
88 uint32 &keySizeInBits);
89
90 /* given a signing key, obtain signing algorithm (int and oid format) */
91 OSStatus getSigAlg(
92 const CSSM_KEY *signingKey,
93 CSSM_ALGORITHMS &sigAlg,
94 const CSSM_OID * &sigOid);
95
96 /*
97 * Obtain key usage.
98 */
99
100 /* these are OR-able bitfields */
101 typedef unsigned CU_KeyUsage;
102 #define kKeyUseSigning 0x01
103 #define kKeyUseEncrypting 0x02
104
105 CU_KeyUsage getKeyUsage(bool isRoot);
106
107 #endif
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif /* _CREATECERT_CERT_UI_H_ */