2
0

v3_alt.c 17 KB

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