ocsp_ext.c 15.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/* ocsp_ext.c */
/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
 * project. */

/* History:
   This file was transfered to Richard Levitte from CertCo by Kathy
   Weinhold in mid-spring 2000 to be included in OpenSSL or released
   as a patch kit. */

/* ====================================================================
 * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
 *
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please contact
 *    openssl-core@openssl.org.
 *
 * 5. Products derived from this software may not be called "OpenSSL"
 *    nor may "OpenSSL" appear in their names without prior written
 *    permission of the OpenSSL Project.
 *
 * 6. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
 *
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 *
 * This product includes cryptographic software written by Eric Young
 * (eay@cryptsoft.com).  This product includes software written by Tim
 * Hudson (tjh@cryptsoft.com).
 *
 */

#include <stdio.h>
#include <cryptlib.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/ocsp.h>
D
 
Dr. Stephen Henson 已提交
69
#include <openssl/rand.h>
70 71
#include <openssl/x509v3.h>

D
Dr. Stephen Henson 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
/* Standard wrapper functions for extensions */

/* OCSP request extensions */

int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x)
	{
	return(X509v3_get_ext_count(x->tbsRequest->requestExtensions));
	}

int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos)
	{
	return(X509v3_get_ext_by_NID(x->tbsRequest->requestExtensions,nid,lastpos));
	}

int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos)
	{
	return(X509v3_get_ext_by_OBJ(x->tbsRequest->requestExtensions,obj,lastpos));
	}

int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos)
	{
	return(X509v3_get_ext_by_critical(x->tbsRequest->requestExtensions,crit,lastpos));
	}

X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc)
	{
	return(X509v3_get_ext(x->tbsRequest->requestExtensions,loc));
	}

X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc)
	{
	return(X509v3_delete_ext(x->tbsRequest->requestExtensions,loc));
	}

void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx)
	{
	return X509V3_get_d2i(x->tbsRequest->requestExtensions, nid, crit, idx);
	}

int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
							unsigned long flags)
	{
	return X509V3_add1_i2d(&x->tbsRequest->requestExtensions, nid, value, crit, flags);
	}

int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc)
	{
	return(X509v3_add_ext(&(x->tbsRequest->requestExtensions),ex,loc) != NULL);
	}

/* Single extensions */

int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x)
	{
	return(X509v3_get_ext_count(x->singleRequestExtensions));
	}

int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos)
	{
	return(X509v3_get_ext_by_NID(x->singleRequestExtensions,nid,lastpos));
	}

int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos)
	{
	return(X509v3_get_ext_by_OBJ(x->singleRequestExtensions,obj,lastpos));
	}

int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos)
	{
	return(X509v3_get_ext_by_critical(x->singleRequestExtensions,crit,lastpos));
	}

X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc)
	{
	return(X509v3_get_ext(x->singleRequestExtensions,loc));
	}

X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc)
	{
	return(X509v3_delete_ext(x->singleRequestExtensions,loc));
	}

void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx)
	{
	return X509V3_get_d2i(x->singleRequestExtensions, nid, crit, idx);
	}

int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
							unsigned long flags)
	{
	return X509V3_add1_i2d(&x->singleRequestExtensions, nid, value, crit, flags);
	}

int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc)
	{
	return(X509v3_add_ext(&(x->singleRequestExtensions),ex,loc) != NULL);
	}

/* OCSP Basic response */

int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x)
	{
	return(X509v3_get_ext_count(x->tbsResponseData->responseExtensions));
	}

int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos)
	{
	return(X509v3_get_ext_by_NID(x->tbsResponseData->responseExtensions,nid,lastpos));
	}

int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos)
	{
	return(X509v3_get_ext_by_OBJ(x->tbsResponseData->responseExtensions,obj,lastpos));
	}

int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos)
	{
	return(X509v3_get_ext_by_critical(x->tbsResponseData->responseExtensions,crit,lastpos));
	}

X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc)
	{
	return(X509v3_get_ext(x->tbsResponseData->responseExtensions,loc));
	}

X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc)
	{
	return(X509v3_delete_ext(x->tbsResponseData->responseExtensions,loc));
	}

void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx)
	{
	return X509V3_get_d2i(x->tbsResponseData->responseExtensions, nid, crit, idx);
	}

int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,
							unsigned long flags)
	{
	return X509V3_add1_i2d(&x->tbsResponseData->responseExtensions, nid, value, crit, flags);
	}

int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc)
	{
	return(X509v3_add_ext(&(x->tbsResponseData->responseExtensions),ex,loc) != NULL);
	}

/* OCSP single response extensions */

int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x)
	{
	return(X509v3_get_ext_count(x->singleExtensions));
	}

int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos)
	{
	return(X509v3_get_ext_by_NID(x->singleExtensions,nid,lastpos));
	}

int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos)
	{
	return(X509v3_get_ext_by_OBJ(x->singleExtensions,obj,lastpos));
	}

int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos)
	{
	return(X509v3_get_ext_by_critical(x->singleExtensions,crit,lastpos));
	}

X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc)
	{
	return(X509v3_get_ext(x->singleExtensions,loc));
	}

X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc)
	{
	return(X509v3_delete_ext(x->singleExtensions,loc));
	}

void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx)
	{
	return X509V3_get_d2i(x->singleExtensions, nid, crit, idx);
	}

int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,
							unsigned long flags)
	{
	return X509V3_add1_i2d(&x->singleExtensions, nid, value, crit, flags);
	}

int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc)
	{
	return(X509v3_add_ext(&(x->singleExtensions),ex,loc) != NULL);
	}
265 266 267 268

/* also CRL Entry Extensions */

ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(), 
B
Ben Laurie 已提交
269
				char *data, STACK_OF(ASN1_OBJECT) *sk)
270 271 272 273 274 275 276 277 278 279 280 281 282
        {
	int i;
	unsigned char *p, *b = NULL;

	if (data)
	        {
		if ((i=i2d(data,NULL)) <= 0) goto err;
		if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
			goto err;
	        if (i2d(data, &p) <= 0) goto err;
		}
	else if (sk)
	        {
B
Ben Laurie 已提交
283
		if ((i=i2d_ASN1_SET_OF_ASN1_OBJECT(sk,NULL,i2d,V_ASN1_SEQUENCE,
284 285 286
				   V_ASN1_UNIVERSAL,IS_SEQUENCE))<=0) goto err;
		if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
			goto err;
B
Ben Laurie 已提交
287
		if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,i2d,V_ASN1_SEQUENCE,
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
				 V_ASN1_UNIVERSAL,IS_SEQUENCE)<=0) goto err;
		}
	else
		{
		OCSPerr(OCSP_F_ASN1_STRING_ENCODE,OCSP_R_BAD_DATA);
		goto err;
		}
	if (!s && !(s = ASN1_STRING_new())) goto err;
	if (!(ASN1_STRING_set(s, b, i))) goto err;
	OPENSSL_free(b);
	return s;
err:
	if (b) OPENSSL_free(b);
	return NULL;
	}

D
 
Dr. Stephen Henson 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
/* Nonce handling functions */

/* Add a nonce to an OCSP request. A nonce can be specificed or if NULL
 * a random nonce will be generated.
 */

int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len)
	{
	unsigned char *tmpval;
	ASN1_OCTET_STRING os;
	int ret = 0;
	if (len <= 0) len = OCSP_DEFAULT_NONCE_LENGTH;
	if (val) tmpval = val;
	else
		{
		if (!(tmpval = OPENSSL_malloc(len))) goto err;
		RAND_pseudo_bytes(tmpval, len);
		}
	os.data = tmpval;
	os.length = len;
	if(!OCSP_REQUEST_add1_ext_i2d(req, NID_id_pkix_OCSP_Nonce,
			&os, 0, X509V3_ADD_REPLACE))
				goto err;
	ret = 1;
	err:
	if(!val) OPENSSL_free(tmpval);
	return ret;
	}

/* Check nonce validity in a request and response: the nonce
 * must be either absent in both or present and equal in both. 
 */
int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs)
	{
	/*
	 * Since we are only interested in the presence or absence of
	 * the nonce and comparing its value there is no need to use
	 * the X509V3 routines: this way we can avoid them allocating an
	 * ASN1_OCTET_STRING structure for the value which would be
	 * freed immediately anyway.
	 */

	int ret = 0, req_idx, resp_idx;
	X509_EXTENSION *req_ext, *resp_ext;
	req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
	resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1);
	/* If both absent its OK */
	if((req_idx < 0) && (resp_idx < 0)) return 1;
	if((req_idx < 0) && (resp_idx >= 0))
		{
		OCSPerr(OCSP_F_OCSP_CHECK_NONCE, OCSP_R_NONCE_MISSING_IN_RESPONSE);
		goto err;
		}
	if((req_idx < 0) && (resp_idx >= 0))
		{
		OCSPerr(OCSP_F_OCSP_CHECK_NONCE, OCSP_R_UNEXPECTED_NONCE_IN_RESPONSE);
		goto err;
		}
	req_ext = OCSP_REQUEST_get_ext(req, req_idx);
	resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx);
	if(ASN1_OCTET_STRING_cmp(req_ext->value, resp_ext->value))
		{
		OCSPerr(OCSP_F_OCSP_CHECK_NONCE, OCSP_R_NONCE_VALUE_MISMATCH);
		goto err;
		}
	ret = 1;
	err:
	return ret;
	}

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
X509_EXTENSION *OCSP_nonce_new(void *p, unsigned int len)
        {
	X509_EXTENSION *x=NULL;
	if (!(x = X509_EXTENSION_new())) goto err;
	if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_Nonce))) goto err;
	if (!(ASN1_OCTET_STRING_set(x->value, p, len))) goto err;
	return x;
err:
	if (x) X509_EXTENSION_free(x);
	return NULL;
	}

X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim)
        {
	X509_EXTENSION *x = NULL;
	OCSP_CRLID *cid = NULL;
	
	if (!(cid = OCSP_CRLID_new())) goto err;
	if (url)
	        {
		if (!(cid->crlUrl = ASN1_IA5STRING_new())) goto err;
		if (!(ASN1_STRING_set(cid->crlUrl, url, -1))) goto err;
		}
	if (n)
	        {
		if (!(cid->crlNum = ASN1_INTEGER_new())) goto err;
		if (!(ASN1_INTEGER_set(cid->crlNum, *n))) goto err;
		}
402
	if (tim)
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
	        {
		if (!(cid->crlTime = ASN1_GENERALIZEDTIME_new())) goto err;
		if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim))) 
		        goto err;
		}
	if (!(x = X509_EXTENSION_new())) goto err;
	if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_CrlID))) goto err;
	if (!(ASN1_STRING_encode(x->value,i2d_OCSP_CRLID,(char*)cid,NULL)))
	        goto err;
	OCSP_CRLID_free(cid);
	return x;
err:
	if (x) X509_EXTENSION_free(x);
	if (cid) OCSP_CRLID_free(cid);
	return NULL;
	}

/*   AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */
X509_EXTENSION *OCSP_accept_responses_new(char **oids)
        {
	int nid;
424
	STACK_OF(ASN1_OBJECT) *sk = NULL;
425 426
	ASN1_OBJECT *o = NULL;
        X509_EXTENSION *x = NULL;
B
Ben Laurie 已提交
427 428

	if (!(sk = sk_ASN1_OBJECT_new(NULL))) goto err;
429 430 431
	while (oids && *oids)
	        {
		if ((nid=OBJ_txt2nid(*oids))!=NID_undef&&(o=OBJ_nid2obj(nid))) 
B
Ben Laurie 已提交
432
		        sk_ASN1_OBJECT_push(sk, o);
433 434 435 436 437 438 439
		oids++;
		}
	if (!(x = X509_EXTENSION_new())) goto err;
	if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_acceptableResponses)))
		goto err;
	if (!(ASN1_STRING_encode(x->value,i2d_ASN1_OBJECT,NULL,sk)))
	        goto err;
440
	sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
441 442 443
	return x;
err:
	if (x) X509_EXTENSION_free(x);
444
	if (sk) sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
	return NULL;
        }

/*  ArchiveCutoff ::= GeneralizedTime */
X509_EXTENSION *OCSP_archive_cutoff_new(char* tim)
        {
	X509_EXTENSION *x=NULL;
	ASN1_GENERALIZEDTIME *gt = NULL;

	if (!(gt = ASN1_GENERALIZEDTIME_new())) goto err;
	if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err;
	if (!(x = X509_EXTENSION_new())) goto err;
	if (!(x->object=OBJ_nid2obj(NID_id_pkix_OCSP_archiveCutoff)))goto err;
	if (!(ASN1_STRING_encode(x->value,i2d_ASN1_GENERALIZEDTIME,
				 (char*)gt,NULL))) goto err;
	ASN1_GENERALIZEDTIME_free(gt);
	return x;
err:
	if (gt) ASN1_GENERALIZEDTIME_free(gt);
	if (x) X509_EXTENSION_free(x);
	return NULL;
	}

/* per ACCESS_DESCRIPTION parameter are oids, of which there are currently
 * two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value.  This
 * method forces NID_ad_ocsp and uniformResourceLocator [6] IA5String.
 */
X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls)
        {
	X509_EXTENSION *x = NULL;
	ASN1_IA5STRING *ia5 = NULL;
	OCSP_SERVICELOC *sloc = NULL;
	ACCESS_DESCRIPTION *ad = NULL;
	
	if (!(sloc = OCSP_SERVICELOC_new())) goto err;
	if (!(sloc->issuer = X509_NAME_dup(issuer))) goto err;
	if (urls && *urls && !(sloc->locator = sk_ACCESS_DESCRIPTION_new(NULL))) goto err;
	while (urls && *urls)
	        {
		if (!(ad = ACCESS_DESCRIPTION_new())) goto err;
		if (!(ad->method=OBJ_nid2obj(NID_ad_OCSP))) goto err;
		if (!(ad->location = GENERAL_NAME_new())) goto err;
	        if (!(ia5 = ASN1_IA5STRING_new())) goto err;
		if (!ASN1_STRING_set((ASN1_STRING*)ia5, *urls, -1)) goto err;
		ad->location->type = GEN_URI;
		ad->location->d.ia5 = ia5;
		if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad)) goto err;
		urls++;
		}
	if (!(x = X509_EXTENSION_new())) goto err;
	if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_serviceLocator))) 
	        goto err;
	if (!(ASN1_STRING_encode(x->value, i2d_OCSP_SERVICELOC,
				 (char*)sloc, NULL))) goto err;
	OCSP_SERVICELOC_free(sloc);
	return x;
err:
	if (x) X509_EXTENSION_free(x);
	if (sloc) OCSP_SERVICELOC_free(sloc);
	return NULL;
	}