1/*
2 * Copyright (c) 2000-2002 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 obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * 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 EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19/*
20 * CLFieldsCommon.h - get/set/free routines common to certs and CRLs
21 */
22
23#ifndef	_CL_FIELDS_COMMON_H_
24#define _CL_FIELDS_COMMON_H_
25
26#include <Security/cssmtype.h>
27#include <security_cdsa_utilities/cssmdata.h>
28
29#include "DecodedItem.h"
30
31#include <security_utilities/globalizer.h>
32
33#include <Security/X509Templates.h>
34
35#ifdef	__cplusplus
36extern "C" {
37#endif
38
39/*
40 * As of the NSS conversion, getField ops do NOT take a const
41 * DecodedItem argument since many of them use the DecodedItem's
42 * SecNssCoder for intermediate ops.
43 */
44typedef bool (getItemFieldFcn) (
45	DecodedItem			&item,
46	unsigned			index,			// which occurrence (0 = first)
47	uint32				&numFields,		// RETURNED
48	CssmOwnedData		&fieldValue);	// RETURNED
49typedef void (setItemFieldFcn) (
50	DecodedItem			&item,
51	const CssmData		&fieldValue);
52typedef void (freeFieldFcn) (
53	CssmOwnedData		&fieldValue);
54
55bool clOidToNssInfo(
56	const CSSM_OID			&oid,
57	unsigned				&nssObjLen,		// RETURNED
58	const SecAsn1Template	*&templ);		// RETURNED
59
60/*
61 * Routines for common validity checking for certificateToSign fields.
62 *
63 * Call from setField*: verify field isn't already set, optionally validate
64 * input length
65 */
66void tbsSetCheck(
67	void				*fieldToSet,
68	const CssmData		&fieldValue,
69	uint32				expLength,
70	const char			*op);
71
72/*
73 * Call from getField* for unique fields - detect missing field or
74 * index out of bounds.
75 */
76bool tbsGetCheck(
77	const void			*requiredField,
78	uint32				reqIndex);
79
80/* common extension get/set/free */
81void getFieldExtenCommon(
82	void 				*cdsaObj,			// e.g. CE_KeyUsage
83											// CSSM_DATA_PTR for berEncoded
84	const DecodedExten &decodedExt,
85	CssmOwnedData		&fieldValue);
86
87CSSM_X509_EXTENSION_PTR verifySetFreeExtension(
88	const CssmData 		&fieldValue,
89	bool 				berEncoded);		// false: value in value.parsedValue
90											// true : value in BERValue
91void freeFieldExtenCommon(
92	CSSM_X509_EXTENSION_PTR	exten,
93	Allocator			&alloc);
94
95/*
96 * Common code for get/set subject/issuer name (C struct version)
97 */
98bool getField_RDN_NSS (
99	const NSS_Name 		&nssName,
100	CssmOwnedData		&fieldValue);	// RETURNED
101
102void freeField_RDN  (
103	CssmOwnedData		&fieldValue);
104
105/* get normalized RDN */
106bool getField_normRDN_NSS (
107	const CSSM_DATA		&derName,
108	uint32				&numFields,		// RETURNED (if successful, 0 or 1)
109	CssmOwnedData		&fieldValue);	// RETURNED
110
111/*
112 * Common code for Time fields - Validity not before/after, this/next update
113 * Format: CSSM_X509_TIME
114 */
115void freeField_Time (
116	CssmOwnedData	&fieldValue);
117
118bool getField_TimeNSS (
119	const NSS_Time 	&derTime,
120	unsigned		index,			// which occurrence (0 = first)
121	uint32			&numFields,		// RETURNED
122	CssmOwnedData	&fieldValue);	// RETURNED
123void setField_TimeNSS (
124	const CssmData	&fieldValue,
125	NSS_Time		&nssTime,
126	SecNssCoder		&coder);
127
128void getField_AlgIdNSS (
129	const CSSM_X509_ALGORITHM_IDENTIFIER 	&srcAlgId,
130	CssmOwnedData							&fieldValue);	// RETURNED
131void setField_AlgIdNSS (
132	const CssmData					&fieldValue,
133	CSSM_X509_ALGORITHM_IDENTIFIER 	&dstAlgId,
134	SecNssCoder						&coder);
135
136void freeField_AlgId (
137	CssmOwnedData				&fieldValue);
138
139getItemFieldFcn getFieldUnknownExt, getField_Unimplemented;
140setItemFieldFcn setFieldUnknownExt, setField_ReadOnly;
141freeFieldFcn freeFieldUnknownExt, freeFieldSimpleExtension;
142
143#ifdef	__cplusplus
144}
145#endif
146
147#endif	/* _CL_FIELDS_COMMON_H_ */
148