v3_alt.c 18 KB

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