2 * Copyright (c) 2003 Apple Computer, 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 <SecurityNssAsn1/SecNssCoder.h>
26 #include <SecurityNssAsn1/certExtensionTemplates.h>
27 #include <Security/cssmalloc.h>
28 #include "DecodedCert.h"
31 * A CssmAllocator which is actually based upon a PLArenaPool. This only
32 * mallocs, it doesn't have a free - all memory allocated with this
33 * object is freed when the SecNssCoder associated with this object is
34 * freed. It's used to malloc the fields in DecodedCert.mCert and
37 class ArenaAllocator
: public Security::CssmAllocator
39 NOCOPY(ArenaAllocator
)
41 ArenaAllocator(SecNssCoder
&coder
)
44 void *malloc(size_t) throw(std::bad_alloc
) ;
45 void free(void *) throw() ;
46 void *realloc(void *, size_t) throw(std::bad_alloc
);
52 * Misc. alloc/copy with arbitrary CssmAllocator
55 /* malloc d.Data, set d.Length */
67 /* return true if two CSSM_DATAs (or two CSSM_OIDs) compare equal */
68 bool clCompareCssmData(
69 const CSSM_DATA
*data1
,
70 const CSSM_DATA
*data2
);
73 * CSSM_DATA --> uint32
76 const CSSM_DATA
&cdata
,
77 CSSM_RETURN toThrow
= CSSMERR_CL_INVALID_CERT_POINTER
);
81 CssmAllocator
&alloc
);
83 /* CSSM_BOOL <--> CSSM_DATA */
84 CSSM_BOOL
clNssBoolToCssm(
85 const CSSM_DATA
&nssBool
);
89 CssmAllocator
&alloc
);
92 void clCssmBitStringToNss(
94 void clNssBitStringToCssm(
97 /* How many items in a NULL-terminated array of pointers? */
98 unsigned clNssArraySize(
101 /* malloc a NULL-ed array of pointers of size num+1 */
102 void **clNssNullArray(
106 CE_KeyUsage
clBitStringToKeyUsage(
107 const CSSM_DATA
&cdata
);
109 CSSM_ALGORITHMS
CL_oidToAlg(
110 const CSSM_OID
&oid
);
113 const CSSM_X509_ALGORITHM_IDENTIFIER
&srcAlgId
,
114 CSSM_X509_ALGORITHM_IDENTIFIER
&destAlgId
,
115 CssmAllocator
&alloc
);
116 void CL_freeCssmAlgId(
117 CSSM_X509_ALGORITHM_IDENTIFIER
*cdsaObj
, // optional
118 CssmAllocator
&alloc
);
121 bool CL_nssTimeToCssm(
122 const NSS_Time
&derTime
,
123 CSSM_X509_TIME
&cssmObj
,
124 CssmAllocator
&alloc
);
125 void CL_cssmTimeToNss(
126 const CSSM_X509_TIME
&cssmTime
,
129 void CL_freeCssmTime(
130 CSSM_X509_TIME
*cssmTime
,
131 CssmAllocator
&alloc
);
133 void CL_nullAlgParams(
134 CSSM_X509_ALGORITHM_IDENTIFIER
&algId
);
136 void CL_copySubjPubKeyInfo(
137 const CSSM_X509_SUBJECT_PUBLIC_KEY_INFO
&srcInfo
,
139 CSSM_X509_SUBJECT_PUBLIC_KEY_INFO
&dstInfo
,
141 CssmAllocator
&alloc
);
142 CSSM_KEY_PTR
CL_extractCSSMKeyNSS(
143 const CSSM_X509_SUBJECT_PUBLIC_KEY_INFO
&keyInfo
,
144 CssmAllocator
&alloc
,
145 const DecodedCert
*decodedCert
); // optional
146 void CL_CSSMKeyToSubjPubKeyInfoNSS(
147 const CSSM_KEY
&cssmKey
,
148 CSSM_X509_SUBJECT_PUBLIC_KEY_INFO
&nssKeyInfo
,
151 CSSM_KEY_PTR cssmKey
,
152 CssmAllocator
&alloc
,
153 bool freeTop
= true); // delete the actual key
154 // as well as contents
156 void CL_cssmAuthorityKeyIdToNss(
157 const CE_AuthorityKeyID
&cdsaObj
,
158 NSS_AuthorityKeyId
&nssObj
,
160 void CL_nssAuthorityKeyIdToCssm(
161 const NSS_AuthorityKeyId
&nssObj
,
162 CE_AuthorityKeyID
&cdsaObj
,
163 SecNssCoder
&coder
, // for temp decoding
164 CssmAllocator
&alloc
);
166 void CL_decodeDistributionPointName(
167 const CSSM_DATA
&nssBlob
,
168 CE_DistributionPointName
&cssmDpn
,
170 CssmAllocator
&alloc
);
171 void CL_encodeDistributionPointName(
172 CE_DistributionPointName
&cpoint
,
175 void CL_cssmDistPointsToNss(
176 const CE_CRLDistPointsSyntax
&cdsaObj
,
177 NSS_CRLDistributionPoints
&nssObj
,
179 void CL_nssDistPointsToCssm(
180 const NSS_CRLDistributionPoints
&nssObj
,
181 CE_CRLDistPointsSyntax
&cdsaObj
,
182 SecNssCoder
&coder
, // for temp decoding
183 CssmAllocator
&alloc
);
185 void CL_nssIssuingDistPointToCssm(
186 NSS_IssuingDistributionPoint
*nssIdp
,
187 CE_IssuingDistributionPoint
*cssmIdp
,
189 CssmAllocator
&alloc
);
191 void CL_certCrlDecodeComponents(
192 const CssmData
&signedItem
, // DER-encoded cert or CRL
193 CssmOwnedData
&tbsBlob
, // still DER-encoded
194 CssmOwnedData
&algId
, // ditto
195 CssmOwnedData
&rawSig
); // raw bits (not an encoded AsnBits)
197 CL_certEncodeComponents(
198 const CssmData
&TBSCert
, // DER-encoded
199 const CssmData
&algId
, // ditto
200 const CssmData
&rawSig
, // raw bits, not encoded
201 CssmOwnedData
&signedCert
); // DER-encoded
203 #endif /* _CL_NSS_UTILS_H_ */