]>
Commit | Line | Data |
---|---|---|
0f113f3e MC |
1 | /* |
2 | * Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL | |
3 | * project. | |
4 | */ | |
eb64730b | 5 | |
0f113f3e | 6 | /* |
0d4fb843 | 7 | * History: This file was transferred to Richard Levitte from CertCo by Kathy |
0f113f3e MC |
8 | * Weinhold in mid-spring 2000 to be included in OpenSSL or released as a |
9 | * patch kit. | |
10 | */ | |
eb64730b RL |
11 | |
12 | /* ==================================================================== | |
13 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | |
14 | * | |
15 | * Redistribution and use in source and binary forms, with or without | |
16 | * modification, are permitted provided that the following conditions | |
17 | * are met: | |
18 | * | |
19 | * 1. Redistributions of source code must retain the above copyright | |
0f113f3e | 20 | * notice, this list of conditions and the following disclaimer. |
eb64730b RL |
21 | * |
22 | * 2. Redistributions in binary form must reproduce the above copyright | |
23 | * notice, this list of conditions and the following disclaimer in | |
24 | * the documentation and/or other materials provided with the | |
25 | * distribution. | |
26 | * | |
27 | * 3. All advertising materials mentioning features or use of this | |
28 | * software must display the following acknowledgment: | |
29 | * "This product includes software developed by the OpenSSL Project | |
30 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | |
31 | * | |
32 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | |
33 | * endorse or promote products derived from this software without | |
34 | * prior written permission. For written permission, please contact | |
35 | * openssl-core@openssl.org. | |
36 | * | |
37 | * 5. Products derived from this software may not be called "OpenSSL" | |
38 | * nor may "OpenSSL" appear in their names without prior written | |
39 | * permission of the OpenSSL Project. | |
40 | * | |
41 | * 6. Redistributions of any form whatsoever must retain the following | |
42 | * acknowledgment: | |
43 | * "This product includes software developed by the OpenSSL Project | |
44 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | |
45 | * | |
46 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | |
47 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
49 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | |
50 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
51 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
52 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
53 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
54 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
55 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
56 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
57 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
58 | * ==================================================================== | |
59 | * | |
60 | * This product includes cryptographic software written by Eric Young | |
61 | * (eay@cryptsoft.com). This product includes software written by Tim | |
62 | * Hudson (tjh@cryptsoft.com). | |
63 | * | |
64 | */ | |
65 | ||
66 | #include <stdio.h> | |
b39fc560 | 67 | #include "internal/cryptlib.h" |
eb64730b | 68 | #include <openssl/objects.h> |
eb64730b RL |
69 | #include <openssl/x509.h> |
70 | #include <openssl/ocsp.h> | |
6ef869d7 | 71 | #include "ocsp_lcl.h" |
0b33bc65 | 72 | #include <openssl/rand.h> |
eb64730b RL |
73 | #include <openssl/x509v3.h> |
74 | ||
ec558b65 DSH |
75 | /* Standard wrapper functions for extensions */ |
76 | ||
77 | /* OCSP request extensions */ | |
78 | ||
79 | int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x) | |
0f113f3e | 80 | { |
a332635e | 81 | return (X509v3_get_ext_count(x->tbsRequest.requestExtensions)); |
0f113f3e | 82 | } |
ec558b65 DSH |
83 | |
84 | int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos) | |
0f113f3e MC |
85 | { |
86 | return (X509v3_get_ext_by_NID | |
a332635e | 87 | (x->tbsRequest.requestExtensions, nid, lastpos)); |
0f113f3e MC |
88 | } |
89 | ||
90 | int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, | |
91 | int lastpos) | |
92 | { | |
93 | return (X509v3_get_ext_by_OBJ | |
a332635e | 94 | (x->tbsRequest.requestExtensions, obj, lastpos)); |
0f113f3e | 95 | } |
ec558b65 DSH |
96 | |
97 | int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos) | |
0f113f3e MC |
98 | { |
99 | return (X509v3_get_ext_by_critical | |
a332635e | 100 | (x->tbsRequest.requestExtensions, crit, lastpos)); |
0f113f3e | 101 | } |
ec558b65 DSH |
102 | |
103 | X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc) | |
0f113f3e | 104 | { |
a332635e | 105 | return (X509v3_get_ext(x->tbsRequest.requestExtensions, loc)); |
0f113f3e | 106 | } |
ec558b65 DSH |
107 | |
108 | X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc) | |
0f113f3e | 109 | { |
a332635e | 110 | return (X509v3_delete_ext(x->tbsRequest.requestExtensions, loc)); |
0f113f3e | 111 | } |
ec558b65 DSH |
112 | |
113 | void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx) | |
0f113f3e | 114 | { |
a332635e | 115 | return X509V3_get_d2i(x->tbsRequest.requestExtensions, nid, crit, idx); |
0f113f3e | 116 | } |
ec558b65 DSH |
117 | |
118 | int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit, | |
0f113f3e MC |
119 | unsigned long flags) |
120 | { | |
a332635e | 121 | return X509V3_add1_i2d(&x->tbsRequest.requestExtensions, nid, value, |
0f113f3e MC |
122 | crit, flags); |
123 | } | |
ec558b65 DSH |
124 | |
125 | int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc) | |
0f113f3e | 126 | { |
a332635e | 127 | return (X509v3_add_ext(&(x->tbsRequest.requestExtensions), ex, loc) != |
0f113f3e MC |
128 | NULL); |
129 | } | |
ec558b65 DSH |
130 | |
131 | /* Single extensions */ | |
132 | ||
133 | int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x) | |
0f113f3e MC |
134 | { |
135 | return (X509v3_get_ext_count(x->singleRequestExtensions)); | |
136 | } | |
ec558b65 DSH |
137 | |
138 | int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos) | |
0f113f3e MC |
139 | { |
140 | return (X509v3_get_ext_by_NID(x->singleRequestExtensions, nid, lastpos)); | |
141 | } | |
ec558b65 DSH |
142 | |
143 | int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos) | |
0f113f3e MC |
144 | { |
145 | return (X509v3_get_ext_by_OBJ(x->singleRequestExtensions, obj, lastpos)); | |
146 | } | |
ec558b65 DSH |
147 | |
148 | int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos) | |
0f113f3e MC |
149 | { |
150 | return (X509v3_get_ext_by_critical | |
151 | (x->singleRequestExtensions, crit, lastpos)); | |
152 | } | |
ec558b65 DSH |
153 | |
154 | X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc) | |
0f113f3e MC |
155 | { |
156 | return (X509v3_get_ext(x->singleRequestExtensions, loc)); | |
157 | } | |
ec558b65 DSH |
158 | |
159 | X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc) | |
0f113f3e MC |
160 | { |
161 | return (X509v3_delete_ext(x->singleRequestExtensions, loc)); | |
162 | } | |
ec558b65 DSH |
163 | |
164 | void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx) | |
0f113f3e MC |
165 | { |
166 | return X509V3_get_d2i(x->singleRequestExtensions, nid, crit, idx); | |
167 | } | |
ec558b65 DSH |
168 | |
169 | int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit, | |
0f113f3e MC |
170 | unsigned long flags) |
171 | { | |
172 | return X509V3_add1_i2d(&x->singleRequestExtensions, nid, value, crit, | |
173 | flags); | |
174 | } | |
ec558b65 DSH |
175 | |
176 | int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc) | |
0f113f3e MC |
177 | { |
178 | return (X509v3_add_ext(&(x->singleRequestExtensions), ex, loc) != NULL); | |
179 | } | |
ec558b65 DSH |
180 | |
181 | /* OCSP Basic response */ | |
182 | ||
183 | int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x) | |
0f113f3e | 184 | { |
a332635e | 185 | return (X509v3_get_ext_count(x->tbsResponseData.responseExtensions)); |
0f113f3e | 186 | } |
ec558b65 DSH |
187 | |
188 | int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos) | |
0f113f3e MC |
189 | { |
190 | return (X509v3_get_ext_by_NID | |
a332635e | 191 | (x->tbsResponseData.responseExtensions, nid, lastpos)); |
0f113f3e MC |
192 | } |
193 | ||
194 | int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, | |
195 | int lastpos) | |
196 | { | |
197 | return (X509v3_get_ext_by_OBJ | |
a332635e | 198 | (x->tbsResponseData.responseExtensions, obj, lastpos)); |
0f113f3e MC |
199 | } |
200 | ||
201 | int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, | |
202 | int lastpos) | |
203 | { | |
204 | return (X509v3_get_ext_by_critical | |
a332635e | 205 | (x->tbsResponseData.responseExtensions, crit, lastpos)); |
0f113f3e | 206 | } |
ec558b65 DSH |
207 | |
208 | X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc) | |
0f113f3e | 209 | { |
a332635e | 210 | return (X509v3_get_ext(x->tbsResponseData.responseExtensions, loc)); |
0f113f3e | 211 | } |
ec558b65 DSH |
212 | |
213 | X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc) | |
0f113f3e | 214 | { |
a332635e | 215 | return (X509v3_delete_ext(x->tbsResponseData.responseExtensions, loc)); |
0f113f3e MC |
216 | } |
217 | ||
218 | void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, | |
219 | int *idx) | |
220 | { | |
a332635e | 221 | return X509V3_get_d2i(x->tbsResponseData.responseExtensions, nid, crit, |
0f113f3e MC |
222 | idx); |
223 | } | |
224 | ||
225 | int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, | |
226 | int crit, unsigned long flags) | |
227 | { | |
a332635e | 228 | return X509V3_add1_i2d(&x->tbsResponseData.responseExtensions, nid, |
0f113f3e MC |
229 | value, crit, flags); |
230 | } | |
ec558b65 DSH |
231 | |
232 | int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc) | |
0f113f3e | 233 | { |
a332635e | 234 | return (X509v3_add_ext(&(x->tbsResponseData.responseExtensions), ex, loc) |
0f113f3e MC |
235 | != NULL); |
236 | } | |
ec558b65 DSH |
237 | |
238 | /* OCSP single response extensions */ | |
239 | ||
240 | int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x) | |
0f113f3e MC |
241 | { |
242 | return (X509v3_get_ext_count(x->singleExtensions)); | |
243 | } | |
ec558b65 DSH |
244 | |
245 | int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos) | |
0f113f3e MC |
246 | { |
247 | return (X509v3_get_ext_by_NID(x->singleExtensions, nid, lastpos)); | |
248 | } | |
249 | ||
250 | int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, | |
251 | int lastpos) | |
252 | { | |
253 | return (X509v3_get_ext_by_OBJ(x->singleExtensions, obj, lastpos)); | |
254 | } | |
255 | ||
256 | int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, | |
257 | int lastpos) | |
258 | { | |
259 | return (X509v3_get_ext_by_critical(x->singleExtensions, crit, lastpos)); | |
260 | } | |
ec558b65 DSH |
261 | |
262 | X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc) | |
0f113f3e MC |
263 | { |
264 | return (X509v3_get_ext(x->singleExtensions, loc)); | |
265 | } | |
ec558b65 DSH |
266 | |
267 | X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc) | |
0f113f3e MC |
268 | { |
269 | return (X509v3_delete_ext(x->singleExtensions, loc)); | |
270 | } | |
271 | ||
272 | void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, | |
273 | int *idx) | |
274 | { | |
275 | return X509V3_get_d2i(x->singleExtensions, nid, crit, idx); | |
276 | } | |
277 | ||
278 | int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, | |
279 | int crit, unsigned long flags) | |
280 | { | |
281 | return X509V3_add1_i2d(&x->singleExtensions, nid, value, crit, flags); | |
282 | } | |
ec558b65 DSH |
283 | |
284 | int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc) | |
0f113f3e MC |
285 | { |
286 | return (X509v3_add_ext(&(x->singleExtensions), ex, loc) != NULL); | |
287 | } | |
eb64730b RL |
288 | |
289 | /* also CRL Entry Extensions */ | |
eb64730b | 290 | |
0b33bc65 DSH |
291 | /* Nonce handling functions */ |
292 | ||
0f113f3e | 293 | /* |
0d4fb843 | 294 | * Add a nonce to an extension stack. A nonce can be specified or if NULL a |
0f113f3e MC |
295 | * random nonce will be generated. Note: OpenSSL 0.9.7d and later create an |
296 | * OCTET STRING containing the nonce, previous versions used the raw nonce. | |
0b33bc65 DSH |
297 | */ |
298 | ||
0f113f3e MC |
299 | static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, |
300 | unsigned char *val, int len) | |
301 | { | |
302 | unsigned char *tmpval; | |
303 | ASN1_OCTET_STRING os; | |
304 | int ret = 0; | |
305 | if (len <= 0) | |
306 | len = OCSP_DEFAULT_NONCE_LENGTH; | |
307 | /* | |
308 | * Create the OCTET STRING manually by writing out the header and | |
309 | * appending the content octets. This avoids an extra memory allocation | |
310 | * operation in some cases. Applications should *NOT* do this because it | |
311 | * relies on library internals. | |
312 | */ | |
313 | os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING); | |
314 | os.data = OPENSSL_malloc(os.length); | |
315 | if (os.data == NULL) | |
316 | goto err; | |
317 | tmpval = os.data; | |
318 | ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL); | |
319 | if (val) | |
320 | memcpy(tmpval, val, len); | |
266483d2 MC |
321 | else if (RAND_bytes(tmpval, len) <= 0) |
322 | goto err; | |
0f113f3e MC |
323 | if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, |
324 | &os, 0, X509V3_ADD_REPLACE)) | |
325 | goto err; | |
326 | ret = 1; | |
327 | err: | |
b548a1f1 | 328 | OPENSSL_free(os.data); |
0f113f3e MC |
329 | return ret; |
330 | } | |
46a58ab9 DSH |
331 | |
332 | /* Add nonce to an OCSP request */ | |
333 | ||
334 | int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len) | |
0f113f3e | 335 | { |
a332635e | 336 | return ocsp_add1_nonce(&req->tbsRequest.requestExtensions, val, len); |
0f113f3e | 337 | } |
46a58ab9 DSH |
338 | |
339 | /* Same as above but for a response */ | |
340 | ||
341 | int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len) | |
0f113f3e | 342 | { |
a332635e | 343 | return ocsp_add1_nonce(&resp->tbsResponseData.responseExtensions, val, |
0f113f3e MC |
344 | len); |
345 | } | |
46a58ab9 | 346 | |
3a83462d MC |
347 | /*- |
348 | * Check nonce validity in a request and response. | |
46a58ab9 DSH |
349 | * Return value reflects result: |
350 | * 1: nonces present and equal. | |
351 | * 2: nonces both absent. | |
352 | * 3: nonce present in response only. | |
353 | * 0: nonces both present and not equal. | |
354 | * -1: nonce in request only. | |
355 | * | |
356 | * For most responders clients can check return > 0. | |
357 | * If responder doesn't handle nonces return != 0 may be | |
358 | * necessary. return == 0 is always an error. | |
0b33bc65 | 359 | */ |
46a58ab9 | 360 | |
0b33bc65 | 361 | int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs) |
0f113f3e MC |
362 | { |
363 | /* | |
364 | * Since we are only interested in the presence or absence of | |
365 | * the nonce and comparing its value there is no need to use | |
366 | * the X509V3 routines: this way we can avoid them allocating an | |
367 | * ASN1_OCTET_STRING structure for the value which would be | |
368 | * freed immediately anyway. | |
369 | */ | |
370 | ||
371 | int req_idx, resp_idx; | |
372 | X509_EXTENSION *req_ext, *resp_ext; | |
373 | req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1); | |
374 | resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1); | |
375 | /* Check both absent */ | |
376 | if ((req_idx < 0) && (resp_idx < 0)) | |
377 | return 2; | |
378 | /* Check in request only */ | |
379 | if ((req_idx >= 0) && (resp_idx < 0)) | |
380 | return -1; | |
381 | /* Check in response but not request */ | |
382 | if ((req_idx < 0) && (resp_idx >= 0)) | |
383 | return 3; | |
384 | /* | |
385 | * Otherwise nonce in request and response so retrieve the extensions | |
386 | */ | |
387 | req_ext = OCSP_REQUEST_get_ext(req, req_idx); | |
388 | resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx); | |
4903abd5 DSH |
389 | if (ASN1_OCTET_STRING_cmp(X509_EXTENSION_get_data(req_ext), |
390 | X509_EXTENSION_get_data(resp_ext))) | |
0f113f3e MC |
391 | return 0; |
392 | return 1; | |
393 | } | |
394 | ||
395 | /* | |
396 | * Copy the nonce value (if any) from an OCSP request to a response. | |
26e083cc DSH |
397 | */ |
398 | ||
399 | int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req) | |
0f113f3e MC |
400 | { |
401 | X509_EXTENSION *req_ext; | |
402 | int req_idx; | |
403 | /* Check for nonce in request */ | |
404 | req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1); | |
405 | /* If no nonce that's OK */ | |
406 | if (req_idx < 0) | |
407 | return 2; | |
408 | req_ext = OCSP_REQUEST_get_ext(req, req_idx); | |
409 | return OCSP_BASICRESP_add_ext(resp, req_ext, -1); | |
410 | } | |
eb64730b RL |
411 | |
412 | X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim) | |
0f113f3e MC |
413 | { |
414 | X509_EXTENSION *x = NULL; | |
415 | OCSP_CRLID *cid = NULL; | |
416 | ||
75ebbd9a | 417 | if ((cid = OCSP_CRLID_new()) == NULL) |
0f113f3e MC |
418 | goto err; |
419 | if (url) { | |
75ebbd9a | 420 | if ((cid->crlUrl = ASN1_IA5STRING_new()) == NULL) |
0f113f3e MC |
421 | goto err; |
422 | if (!(ASN1_STRING_set(cid->crlUrl, url, -1))) | |
423 | goto err; | |
424 | } | |
425 | if (n) { | |
75ebbd9a | 426 | if ((cid->crlNum = ASN1_INTEGER_new()) == NULL) |
0f113f3e MC |
427 | goto err; |
428 | if (!(ASN1_INTEGER_set(cid->crlNum, *n))) | |
429 | goto err; | |
430 | } | |
431 | if (tim) { | |
75ebbd9a | 432 | if ((cid->crlTime = ASN1_GENERALIZEDTIME_new()) == NULL) |
0f113f3e MC |
433 | goto err; |
434 | if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim))) | |
435 | goto err; | |
436 | } | |
437 | x = X509V3_EXT_i2d(NID_id_pkix_OCSP_CrlID, 0, cid); | |
438 | err: | |
25aaa98a | 439 | OCSP_CRLID_free(cid); |
0f113f3e MC |
440 | return x; |
441 | } | |
eb64730b RL |
442 | |
443 | /* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */ | |
444 | X509_EXTENSION *OCSP_accept_responses_new(char **oids) | |
0f113f3e MC |
445 | { |
446 | int nid; | |
447 | STACK_OF(ASN1_OBJECT) *sk = NULL; | |
448 | ASN1_OBJECT *o = NULL; | |
449 | X509_EXTENSION *x = NULL; | |
450 | ||
75ebbd9a | 451 | if ((sk = sk_ASN1_OBJECT_new_null()) == NULL) |
0f113f3e MC |
452 | goto err; |
453 | while (oids && *oids) { | |
454 | if ((nid = OBJ_txt2nid(*oids)) != NID_undef && (o = OBJ_nid2obj(nid))) | |
455 | sk_ASN1_OBJECT_push(sk, o); | |
456 | oids++; | |
457 | } | |
458 | x = X509V3_EXT_i2d(NID_id_pkix_OCSP_acceptableResponses, 0, sk); | |
459 | err: | |
2ace7450 | 460 | sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free); |
0f113f3e MC |
461 | return x; |
462 | } | |
eb64730b RL |
463 | |
464 | /* ArchiveCutoff ::= GeneralizedTime */ | |
0f113f3e MC |
465 | X509_EXTENSION *OCSP_archive_cutoff_new(char *tim) |
466 | { | |
467 | X509_EXTENSION *x = NULL; | |
468 | ASN1_GENERALIZEDTIME *gt = NULL; | |
469 | ||
75ebbd9a | 470 | if ((gt = ASN1_GENERALIZEDTIME_new()) == NULL) |
0f113f3e MC |
471 | goto err; |
472 | if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) | |
473 | goto err; | |
474 | x = X509V3_EXT_i2d(NID_id_pkix_OCSP_archiveCutoff, 0, gt); | |
475 | err: | |
2ace7450 | 476 | ASN1_GENERALIZEDTIME_free(gt); |
0f113f3e MC |
477 | return x; |
478 | } | |
479 | ||
480 | /* | |
481 | * per ACCESS_DESCRIPTION parameter are oids, of which there are currently | |
482 | * two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value. This method | |
483 | * forces NID_ad_ocsp and uniformResourceLocator [6] IA5String. | |
eb64730b | 484 | */ |
0f113f3e MC |
485 | X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, char **urls) |
486 | { | |
487 | X509_EXTENSION *x = NULL; | |
488 | ASN1_IA5STRING *ia5 = NULL; | |
489 | OCSP_SERVICELOC *sloc = NULL; | |
490 | ACCESS_DESCRIPTION *ad = NULL; | |
491 | ||
75ebbd9a | 492 | if ((sloc = OCSP_SERVICELOC_new()) == NULL) |
0f113f3e | 493 | goto err; |
75ebbd9a | 494 | if ((sloc->issuer = X509_NAME_dup(issuer)) == NULL) |
0f113f3e | 495 | goto err; |
75ebbd9a RS |
496 | if (urls && *urls |
497 | && (sloc->locator = sk_ACCESS_DESCRIPTION_new_null()) == NULL) | |
0f113f3e MC |
498 | goto err; |
499 | while (urls && *urls) { | |
75ebbd9a | 500 | if ((ad = ACCESS_DESCRIPTION_new()) == NULL) |
0f113f3e | 501 | goto err; |
75ebbd9a | 502 | if ((ad->method = OBJ_nid2obj(NID_ad_OCSP)) == NULL) |
0f113f3e | 503 | goto err; |
75ebbd9a | 504 | if ((ad->location = GENERAL_NAME_new()) == NULL) |
0f113f3e | 505 | goto err; |
75ebbd9a | 506 | if ((ia5 = ASN1_IA5STRING_new()) == NULL) |
0f113f3e MC |
507 | goto err; |
508 | if (!ASN1_STRING_set((ASN1_STRING *)ia5, *urls, -1)) | |
509 | goto err; | |
510 | ad->location->type = GEN_URI; | |
511 | ad->location->d.ia5 = ia5; | |
a4e584a6 | 512 | ia5 = NULL; |
0f113f3e MC |
513 | if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad)) |
514 | goto err; | |
a4e584a6 | 515 | ad = NULL; |
0f113f3e MC |
516 | urls++; |
517 | } | |
518 | x = X509V3_EXT_i2d(NID_id_pkix_OCSP_serviceLocator, 0, sloc); | |
519 | err: | |
a4e584a6 MC |
520 | ASN1_IA5STRING_free(ia5); |
521 | ACCESS_DESCRIPTION_free(ad); | |
25aaa98a | 522 | OCSP_SERVICELOC_free(sloc); |
0f113f3e MC |
523 | return x; |
524 | } |