OLD | NEW |
1 /* -*- Mode: C; tab-width: 8 -*-*/ | 1 /* -*- Mode: C; tab-width: 8 -*-*/ |
2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | 5 |
6 #include "crmf.h" | 6 #include "crmf.h" |
7 #include "crmfi.h" | 7 #include "crmfi.h" |
8 #include "keyhi.h" | 8 #include "keyhi.h" |
9 #include "secder.h" | 9 #include "secder.h" |
10 | 10 |
11 | 11 CRMFPOPChoice CRMF_CertReqMsgGetPOPType(CRMFCertReqMsg *inCertReqMsg) { |
12 CRMFPOPChoice | 12 PORT_Assert(inCertReqMsg != NULL); |
13 CRMF_CertReqMsgGetPOPType(CRMFCertReqMsg *inCertReqMsg) | 13 if (inCertReqMsg != NULL && inCertReqMsg->pop != NULL) { |
14 { | 14 return inCertReqMsg->pop->popUsed; |
15 PORT_Assert(inCertReqMsg != NULL); | 15 } |
16 if (inCertReqMsg != NULL && inCertReqMsg->pop != NULL) { | 16 return crmfNoPOPChoice; |
17 return inCertReqMsg->pop->popUsed; | 17 } |
18 } | 18 |
19 return crmfNoPOPChoice; | 19 static SECStatus crmf_destroy_validity(CRMFOptionalValidity *inValidity, |
20 } | 20 PRBool freeit) { |
21 | 21 if (inValidity != NULL) { |
22 static SECStatus | 22 if (inValidity->notBefore.data != NULL) { |
23 crmf_destroy_validity(CRMFOptionalValidity *inValidity, PRBool freeit) | 23 PORT_Free(inValidity->notBefore.data); |
24 { | 24 } |
25 if (inValidity != NULL){ | 25 if (inValidity->notAfter.data != NULL) { |
26 if (inValidity->notBefore.data != NULL) { | 26 PORT_Free(inValidity->notAfter.data); |
27 » PORT_Free(inValidity->notBefore.data); | 27 } |
28 » } | 28 if (freeit) { |
29 » if (inValidity->notAfter.data != NULL) { | 29 PORT_Free(inValidity); |
30 » PORT_Free(inValidity->notAfter.data); | 30 } |
31 » } | 31 } |
32 » if (freeit) { | 32 return SECSuccess; |
33 » PORT_Free(inValidity); | 33 } |
34 » } | 34 |
35 } | 35 static SECStatus crmf_copy_cert_request_validity( |
36 return SECSuccess; | 36 PLArenaPool *poolp, CRMFOptionalValidity **destValidity, |
37 } | 37 CRMFOptionalValidity *srcValidity) { |
38 | 38 CRMFOptionalValidity *myValidity = NULL; |
39 static SECStatus· | 39 SECStatus rv; |
40 crmf_copy_cert_request_validity(PLArenaPool *poolp, | 40 |
41 » » » » CRMFOptionalValidity **destValidity, | 41 *destValidity = myValidity = |
42 » » » » CRMFOptionalValidity *srcValidity) | 42 (poolp == NULL) ? PORT_ZNew(CRMFOptionalValidity) |
43 { | 43 : PORT_ArenaZNew(poolp, CRMFOptionalValidity); |
44 CRMFOptionalValidity *myValidity = NULL; | 44 if (myValidity == NULL) { |
45 SECStatus rv; | 45 goto loser; |
46 | 46 } |
47 *destValidity = myValidity = (poolp == NULL) ? | 47 if (srcValidity->notBefore.data != NULL) { |
48 PORT_ZNew(CRMFOptionalValidity) : | 48 rv = SECITEM_CopyItem(poolp, &myValidity->notBefore, |
49 PORT_ArenaZNew(poolp, CRMFOptionalValidity); | 49 &srcValidity->notBefore); |
50 if (myValidity == NULL) { | 50 if (rv != SECSuccess) { |
51 goto loser; | 51 goto loser; |
52 } | 52 } |
53 if (srcValidity->notBefore.data != NULL) { | 53 } |
54 rv = SECITEM_CopyItem(poolp, &myValidity->notBefore,· | 54 if (srcValidity->notAfter.data != NULL) { |
55 » » » &srcValidity->notBefore); | 55 rv = SECITEM_CopyItem(poolp, &myValidity->notAfter, &srcValidity->notAfter); |
56 » if (rv != SECSuccess) { | 56 if (rv != SECSuccess) { |
57 » goto loser; | 57 goto loser; |
58 » } | 58 } |
59 } | 59 } |
60 if (srcValidity->notAfter.data != NULL) { | 60 return SECSuccess; |
61 rv = SECITEM_CopyItem(poolp, &myValidity->notAfter,· | 61 loser: |
62 » » » &srcValidity->notAfter); | 62 if (myValidity != NULL && poolp == NULL) { |
63 » if (rv != SECSuccess) { | 63 crmf_destroy_validity(myValidity, PR_TRUE); |
64 » goto loser; | 64 } |
65 » } | 65 return SECFailure; |
66 } | 66 } |
67 return SECSuccess; | 67 |
68 loser: | 68 static SECStatus crmf_copy_extensions(PLArenaPool *poolp, |
69 if (myValidity != NULL && poolp == NULL) { | 69 CRMFCertTemplate *destTemplate, |
70 crmf_destroy_validity(myValidity, PR_TRUE); | 70 CRMFCertExtension **srcExt) { |
71 } | 71 int numExt = 0, i; |
72 return SECFailure; | 72 CRMFCertExtension **myExtArray = NULL; |
73 } | 73 |
74 | 74 while (srcExt[numExt] != NULL) { |
75 static SECStatus | 75 numExt++; |
76 crmf_copy_extensions(PLArenaPool *poolp, | 76 } |
77 » » CRMFCertTemplate *destTemplate, | 77 if (numExt == 0) { |
78 » » CRMFCertExtension **srcExt) | 78 /*No extensions to copy.*/ |
79 { | |
80 int numExt = 0, i; | |
81 CRMFCertExtension **myExtArray = NULL; | |
82 | |
83 while (srcExt[numExt] != NULL) { | |
84 numExt++; | |
85 } | |
86 if (numExt == 0) { | |
87 /*No extensions to copy.*/ | |
88 destTemplate->extensions = NULL; | |
89 » destTemplate->numExtensions = 0; | |
90 return SECSuccess; | |
91 } | |
92 destTemplate->extensions = myExtArray =· | |
93 PORT_NewArray(CRMFCertExtension*, numExt+1); | |
94 if (myExtArray == NULL) { | |
95 goto loser; | |
96 } | |
97 ····· | |
98 for (i=0; i<numExt; i++) { | |
99 myExtArray[i] = crmf_copy_cert_extension(poolp, srcExt[i]); | |
100 » if (myExtArray[i] == NULL) { | |
101 » goto loser; | |
102 » } | |
103 } | |
104 destTemplate->numExtensions = numExt; | |
105 myExtArray[numExt] = NULL; | |
106 return SECSuccess; | |
107 loser: | |
108 if (myExtArray != NULL) { | |
109 if (poolp == NULL) { | |
110 » for (i=0; myExtArray[i] != NULL; i++) { | |
111 » CRMF_DestroyCertExtension(myExtArray[i]); | |
112 » } | |
113 » } | |
114 » PORT_Free(myExtArray); | |
115 } | |
116 destTemplate->extensions = NULL; | 79 destTemplate->extensions = NULL; |
117 destTemplate->numExtensions = 0; | 80 destTemplate->numExtensions = 0; |
118 return SECFailure; | |
119 } | |
120 | |
121 static SECStatus | |
122 crmf_copy_cert_request_template(PLArenaPool *poolp, | |
123 CRMFCertTemplate *destTemplate, | |
124 CRMFCertTemplate *srcTemplate) | |
125 { | |
126 SECStatus rv; | |
127 | |
128 if (srcTemplate->version.data != NULL) { | |
129 rv = SECITEM_CopyItem(poolp, &destTemplate->version,· | |
130 &srcTemplate->version); | |
131 if (rv != SECSuccess) { | |
132 goto loser; | |
133 } | |
134 } | |
135 if (srcTemplate->serialNumber.data != NULL) { | |
136 rv = SECITEM_CopyItem(poolp, &destTemplate->serialNumber, | |
137 &srcTemplate->serialNumber); | |
138 if (rv != SECSuccess) { | |
139 goto loser; | |
140 } | |
141 } | |
142 if (srcTemplate->signingAlg != NULL) { | |
143 rv = crmf_template_copy_secalg(poolp, &destTemplate->signingAlg, | |
144 srcTemplate->signingAlg); | |
145 if (rv != SECSuccess) { | |
146 goto loser; | |
147 } | |
148 } | |
149 if (srcTemplate->issuer != NULL) { | |
150 rv = crmf_copy_cert_name(poolp, &destTemplate->issuer, | |
151 srcTemplate->issuer); | |
152 if (rv != SECSuccess) { | |
153 goto loser; | |
154 } | |
155 } | |
156 if (srcTemplate->validity != NULL) { | |
157 rv = crmf_copy_cert_request_validity(poolp, &destTemplate->validity, | |
158 srcTemplate->validity); | |
159 if (rv != SECSuccess) { | |
160 goto loser; | |
161 } | |
162 } | |
163 if (srcTemplate->subject != NULL) { | |
164 rv = crmf_copy_cert_name(poolp, &destTemplate->subject,· | |
165 srcTemplate->subject); | |
166 if (rv != SECSuccess) { | |
167 goto loser; | |
168 } | |
169 } | |
170 if (srcTemplate->publicKey != NULL) { | |
171 rv = crmf_template_add_public_key(poolp, &destTemplate->publicKey, | |
172 srcTemplate->publicKey); | |
173 if (rv != SECSuccess) { | |
174 goto loser; | |
175 } | |
176 } | |
177 if (srcTemplate->issuerUID.data != NULL) { | |
178 rv = crmf_make_bitstring_copy(poolp, &destTemplate->issuerUID, | |
179 &srcTemplate->issuerUID); | |
180 if (rv != SECSuccess) { | |
181 goto loser; | |
182 } | |
183 } | |
184 if (srcTemplate->subjectUID.data != NULL) { | |
185 rv = crmf_make_bitstring_copy(poolp, &destTemplate->subjectUID, | |
186 &srcTemplate->subjectUID); | |
187 if (rv != SECSuccess) { | |
188 goto loser; | |
189 } | |
190 } | |
191 if (srcTemplate->extensions != NULL) { | |
192 rv = crmf_copy_extensions(poolp, destTemplate, | |
193 srcTemplate->extensions); | |
194 if (rv != SECSuccess) { | |
195 goto loser; | |
196 } | |
197 } | |
198 return SECSuccess; | 81 return SECSuccess; |
199 loser: | 82 } |
200 return SECFailure; | 83 destTemplate->extensions = myExtArray = |
201 } | 84 PORT_NewArray(CRMFCertExtension *, numExt + 1); |
202 | 85 if (myExtArray == NULL) { |
203 static CRMFControl* | 86 goto loser; |
204 crmf_copy_control(PLArenaPool *poolp, CRMFControl *srcControl) | 87 } |
205 { | 88 |
206 CRMFControl *newControl; | 89 for (i = 0; i < numExt; i++) { |
207 SECStatus rv; | 90 myExtArray[i] = crmf_copy_cert_extension(poolp, srcExt[i]); |
208 | 91 if (myExtArray[i] == NULL) { |
209 newControl = (poolp == NULL) ? PORT_ZNew(CRMFControl) : | 92 goto loser; |
210 PORT_ArenaZNew(poolp, CRMFControl); | 93 } |
211 if (newControl == NULL) { | 94 } |
212 goto loser; | 95 destTemplate->numExtensions = numExt; |
213 } | 96 myExtArray[numExt] = NULL; |
214 newControl->tag = srcControl->tag; | 97 return SECSuccess; |
215 rv = SECITEM_CopyItem(poolp, &newControl->derTag, &srcControl->derTag); | 98 loser: |
216 if (rv != SECSuccess) { | 99 if (myExtArray != NULL) { |
217 goto loser; | 100 if (poolp == NULL) { |
218 } | 101 for (i = 0; myExtArray[i] != NULL; i++) { |
219 rv = SECITEM_CopyItem(poolp, &newControl->derValue, &srcControl->derValue); | 102 CRMF_DestroyCertExtension(myExtArray[i]); |
220 if (rv != SECSuccess) { | 103 } |
221 goto loser; | 104 } |
222 } | 105 PORT_Free(myExtArray); |
223 /* We only handle PKIArchiveOptions Control right now. But if in | 106 } |
224 * the future, more controls that are part of the union are added, | 107 destTemplate->extensions = NULL; |
225 * then they need to be handled here as well. | 108 destTemplate->numExtensions = 0; |
226 */ | 109 return SECFailure; |
227 switch (newControl->tag) { | 110 } |
| 111 |
| 112 static SECStatus crmf_copy_cert_request_template( |
| 113 PLArenaPool *poolp, CRMFCertTemplate *destTemplate, |
| 114 CRMFCertTemplate *srcTemplate) { |
| 115 SECStatus rv; |
| 116 |
| 117 if (srcTemplate->version.data != NULL) { |
| 118 rv = SECITEM_CopyItem(poolp, &destTemplate->version, &srcTemplate->version); |
| 119 if (rv != SECSuccess) { |
| 120 goto loser; |
| 121 } |
| 122 } |
| 123 if (srcTemplate->serialNumber.data != NULL) { |
| 124 rv = SECITEM_CopyItem(poolp, &destTemplate->serialNumber, |
| 125 &srcTemplate->serialNumber); |
| 126 if (rv != SECSuccess) { |
| 127 goto loser; |
| 128 } |
| 129 } |
| 130 if (srcTemplate->signingAlg != NULL) { |
| 131 rv = crmf_template_copy_secalg(poolp, &destTemplate->signingAlg, |
| 132 srcTemplate->signingAlg); |
| 133 if (rv != SECSuccess) { |
| 134 goto loser; |
| 135 } |
| 136 } |
| 137 if (srcTemplate->issuer != NULL) { |
| 138 rv = crmf_copy_cert_name(poolp, &destTemplate->issuer, srcTemplate->issuer); |
| 139 if (rv != SECSuccess) { |
| 140 goto loser; |
| 141 } |
| 142 } |
| 143 if (srcTemplate->validity != NULL) { |
| 144 rv = crmf_copy_cert_request_validity(poolp, &destTemplate->validity, |
| 145 srcTemplate->validity); |
| 146 if (rv != SECSuccess) { |
| 147 goto loser; |
| 148 } |
| 149 } |
| 150 if (srcTemplate->subject != NULL) { |
| 151 rv = crmf_copy_cert_name(poolp, &destTemplate->subject, |
| 152 srcTemplate->subject); |
| 153 if (rv != SECSuccess) { |
| 154 goto loser; |
| 155 } |
| 156 } |
| 157 if (srcTemplate->publicKey != NULL) { |
| 158 rv = crmf_template_add_public_key(poolp, &destTemplate->publicKey, |
| 159 srcTemplate->publicKey); |
| 160 if (rv != SECSuccess) { |
| 161 goto loser; |
| 162 } |
| 163 } |
| 164 if (srcTemplate->issuerUID.data != NULL) { |
| 165 rv = crmf_make_bitstring_copy(poolp, &destTemplate->issuerUID, |
| 166 &srcTemplate->issuerUID); |
| 167 if (rv != SECSuccess) { |
| 168 goto loser; |
| 169 } |
| 170 } |
| 171 if (srcTemplate->subjectUID.data != NULL) { |
| 172 rv = crmf_make_bitstring_copy(poolp, &destTemplate->subjectUID, |
| 173 &srcTemplate->subjectUID); |
| 174 if (rv != SECSuccess) { |
| 175 goto loser; |
| 176 } |
| 177 } |
| 178 if (srcTemplate->extensions != NULL) { |
| 179 rv = crmf_copy_extensions(poolp, destTemplate, srcTemplate->extensions); |
| 180 if (rv != SECSuccess) { |
| 181 goto loser; |
| 182 } |
| 183 } |
| 184 return SECSuccess; |
| 185 loser: |
| 186 return SECFailure; |
| 187 } |
| 188 |
| 189 static CRMFControl *crmf_copy_control(PLArenaPool *poolp, |
| 190 CRMFControl *srcControl) { |
| 191 CRMFControl *newControl; |
| 192 SECStatus rv; |
| 193 |
| 194 newControl = (poolp == NULL) ? PORT_ZNew(CRMFControl) |
| 195 : PORT_ArenaZNew(poolp, CRMFControl); |
| 196 if (newControl == NULL) { |
| 197 goto loser; |
| 198 } |
| 199 newControl->tag = srcControl->tag; |
| 200 rv = SECITEM_CopyItem(poolp, &newControl->derTag, &srcControl->derTag); |
| 201 if (rv != SECSuccess) { |
| 202 goto loser; |
| 203 } |
| 204 rv = SECITEM_CopyItem(poolp, &newControl->derValue, &srcControl->derValue); |
| 205 if (rv != SECSuccess) { |
| 206 goto loser; |
| 207 } |
| 208 /* We only handle PKIArchiveOptions Control right now. But if in |
| 209 * the future, more controls that are part of the union are added, |
| 210 * then they need to be handled here as well. |
| 211 */ |
| 212 switch (newControl->tag) { |
228 case SEC_OID_PKIX_REGCTRL_PKI_ARCH_OPTIONS: | 213 case SEC_OID_PKIX_REGCTRL_PKI_ARCH_OPTIONS: |
229 rv = crmf_copy_pkiarchiveoptions(poolp, | 214 rv = crmf_copy_pkiarchiveoptions(poolp, &newControl->value.archiveOptions, |
230 » » » » » &newControl->value.archiveOptions, | 215 &srcControl->value.archiveOptions); |
231 » » » » » &srcControl->value.archiveOptions); | |
232 break; | 216 break; |
233 default: | 217 default: |
234 rv = SECSuccess; | 218 rv = SECSuccess; |
235 } | 219 } |
236 if (rv != SECSuccess) { | 220 if (rv != SECSuccess) { |
237 goto loser; | 221 goto loser; |
238 } | 222 } |
239 return newControl; | 223 return newControl; |
240 | 224 |
241 loser: | 225 loser: |
242 if (poolp == NULL && newControl != NULL) { | 226 if (poolp == NULL && newControl != NULL) { |
243 CRMF_DestroyControl(newControl); | 227 CRMF_DestroyControl(newControl); |
244 } | 228 } |
| 229 return NULL; |
| 230 } |
| 231 |
| 232 static SECStatus crmf_copy_cert_request_controls(PLArenaPool *poolp, |
| 233 CRMFCertRequest *destReq, |
| 234 CRMFCertRequest *srcReq) { |
| 235 int numControls, i; |
| 236 CRMFControl **myControls = NULL; |
| 237 |
| 238 numControls = CRMF_CertRequestGetNumControls(srcReq); |
| 239 if (numControls == 0) { |
| 240 /* No Controls To Copy*/ |
| 241 return SECSuccess; |
| 242 } |
| 243 myControls = destReq->controls = |
| 244 PORT_NewArray(CRMFControl *, numControls + 1); |
| 245 if (myControls == NULL) { |
| 246 goto loser; |
| 247 } |
| 248 for (i = 0; i < numControls; i++) { |
| 249 myControls[i] = crmf_copy_control(poolp, srcReq->controls[i]); |
| 250 if (myControls[i] == NULL) { |
| 251 goto loser; |
| 252 } |
| 253 } |
| 254 myControls[numControls] = NULL; |
| 255 return SECSuccess; |
| 256 loser: |
| 257 if (myControls != NULL) { |
| 258 if (poolp == NULL) { |
| 259 for (i = 0; myControls[i] != NULL; i++) { |
| 260 CRMF_DestroyControl(myControls[i]); |
| 261 } |
| 262 } |
| 263 PORT_Free(myControls); |
| 264 } |
| 265 return SECFailure; |
| 266 } |
| 267 |
| 268 CRMFCertRequest *crmf_copy_cert_request(PLArenaPool *poolp, |
| 269 CRMFCertRequest *srcReq) { |
| 270 CRMFCertRequest *newReq = NULL; |
| 271 SECStatus rv; |
| 272 |
| 273 if (srcReq == NULL) { |
245 return NULL; | 274 return NULL; |
246 } | 275 } |
247 | 276 newReq = (poolp == NULL) ? PORT_ZNew(CRMFCertRequest) |
248 static SECStatus | 277 : PORT_ArenaZNew(poolp, CRMFCertRequest); |
249 crmf_copy_cert_request_controls(PLArenaPool *poolp, | 278 if (newReq == NULL) { |
250 » » » » CRMFCertRequest *destReq,· | 279 goto loser; |
251 » » » » CRMFCertRequest *srcReq) | 280 } |
252 { | 281 rv = SECITEM_CopyItem(poolp, &newReq->certReqId, &srcReq->certReqId); |
253 int numControls, i; | 282 if (rv != SECSuccess) { |
254 CRMFControl **myControls = NULL; | 283 goto loser; |
255 | 284 } |
256 numControls = CRMF_CertRequestGetNumControls(srcReq); | 285 rv = crmf_copy_cert_request_template(poolp, &newReq->certTemplate, |
257 if (numControls == 0) { | 286 &srcReq->certTemplate); |
258 /* No Controls To Copy*/ | 287 if (rv != SECSuccess) { |
259 return SECSuccess; | 288 goto loser; |
260 } | 289 } |
261 myControls = destReq->controls = PORT_NewArray(CRMFControl*,· | 290 rv = crmf_copy_cert_request_controls(poolp, newReq, srcReq); |
262 » » » » » » numControls+1); | 291 if (rv != SECSuccess) { |
263 if (myControls == NULL) { | 292 goto loser; |
264 goto loser; | 293 } |
265 } | 294 return newReq; |
266 for (i=0; i<numControls; i++) { | 295 loser: |
267 myControls[i] = crmf_copy_control(poolp, srcReq->controls[i]); | 296 if (newReq != NULL && poolp == NULL) { |
268 » if (myControls[i] == NULL) { | 297 CRMF_DestroyCertRequest(newReq); |
269 » goto loser; | 298 PORT_Free(newReq); |
270 » } | 299 } |
271 } | 300 return NULL; |
272 myControls[numControls] = NULL; | 301 } |
273 return SECSuccess; | 302 |
274 loser: | 303 SECStatus CRMF_DestroyGetValidity(CRMFGetValidity *inValidity) { |
275 if (myControls != NULL) { | 304 PORT_Assert(inValidity != NULL); |
276 if (poolp == NULL) { | 305 if (inValidity != NULL) { |
277 » for (i=0; myControls[i] != NULL; i++) { | 306 if (inValidity->notAfter) { |
278 » CRMF_DestroyControl(myControls[i]); | 307 PORT_Free(inValidity->notAfter); |
279 » } | 308 inValidity->notAfter = NULL; |
280 » } | 309 } |
281 » PORT_Free(myControls); | 310 if (inValidity->notBefore) { |
282 } | 311 PORT_Free(inValidity->notBefore); |
283 return SECFailure; | 312 inValidity->notBefore = NULL; |
284 } | 313 } |
285 | 314 } |
286 | 315 return SECSuccess; |
287 CRMFCertRequest* | 316 } |
288 crmf_copy_cert_request(PLArenaPool *poolp, CRMFCertRequest *srcReq) | 317 |
289 { | 318 SECStatus crmf_make_bitstring_copy(PLArenaPool *arena, SECItem *dest, |
290 CRMFCertRequest *newReq = NULL; | 319 SECItem *src) { |
291 SECStatus rv; | 320 int origLenBits; |
292 | 321 int bytesToCopy; |
293 if (srcReq == NULL) { | 322 SECStatus rv; |
294 return NULL; | 323 |
295 } | 324 origLenBits = src->len; |
296 newReq = (poolp == NULL) ? PORT_ZNew(CRMFCertRequest) : | 325 bytesToCopy = CRMF_BITS_TO_BYTES(origLenBits); |
297 PORT_ArenaZNew(poolp, CRMFCertRequest); | 326 src->len = bytesToCopy; |
298 if (newReq == NULL) { | 327 rv = SECITEM_CopyItem(arena, dest, src); |
299 goto loser; | 328 src->len = origLenBits; |
300 } | 329 if (rv != SECSuccess) { |
301 rv = SECITEM_CopyItem(poolp, &newReq->certReqId, &srcReq->certReqId); | 330 return rv; |
302 if (rv != SECSuccess) { | 331 } |
303 goto loser; | 332 dest->len = origLenBits; |
304 } | 333 return SECSuccess; |
305 rv = crmf_copy_cert_request_template(poolp, &newReq->certTemplate,· | 334 } |
306 » » » » » &srcReq->certTemplate); | 335 |
307 if (rv != SECSuccess) { | 336 int CRMF_CertRequestGetNumberOfExtensions(CRMFCertRequest *inCertReq) { |
308 goto loser; | 337 CRMFCertTemplate *certTemplate; |
309 } | 338 int count = 0; |
310 rv = crmf_copy_cert_request_controls(poolp, newReq, srcReq); | 339 |
311 if (rv != SECSuccess) { | 340 certTemplate = &inCertReq->certTemplate; |
312 goto loser; | 341 if (certTemplate->extensions) { |
313 } | 342 while (certTemplate->extensions[count] != NULL) count++; |
314 return newReq; | 343 } |
315 loser: | 344 return count; |
316 if (newReq != NULL && poolp == NULL) { | 345 } |
317 CRMF_DestroyCertRequest(newReq); | 346 |
318 PORT_Free(newReq); | 347 SECOidTag CRMF_CertExtensionGetOidTag(CRMFCertExtension *inExtension) { |
319 } | 348 PORT_Assert(inExtension != NULL); |
| 349 if (inExtension == NULL) { |
| 350 return SEC_OID_UNKNOWN; |
| 351 } |
| 352 return SECOID_FindOIDTag(&inExtension->id); |
| 353 } |
| 354 |
| 355 PRBool CRMF_CertExtensionGetIsCritical(CRMFCertExtension *inExt) { |
| 356 PORT_Assert(inExt != NULL); |
| 357 if (inExt == NULL) { |
| 358 return PR_FALSE; |
| 359 } |
| 360 return inExt->critical.data != NULL; |
| 361 } |
| 362 |
| 363 SECItem *CRMF_CertExtensionGetValue(CRMFCertExtension *inExtension) { |
| 364 PORT_Assert(inExtension != NULL); |
| 365 if (inExtension == NULL) { |
320 return NULL; | 366 return NULL; |
321 } | 367 } |
322 | 368 |
323 SECStatus· | 369 return SECITEM_DupItem(&inExtension->value); |
324 CRMF_DestroyGetValidity(CRMFGetValidity *inValidity) | 370 } |
325 { | 371 |
326 PORT_Assert(inValidity != NULL); | 372 SECStatus CRMF_DestroyPOPOSigningKey(CRMFPOPOSigningKey *inKey) { |
327 if (inValidity != NULL) { | 373 PORT_Assert(inKey != NULL); |
328 if (inValidity->notAfter) { | 374 if (inKey != NULL) { |
329 » PORT_Free(inValidity->notAfter); | 375 if (inKey->derInput.data != NULL) { |
330 » inValidity->notAfter = NULL; | 376 SECITEM_FreeItem(&inKey->derInput, PR_FALSE); |
331 » } | 377 } |
332 » if (inValidity->notBefore) { | 378 if (inKey->algorithmIdentifier != NULL) { |
333 » PORT_Free(inValidity->notBefore); | 379 SECOID_DestroyAlgorithmID(inKey->algorithmIdentifier, PR_TRUE); |
334 » inValidity->notBefore = NULL; | 380 } |
335 » } | 381 if (inKey->signature.data != NULL) { |
336 } | 382 SECITEM_FreeItem(&inKey->signature, PR_FALSE); |
337 return SECSuccess; | 383 } |
338 } | 384 PORT_Free(inKey); |
339 | 385 } |
340 SECStatus | 386 return SECSuccess; |
341 crmf_make_bitstring_copy(PLArenaPool *arena, SECItem *dest, SECItem *src) | 387 } |
342 { | 388 |
343 int origLenBits; | 389 SECStatus CRMF_DestroyPOPOPrivKey(CRMFPOPOPrivKey *inPrivKey) { |
344 int bytesToCopy; | 390 PORT_Assert(inPrivKey != NULL); |
345 SECStatus rv; | 391 if (inPrivKey != NULL) { |
346 | 392 SECITEM_FreeItem(&inPrivKey->message.thisMessage, PR_FALSE); |
347 origLenBits = src->len; | 393 PORT_Free(inPrivKey); |
348 bytesToCopy = CRMF_BITS_TO_BYTES(origLenBits); | 394 } |
349 src->len = bytesToCopy;········· | 395 return SECSuccess; |
350 rv = SECITEM_CopyItem(arena, dest, src); | 396 } |
351 src->len = origLenBits; | 397 |
352 if (rv != SECSuccess) { | 398 int CRMF_CertRequestGetNumControls(CRMFCertRequest *inCertReq) { |
353 return rv; | 399 int count = 0; |
354 } | 400 |
355 dest->len = origLenBits; | 401 PORT_Assert(inCertReq != NULL); |
356 return SECSuccess; | 402 if (inCertReq == NULL) { |
357 } | 403 return 0; |
358 | 404 } |
359 int | 405 if (inCertReq->controls) { |
360 CRMF_CertRequestGetNumberOfExtensions(CRMFCertRequest *inCertReq) | 406 while (inCertReq->controls[count] != NULL) count++; |
361 { | 407 } |
362 CRMFCertTemplate *certTemplate; | 408 return count; |
363 int count = 0; | 409 } |
364 ···· | |
365 certTemplate = &inCertReq->certTemplate; | |
366 if (certTemplate->extensions) { | |
367 while (certTemplate->extensions[count] != NULL) | |
368 » count++; | |
369 } | |
370 return count; | |
371 } | |
372 | |
373 SECOidTag | |
374 CRMF_CertExtensionGetOidTag(CRMFCertExtension *inExtension) | |
375 { | |
376 PORT_Assert(inExtension != NULL); | |
377 if (inExtension == NULL) { | |
378 return SEC_OID_UNKNOWN; | |
379 } | |
380 return SECOID_FindOIDTag(&inExtension->id); | |
381 } | |
382 | |
383 PRBool | |
384 CRMF_CertExtensionGetIsCritical(CRMFCertExtension *inExt) | |
385 { | |
386 PORT_Assert(inExt != NULL); | |
387 if (inExt == NULL) { | |
388 return PR_FALSE; | |
389 } | |
390 return inExt->critical.data != NULL; | |
391 } | |
392 | |
393 SECItem* | |
394 CRMF_CertExtensionGetValue(CRMFCertExtension *inExtension) | |
395 { | |
396 PORT_Assert(inExtension != NULL); | |
397 if (inExtension == NULL) { | |
398 return NULL; | |
399 } | |
400 ···· | |
401 return SECITEM_DupItem(&inExtension->value); | |
402 } | |
403 » » »········· | |
404 | |
405 SECStatus | |
406 CRMF_DestroyPOPOSigningKey(CRMFPOPOSigningKey *inKey) | |
407 { | |
408 PORT_Assert(inKey != NULL); | |
409 if (inKey != NULL) { | |
410 if (inKey->derInput.data != NULL) { | |
411 » SECITEM_FreeItem(&inKey->derInput, PR_FALSE); | |
412 » } | |
413 » if (inKey->algorithmIdentifier != NULL) { | |
414 » SECOID_DestroyAlgorithmID(inKey->algorithmIdentifier, PR_TRUE); | |
415 » } | |
416 » if (inKey->signature.data != NULL) { | |
417 » SECITEM_FreeItem(&inKey->signature, PR_FALSE); | |
418 » } | |
419 » PORT_Free(inKey); | |
420 } | |
421 return SECSuccess; | |
422 } | |
423 | |
424 SECStatus | |
425 CRMF_DestroyPOPOPrivKey(CRMFPOPOPrivKey *inPrivKey) | |
426 { | |
427 PORT_Assert(inPrivKey != NULL); | |
428 if (inPrivKey != NULL) { | |
429 SECITEM_FreeItem(&inPrivKey->message.thisMessage, PR_FALSE); | |
430 » PORT_Free(inPrivKey); | |
431 } | |
432 return SECSuccess; | |
433 } | |
434 | |
435 int | |
436 CRMF_CertRequestGetNumControls(CRMFCertRequest *inCertReq) | |
437 { | |
438 int count = 0; | |
439 | |
440 PORT_Assert(inCertReq != NULL); | |
441 if (inCertReq == NULL) { | |
442 return 0; | |
443 } | |
444 if (inCertReq->controls) { | |
445 while (inCertReq->controls[count] != NULL) | |
446 » count++; | |
447 } | |
448 return count; | |
449 } | |
450 | |
OLD | NEW |