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.
 
 
 
 
 
 

624 lines
18 KiB

  1. /* v3_alt.c */
  2. /*
  3. * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  4. * project.
  5. */
  6. /* ====================================================================
  7. * Copyright (c) 1999-2003 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. #include <stdio.h>
  58. #include <string.h>
  59. #include <openssl/conf.h>
  60. #include <openssl/err.h>
  61. #include <openssl/mem.h>
  62. #include <openssl/obj.h>
  63. #include <openssl/x509v3.h>
  64. static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method,
  65. X509V3_CTX *ctx,
  66. STACK_OF(CONF_VALUE) *nval);
  67. static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method,
  68. X509V3_CTX *ctx,
  69. STACK_OF(CONF_VALUE) *nval);
  70. static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p);
  71. static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens);
  72. static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx);
  73. static int do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx);
  74. const X509V3_EXT_METHOD v3_alt[] = {
  75. {NID_subject_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
  76. 0, 0, 0, 0,
  77. 0, 0,
  78. (X509V3_EXT_I2V) i2v_GENERAL_NAMES,
  79. (X509V3_EXT_V2I)v2i_subject_alt,
  80. NULL, NULL, NULL},
  81. {NID_issuer_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
  82. 0, 0, 0, 0,
  83. 0, 0,
  84. (X509V3_EXT_I2V) i2v_GENERAL_NAMES,
  85. (X509V3_EXT_V2I)v2i_issuer_alt,
  86. NULL, NULL, NULL},
  87. {NID_certificate_issuer, 0, ASN1_ITEM_ref(GENERAL_NAMES),
  88. 0, 0, 0, 0,
  89. 0, 0,
  90. (X509V3_EXT_I2V) i2v_GENERAL_NAMES,
  91. NULL, NULL, NULL, NULL},
  92. };
  93. STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
  94. GENERAL_NAMES *gens,
  95. STACK_OF(CONF_VALUE) *ret)
  96. {
  97. size_t i;
  98. GENERAL_NAME *gen;
  99. for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
  100. gen = sk_GENERAL_NAME_value(gens, i);
  101. ret = i2v_GENERAL_NAME(method, gen, ret);
  102. }
  103. if (!ret)
  104. return sk_CONF_VALUE_new_null();
  105. return ret;
  106. }
  107. STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
  108. GENERAL_NAME *gen,
  109. STACK_OF(CONF_VALUE) *ret)
  110. {
  111. unsigned char *p;
  112. char oline[256], htmp[5];
  113. int i;
  114. switch (gen->type) {
  115. case GEN_OTHERNAME:
  116. if (!X509V3_add_value("othername", "<unsupported>", &ret))
  117. return NULL;
  118. break;
  119. case GEN_X400:
  120. if (!X509V3_add_value("X400Name", "<unsupported>", &ret))
  121. return NULL;
  122. break;
  123. case GEN_EDIPARTY:
  124. if (!X509V3_add_value("EdiPartyName", "<unsupported>", &ret))
  125. return NULL;
  126. break;
  127. case GEN_EMAIL:
  128. if (!X509V3_add_value_uchar("email", gen->d.ia5->data, &ret))
  129. return NULL;
  130. break;
  131. case GEN_DNS:
  132. if (!X509V3_add_value_uchar("DNS", gen->d.ia5->data, &ret))
  133. return NULL;
  134. break;
  135. case GEN_URI:
  136. if (!X509V3_add_value_uchar("URI", gen->d.ia5->data, &ret))
  137. return NULL;
  138. break;
  139. case GEN_DIRNAME:
  140. if (X509_NAME_oneline(gen->d.dirn, oline, 256) == NULL
  141. || !X509V3_add_value("DirName", oline, &ret))
  142. return NULL;
  143. break;
  144. case GEN_IPADD:
  145. p = gen->d.ip->data;
  146. if (gen->d.ip->length == 4)
  147. BIO_snprintf(oline, sizeof oline,
  148. "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
  149. else if (gen->d.ip->length == 16) {
  150. oline[0] = 0;
  151. for (i = 0; i < 8; i++) {
  152. BIO_snprintf(htmp, sizeof htmp, "%X", p[0] << 8 | p[1]);
  153. p += 2;
  154. BUF_strlcat(oline, htmp, sizeof(oline));
  155. if (i != 7)
  156. BUF_strlcat(oline, ":", sizeof(oline));
  157. }
  158. } else {
  159. if (!X509V3_add_value("IP Address", "<invalid>", &ret))
  160. return NULL;
  161. break;
  162. }
  163. if (!X509V3_add_value("IP Address", oline, &ret))
  164. return NULL;
  165. break;
  166. case GEN_RID:
  167. i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
  168. if (!X509V3_add_value("Registered ID", oline, &ret))
  169. return NULL;
  170. break;
  171. }
  172. return ret;
  173. }
  174. int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen)
  175. {
  176. unsigned char *p;
  177. int i;
  178. switch (gen->type) {
  179. case GEN_OTHERNAME:
  180. BIO_printf(out, "othername:<unsupported>");
  181. break;
  182. case GEN_X400:
  183. BIO_printf(out, "X400Name:<unsupported>");
  184. break;
  185. case GEN_EDIPARTY:
  186. /* Maybe fix this: it is supported now */
  187. BIO_printf(out, "EdiPartyName:<unsupported>");
  188. break;
  189. case GEN_EMAIL:
  190. BIO_printf(out, "email:%s", gen->d.ia5->data);
  191. break;
  192. case GEN_DNS:
  193. BIO_printf(out, "DNS:%s", gen->d.ia5->data);
  194. break;
  195. case GEN_URI:
  196. BIO_printf(out, "URI:%s", gen->d.ia5->data);
  197. break;
  198. case GEN_DIRNAME:
  199. BIO_printf(out, "DirName: ");
  200. X509_NAME_print_ex(out, gen->d.dirn, 0, XN_FLAG_ONELINE);
  201. break;
  202. case GEN_IPADD:
  203. p = gen->d.ip->data;
  204. if (gen->d.ip->length == 4)
  205. BIO_printf(out, "IP Address:%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
  206. else if (gen->d.ip->length == 16) {
  207. BIO_printf(out, "IP Address");
  208. for (i = 0; i < 8; i++) {
  209. BIO_printf(out, ":%X", p[0] << 8 | p[1]);
  210. p += 2;
  211. }
  212. BIO_puts(out, "\n");
  213. } else {
  214. BIO_printf(out, "IP Address:<invalid>");
  215. break;
  216. }
  217. break;
  218. case GEN_RID:
  219. BIO_printf(out, "Registered ID");
  220. i2a_ASN1_OBJECT(out, gen->d.rid);
  221. break;
  222. }
  223. return 1;
  224. }
  225. static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method,
  226. X509V3_CTX *ctx,
  227. STACK_OF(CONF_VALUE) *nval)
  228. {
  229. GENERAL_NAMES *gens = NULL;
  230. CONF_VALUE *cnf;
  231. size_t i;
  232. if (!(gens = sk_GENERAL_NAME_new_null())) {
  233. OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
  234. return NULL;
  235. }
  236. for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
  237. cnf = sk_CONF_VALUE_value(nval, i);
  238. if (!name_cmp(cnf->name, "issuer") && cnf->value &&
  239. !strcmp(cnf->value, "copy")) {
  240. if (!copy_issuer(ctx, gens))
  241. goto err;
  242. } else {
  243. GENERAL_NAME *gen;
  244. if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
  245. goto err;
  246. sk_GENERAL_NAME_push(gens, gen);
  247. }
  248. }
  249. return gens;
  250. err:
  251. sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
  252. return NULL;
  253. }
  254. /* Append subject altname of issuer to issuer alt name of subject */
  255. static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens)
  256. {
  257. GENERAL_NAMES *ialt;
  258. GENERAL_NAME *gen;
  259. X509_EXTENSION *ext;
  260. int i;
  261. size_t j;
  262. if (ctx && (ctx->flags == CTX_TEST))
  263. return 1;
  264. if (!ctx || !ctx->issuer_cert) {
  265. OPENSSL_PUT_ERROR(X509V3, X509V3_R_NO_ISSUER_DETAILS);
  266. goto err;
  267. }
  268. i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
  269. if (i < 0)
  270. return 1;
  271. if (!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
  272. !(ialt = X509V3_EXT_d2i(ext))) {
  273. OPENSSL_PUT_ERROR(X509V3, X509V3_R_ISSUER_DECODE_ERROR);
  274. goto err;
  275. }
  276. for (j = 0; j < sk_GENERAL_NAME_num(ialt); j++) {
  277. gen = sk_GENERAL_NAME_value(ialt, j);
  278. if (!sk_GENERAL_NAME_push(gens, gen)) {
  279. OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
  280. goto err;
  281. }
  282. }
  283. sk_GENERAL_NAME_free(ialt);
  284. return 1;
  285. err:
  286. return 0;
  287. }
  288. static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method,
  289. X509V3_CTX *ctx,
  290. STACK_OF(CONF_VALUE) *nval)
  291. {
  292. GENERAL_NAMES *gens = NULL;
  293. CONF_VALUE *cnf;
  294. size_t i;
  295. if (!(gens = sk_GENERAL_NAME_new_null())) {
  296. OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
  297. return NULL;
  298. }
  299. for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
  300. cnf = sk_CONF_VALUE_value(nval, i);
  301. if (!name_cmp(cnf->name, "email") && cnf->value &&
  302. !strcmp(cnf->value, "copy")) {
  303. if (!copy_email(ctx, gens, 0))
  304. goto err;
  305. } else if (!name_cmp(cnf->name, "email") && cnf->value &&
  306. !strcmp(cnf->value, "move")) {
  307. if (!copy_email(ctx, gens, 1))
  308. goto err;
  309. } else {
  310. GENERAL_NAME *gen;
  311. if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
  312. goto err;
  313. sk_GENERAL_NAME_push(gens, gen);
  314. }
  315. }
  316. return gens;
  317. err:
  318. sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
  319. return NULL;
  320. }
  321. /*
  322. * Copy any email addresses in a certificate or request to GENERAL_NAMES
  323. */
  324. static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
  325. {
  326. X509_NAME *nm;
  327. ASN1_IA5STRING *email = NULL;
  328. X509_NAME_ENTRY *ne;
  329. GENERAL_NAME *gen = NULL;
  330. int i;
  331. if (ctx != NULL && ctx->flags == CTX_TEST)
  332. return 1;
  333. if (!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
  334. OPENSSL_PUT_ERROR(X509V3, X509V3_R_NO_SUBJECT_DETAILS);
  335. goto err;
  336. }
  337. /* Find the subject name */
  338. if (ctx->subject_cert)
  339. nm = X509_get_subject_name(ctx->subject_cert);
  340. else
  341. nm = X509_REQ_get_subject_name(ctx->subject_req);
  342. /* Now add any email address(es) to STACK */
  343. i = -1;
  344. while ((i = X509_NAME_get_index_by_NID(nm,
  345. NID_pkcs9_emailAddress, i)) >= 0) {
  346. ne = X509_NAME_get_entry(nm, i);
  347. email = M_ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne));
  348. if (move_p) {
  349. X509_NAME_delete_entry(nm, i);
  350. X509_NAME_ENTRY_free(ne);
  351. i--;
  352. }
  353. if (!email || !(gen = GENERAL_NAME_new())) {
  354. OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
  355. goto err;
  356. }
  357. gen->d.ia5 = email;
  358. email = NULL;
  359. gen->type = GEN_EMAIL;
  360. if (!sk_GENERAL_NAME_push(gens, gen)) {
  361. OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
  362. goto err;
  363. }
  364. gen = NULL;
  365. }
  366. return 1;
  367. err:
  368. GENERAL_NAME_free(gen);
  369. M_ASN1_IA5STRING_free(email);
  370. return 0;
  371. }
  372. GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method,
  373. X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
  374. {
  375. GENERAL_NAME *gen;
  376. GENERAL_NAMES *gens = NULL;
  377. CONF_VALUE *cnf;
  378. size_t i;
  379. if (!(gens = sk_GENERAL_NAME_new_null())) {
  380. OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
  381. return NULL;
  382. }
  383. for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
  384. cnf = sk_CONF_VALUE_value(nval, i);
  385. if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
  386. goto err;
  387. sk_GENERAL_NAME_push(gens, gen);
  388. }
  389. return gens;
  390. err:
  391. sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
  392. return NULL;
  393. }
  394. GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method,
  395. X509V3_CTX *ctx, CONF_VALUE *cnf)
  396. {
  397. return v2i_GENERAL_NAME_ex(NULL, method, ctx, cnf, 0);
  398. }
  399. GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out,
  400. const X509V3_EXT_METHOD *method,
  401. X509V3_CTX *ctx, int gen_type, char *value,
  402. int is_nc)
  403. {
  404. char is_string = 0;
  405. GENERAL_NAME *gen = NULL;
  406. if (!value) {
  407. OPENSSL_PUT_ERROR(X509V3, X509V3_R_MISSING_VALUE);
  408. return NULL;
  409. }
  410. if (out)
  411. gen = out;
  412. else {
  413. gen = GENERAL_NAME_new();
  414. if (gen == NULL) {
  415. OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
  416. return NULL;
  417. }
  418. }
  419. switch (gen_type) {
  420. case GEN_URI:
  421. case GEN_EMAIL:
  422. case GEN_DNS:
  423. is_string = 1;
  424. break;
  425. case GEN_RID:
  426. {
  427. ASN1_OBJECT *obj;
  428. if (!(obj = OBJ_txt2obj(value, 0))) {
  429. OPENSSL_PUT_ERROR(X509V3, X509V3_R_BAD_OBJECT);
  430. ERR_add_error_data(2, "value=", value);
  431. goto err;
  432. }
  433. gen->d.rid = obj;
  434. }
  435. break;
  436. case GEN_IPADD:
  437. if (is_nc)
  438. gen->d.ip = a2i_IPADDRESS_NC(value);
  439. else
  440. gen->d.ip = a2i_IPADDRESS(value);
  441. if (gen->d.ip == NULL) {
  442. OPENSSL_PUT_ERROR(X509V3, X509V3_R_BAD_IP_ADDRESS);
  443. ERR_add_error_data(2, "value=", value);
  444. goto err;
  445. }
  446. break;
  447. case GEN_DIRNAME:
  448. if (!do_dirname(gen, value, ctx)) {
  449. OPENSSL_PUT_ERROR(X509V3, X509V3_R_DIRNAME_ERROR);
  450. goto err;
  451. }
  452. break;
  453. case GEN_OTHERNAME:
  454. if (!do_othername(gen, value, ctx)) {
  455. OPENSSL_PUT_ERROR(X509V3, X509V3_R_OTHERNAME_ERROR);
  456. goto err;
  457. }
  458. break;
  459. default:
  460. OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNSUPPORTED_TYPE);
  461. goto err;
  462. }
  463. if (is_string) {
  464. if (!(gen->d.ia5 = M_ASN1_IA5STRING_new()) ||
  465. !ASN1_STRING_set(gen->d.ia5, (unsigned char *)value,
  466. strlen(value))) {
  467. OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
  468. goto err;
  469. }
  470. }
  471. gen->type = gen_type;
  472. return gen;
  473. err:
  474. if (!out)
  475. GENERAL_NAME_free(gen);
  476. return NULL;
  477. }
  478. GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
  479. const X509V3_EXT_METHOD *method,
  480. X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc)
  481. {
  482. int type;
  483. char *name, *value;
  484. name = cnf->name;
  485. value = cnf->value;
  486. if (!value) {
  487. OPENSSL_PUT_ERROR(X509V3, X509V3_R_MISSING_VALUE);
  488. return NULL;
  489. }
  490. if (!name_cmp(name, "email"))
  491. type = GEN_EMAIL;
  492. else if (!name_cmp(name, "URI"))
  493. type = GEN_URI;
  494. else if (!name_cmp(name, "DNS"))
  495. type = GEN_DNS;
  496. else if (!name_cmp(name, "RID"))
  497. type = GEN_RID;
  498. else if (!name_cmp(name, "IP"))
  499. type = GEN_IPADD;
  500. else if (!name_cmp(name, "dirName"))
  501. type = GEN_DIRNAME;
  502. else if (!name_cmp(name, "otherName"))
  503. type = GEN_OTHERNAME;
  504. else {
  505. OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNSUPPORTED_OPTION);
  506. ERR_add_error_data(2, "name=", name);
  507. return NULL;
  508. }
  509. return a2i_GENERAL_NAME(out, method, ctx, type, value, is_nc);
  510. }
  511. static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
  512. {
  513. char *objtmp = NULL, *p;
  514. int objlen;
  515. if (!(p = strchr(value, ';')))
  516. return 0;
  517. if (!(gen->d.otherName = OTHERNAME_new()))
  518. return 0;
  519. /*
  520. * Free this up because we will overwrite it. no need to free type_id
  521. * because it is static
  522. */
  523. ASN1_TYPE_free(gen->d.otherName->value);
  524. if (!(gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx)))
  525. return 0;
  526. objlen = p - value;
  527. objtmp = OPENSSL_malloc(objlen + 1);
  528. if (objtmp == NULL)
  529. return 0;
  530. BUF_strlcpy(objtmp, value, objlen + 1);
  531. gen->d.otherName->type_id = OBJ_txt2obj(objtmp, 0);
  532. OPENSSL_free(objtmp);
  533. if (!gen->d.otherName->type_id)
  534. return 0;
  535. return 1;
  536. }
  537. static int do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
  538. {
  539. int ret = 0;
  540. STACK_OF(CONF_VALUE) *sk = NULL;
  541. X509_NAME *nm = X509_NAME_new();
  542. if (nm == NULL)
  543. goto err;
  544. sk = X509V3_get_section(ctx, value);
  545. if (sk == NULL) {
  546. OPENSSL_PUT_ERROR(X509V3, X509V3_R_SECTION_NOT_FOUND);
  547. ERR_add_error_data(2, "section=", value);
  548. goto err;
  549. }
  550. /* FIXME: should allow other character types... */
  551. if (!X509V3_NAME_from_section(nm, sk, MBSTRING_ASC))
  552. goto err;
  553. gen->d.dirn = nm;
  554. ret = 1;
  555. err:
  556. if (!ret)
  557. X509_NAME_free(nm);
  558. X509V3_section_free(ctx, sk);
  559. return ret;
  560. }