v3_crld.c 17 KB

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