]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 A |
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 | * CLCrlExtensions.cpp - CRL extensions support. | |
21 | */ | |
22 | ||
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> | |
34 | ||
35 | #include <Security/SecAsn1Templates.h> | |
36 | ||
37 | /*** | |
38 | *** get/set/free functions called out from CrlFields.cpp | |
39 | ***/ | |
40 | /*** | |
41 | *** CrlNumber , DeltaCRL | |
42 | *** CDSA format CE_CrlNumber (a uint32) | |
43 | *** NSS format CSSM_DATA, length 4 | |
44 | *** OID CSSMOID_CrlNumber, CSSMOID_DeltaCrlIndicator | |
45 | ***/ | |
46 | ||
47 | /* set function for both */ | |
48 | void setFieldCrlNumber( | |
49 | DecodedItem &crl, | |
50 | const CssmData &fieldValue) | |
51 | { | |
52 | CSSM_X509_EXTENSION_PTR cssmExt = verifySetFreeExtension(fieldValue, | |
53 | false); | |
54 | CE_CrlNumber *cdsaObj = (CE_CrlNumber *)cssmExt->value.parsedValue; | |
55 | ||
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); | |
60 | ||
61 | /* add to mExtensions */ | |
62 | crl.addExtension(nssVal, cssmExt->extnId, cssmExt->critical, false, | |
63 | kSecAsn1IntegerTemplate); | |
64 | } | |
65 | ||
66 | ||
67 | bool getFieldCrlCommon( | |
68 | DecodedItem &crl, | |
69 | const CSSM_OID &fieldId, // identifies extension we seek | |
70 | unsigned index, // which occurrence (0 = first) | |
71 | uint32 &numFields, // RETURNED | |
72 | CssmOwnedData &fieldValue) | |
73 | { | |
74 | const DecodedExten *decodedExt; | |
75 | CSSM_DATA *nssObj; | |
76 | CE_CrlNumber *cdsaObj; | |
77 | bool brtn; | |
78 | ||
79 | brtn = crl.GetExtenTop<CSSM_DATA, CE_CrlNumber>( | |
80 | index, | |
81 | numFields, | |
82 | fieldValue.allocator, | |
83 | fieldId, | |
84 | nssObj, | |
85 | cdsaObj, | |
86 | decodedExt); | |
87 | if(!brtn) { | |
88 | return false; | |
89 | } | |
90 | *cdsaObj = clDataToInt(*nssObj, CSSMERR_CL_INVALID_CRL_POINTER); | |
91 | ||
92 | /* pass back to caller */ | |
93 | getFieldExtenCommon(cdsaObj, *decodedExt, fieldValue); | |
94 | return true; | |
95 | } | |
96 | ||
97 | bool getFieldCrlNumber( | |
98 | DecodedItem &crl, | |
99 | unsigned index, // which occurrence (0 = first) | |
100 | uint32 &numFields, // RETURNED | |
101 | CssmOwnedData &fieldValue) | |
102 | { | |
103 | return getFieldCrlCommon(crl, CSSMOID_CrlNumber, index, numFields, | |
104 | fieldValue); | |
105 | } | |
106 | ||
107 | bool getFieldDeltaCrl( | |
108 | DecodedItem &crl, | |
109 | unsigned index, // which occurrence (0 = first) | |
110 | uint32 &numFields, // RETURNED | |
111 | CssmOwnedData &fieldValue) | |
112 | { | |
113 | return getFieldCrlCommon(crl, CSSMOID_DeltaCrlIndicator, index, | |
114 | numFields, fieldValue); | |
115 | } | |
116 | ||
117 | void freeFieldIssuingDistPoint ( | |
118 | CssmOwnedData &fieldValue) | |
119 | { | |
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 | |
126 | } | |
127 | ||
128 | void freeFieldCrlDistributionPoints ( | |
129 | CssmOwnedData &fieldValue) | |
130 | { | |
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 | |
137 | } | |
138 | ||
139 | /* HoldInstructionCode - CSSM_OID */ | |
140 | /* InvalidityDate - CSSM_DATA */ | |
141 | void freeFieldOidOrData ( | |
142 | CssmOwnedData &fieldValue) | |
143 | { | |
144 | CSSM_X509_EXTENSION_PTR cssmExt = verifySetFreeExtension(fieldValue, false); | |
145 | Allocator &alloc = fieldValue.allocator; | |
146 | CSSM_DATA *cdsaObj = | |
147 | (CSSM_DATA *)cssmExt->value.parsedValue; | |
148 | if(cdsaObj) { | |
149 | alloc.free(cdsaObj->Data); | |
150 | } | |
151 | freeFieldExtenCommon(cssmExt, alloc); // frees extnId, parsedValue, BERvalue | |
152 | } | |
153 |