2
0

ocsp_ext.c 17 KB

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