2 * Copyright (c) 2000-2002,2011,2014 Apple Inc. All Rights Reserved.
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
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.
20 * DecodedExtensions.h - Intermediate representation of extensions.
23 #ifndef _DECODED_EXTENSIONS_H_
24 #define _DECODED_EXTENSIONS_H_
26 #include <Security/cssmtype.h>
27 #include <security_cdsa_utilities/cssmdata.h>
29 #include <security_asn1/SecNssCoder.h>
30 #include <Security/X509Templates.h>
32 #include "cldebugging.h"
39 /* member variables only set on construct */
41 const CSSM_OID
&extnId
, // copied
43 void *nssObj
, // NSS_KeyUsage, NSS_BasicConstraints,
44 // etc. NOT COPIED, exists in same
45 // memory space as coder
46 bool berEncoded
, // indicates unknown extension
47 // which we do not BER-decode
48 // when parsing a cert
49 const SecAsn1Template
*templ
, // to decode/encode if !berEncoded
50 SecNssCoder
&coder
, // all local allocs from here
51 const CSSM_DATA
*rawExtn
=NULL
); // NSS_CertExtension.value, copied to
52 // mRawExtn, optional (not present
53 // during a SetField op)
57 * Convert this extension to a CSSM_X509_EXTENSION, after its contents
58 * have been converted to a native CDSA object (CE_KeyUsage, etc.).
59 * This is the final step of a getField op involving an extension.
62 void *cdsaObj
, // e.g. CE_KeyUsage
63 // CSSM_DATA_PTR for berEncoded
64 CSSM_X509_EXTENSION_PTR cssmExt
, // contents mallocd in alloc's space
66 Allocator
&alloc
) const;
69 * Convert a DecodedExten to a CSSM_X509_EXTENSION. This includes
70 * the mapping of the extnId to a known CDSA type and type and doing the
71 * actual NSS-to-CDSA conversion.
74 CSSM_X509_EXTENSION_PTR cssmExt
, // mallocd by caller, contents
75 // mallocd in alloc's space,
77 Allocator
&alloc
) const;
79 const CSSM_OID
&extnId() const { return mExtnId
; }
80 bool critical() const { return mCritical
; }
81 void *nssObj() const { return mNssObj
; }
82 bool berEncoded() const { return mBerEncoded
; }
83 const SecAsn1Template
*templ() const { return mTempl
; }
84 CSSM_DATA
*rawExtn() const { return mRawExtn
; }
86 CSSM_X509EXT_TAGandVALUE
*createTagAndValue(
87 const CSSM_DATA
&berValue
,
88 Allocator
&alloc
) const;
92 void *mNssObj
; // NSS_KeyUsage, NSS_BasicConstraints, etc.
93 bool mBerEncoded
; // indicates unknown extension which we
94 // do not BER-decode when parsing a cert
95 const SecAsn1Template
*mTempl
;
96 // used for decode/encode
98 CSSM_DATA
*mRawExtn
; // optional BER-encoded extension data, not
99 // present if created via SetField()
103 * A variable-size array of DecodedExtens.
104 * Used for storing cert and CRL extensions as well as per-CRL-entry
107 class DecodedExtensions
109 NOCOPY(DecodedExtensions
)
112 SecNssCoder
&coder
, // for local allocs
113 Allocator
&alloc
); // for user space (copyout) allocs
114 ~DecodedExtensions();
116 /* Initialize by decoding an NSS-style NSS_CertExtension array */
118 NSS_CertExtension
**extensions
);
120 /* Encode into a NSS-style NSS_CertExtension array, allocating
121 * both the array pointers and the NSS_Extension elements themselves */
123 NSS_CertExtension
**&extensions
);
125 /* add/retrieve entries */
127 const CSSM_OID
&extnId
, // copied
129 void *nssObj
, // NSS_BasicConstraints,
130 // etc. NOT COPIED, exists in same
131 // memory space as coder
132 bool berEncoded
, // indicates unknown extension
133 // which we do not BER-decode
134 // when parsing a cert
135 const SecAsn1Template
*templ
, // required if !berEncoded
136 const CSSM_DATA
*rawExtn
=NULL
); // NSS_CertExtension.value, copied,
137 // optional (not present during a
139 const DecodedExten
*getExtension(
140 unsigned extenDex
) const;
143 * Convert to CSSM_X509_EXTENSIONS, including conversion to
144 * native CDSA C structs. Only used on CRL side, on a getField
145 * returning the entire parsed CRL. */
147 CSSM_X509_EXTENSIONS
&cssmExtens
,
148 Allocator
&alloc
) const;
150 unsigned numExtensions() const { return mNumExtensions
; }
155 DecodedExten
**mExtensions
;
156 unsigned mNumExtensions
; // # valid DecodedExtens
157 unsigned mSizeofExtensions
; // mallocd size in mExtensions
160 #endif /* _DECODED_EXTENSIONS_H_ */