2 * Copyright (c) 2000-2002,2011-2012,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 * CLCrlExtensions.cpp - CRL extensions support.
23 #include "DecodedCrl.h"
24 #include "CLCrlExtensions.h"
25 #include "CLCertExtensions.h"
26 #include "clNssUtils.h"
27 #include "clNameUtils.h"
28 #include "CLFieldsCommon.h"
29 #include <security_utilities/utilities.h>
30 #include <Security/oidscert.h>
31 #include <Security/cssmerr.h>
32 #include <Security/x509defs.h>
33 #include <Security/certextensions.h>
35 #include <Security/SecAsn1Templates.h>
38 *** get/set/free functions called out from CrlFields.cpp
41 *** CrlNumber , DeltaCRL
42 *** CDSA format CE_CrlNumber (a uint32)
43 *** NSS format CSSM_DATA, length 4
44 *** OID CSSMOID_CrlNumber, CSSMOID_DeltaCrlIndicator
47 /* set function for both */
48 void setFieldCrlNumber(
50 const CssmData
&fieldValue
)
52 CSSM_X509_EXTENSION_PTR cssmExt
= verifySetFreeExtension(fieldValue
,
54 CE_CrlNumber
*cdsaObj
= (CE_CrlNumber
*)cssmExt
->value
.parsedValue
;
56 /* CSSM_DATA and its contents in crl.coder's memory */
57 ArenaAllocator
alloc(crl
.coder());
58 CSSM_DATA_PTR nssVal
= (CSSM_DATA_PTR
)alloc
.malloc(sizeof(CSSM_DATA
));
59 clIntToData(*cdsaObj
, *nssVal
, alloc
);
61 /* add to mExtensions */
62 crl
.addExtension(nssVal
, cssmExt
->extnId
, cssmExt
->critical
, false,
63 kSecAsn1IntegerTemplate
);
67 bool getFieldCrlCommon(
69 const CSSM_OID
&fieldId
, // identifies extension we seek
70 unsigned index
, // which occurrence (0 = first)
71 uint32
&numFields
, // RETURNED
72 CssmOwnedData
&fieldValue
)
74 const DecodedExten
*decodedExt
;
76 CE_CrlNumber
*cdsaObj
;
79 brtn
= crl
.GetExtenTop
<CSSM_DATA
, CE_CrlNumber
>(
90 *cdsaObj
= clDataToInt(*nssObj
, CSSMERR_CL_INVALID_CRL_POINTER
);
92 /* pass back to caller */
93 getFieldExtenCommon(cdsaObj
, *decodedExt
, fieldValue
);
97 bool getFieldCrlNumber(
99 unsigned index
, // which occurrence (0 = first)
100 uint32
&numFields
, // RETURNED
101 CssmOwnedData
&fieldValue
)
103 return getFieldCrlCommon(crl
, CSSMOID_CrlNumber
, index
, numFields
,
107 bool getFieldDeltaCrl(
109 unsigned index
, // which occurrence (0 = first)
110 uint32
&numFields
, // RETURNED
111 CssmOwnedData
&fieldValue
)
113 return getFieldCrlCommon(crl
, CSSMOID_DeltaCrlIndicator
, index
,
114 numFields
, fieldValue
);
117 void freeFieldIssuingDistPoint (
118 CssmOwnedData
&fieldValue
)
120 CSSM_X509_EXTENSION_PTR cssmExt
= verifySetFreeExtension(fieldValue
, false);
121 Allocator
&alloc
= fieldValue
.allocator
;
122 CE_IssuingDistributionPoint
*cdsaObj
=
123 (CE_IssuingDistributionPoint
*)cssmExt
->value
.parsedValue
;
124 CL_freeCssmIssuingDistPoint(cdsaObj
, alloc
);
125 freeFieldExtenCommon(cssmExt
, alloc
); // frees extnId, parsedValue, BERvalue
128 void freeFieldCrlDistributionPoints (
129 CssmOwnedData
&fieldValue
)
131 CSSM_X509_EXTENSION_PTR cssmExt
= verifySetFreeExtension(fieldValue
, false);
132 Allocator
&alloc
= fieldValue
.allocator
;
133 CE_CRLDistPointsSyntax
*cdsaObj
=
134 (CE_CRLDistPointsSyntax
*)cssmExt
->value
.parsedValue
;
135 CL_freeCssmDistPoints(cdsaObj
, alloc
);
136 freeFieldExtenCommon(cssmExt
, alloc
); // frees extnId, parsedValue, BERvalue
139 /* HoldInstructionCode - CSSM_OID */
140 /* InvalidityDate - CSSM_DATA */
141 void freeFieldOidOrData (
142 CssmOwnedData
&fieldValue
)
144 CSSM_X509_EXTENSION_PTR cssmExt
= verifySetFreeExtension(fieldValue
, false);
145 Allocator
&alloc
= fieldValue
.allocator
;
147 (CSSM_DATA
*)cssmExt
->value
.parsedValue
;
149 alloc
.free(cdsaObj
->Data
);
151 freeFieldExtenCommon(cssmExt
, alloc
); // frees extnId, parsedValue, BERvalue