v3_crld.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /* v3_crld.c */
  2. /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  3. * project 1999.
  4. */
  5. /* ====================================================================
  6. * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. All advertising materials mentioning features or use of this
  21. * software must display the following acknowledgment:
  22. * "This product includes software developed by the OpenSSL Project
  23. * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  24. *
  25. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  26. * endorse or promote products derived from this software without
  27. * prior written permission. For written permission, please contact
  28. * licensing@OpenSSL.org.
  29. *
  30. * 5. Products derived from this software may not be called "OpenSSL"
  31. * nor may "OpenSSL" appear in their names without prior written
  32. * permission of the OpenSSL Project.
  33. *
  34. * 6. Redistributions of any form whatsoever must retain the following
  35. * acknowledgment:
  36. * "This product includes software developed by the OpenSSL Project
  37. * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  38. *
  39. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  40. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  41. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  43. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  44. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  45. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  46. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  48. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  50. * OF THE POSSIBILITY OF SUCH DAMAGE.
  51. * ====================================================================
  52. *
  53. * This product includes cryptographic software written by Eric Young
  54. * (eay@cryptsoft.com). This product includes software written by Tim
  55. * Hudson (tjh@cryptsoft.com).
  56. *
  57. */
  58. #include <stdio.h>
  59. #include "cryptlib.h"
  60. #include <openssl/conf.h>
  61. #include <openssl/asn1.h>
  62. #include <openssl/asn1t.h>
  63. #include <openssl/x509v3.h>
  64. static void *v2i_crld(const X509V3_EXT_METHOD *method,
  65. X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
  66. static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out,
  67. int indent);
  68. const X509V3_EXT_METHOD v3_crld =
  69. {
  70. NID_crl_distribution_points, 0, ASN1_ITEM_ref(CRL_DIST_POINTS),
  71. 0,0,0,0,
  72. 0,0,
  73. 0,
  74. v2i_crld,
  75. i2r_crldp,0,
  76. NULL
  77. };
  78. const X509V3_EXT_METHOD v3_freshest_crl =
  79. {
  80. NID_freshest_crl, 0, ASN1_ITEM_ref(CRL_DIST_POINTS),
  81. 0,0,0,0,
  82. 0,0,
  83. 0,
  84. v2i_crld,
  85. i2r_crldp,0,
  86. NULL
  87. };
  88. static STACK_OF(GENERAL_NAME) *gnames_from_sectname(X509V3_CTX *ctx, char *sect)
  89. {
  90. STACK_OF(CONF_VALUE) *gnsect;
  91. STACK_OF(GENERAL_NAME) *gens;
  92. if (*sect == '@')
  93. gnsect = X509V3_get_section(ctx, sect + 1);
  94. else
  95. gnsect = X509V3_parse_list(sect);
  96. if (!gnsect)
  97. {
  98. X509V3err(X509V3_F_GNAMES_FROM_SECTNAME,
  99. X509V3_R_SECTION_NOT_FOUND);
  100. return NULL;
  101. }
  102. gens = v2i_GENERAL_NAMES(NULL, ctx, gnsect);
  103. if (*sect == '@')
  104. X509V3_section_free(ctx, gnsect);
  105. else
  106. sk_CONF_VALUE_pop_free(gnsect, X509V3_conf_free);
  107. return gens;
  108. }
  109. static int set_dist_point_name(DIST_POINT_NAME **pdp, X509V3_CTX *ctx,
  110. CONF_VALUE *cnf)
  111. {
  112. STACK_OF(GENERAL_NAME) *fnm = NULL;
  113. STACK_OF(X509_NAME_ENTRY) *rnm = NULL;
  114. if (!strncmp(cnf->name, "fullname", 9))
  115. {
  116. fnm = gnames_from_sectname(ctx, cnf->value);
  117. if (!fnm)
  118. goto err;
  119. }
  120. else if (!strcmp(cnf->name, "relativename"))
  121. {
  122. int ret;
  123. STACK_OF(CONF_VALUE) *dnsect;
  124. X509_NAME *nm;
  125. nm = X509_NAME_new();
  126. if (!nm)
  127. return -1;
  128. dnsect = X509V3_get_section(ctx, cnf->value);
  129. if (!dnsect)
  130. {
  131. X509V3err(X509V3_F_SET_DIST_POINT_NAME,
  132. X509V3_R_SECTION_NOT_FOUND);
  133. return -1;
  134. }
  135. ret = X509V3_NAME_from_section(nm, dnsect, MBSTRING_ASC);
  136. X509V3_section_free(ctx, dnsect);
  137. rnm = nm->entries;
  138. nm->entries = NULL;
  139. X509_NAME_free(nm);
  140. if (!ret || sk_X509_NAME_ENTRY_num(rnm) <= 0)
  141. goto err;
  142. /* Since its a name fragment can't have more than one
  143. * RDNSequence
  144. */
  145. if (sk_X509_NAME_ENTRY_value(rnm,
  146. sk_X509_NAME_ENTRY_num(rnm) - 1)->set)
  147. {
  148. X509V3err(X509V3_F_SET_DIST_POINT_NAME,
  149. X509V3_R_INVALID_MULTIPLE_RDNS);
  150. goto err;
  151. }
  152. }
  153. else
  154. return 0;
  155. if (*pdp)
  156. {
  157. X509V3err(X509V3_F_SET_DIST_POINT_NAME,
  158. X509V3_R_DISTPOINT_ALREADY_SET);
  159. goto err;
  160. }
  161. *pdp = DIST_POINT_NAME_new();
  162. if (!*pdp)
  163. goto err;
  164. if (fnm)
  165. {
  166. (*pdp)->type = 0;
  167. (*pdp)->name.fullname = fnm;
  168. }
  169. else
  170. {
  171. (*pdp)->type = 1;
  172. (*pdp)->name.relativename = rnm;
  173. }
  174. return 1;
  175. err:
  176. if (fnm)
  177. sk_GENERAL_NAME_pop_free(fnm, GENERAL_NAME_free);
  178. if (rnm)
  179. sk_X509_NAME_ENTRY_pop_free(rnm, X509_NAME_ENTRY_free);
  180. return -1;
  181. }
  182. static const BIT_STRING_BITNAME reason_flags[] = {
  183. {0, "Unused", "unused"},
  184. {1, "Key Compromise", "keyCompromise"},
  185. {2, "CA Compromise", "CACompromise"},
  186. {3, "Affiliation Changed", "affiliationChanged"},
  187. {4, "Superseded", "superseded"},
  188. {5, "Cessation Of Operation", "cessationOfOperation"},
  189. {6, "Certificate Hold", "certificateHold"},
  190. {7, "Privilege Withdrawn", "privilegeWithdrawn"},
  191. {8, "AA Compromise", "AACompromise"},
  192. {-1, NULL, NULL}
  193. };
  194. static int set_reasons(ASN1_BIT_STRING **preas, char *value)
  195. {
  196. STACK_OF(CONF_VALUE) *rsk = NULL;
  197. const BIT_STRING_BITNAME *pbn;
  198. const char *bnam;
  199. int i, ret = 0;
  200. rsk = X509V3_parse_list(value);
  201. if (!rsk)
  202. return 0;
  203. if (*preas)
  204. return 0;
  205. for (i = 0; i < sk_CONF_VALUE_num(rsk); i++)
  206. {
  207. bnam = sk_CONF_VALUE_value(rsk, i)->name;
  208. if (!*preas)
  209. {
  210. *preas = ASN1_BIT_STRING_new();
  211. if (!*preas)
  212. goto err;
  213. }
  214. for (pbn = reason_flags; pbn->lname; pbn++)
  215. {
  216. if (!strcmp(pbn->sname, bnam))
  217. {
  218. if (!ASN1_BIT_STRING_set_bit(*preas,
  219. pbn->bitnum, 1))
  220. goto err;
  221. break;
  222. }
  223. }
  224. if (!pbn->lname)
  225. goto err;
  226. }
  227. ret = 1;
  228. err:
  229. sk_CONF_VALUE_pop_free(rsk, X509V3_conf_free);
  230. return ret;
  231. }
  232. static int print_reasons(BIO *out, const char *rname,
  233. ASN1_BIT_STRING *rflags, int indent)
  234. {
  235. int first = 1;
  236. const BIT_STRING_BITNAME *pbn;
  237. BIO_printf(out, "%*s%s:\n%*s", indent, "", rname, indent + 2, "");
  238. for (pbn = reason_flags; pbn->lname; pbn++)
  239. {
  240. if (ASN1_BIT_STRING_get_bit(rflags, pbn->bitnum))
  241. {
  242. if (first)
  243. first = 0;
  244. else
  245. BIO_puts(out, ", ");
  246. BIO_puts(out, pbn->lname);
  247. }
  248. }
  249. if (first)
  250. BIO_puts(out, "<EMPTY>\n");
  251. else
  252. BIO_puts(out, "\n");
  253. return 1;
  254. }
  255. static DIST_POINT *crldp_from_section(X509V3_CTX *ctx,
  256. STACK_OF(CONF_VALUE) *nval)
  257. {
  258. int i;
  259. CONF_VALUE *cnf;
  260. DIST_POINT *point = NULL;
  261. point = DIST_POINT_new();
  262. if (!point)
  263. goto err;
  264. for(i = 0; i < sk_CONF_VALUE_num(nval); i++)
  265. {
  266. int ret;
  267. cnf = sk_CONF_VALUE_value(nval, i);
  268. ret = set_dist_point_name(&point->distpoint, ctx, cnf);
  269. if (ret > 0)
  270. continue;
  271. if (ret < 0)
  272. goto err;
  273. if (!strcmp(cnf->name, "reasons"))
  274. {
  275. if (!set_reasons(&point->reasons, cnf->value))
  276. goto err;
  277. }
  278. else if (!strcmp(cnf->name, "CRLissuer"))
  279. {
  280. point->CRLissuer =
  281. gnames_from_sectname(ctx, cnf->value);
  282. if (!point->CRLissuer)
  283. goto err;
  284. }
  285. }
  286. return point;
  287. err:
  288. if (point)
  289. DIST_POINT_free(point);
  290. return NULL;
  291. }
  292. static void *v2i_crld(const X509V3_EXT_METHOD *method,
  293. X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
  294. {
  295. STACK_OF(DIST_POINT) *crld = NULL;
  296. GENERAL_NAMES *gens = NULL;
  297. GENERAL_NAME *gen = NULL;
  298. CONF_VALUE *cnf;
  299. int i;
  300. if(!(crld = sk_DIST_POINT_new_null())) goto merr;
  301. for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
  302. DIST_POINT *point;
  303. cnf = sk_CONF_VALUE_value(nval, i);
  304. if (!cnf->value)
  305. {
  306. STACK_OF(CONF_VALUE) *dpsect;
  307. dpsect = X509V3_get_section(ctx, cnf->name);
  308. if (!dpsect)
  309. goto err;
  310. point = crldp_from_section(ctx, dpsect);
  311. X509V3_section_free(ctx, dpsect);
  312. if (!point)
  313. goto err;
  314. if(!sk_DIST_POINT_push(crld, point))
  315. {
  316. DIST_POINT_free(point);
  317. goto merr;
  318. }
  319. }
  320. else
  321. {
  322. if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
  323. goto err;
  324. if(!(gens = GENERAL_NAMES_new()))
  325. goto merr;
  326. if(!sk_GENERAL_NAME_push(gens, gen))
  327. goto merr;
  328. gen = NULL;
  329. if(!(point = DIST_POINT_new()))
  330. goto merr;
  331. if(!sk_DIST_POINT_push(crld, point))
  332. {
  333. DIST_POINT_free(point);
  334. goto merr;
  335. }
  336. if(!(point->distpoint = DIST_POINT_NAME_new()))
  337. goto merr;
  338. point->distpoint->name.fullname = gens;
  339. point->distpoint->type = 0;
  340. gens = NULL;
  341. }
  342. }
  343. return crld;
  344. merr:
  345. X509V3err(X509V3_F_V2I_CRLD,ERR_R_MALLOC_FAILURE);
  346. err:
  347. GENERAL_NAME_free(gen);
  348. GENERAL_NAMES_free(gens);
  349. sk_DIST_POINT_pop_free(crld, DIST_POINT_free);
  350. return NULL;
  351. }
  352. IMPLEMENT_STACK_OF(DIST_POINT)
  353. IMPLEMENT_ASN1_SET_OF(DIST_POINT)
  354. static int dpn_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
  355. void *exarg)
  356. {
  357. DIST_POINT_NAME *dpn = (DIST_POINT_NAME *)*pval;
  358. switch(operation)
  359. {
  360. case ASN1_OP_NEW_POST:
  361. dpn->dpname = NULL;
  362. break;
  363. case ASN1_OP_FREE_POST:
  364. if (dpn->dpname)
  365. X509_NAME_free(dpn->dpname);
  366. break;
  367. }
  368. return 1;
  369. }
  370. ASN1_CHOICE_cb(DIST_POINT_NAME, dpn_cb) = {
  371. ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0),
  372. ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1)
  373. } ASN1_CHOICE_END_cb(DIST_POINT_NAME, DIST_POINT_NAME, type)
  374. IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT_NAME)
  375. ASN1_SEQUENCE(DIST_POINT) = {
  376. ASN1_EXP_OPT(DIST_POINT, distpoint, DIST_POINT_NAME, 0),
  377. ASN1_IMP_OPT(DIST_POINT, reasons, ASN1_BIT_STRING, 1),
  378. ASN1_IMP_SEQUENCE_OF_OPT(DIST_POINT, CRLissuer, GENERAL_NAME, 2)
  379. } ASN1_SEQUENCE_END(DIST_POINT)
  380. IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT)
  381. ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) =
  382. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CRLDistributionPoints, DIST_POINT)
  383. ASN1_ITEM_TEMPLATE_END(CRL_DIST_POINTS)
  384. IMPLEMENT_ASN1_FUNCTIONS(CRL_DIST_POINTS)
  385. ASN1_SEQUENCE(ISSUING_DIST_POINT) = {
  386. ASN1_EXP_OPT(ISSUING_DIST_POINT, distpoint, DIST_POINT_NAME, 0),
  387. ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyuser, ASN1_FBOOLEAN, 1),
  388. ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyCA, ASN1_FBOOLEAN, 2),
  389. ASN1_IMP_OPT(ISSUING_DIST_POINT, onlysomereasons, ASN1_BIT_STRING, 3),
  390. ASN1_IMP_OPT(ISSUING_DIST_POINT, indirectCRL, ASN1_FBOOLEAN, 4),
  391. ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyattr, ASN1_FBOOLEAN, 5)
  392. } ASN1_SEQUENCE_END(ISSUING_DIST_POINT)
  393. IMPLEMENT_ASN1_FUNCTIONS(ISSUING_DIST_POINT)
  394. static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out,
  395. int indent);
  396. static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
  397. STACK_OF(CONF_VALUE) *nval);
  398. const X509V3_EXT_METHOD v3_idp =
  399. {
  400. NID_issuing_distribution_point, X509V3_EXT_MULTILINE,
  401. ASN1_ITEM_ref(ISSUING_DIST_POINT),
  402. 0,0,0,0,
  403. 0,0,
  404. 0,
  405. v2i_idp,
  406. i2r_idp,0,
  407. NULL
  408. };
  409. static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
  410. STACK_OF(CONF_VALUE) *nval)
  411. {
  412. ISSUING_DIST_POINT *idp = NULL;
  413. CONF_VALUE *cnf;
  414. char *name, *val;
  415. int i, ret;
  416. idp = ISSUING_DIST_POINT_new();
  417. if (!idp)
  418. goto merr;
  419. for(i = 0; i < sk_CONF_VALUE_num(nval); i++)
  420. {
  421. cnf = sk_CONF_VALUE_value(nval, i);
  422. name = cnf->name;
  423. val = cnf->value;
  424. ret = set_dist_point_name(&idp->distpoint, ctx, cnf);
  425. if (ret > 0)
  426. continue;
  427. if (ret < 0)
  428. goto err;
  429. if (!strcmp(name, "onlyuser"))
  430. {
  431. if (!X509V3_get_value_bool(cnf, &idp->onlyuser))
  432. goto err;
  433. }
  434. else if (!strcmp(name, "onlyCA"))
  435. {
  436. if (!X509V3_get_value_bool(cnf, &idp->onlyCA))
  437. goto err;
  438. }
  439. else if (!strcmp(name, "onlyAA"))
  440. {
  441. if (!X509V3_get_value_bool(cnf, &idp->onlyattr))
  442. goto err;
  443. }
  444. else if (!strcmp(name, "indirectCRL"))
  445. {
  446. if (!X509V3_get_value_bool(cnf, &idp->indirectCRL))
  447. goto err;
  448. }
  449. else if (!strcmp(name, "onlysomereasons"))
  450. {
  451. if (!set_reasons(&idp->onlysomereasons, val))
  452. goto err;
  453. }
  454. else
  455. {
  456. X509V3err(X509V3_F_V2I_IDP, X509V3_R_INVALID_NAME);
  457. X509V3_conf_err(cnf);
  458. goto err;
  459. }
  460. }
  461. return idp;
  462. merr:
  463. X509V3err(X509V3_F_V2I_IDP,ERR_R_MALLOC_FAILURE);
  464. err:
  465. ISSUING_DIST_POINT_free(idp);
  466. return NULL;
  467. }
  468. static int print_gens(BIO *out, STACK_OF(GENERAL_NAME) *gens, int indent)
  469. {
  470. int i;
  471. for (i = 0; i < sk_GENERAL_NAME_num(gens); i++)
  472. {
  473. BIO_printf(out, "%*s", indent + 2, "");
  474. GENERAL_NAME_print(out, sk_GENERAL_NAME_value(gens, i));
  475. BIO_puts(out, "\n");
  476. }
  477. return 1;
  478. }
  479. static int print_distpoint(BIO *out, DIST_POINT_NAME *dpn, int indent)
  480. {
  481. if (dpn->type == 0)
  482. {
  483. BIO_printf(out, "%*sFull Name:\n", indent, "");
  484. print_gens(out, dpn->name.fullname, indent);
  485. }
  486. else
  487. {
  488. X509_NAME ntmp;
  489. ntmp.entries = dpn->name.relativename;
  490. BIO_printf(out, "%*sRelative Name:\n%*s",
  491. indent, "", indent + 2, "");
  492. X509_NAME_print_ex(out, &ntmp, 0, XN_FLAG_ONELINE);
  493. BIO_puts(out, "\n");
  494. }
  495. return 1;
  496. }
  497. static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out,
  498. int indent)
  499. {
  500. ISSUING_DIST_POINT *idp = pidp;
  501. if (idp->distpoint)
  502. print_distpoint(out, idp->distpoint, indent);
  503. if (idp->onlyuser > 0)
  504. BIO_printf(out, "%*sOnly User Certificates\n", indent, "");
  505. if (idp->onlyCA > 0)
  506. BIO_printf(out, "%*sOnly CA Certificates\n", indent, "");
  507. if (idp->indirectCRL > 0)
  508. BIO_printf(out, "%*sIndirect CRL\n", indent, "");
  509. if (idp->onlysomereasons)
  510. print_reasons(out, "Only Some Reasons",
  511. idp->onlysomereasons, indent);
  512. if (idp->onlyattr > 0)
  513. BIO_printf(out, "%*sOnly Attribute Certificates\n", indent, "");
  514. if (!idp->distpoint && (idp->onlyuser <= 0) && (idp->onlyCA <= 0)
  515. && (idp->indirectCRL <= 0) && !idp->onlysomereasons
  516. && (idp->onlyattr <= 0))
  517. BIO_printf(out, "%*s<EMPTY>\n", indent, "");
  518. return 1;
  519. }
  520. static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out,
  521. int indent)
  522. {
  523. STACK_OF(DIST_POINT) *crld = pcrldp;
  524. DIST_POINT *point;
  525. int i;
  526. for(i = 0; i < sk_DIST_POINT_num(crld); i++)
  527. {
  528. BIO_puts(out, "\n");
  529. point = sk_DIST_POINT_value(crld, i);
  530. if(point->distpoint)
  531. print_distpoint(out, point->distpoint, indent);
  532. if(point->reasons)
  533. print_reasons(out, "Reasons", point->reasons,
  534. indent);
  535. if(point->CRLissuer)
  536. {
  537. BIO_printf(out, "%*sCRL Issuer:\n", indent, "");
  538. print_gens(out, point->CRLissuer, indent);
  539. }
  540. }
  541. return 1;
  542. }
  543. int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname)
  544. {
  545. int i;
  546. STACK_OF(X509_NAME_ENTRY) *frag;
  547. X509_NAME_ENTRY *ne;
  548. if (!dpn || (dpn->type != 1))
  549. return 1;
  550. frag = dpn->name.relativename;
  551. dpn->dpname = X509_NAME_dup(iname);
  552. if (!dpn->dpname)
  553. return 0;
  554. for (i = 0; i < sk_X509_NAME_ENTRY_num(frag); i++)
  555. {
  556. ne = sk_X509_NAME_ENTRY_value(frag, i);
  557. if (!X509_NAME_add_entry(dpn->dpname, ne, -1, i ? 0 : 1))
  558. {
  559. X509_NAME_free(dpn->dpname);
  560. dpn->dpname = NULL;
  561. return 0;
  562. }
  563. }
  564. /* generate cached encoding of name */
  565. if (i2d_X509_NAME(dpn->dpname, NULL) < 0)
  566. {
  567. X509_NAME_free(dpn->dpname);
  568. dpn->dpname = NULL;
  569. return 0;
  570. }
  571. return 1;
  572. }