2 * Copyright (c) 2003,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.
19 * clNssUtils.h - support for libnssasn1-based ASN1 encode/decode
22 #ifndef _CL_NSS_UTILS_H_
23 #define _CL_NSS_UTILS_H_
25 #include <security_asn1/SecNssCoder.h>
26 #include <Security/certExtensionTemplates.h>
27 #include <security_utilities/alloc.h>
28 #include <Security/cssm.h>
29 #include "DecodedCert.h"
32 * A Allocator which is actually based upon a PLArenaPool. This only
33 * mallocs, it doesn't have a free - all memory allocated with this
34 * object is freed when the SecNssCoder associated with this object is
35 * freed. It's used to malloc the fields in DecodedCert.mCert and
38 class ArenaAllocator
: public Security::Allocator
40 NOCOPY(ArenaAllocator
)
42 ArenaAllocator(SecNssCoder
&coder
)
46 void free(void *) _NOEXCEPT
;
47 void *realloc(void *, size_t);
53 * Misc. alloc/copy with arbitrary Allocator
56 /* malloc d.Data, set d.Length */
68 /* return true if two CSSM_DATAs (or two CSSM_OIDs) compare equal */
69 bool clCompareCssmData(
70 const CSSM_DATA
*data1
,
71 const CSSM_DATA
*data2
);
74 * CSSM_DATA --> uint32
77 const CSSM_DATA
&cdata
,
78 CSSM_RETURN toThrow
= CSSMERR_CL_INVALID_CERT_POINTER
);
84 /* CSSM_BOOL <--> CSSM_DATA */
85 CSSM_BOOL
clNssBoolToCssm(
86 const CSSM_DATA
&nssBool
);
93 void clCssmBitStringToNss(
95 void clNssBitStringToCssm(
98 /* How many items in a NULL-terminated array of pointers? */
99 unsigned clNssArraySize(
102 /* malloc a NULL-ed array of pointers of size num+1 */
103 void **clNssNullArray(
107 CE_KeyUsage
clBitStringToKeyUsage(
108 const CSSM_DATA
&cdata
);
110 CSSM_ALGORITHMS
CL_oidToAlg(
111 const CSSM_OID
&oid
);
114 const CSSM_X509_ALGORITHM_IDENTIFIER
&srcAlgId
,
115 CSSM_X509_ALGORITHM_IDENTIFIER
&destAlgId
,
117 void CL_freeCssmAlgId(
118 CSSM_X509_ALGORITHM_IDENTIFIER
*cdsaObj
, // optional
122 bool CL_nssTimeToCssm(
123 const NSS_Time
&derTime
,
124 CSSM_X509_TIME
&cssmObj
,
126 void CL_cssmTimeToNss(
127 const CSSM_X509_TIME
&cssmTime
,
130 void CL_freeCssmTime(
131 CSSM_X509_TIME
*cssmTime
,
134 void CL_nullAlgParams(
135 CSSM_X509_ALGORITHM_IDENTIFIER
&algId
);
137 void CL_copySubjPubKeyInfo(
138 const CSSM_X509_SUBJECT_PUBLIC_KEY_INFO
&srcInfo
,
140 CSSM_X509_SUBJECT_PUBLIC_KEY_INFO
&dstInfo
,
143 CSSM_KEY_PTR
CL_extractCSSMKeyNSS(
144 const CSSM_X509_SUBJECT_PUBLIC_KEY_INFO
&keyInfo
,
146 const DecodedCert
*decodedCert
); // optional
147 void CL_CSSMKeyToSubjPubKeyInfoNSS(
148 const CSSM_KEY
&cssmKey
,
149 CSSM_X509_SUBJECT_PUBLIC_KEY_INFO
&nssKeyInfo
,
152 CSSM_KEY_PTR cssmKey
,
154 bool freeTop
= true); // delete the actual key
155 // as well as contents
157 void CL_cssmAuthorityKeyIdToNss(
158 const CE_AuthorityKeyID
&cdsaObj
,
159 NSS_AuthorityKeyId
&nssObj
,
161 void CL_nssAuthorityKeyIdToCssm(
162 const NSS_AuthorityKeyId
&nssObj
,
163 CE_AuthorityKeyID
&cdsaObj
,
164 SecNssCoder
&coder
, // for temp decoding
167 void CL_cssmInfoAccessToNss(
168 const CE_AuthorityInfoAccess
&cdsaObj
,
169 NSS_AuthorityInfoAccess
&nssObj
,
171 void CL_infoAccessToCssm(
172 const NSS_AuthorityInfoAccess
&nssObj
,
173 CE_AuthorityInfoAccess
&cdsaObj
,
174 SecNssCoder
&coder
, // for temp decoding
176 void CL_freeInfoAccess(
177 CE_AuthorityInfoAccess
&cssmInfo
,
180 void CL_cssmQualCertStatementsToNss(
181 const CE_QC_Statements
&cdsaObj
,
182 NSS_QC_Statements
&nssObj
,
184 void CL_qualCertStatementsToCssm(
185 const NSS_QC_Statements
&nssObj
,
186 CE_QC_Statements
&cdsaObj
,
187 SecNssCoder
&coder
, // for temp decoding
189 void CL_freeQualCertStatements(
190 CE_QC_Statements
&cssmQCs
,
193 void CL_decodeDistributionPointName(
194 const CSSM_DATA
&nssBlob
,
195 CE_DistributionPointName
&cssmDpn
,
198 void CL_encodeDistributionPointName(
199 CE_DistributionPointName
&cpoint
,
202 void CL_cssmDistPointsToNss(
203 const CE_CRLDistPointsSyntax
&cdsaObj
,
204 NSS_CRLDistributionPoints
&nssObj
,
206 void CL_nssDistPointsToCssm(
207 const NSS_CRLDistributionPoints
&nssObj
,
208 CE_CRLDistPointsSyntax
&cdsaObj
,
209 SecNssCoder
&coder
, // for temp decoding
212 void CL_nssIssuingDistPointToCssm(
213 NSS_IssuingDistributionPoint
*nssIdp
,
214 CE_IssuingDistributionPoint
*cssmIdp
,
218 void CL_cssmNameConstraintsToNss(
219 const CE_NameConstraints
&cdsaObj
,
220 NSS_NameConstraints
&nssObj
,
222 void CL_nssNameConstraintsToCssm(
223 const NSS_NameConstraints
&nssObj
,
224 CE_NameConstraints
&cdsaObj
,
225 SecNssCoder
&coder
, // for temp decoding
227 void CL_freeCssmNameConstraints(
228 CE_NameConstraints
*cssmNcs
,
231 void CL_cssmPolicyMappingsToNss(
232 const CE_PolicyMappings
&cdsaObj
,
233 NSS_PolicyMappings
&nssObj
,
235 void CL_nssPolicyMappingsToCssm(
236 const NSS_PolicyMappings
&nssObj
,
237 CE_PolicyMappings
&cdsaObj
,
238 SecNssCoder
&coder
, // for temp decoding
240 void CL_freeCssmPolicyMappings(
241 CE_PolicyMappings
*cssmPms
,
244 void CL_cssmPolicyConstraintsToNss(
245 const CE_PolicyConstraints
*cdsaObj
,
246 NSS_PolicyConstraints
*nssObj
,
248 void CL_nssPolicyConstraintsToCssm(
249 const NSS_PolicyConstraints
*nssObj
,
250 CE_PolicyConstraints
*cdsaObj
,
251 SecNssCoder
&coder
, // for temp decoding
253 void CL_freeCssmPolicyConstraints(
254 CE_PolicyConstraints
*cssmPcs
,
257 CSSM_ALGORITHMS
CL_nssDecodeECDSASigAlgParams(
258 const CSSM_DATA
&algParams
,
261 void CL_certCrlDecodeComponents(
262 const CssmData
&signedItem
, // DER-encoded cert or CRL
263 CssmOwnedData
&tbsBlob
, // still DER-encoded
264 CssmOwnedData
&algId
, // ditto
265 CssmOwnedData
&rawSig
); // raw bits (not an encoded AsnBits)
267 CL_certEncodeComponents(
268 const CssmData
&TBSCert
, // DER-encoded
269 const CssmData
&algId
, // ditto
270 const CssmData
&rawSig
, // raw bits, not encoded
271 CssmOwnedData
&signedCert
); // DER-encoded
273 #endif /* _CL_NSS_UTILS_H_ */