summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ocsp/ocsp_ext.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ext.c655
1 files changed, 364 insertions, 291 deletions
diff --git a/src/lib/libcrypto/ocsp/ocsp_ext.c b/src/lib/libcrypto/ocsp/ocsp_ext.c
index 9c7832b301..6ec8ca4adf 100644
--- a/src/lib/libcrypto/ocsp/ocsp_ext.c
+++ b/src/lib/libcrypto/ocsp/ocsp_ext.c
@@ -73,238 +73,285 @@
73 73
74/* OCSP request extensions */ 74/* OCSP request extensions */
75 75
76int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x) 76int
77 { 77OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x)
78 return(X509v3_get_ext_count(x->tbsRequest->requestExtensions)); 78{
79 } 79 return X509v3_get_ext_count(x->tbsRequest->requestExtensions);
80 80}
81int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos) 81
82 { 82int
83 return(X509v3_get_ext_by_NID(x->tbsRequest->requestExtensions,nid,lastpos)); 83OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos)
84 } 84{
85 85 return X509v3_get_ext_by_NID(x->tbsRequest->requestExtensions, nid,
86int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos) 86 lastpos);
87 { 87}
88 return(X509v3_get_ext_by_OBJ(x->tbsRequest->requestExtensions,obj,lastpos)); 88
89 } 89int
90 90OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos)
91int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos) 91{
92 { 92 return X509v3_get_ext_by_OBJ(x->tbsRequest->requestExtensions, obj,
93 return(X509v3_get_ext_by_critical(x->tbsRequest->requestExtensions,crit,lastpos)); 93 lastpos);
94 } 94}
95 95
96X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc) 96int
97 { 97OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos)
98 return(X509v3_get_ext(x->tbsRequest->requestExtensions,loc)); 98{
99 } 99 return X509v3_get_ext_by_critical(x->tbsRequest->requestExtensions,
100 100 crit, lastpos);
101X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc) 101}
102 { 102
103 return(X509v3_delete_ext(x->tbsRequest->requestExtensions,loc)); 103X509_EXTENSION *
104 } 104OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc)
105 105{
106void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx) 106 return X509v3_get_ext(x->tbsRequest->requestExtensions, loc);
107 { 107}
108
109X509_EXTENSION *
110OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc)
111{
112 return X509v3_delete_ext(x->tbsRequest->requestExtensions, loc);
113}
114
115void *
116OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx)
117{
108 return X509V3_get_d2i(x->tbsRequest->requestExtensions, nid, crit, idx); 118 return X509V3_get_d2i(x->tbsRequest->requestExtensions, nid, crit, idx);
109 } 119}
110 120
111int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit, 121int
112 unsigned long flags) 122OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
113 { 123 unsigned long flags)
114 return X509V3_add1_i2d(&x->tbsRequest->requestExtensions, nid, value, crit, flags); 124{
115 } 125 return X509V3_add1_i2d(&x->tbsRequest->requestExtensions, nid, value,
116 126 crit, flags);
117int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc) 127}
118 { 128
119 return(X509v3_add_ext(&(x->tbsRequest->requestExtensions),ex,loc) != NULL); 129int
120 } 130OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc)
131{
132 return X509v3_add_ext(&(x->tbsRequest->requestExtensions), ex, loc) !=
133 NULL;
134}
121 135
122/* Single extensions */ 136/* Single extensions */
123 137
124int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x) 138int
125 { 139OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x)
126 return(X509v3_get_ext_count(x->singleRequestExtensions)); 140{
127 } 141 return X509v3_get_ext_count(x->singleRequestExtensions);
128 142}
129int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos) 143
130 { 144int
131 return(X509v3_get_ext_by_NID(x->singleRequestExtensions,nid,lastpos)); 145OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos)
132 } 146{
133 147 return X509v3_get_ext_by_NID(x->singleRequestExtensions, nid, lastpos);
134int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos) 148}
135 { 149
136 return(X509v3_get_ext_by_OBJ(x->singleRequestExtensions,obj,lastpos)); 150int
137 } 151OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos)
138 152{
139int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos) 153 return X509v3_get_ext_by_OBJ(x->singleRequestExtensions, obj, lastpos);
140 { 154}
141 return(X509v3_get_ext_by_critical(x->singleRequestExtensions,crit,lastpos)); 155
142 } 156int
143 157OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos)
144X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc) 158{
145 { 159 return X509v3_get_ext_by_critical(x->singleRequestExtensions, crit,
146 return(X509v3_get_ext(x->singleRequestExtensions,loc)); 160 lastpos);
147 } 161}
148 162
149X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc) 163X509_EXTENSION *
150 { 164OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc)
151 return(X509v3_delete_ext(x->singleRequestExtensions,loc)); 165{
152 } 166 return X509v3_get_ext(x->singleRequestExtensions, loc);
167}
168
169X509_EXTENSION *
170OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc)
171{
172 return X509v3_delete_ext(x->singleRequestExtensions, loc);
173}
153 174
154void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx) 175void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx)
155 { 176{
156 return X509V3_get_d2i(x->singleRequestExtensions, nid, crit, idx); 177 return X509V3_get_d2i(x->singleRequestExtensions, nid, crit, idx);
157 } 178}
158 179
159int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit, 180int
160 unsigned long flags) 181OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
161 { 182 unsigned long flags)
162 return X509V3_add1_i2d(&x->singleRequestExtensions, nid, value, crit, flags); 183{
163 } 184 return X509V3_add1_i2d(&x->singleRequestExtensions, nid, value, crit,
164 185 flags);
165int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc) 186}
166 { 187
167 return(X509v3_add_ext(&(x->singleRequestExtensions),ex,loc) != NULL); 188int
168 } 189OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc)
190{
191 return X509v3_add_ext(&(x->singleRequestExtensions), ex, loc) != NULL;
192}
169 193
170/* OCSP Basic response */ 194/* OCSP Basic response */
171 195
172int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x) 196int
173 { 197OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x)
174 return(X509v3_get_ext_count(x->tbsResponseData->responseExtensions)); 198{
175 } 199 return X509v3_get_ext_count(x->tbsResponseData->responseExtensions);
176 200}
177int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos) 201
178 { 202int
179 return(X509v3_get_ext_by_NID(x->tbsResponseData->responseExtensions,nid,lastpos)); 203OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos)
180 } 204{
181 205 return X509v3_get_ext_by_NID(x->tbsResponseData->responseExtensions,
182int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos) 206 nid ,lastpos);
183 { 207}
184 return(X509v3_get_ext_by_OBJ(x->tbsResponseData->responseExtensions,obj,lastpos)); 208
185 } 209int
186 210OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos)
187int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos) 211{
188 { 212 return X509v3_get_ext_by_OBJ(x->tbsResponseData->responseExtensions,
189 return(X509v3_get_ext_by_critical(x->tbsResponseData->responseExtensions,crit,lastpos)); 213 obj, lastpos);
190 } 214}
191 215
192X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc) 216int
193 { 217OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos)
194 return(X509v3_get_ext(x->tbsResponseData->responseExtensions,loc)); 218{
195 } 219 return X509v3_get_ext_by_critical(x->tbsResponseData->responseExtensions,
196 220 crit, lastpos);
197X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc) 221}
198 { 222
199 return(X509v3_delete_ext(x->tbsResponseData->responseExtensions,loc)); 223X509_EXTENSION *
200 } 224OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc)
201 225{
202void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx) 226 return X509v3_get_ext(x->tbsResponseData->responseExtensions, loc);
203 { 227}
204 return X509V3_get_d2i(x->tbsResponseData->responseExtensions, nid, crit, idx); 228
205 } 229X509_EXTENSION *
206 230OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc)
207int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit, 231{
208 unsigned long flags) 232 return X509v3_delete_ext(x->tbsResponseData->responseExtensions, loc);
209 { 233}
210 return X509V3_add1_i2d(&x->tbsResponseData->responseExtensions, nid, value, crit, flags); 234
211 } 235void *
212 236OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx)
213int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc) 237{
214 { 238 return X509V3_get_d2i(x->tbsResponseData->responseExtensions, nid,
215 return(X509v3_add_ext(&(x->tbsResponseData->responseExtensions),ex,loc) != NULL); 239 crit, idx);
216 } 240}
241
242int
243OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,
244 unsigned long flags)
245{
246 return X509V3_add1_i2d(&x->tbsResponseData->responseExtensions, nid,
247 value, crit, flags);
248}
249
250int
251OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc)
252{
253 return X509v3_add_ext(&(x->tbsResponseData->responseExtensions), ex,
254 loc) != NULL;
255}
217 256
218/* OCSP single response extensions */ 257/* OCSP single response extensions */
219 258
220int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x) 259int
221 { 260OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x)
222 return(X509v3_get_ext_count(x->singleExtensions)); 261{
223 } 262 return X509v3_get_ext_count(x->singleExtensions);
224 263}
225int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos) 264
226 { 265int
227 return(X509v3_get_ext_by_NID(x->singleExtensions,nid,lastpos)); 266OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos)
228 } 267{
229 268 return X509v3_get_ext_by_NID(x->singleExtensions, nid, lastpos);
230int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos) 269}
231 { 270
232 return(X509v3_get_ext_by_OBJ(x->singleExtensions,obj,lastpos)); 271int
233 } 272OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj,
234 273 int lastpos)
235int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos) 274{
236 { 275 return X509v3_get_ext_by_OBJ(x->singleExtensions, obj, lastpos);
237 return(X509v3_get_ext_by_critical(x->singleExtensions,crit,lastpos)); 276}
238 } 277
239 278int
240X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc) 279OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos)
241 { 280{
242 return(X509v3_get_ext(x->singleExtensions,loc)); 281 return X509v3_get_ext_by_critical(x->singleExtensions, crit, lastpos);
243 } 282}
244 283
245X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc) 284X509_EXTENSION *
246 { 285OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc)
247 return(X509v3_delete_ext(x->singleExtensions,loc)); 286{
248 } 287 return X509v3_get_ext(x->singleExtensions, loc);
249 288}
250void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx) 289
251 { 290X509_EXTENSION *
291OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc)
292{
293 return X509v3_delete_ext(x->singleExtensions, loc);
294}
295
296void *
297OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx)
298{
252 return X509V3_get_d2i(x->singleExtensions, nid, crit, idx); 299 return X509V3_get_d2i(x->singleExtensions, nid, crit, idx);
253 } 300}
254 301
255int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit, 302int
256 unsigned long flags) 303OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,
257 { 304 unsigned long flags)
305{
258 return X509V3_add1_i2d(&x->singleExtensions, nid, value, crit, flags); 306 return X509V3_add1_i2d(&x->singleExtensions, nid, value, crit, flags);
259 } 307}
260 308
261int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc) 309int
262 { 310OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc)
263 return(X509v3_add_ext(&(x->singleExtensions),ex,loc) != NULL); 311{
264 } 312 return X509v3_add_ext(&(x->singleExtensions), ex, loc) != NULL;
313}
265 314
266/* also CRL Entry Extensions */ 315/* also CRL Entry Extensions */
267#if 0 316#if 0
268ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d, 317ASN1_STRING *
269 void *data, STACK_OF(ASN1_OBJECT) *sk) 318ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d, void *data,
270 { 319 STACK_OF(ASN1_OBJECT) *sk)
320{
271 int i; 321 int i;
272 unsigned char *p, *b = NULL; 322 unsigned char *p, *b = NULL;
273 323
274 if (data) 324 if (data) {
275 { 325 if ((i = i2d(data, NULL)) <= 0)
276 if ((i=i2d(data,NULL)) <= 0) goto err;
277 if (!(b=p=malloc((unsigned int)i)))
278 goto err; 326 goto err;
279 if (i2d(data, &p) <= 0) goto err; 327 if (!(b = p = malloc((unsigned int)i)))
280 } 328 goto err;
281 else if (sk) 329 if (i2d(data, &p) <= 0)
282 { 330 goto err;
283 if ((i=i2d_ASN1_SET_OF_ASN1_OBJECT(sk,NULL, 331 } else if (sk) {
284 (I2D_OF(ASN1_OBJECT))i2d, 332 if ((i = i2d_ASN1_SET_OF_ASN1_OBJECT(sk,NULL,
285 V_ASN1_SEQUENCE, 333 (I2D_OF(ASN1_OBJECT))i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
286 V_ASN1_UNIVERSAL, 334 IS_SEQUENCE)) <= 0)
287 IS_SEQUENCE))<=0) goto err; 335 goto err;
288 if (!(b=p=malloc((unsigned int)i))) 336 if (!(b = p = malloc((unsigned int)i)))
289 goto err; 337 goto err;
290 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,(I2D_OF(ASN1_OBJECT))i2d, 338 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,(I2D_OF(ASN1_OBJECT))i2d,
291 V_ASN1_SEQUENCE, 339 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE) <= 0)
292 V_ASN1_UNIVERSAL, 340 goto err;
293 IS_SEQUENCE)<=0) goto err; 341 } else {
294 } 342 OCSPerr(OCSP_F_ASN1_STRING_ENCODE, OCSP_R_BAD_DATA);
295 else 343 goto err;
296 { 344 }
297 OCSPerr(OCSP_F_ASN1_STRING_ENCODE,OCSP_R_BAD_DATA); 345 if (!s && !(s = ASN1_STRING_new()))
346 goto err;
347 if (!(ASN1_STRING_set(s, b, i)))
298 goto err; 348 goto err;
299 }
300 if (!s && !(s = ASN1_STRING_new())) goto err;
301 if (!(ASN1_STRING_set(s, b, i))) goto err;
302 free(b); 349 free(b);
303 return s; 350 return s;
304err: 351err:
305 if (b) free(b); 352 free(b);
306 return NULL; 353 return NULL;
307 } 354}
308#endif 355#endif
309 356
310/* Nonce handling functions */ 357/* Nonce handling functions */
@@ -315,16 +362,19 @@ err:
315 * nonce, previous versions used the raw nonce. 362 * nonce, previous versions used the raw nonce.
316 */ 363 */
317 364
318static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len) 365static int
319 { 366ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len)
367{
320 unsigned char *tmpval; 368 unsigned char *tmpval;
321 ASN1_OCTET_STRING os; 369 ASN1_OCTET_STRING os;
322 int ret = 0; 370 int ret = 0;
323 if (len <= 0) len = OCSP_DEFAULT_NONCE_LENGTH; 371
372 if (len <= 0)
373 len = OCSP_DEFAULT_NONCE_LENGTH;
324 /* Create the OCTET STRING manually by writing out the header and 374 /* Create the OCTET STRING manually by writing out the header and
325 * appending the content octets. This avoids an extra memory allocation 375 * appending the content octets. This avoids an extra memory allocation
326 * operation in some cases. Applications should *NOT* do this because 376 * operation in some cases. Applications should *NOT* do this because
327 * it relies on library internals. 377 * it relies on library internals.
328 */ 378 */
329 os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING); 379 os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);
330 os.data = malloc(os.length); 380 os.data = malloc(os.length);
@@ -336,30 +386,29 @@ static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val,
336 memcpy(tmpval, val, len); 386 memcpy(tmpval, val, len);
337 else 387 else
338 RAND_pseudo_bytes(tmpval, len); 388 RAND_pseudo_bytes(tmpval, len);
339 if(!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, 389 if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, &os, 0,
340 &os, 0, X509V3_ADD_REPLACE)) 390 X509V3_ADD_REPLACE))
341 goto err; 391 goto err;
342 ret = 1; 392 ret = 1;
343 err: 393err:
344 if (os.data) 394 free(os.data);
345 free(os.data);
346 return ret; 395 return ret;
347 } 396}
348
349 397
350/* Add nonce to an OCSP request */ 398/* Add nonce to an OCSP request */
351 399int
352int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len) 400OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len)
353 { 401{
354 return ocsp_add1_nonce(&req->tbsRequest->requestExtensions, val, len); 402 return ocsp_add1_nonce(&req->tbsRequest->requestExtensions, val, len);
355 } 403}
356 404
357/* Same as above but for a response */ 405/* Same as above but for a response */
358 406int
359int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len) 407OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len)
360 { 408{
361 return ocsp_add1_nonce(&resp->tbsResponseData->responseExtensions, val, len); 409 return ocsp_add1_nonce(&resp->tbsResponseData->responseExtensions, val,
362 } 410 len);
411}
363 412
364/* Check nonce validity in a request and response. 413/* Check nonce validity in a request and response.
365 * Return value reflects result: 414 * Return value reflects result:
@@ -373,9 +422,9 @@ int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len)
373 * If responder doesn't handle nonces return != 0 may be 422 * If responder doesn't handle nonces return != 0 may be
374 * necessary. return == 0 is always an error. 423 * necessary. return == 0 is always an error.
375 */ 424 */
376 425int
377int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs) 426OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs)
378 { 427{
379 /* 428 /*
380 * Since we are only interested in the presence or absence of 429 * Since we are only interested in the presence or absence of
381 * the nonce and comparing its value there is no need to use 430 * the nonce and comparing its value there is no need to use
@@ -383,136 +432,160 @@ int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs)
383 * ASN1_OCTET_STRING structure for the value which would be 432 * ASN1_OCTET_STRING structure for the value which would be
384 * freed immediately anyway. 433 * freed immediately anyway.
385 */ 434 */
386
387 int req_idx, resp_idx; 435 int req_idx, resp_idx;
388 X509_EXTENSION *req_ext, *resp_ext; 436 X509_EXTENSION *req_ext, *resp_ext;
437
389 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1); 438 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
390 resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1); 439 resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1);
391 /* Check both absent */ 440 /* Check both absent */
392 if((req_idx < 0) && (resp_idx < 0)) 441 if (req_idx < 0 && resp_idx < 0)
393 return 2; 442 return 2;
394 /* Check in request only */ 443 /* Check in request only */
395 if((req_idx >= 0) && (resp_idx < 0)) 444 if (req_idx >= 0 && resp_idx < 0)
396 return -1; 445 return -1;
397 /* Check in response but not request */ 446 /* Check in response but not request */
398 if((req_idx < 0) && (resp_idx >= 0)) 447 if (req_idx < 0 && resp_idx >= 0)
399 return 3; 448 return 3;
400 /* Otherwise nonce in request and response so retrieve the extensions */ 449 /* Otherwise nonce in request and response so retrieve the extensions */
401 req_ext = OCSP_REQUEST_get_ext(req, req_idx); 450 req_ext = OCSP_REQUEST_get_ext(req, req_idx);
402 resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx); 451 resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx);
403 if(ASN1_OCTET_STRING_cmp(req_ext->value, resp_ext->value)) 452 if (ASN1_OCTET_STRING_cmp(req_ext->value, resp_ext->value))
404 return 0; 453 return 0;
405 return 1; 454 return 1;
406 } 455}
407 456
408/* Copy the nonce value (if any) from an OCSP request to 457/* Copy the nonce value (if any) from an OCSP request to
409 * a response. 458 * a response.
410 */ 459 */
411 460int
412int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req) 461OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req)
413 { 462{
414 X509_EXTENSION *req_ext; 463 X509_EXTENSION *req_ext;
415 int req_idx; 464 int req_idx;
465
416 /* Check for nonce in request */ 466 /* Check for nonce in request */
417 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1); 467 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
418 /* If no nonce that's OK */ 468 /* If no nonce that's OK */
419 if (req_idx < 0) return 2; 469 if (req_idx < 0)
470 return 2;
420 req_ext = OCSP_REQUEST_get_ext(req, req_idx); 471 req_ext = OCSP_REQUEST_get_ext(req, req_idx);
421 return OCSP_BASICRESP_add_ext(resp, req_ext, -1); 472 return OCSP_BASICRESP_add_ext(resp, req_ext, -1);
422 } 473}
423 474
424X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim) 475X509_EXTENSION *
425 { 476OCSP_crlID_new(char *url, long *n, char *tim)
477{
426 X509_EXTENSION *x = NULL; 478 X509_EXTENSION *x = NULL;
427 OCSP_CRLID *cid = NULL; 479 OCSP_CRLID *cid = NULL;
428 480
429 if (!(cid = OCSP_CRLID_new())) goto err; 481 if (!(cid = OCSP_CRLID_new()))
430 if (url) 482 goto err;
431 { 483 if (url) {
432 if (!(cid->crlUrl = ASN1_IA5STRING_new())) goto err; 484 if (!(cid->crlUrl = ASN1_IA5STRING_new()))
433 if (!(ASN1_STRING_set(cid->crlUrl, url, -1))) goto err; 485 goto err;
434 } 486 if (!(ASN1_STRING_set(cid->crlUrl, url, -1)))
435 if (n) 487 goto err;
436 { 488 }
437 if (!(cid->crlNum = ASN1_INTEGER_new())) goto err; 489 if (n) {
438 if (!(ASN1_INTEGER_set(cid->crlNum, *n))) goto err; 490 if (!(cid->crlNum = ASN1_INTEGER_new()))
439 } 491 goto err;
440 if (tim) 492 if (!(ASN1_INTEGER_set(cid->crlNum, *n)))
441 { 493 goto err;
442 if (!(cid->crlTime = ASN1_GENERALIZEDTIME_new())) goto err; 494 }
495 if (tim) {
496 if (!(cid->crlTime = ASN1_GENERALIZEDTIME_new()))
497 goto err;
443 if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim))) 498 if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim)))
444 goto err; 499 goto err;
445 } 500 }
446 x = X509V3_EXT_i2d(NID_id_pkix_OCSP_CrlID, 0, cid); 501 x = X509V3_EXT_i2d(NID_id_pkix_OCSP_CrlID, 0, cid);
447err: 502err:
448 if (cid) OCSP_CRLID_free(cid); 503 if (cid)
504 OCSP_CRLID_free(cid);
449 return x; 505 return x;
450 } 506}
451 507
452/* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */ 508/* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */
453X509_EXTENSION *OCSP_accept_responses_new(char **oids) 509X509_EXTENSION *
454 { 510OCSP_accept_responses_new(char **oids)
511{
455 int nid; 512 int nid;
456 STACK_OF(ASN1_OBJECT) *sk = NULL; 513 STACK_OF(ASN1_OBJECT) *sk = NULL;
457 ASN1_OBJECT *o = NULL; 514 ASN1_OBJECT *o = NULL;
458 X509_EXTENSION *x = NULL; 515 X509_EXTENSION *x = NULL;
459 516
460 if (!(sk = sk_ASN1_OBJECT_new_null())) goto err; 517 if (!(sk = sk_ASN1_OBJECT_new_null()))
461 while (oids && *oids) 518 goto err;
462 { 519 while (oids && *oids) {
463 if ((nid=OBJ_txt2nid(*oids))!=NID_undef&&(o=OBJ_nid2obj(nid))) 520 if ((nid = OBJ_txt2nid(*oids)) != NID_undef &&
464 sk_ASN1_OBJECT_push(sk, o); 521 (o = OBJ_nid2obj(nid)))
522 sk_ASN1_OBJECT_push(sk, o);
465 oids++; 523 oids++;
466 } 524 }
467 x = X509V3_EXT_i2d(NID_id_pkix_OCSP_acceptableResponses, 0, sk); 525 x = X509V3_EXT_i2d(NID_id_pkix_OCSP_acceptableResponses, 0, sk);
468err: 526err:
469 if (sk) sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free); 527 if (sk)
528 sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
470 return x; 529 return x;
471 } 530}
472 531
473/* ArchiveCutoff ::= GeneralizedTime */ 532/* ArchiveCutoff ::= GeneralizedTime */
474X509_EXTENSION *OCSP_archive_cutoff_new(char* tim) 533X509_EXTENSION *
475 { 534OCSP_archive_cutoff_new(char* tim)
476 X509_EXTENSION *x=NULL; 535{
536 X509_EXTENSION *x = NULL;
477 ASN1_GENERALIZEDTIME *gt = NULL; 537 ASN1_GENERALIZEDTIME *gt = NULL;
478 538
479 if (!(gt = ASN1_GENERALIZEDTIME_new())) goto err; 539 if (!(gt = ASN1_GENERALIZEDTIME_new()))
480 if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err; 540 goto err;
541 if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim)))
542 goto err;
481 x = X509V3_EXT_i2d(NID_id_pkix_OCSP_archiveCutoff, 0, gt); 543 x = X509V3_EXT_i2d(NID_id_pkix_OCSP_archiveCutoff, 0, gt);
482err: 544err:
483 if (gt) ASN1_GENERALIZEDTIME_free(gt); 545 if (gt)
546 ASN1_GENERALIZEDTIME_free(gt);
484 return x; 547 return x;
485 } 548}
486 549
487/* per ACCESS_DESCRIPTION parameter are oids, of which there are currently 550/* per ACCESS_DESCRIPTION parameter are oids, of which there are currently
488 * two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value. This 551 * two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value. This
489 * method forces NID_ad_ocsp and uniformResourceLocator [6] IA5String. 552 * method forces NID_ad_ocsp and uniformResourceLocator [6] IA5String.
490 */ 553 */
491X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls) 554X509_EXTENSION *
492 { 555OCSP_url_svcloc_new(X509_NAME* issuer, char **urls)
556{
493 X509_EXTENSION *x = NULL; 557 X509_EXTENSION *x = NULL;
494 ASN1_IA5STRING *ia5 = NULL; 558 ASN1_IA5STRING *ia5 = NULL;
495 OCSP_SERVICELOC *sloc = NULL; 559 OCSP_SERVICELOC *sloc = NULL;
496 ACCESS_DESCRIPTION *ad = NULL; 560 ACCESS_DESCRIPTION *ad = NULL;
497 561
498 if (!(sloc = OCSP_SERVICELOC_new())) goto err; 562 if (!(sloc = OCSP_SERVICELOC_new()))
499 if (!(sloc->issuer = X509_NAME_dup(issuer))) goto err; 563 goto err;
500 if (urls && *urls && !(sloc->locator = sk_ACCESS_DESCRIPTION_new_null())) goto err; 564 if (!(sloc->issuer = X509_NAME_dup(issuer)))
501 while (urls && *urls) 565 goto err;
502 { 566 if (urls && *urls &&
503 if (!(ad = ACCESS_DESCRIPTION_new())) goto err; 567 !(sloc->locator = sk_ACCESS_DESCRIPTION_new_null()))
504 if (!(ad->method=OBJ_nid2obj(NID_ad_OCSP))) goto err; 568 goto err;
505 if (!(ad->location = GENERAL_NAME_new())) goto err; 569 while (urls && *urls) {
506 if (!(ia5 = ASN1_IA5STRING_new())) goto err; 570 if (!(ad = ACCESS_DESCRIPTION_new()))
507 if (!ASN1_STRING_set((ASN1_STRING*)ia5, *urls, -1)) goto err; 571 goto err;
572 if (!(ad->method = OBJ_nid2obj(NID_ad_OCSP)))
573 goto err;
574 if (!(ad->location = GENERAL_NAME_new()))
575 goto err;
576 if (!(ia5 = ASN1_IA5STRING_new()))
577 goto err;
578 if (!ASN1_STRING_set((ASN1_STRING*)ia5, *urls, -1))
579 goto err;
508 ad->location->type = GEN_URI; 580 ad->location->type = GEN_URI;
509 ad->location->d.ia5 = ia5; 581 ad->location->d.ia5 = ia5;
510 if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad)) goto err; 582 if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad))
583 goto err;
511 urls++; 584 urls++;
512 } 585 }
513 x = X509V3_EXT_i2d(NID_id_pkix_OCSP_serviceLocator, 0, sloc); 586 x = X509V3_EXT_i2d(NID_id_pkix_OCSP_serviceLocator, 0, sloc);
514err: 587err:
515 if (sloc) OCSP_SERVICELOC_free(sloc); 588 if (sloc)
589 OCSP_SERVICELOC_free(sloc);
516 return x; 590 return x;
517 } 591}
518