You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

617 lines
16 KiB

  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. #include <stdio.h>
  57. #include <string.h>
  58. #include <openssl/asn1.h>
  59. #include <openssl/asn1t.h>
  60. #include <openssl/conf.h>
  61. #include <openssl/err.h>
  62. #include <openssl/mem.h>
  63. #include <openssl/obj.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. {
  71. NID_crl_distribution_points, 0, ASN1_ITEM_ref(CRL_DIST_POINTS),
  72. 0,0,0,0,
  73. 0,0,
  74. 0,
  75. v2i_crld,
  76. i2r_crldp,0,
  77. NULL
  78. };
  79. const X509V3_EXT_METHOD v3_freshest_crl =
  80. {
  81. NID_freshest_crl, 0, ASN1_ITEM_ref(CRL_DIST_POINTS),
  82. 0,0,0,0,
  83. 0,0,
  84. 0,
  85. v2i_crld,
  86. i2r_crldp,0,
  87. NULL
  88. };
  89. static STACK_OF(GENERAL_NAME) *gnames_from_sectname(X509V3_CTX *ctx, char *sect)
  90. {
  91. STACK_OF(CONF_VALUE) *gnsect;
  92. STACK_OF(GENERAL_NAME) *gens;
  93. if (*sect == '@')
  94. gnsect = X509V3_get_section(ctx, sect + 1);
  95. else
  96. gnsect = X509V3_parse_list(sect);
  97. if (!gnsect)
  98. {
  99. OPENSSL_PUT_ERROR(X509V3, gnames_from_sectname, 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. OPENSSL_PUT_ERROR(X509V3, set_dist_point_name, X509V3_R_SECTION_NOT_FOUND);
  132. return -1;
  133. }
  134. ret = X509V3_NAME_from_section(nm, dnsect, MBSTRING_ASC);
  135. X509V3_section_free(ctx, dnsect);
  136. rnm = nm->entries;
  137. nm->entries = NULL;
  138. X509_NAME_free(nm);
  139. if (!ret || sk_X509_NAME_ENTRY_num(rnm) <= 0)
  140. goto err;
  141. /* Since its a name fragment can't have more than one
  142. * RDNSequence
  143. */
  144. if (sk_X509_NAME_ENTRY_value(rnm,
  145. sk_X509_NAME_ENTRY_num(rnm) - 1)->set)
  146. {
  147. OPENSSL_PUT_ERROR(X509V3, set_dist_point_name, X509V3_R_INVALID_MULTIPLE_RDNS);
  148. goto err;
  149. }
  150. }
  151. else
  152. return 0;
  153. if (*pdp)
  154. {
  155. OPENSSL_PUT_ERROR(X509V3, set_dist_point_name, X509V3_R_DISTPOINT_ALREADY_SET);
  156. goto err;
  157. }
  158. *pdp = DIST_POINT_NAME_new();
  159. if (!*pdp)
  160. goto err;
  161. if (fnm)
  162. {
  163. (*pdp)->type = 0;
  164. (*pdp)->name.fullname = fnm;
  165. }
  166. else
  167. {
  168. (*pdp)->type = 1;
  169. (*pdp)->name.relativename = rnm;
  170. }
  171. return 1;
  172. err:
  173. if (fnm)
  174. sk_GENERAL_NAME_pop_free(fnm, GENERAL_NAME_free);
  175. if (rnm)
  176. sk_X509_NAME_ENTRY_pop_free(rnm, X509_NAME_ENTRY_free);
  177. return -1;
  178. }
  179. static const BIT_STRING_BITNAME reason_flags[] = {
  180. {0, "Unused", "unused"},
  181. {1, "Key Compromise", "keyCompromise"},
  182. {2, "CA Compromise", "CACompromise"},
  183. {3, "Affiliation Changed", "affiliationChanged"},
  184. {4, "Superseded", "superseded"},
  185. {5, "Cessation Of Operation", "cessationOfOperation"},
  186. {6, "Certificate Hold", "certificateHold"},
  187. {7, "Privilege Withdrawn", "privilegeWithdrawn"},
  188. {8, "AA Compromise", "AACompromise"},
  189. {-1, NULL, NULL}
  190. };
  191. static int set_reasons(ASN1_BIT_STRING **preas, char *value)
  192. {
  193. STACK_OF(CONF_VALUE) *rsk = NULL;
  194. const BIT_STRING_BITNAME *pbn;
  195. const char *bnam;
  196. size_t i;
  197. int ret = 0;
  198. rsk = X509V3_parse_list(value);
  199. if (!rsk)
  200. return 0;
  201. if (*preas)
  202. return 0;
  203. for (i = 0; i < sk_CONF_VALUE_num(rsk); i++)
  204. {
  205. bnam = sk_CONF_VALUE_value(rsk, i)->name;
  206. if (!*preas)
  207. {
  208. *preas = ASN1_BIT_STRING_new();
  209. if (!*preas)
  210. goto err;
  211. }
  212. for (pbn = reason_flags; pbn->lname; pbn++)
  213. {
  214. if (!strcmp(pbn->sname, bnam))
  215. {
  216. if (!ASN1_BIT_STRING_set_bit(*preas,
  217. pbn->bitnum, 1))
  218. goto err;
  219. break;
  220. }
  221. }
  222. if (!pbn->lname)
  223. goto err;
  224. }
  225. ret = 1;
  226. err:
  227. sk_CONF_VALUE_pop_free(rsk, X509V3_conf_free);
  228. return ret;
  229. }
  230. static int print_reasons(BIO *out, const char *rname,
  231. ASN1_BIT_STRING *rflags, int indent)
  232. {
  233. int first = 1;
  234. const BIT_STRING_BITNAME *pbn;
  235. BIO_printf(out, "%*s%s:\n%*s", indent, "", rname, indent + 2, "");
  236. for (pbn = reason_flags; pbn->lname; pbn++)
  237. {
  238. if (ASN1_BIT_STRING_get_bit(rflags, pbn->bitnum))
  239. {
  240. if (first)
  241. first = 0;
  242. else
  243. BIO_puts(out, ", ");
  244. BIO_puts(out, pbn->lname);
  245. }
  246. }
  247. if (first)
  248. BIO_puts(out, "<EMPTY>\n");
  249. else
  250. BIO_puts(out, "\n");
  251. return 1;
  252. }
  253. static DIST_POINT *crldp_from_section(X509V3_CTX *ctx,
  254. STACK_OF(CONF_VALUE) *nval)
  255. {
  256. size_t i;
  257. CONF_VALUE *cnf;
  258. DIST_POINT *point = NULL;
  259. point = DIST_POINT_new();
  260. if (!point)
  261. goto err;
  262. for(i = 0; i < sk_CONF_VALUE_num(nval); i++)
  263. {
  264. int ret;
  265. cnf = sk_CONF_VALUE_value(nval, i);
  266. ret = set_dist_point_name(&point->distpoint, ctx, cnf);
  267. if (ret > 0)
  268. continue;
  269. if (ret < 0)
  270. goto err;
  271. if (!strcmp(cnf->name, "reasons"))
  272. {
  273. if (!set_reasons(&point->reasons, cnf->value))
  274. goto err;
  275. }
  276. else if (!strcmp(cnf->name, "CRLissuer"))
  277. {
  278. point->CRLissuer =
  279. gnames_from_sectname(ctx, cnf->value);
  280. if (!point->CRLissuer)
  281. goto err;
  282. }
  283. }
  284. return point;
  285. err:
  286. if (point)
  287. DIST_POINT_free(point);
  288. return NULL;
  289. }
  290. static void *v2i_crld(const X509V3_EXT_METHOD *method,
  291. X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
  292. {
  293. STACK_OF(DIST_POINT) *crld = NULL;
  294. GENERAL_NAMES *gens = NULL;
  295. GENERAL_NAME *gen = NULL;
  296. CONF_VALUE *cnf;
  297. size_t i;
  298. if(!(crld = sk_DIST_POINT_new_null())) goto merr;
  299. for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
  300. DIST_POINT *point;
  301. cnf = sk_CONF_VALUE_value(nval, i);
  302. if (!cnf->value)
  303. {
  304. STACK_OF(CONF_VALUE) *dpsect;
  305. dpsect = X509V3_get_section(ctx, cnf->name);
  306. if (!dpsect)
  307. goto err;
  308. point = crldp_from_section(ctx, dpsect);
  309. X509V3_section_free(ctx, dpsect);
  310. if (!point)
  311. goto err;
  312. if(!sk_DIST_POINT_push(crld, point))
  313. {
  314. DIST_POINT_free(point);
  315. goto merr;
  316. }
  317. }
  318. else
  319. {
  320. if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
  321. goto err;
  322. if(!(gens = GENERAL_NAMES_new()))
  323. goto merr;
  324. if(!sk_GENERAL_NAME_push(gens, gen))
  325. goto merr;
  326. gen = NULL;
  327. if(!(point = DIST_POINT_new()))
  328. goto merr;
  329. if(!sk_DIST_POINT_push(crld, point))
  330. {
  331. DIST_POINT_free(point);
  332. goto merr;
  333. }
  334. if(!(point->distpoint = DIST_POINT_NAME_new()))
  335. goto merr;
  336. point->distpoint->name.fullname = gens;
  337. point->distpoint->type = 0;
  338. gens = NULL;
  339. }
  340. }
  341. return crld;
  342. merr:
  343. OPENSSL_PUT_ERROR(X509V3, v2i_crld, ERR_R_MALLOC_FAILURE);
  344. err:
  345. GENERAL_NAME_free(gen);
  346. GENERAL_NAMES_free(gens);
  347. sk_DIST_POINT_pop_free(crld, DIST_POINT_free);
  348. return NULL;
  349. }
  350. IMPLEMENT_ASN1_SET_OF(DIST_POINT)
  351. static int dpn_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
  352. void *exarg)
  353. {
  354. DIST_POINT_NAME *dpn = (DIST_POINT_NAME *)*pval;
  355. switch(operation)
  356. {
  357. case ASN1_OP_NEW_POST:
  358. dpn->dpname = NULL;
  359. break;
  360. case ASN1_OP_FREE_POST:
  361. if (dpn->dpname)
  362. X509_NAME_free(dpn->dpname);
  363. break;
  364. }
  365. return 1;
  366. }
  367. ASN1_CHOICE_cb(DIST_POINT_NAME, dpn_cb) = {
  368. ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0),
  369. ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1)
  370. } ASN1_CHOICE_END_cb(DIST_POINT_NAME, DIST_POINT_NAME, type)
  371. IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT_NAME)
  372. ASN1_SEQUENCE(DIST_POINT) = {
  373. ASN1_EXP_OPT(DIST_POINT, distpoint, DIST_POINT_NAME, 0),
  374. ASN1_IMP_OPT(DIST_POINT, reasons, ASN1_BIT_STRING, 1),
  375. ASN1_IMP_SEQUENCE_OF_OPT(DIST_POINT, CRLissuer, GENERAL_NAME, 2)
  376. } ASN1_SEQUENCE_END(DIST_POINT)
  377. IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT)
  378. ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) =
  379. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CRLDistributionPoints, DIST_POINT)
  380. ASN1_ITEM_TEMPLATE_END(CRL_DIST_POINTS)
  381. IMPLEMENT_ASN1_FUNCTIONS(CRL_DIST_POINTS)
  382. ASN1_SEQUENCE(ISSUING_DIST_POINT) = {
  383. ASN1_EXP_OPT(ISSUING_DIST_POINT, distpoint, DIST_POINT_NAME, 0),
  384. ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyuser, ASN1_FBOOLEAN, 1),
  385. ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyCA, ASN1_FBOOLEAN, 2),
  386. ASN1_IMP_OPT(ISSUING_DIST_POINT, onlysomereasons, ASN1_BIT_STRING, 3),
  387. ASN1_IMP_OPT(ISSUING_DIST_POINT, indirectCRL, ASN1_FBOOLEAN, 4),
  388. ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyattr, ASN1_FBOOLEAN, 5)
  389. } ASN1_SEQUENCE_END(ISSUING_DIST_POINT)
  390. IMPLEMENT_ASN1_FUNCTIONS(ISSUING_DIST_POINT)
  391. static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out,
  392. int indent);
  393. static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
  394. STACK_OF(CONF_VALUE) *nval);
  395. const X509V3_EXT_METHOD v3_idp =
  396. {
  397. NID_issuing_distribution_point, X509V3_EXT_MULTILINE,
  398. ASN1_ITEM_ref(ISSUING_DIST_POINT),
  399. 0,0,0,0,
  400. 0,0,
  401. 0,
  402. v2i_idp,
  403. i2r_idp,0,
  404. NULL
  405. };
  406. static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
  407. STACK_OF(CONF_VALUE) *nval)
  408. {
  409. ISSUING_DIST_POINT *idp = NULL;
  410. CONF_VALUE *cnf;
  411. char *name, *val;
  412. size_t i;
  413. int ret;
  414. idp = ISSUING_DIST_POINT_new();
  415. if (!idp)
  416. goto merr;
  417. for(i = 0; i < sk_CONF_VALUE_num(nval); i++)
  418. {
  419. cnf = sk_CONF_VALUE_value(nval, i);
  420. name = cnf->name;
  421. val = cnf->value;
  422. ret = set_dist_point_name(&idp->distpoint, ctx, cnf);
  423. if (ret > 0)
  424. continue;
  425. if (ret < 0)
  426. goto err;
  427. if (!strcmp(name, "onlyuser"))
  428. {
  429. if (!X509V3_get_value_bool(cnf, &idp->onlyuser))
  430. goto err;
  431. }
  432. else if (!strcmp(name, "onlyCA"))
  433. {
  434. if (!X509V3_get_value_bool(cnf, &idp->onlyCA))
  435. goto err;
  436. }
  437. else if (!strcmp(name, "onlyAA"))
  438. {
  439. if (!X509V3_get_value_bool(cnf, &idp->onlyattr))
  440. goto err;
  441. }
  442. else if (!strcmp(name, "indirectCRL"))
  443. {
  444. if (!X509V3_get_value_bool(cnf, &idp->indirectCRL))
  445. goto err;
  446. }
  447. else if (!strcmp(name, "onlysomereasons"))
  448. {
  449. if (!set_reasons(&idp->onlysomereasons, val))
  450. goto err;
  451. }
  452. else
  453. {
  454. OPENSSL_PUT_ERROR(X509V3, v2i_idp, X509V3_R_INVALID_NAME);
  455. X509V3_conf_err(cnf);
  456. goto err;
  457. }
  458. }
  459. return idp;
  460. merr:
  461. OPENSSL_PUT_ERROR(X509V3, v2i_idp, ERR_R_MALLOC_FAILURE);
  462. err:
  463. ISSUING_DIST_POINT_free(idp);
  464. return NULL;
  465. }
  466. static int print_gens(BIO *out, STACK_OF(GENERAL_NAME) *gens, int indent)
  467. {
  468. size_t i;
  469. for (i = 0; i < sk_GENERAL_NAME_num(gens); i++)
  470. {
  471. BIO_printf(out, "%*s", indent + 2, "");
  472. GENERAL_NAME_print(out, sk_GENERAL_NAME_value(gens, i));
  473. BIO_puts(out, "\n");
  474. }
  475. return 1;
  476. }
  477. static int print_distpoint(BIO *out, DIST_POINT_NAME *dpn, int indent)
  478. {
  479. if (dpn->type == 0)
  480. {
  481. BIO_printf(out, "%*sFull Name:\n", indent, "");
  482. print_gens(out, dpn->name.fullname, indent);
  483. }
  484. else
  485. {
  486. X509_NAME ntmp;
  487. ntmp.entries = dpn->name.relativename;
  488. BIO_printf(out, "%*sRelative Name:\n%*s",
  489. indent, "", indent + 2, "");
  490. X509_NAME_print_ex(out, &ntmp, 0, XN_FLAG_ONELINE);
  491. BIO_puts(out, "\n");
  492. }
  493. return 1;
  494. }
  495. static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out,
  496. int indent)
  497. {
  498. ISSUING_DIST_POINT *idp = pidp;
  499. if (idp->distpoint)
  500. print_distpoint(out, idp->distpoint, indent);
  501. if (idp->onlyuser > 0)
  502. BIO_printf(out, "%*sOnly User Certificates\n", indent, "");
  503. if (idp->onlyCA > 0)
  504. BIO_printf(out, "%*sOnly CA Certificates\n", indent, "");
  505. if (idp->indirectCRL > 0)
  506. BIO_printf(out, "%*sIndirect CRL\n", indent, "");
  507. if (idp->onlysomereasons)
  508. print_reasons(out, "Only Some Reasons",
  509. idp->onlysomereasons, indent);
  510. if (idp->onlyattr > 0)
  511. BIO_printf(out, "%*sOnly Attribute Certificates\n", indent, "");
  512. if (!idp->distpoint && (idp->onlyuser <= 0) && (idp->onlyCA <= 0)
  513. && (idp->indirectCRL <= 0) && !idp->onlysomereasons
  514. && (idp->onlyattr <= 0))
  515. BIO_printf(out, "%*s<EMPTY>\n", indent, "");
  516. return 1;
  517. }
  518. static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out,
  519. int indent)
  520. {
  521. STACK_OF(DIST_POINT) *crld = pcrldp;
  522. DIST_POINT *point;
  523. size_t i;
  524. for(i = 0; i < sk_DIST_POINT_num(crld); i++)
  525. {
  526. BIO_puts(out, "\n");
  527. point = sk_DIST_POINT_value(crld, i);
  528. if(point->distpoint)
  529. print_distpoint(out, point->distpoint, indent);
  530. if(point->reasons)
  531. print_reasons(out, "Reasons", point->reasons,
  532. indent);
  533. if(point->CRLissuer)
  534. {
  535. BIO_printf(out, "%*sCRL Issuer:\n", indent, "");
  536. print_gens(out, point->CRLissuer, indent);
  537. }
  538. }
  539. return 1;
  540. }
  541. int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname)
  542. {
  543. size_t i;
  544. STACK_OF(X509_NAME_ENTRY) *frag;
  545. X509_NAME_ENTRY *ne;
  546. if (!dpn || (dpn->type != 1))
  547. return 1;
  548. frag = dpn->name.relativename;
  549. dpn->dpname = X509_NAME_dup(iname);
  550. if (!dpn->dpname)
  551. return 0;
  552. for (i = 0; i < sk_X509_NAME_ENTRY_num(frag); i++)
  553. {
  554. ne = sk_X509_NAME_ENTRY_value(frag, i);
  555. if (!X509_NAME_add_entry(dpn->dpname, ne, -1, i ? 0 : 1))
  556. {
  557. X509_NAME_free(dpn->dpname);
  558. dpn->dpname = NULL;
  559. return 0;
  560. }
  561. }
  562. /* generate cached encoding of name */
  563. if (i2d_X509_NAME(dpn->dpname, NULL) < 0)
  564. {
  565. X509_NAME_free(dpn->dpname);
  566. dpn->dpname = NULL;
  567. return 0;
  568. }
  569. return 1;
  570. }