srp.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * Copyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. *
  10. * Originally written by Christophe Renou and Peter Sylvester,
  11. * for the EdelKey project.
  12. */
  13. /* SRP is deprecated, so we're going to have to use some deprecated APIs */
  14. #define OPENSSL_SUPPRESS_DEPRECATED
  15. #include <openssl/opensslconf.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <openssl/conf.h>
  20. #include <openssl/bio.h>
  21. #include <openssl/err.h>
  22. #include <openssl/txt_db.h>
  23. #include <openssl/buffer.h>
  24. #include <openssl/srp.h>
  25. #include "apps.h"
  26. #include "progs.h"
  27. #define BASE_SECTION "srp"
  28. #define CONFIG_FILE "openssl.cnf"
  29. #define ENV_DATABASE "srpvfile"
  30. #define ENV_DEFAULT_SRP "default_srp"
  31. static int get_index(CA_DB *db, char *id, char type)
  32. {
  33. char **pp;
  34. int i;
  35. if (id == NULL)
  36. return -1;
  37. if (type == DB_SRP_INDEX) {
  38. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  39. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  40. if (pp[DB_srptype][0] == DB_SRP_INDEX
  41. && strcmp(id, pp[DB_srpid]) == 0)
  42. return i;
  43. }
  44. } else {
  45. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  46. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  47. if (pp[DB_srptype][0] != DB_SRP_INDEX
  48. && strcmp(id, pp[DB_srpid]) == 0)
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. static void print_entry(CA_DB *db, int indx, int verbose, char *s)
  55. {
  56. if (indx >= 0 && verbose) {
  57. int j;
  58. char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
  59. BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
  60. for (j = 0; j < DB_NUMBER; j++) {
  61. BIO_printf(bio_err, " %d = \"%s\"\n", j, pp[j]);
  62. }
  63. }
  64. }
  65. static void print_index(CA_DB *db, int indexindex, int verbose)
  66. {
  67. print_entry(db, indexindex, verbose, "g N entry");
  68. }
  69. static void print_user(CA_DB *db, int userindex, int verbose)
  70. {
  71. if (verbose > 0) {
  72. char **pp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  73. if (pp[DB_srptype][0] != 'I') {
  74. print_entry(db, userindex, verbose, "User entry");
  75. print_entry(db, get_index(db, pp[DB_srpgN], 'I'), verbose,
  76. "g N entry");
  77. }
  78. }
  79. }
  80. static int update_index(CA_DB *db, char **row)
  81. {
  82. char **irow;
  83. int i;
  84. irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");
  85. for (i = 0; i < DB_NUMBER; i++)
  86. irow[i] = row[i];
  87. irow[DB_NUMBER] = NULL;
  88. if (!TXT_DB_insert(db->db, irow)) {
  89. BIO_printf(bio_err, "failed to update srpvfile\n");
  90. BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
  91. OPENSSL_free(irow);
  92. return 0;
  93. }
  94. return 1;
  95. }
  96. static char *lookup_conf(const CONF *conf, const char *section, const char *tag)
  97. {
  98. char *entry = NCONF_get_string(conf, section, tag);
  99. if (entry == NULL)
  100. BIO_printf(bio_err, "variable lookup failed for %s::%s\n", section, tag);
  101. return entry;
  102. }
  103. static char *srp_verify_user(const char *user, const char *srp_verifier,
  104. char *srp_usersalt, const char *g, const char *N,
  105. const char *passin, int verbose)
  106. {
  107. char password[1025];
  108. PW_CB_DATA cb_tmp;
  109. char *verifier = NULL;
  110. char *gNid = NULL;
  111. int len;
  112. cb_tmp.prompt_info = user;
  113. cb_tmp.password = passin;
  114. len = password_callback(password, sizeof(password)-1, 0, &cb_tmp);
  115. if (len > 0) {
  116. password[len] = 0;
  117. if (verbose)
  118. BIO_printf(bio_err,
  119. "Validating\n user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
  120. user, srp_verifier, srp_usersalt, g, N);
  121. if (verbose > 1)
  122. BIO_printf(bio_err, "Pass %s\n", password);
  123. OPENSSL_assert(srp_usersalt != NULL);
  124. if ((gNid = SRP_create_verifier(user, password, &srp_usersalt,
  125. &verifier, N, g)) == NULL) {
  126. BIO_printf(bio_err, "Internal error validating SRP verifier\n");
  127. } else {
  128. if (strcmp(verifier, srp_verifier))
  129. gNid = NULL;
  130. OPENSSL_free(verifier);
  131. }
  132. OPENSSL_cleanse(password, len);
  133. }
  134. return gNid;
  135. }
  136. static char *srp_create_user(char *user, char **srp_verifier,
  137. char **srp_usersalt, char *g, char *N,
  138. char *passout, int verbose)
  139. {
  140. char password[1025];
  141. PW_CB_DATA cb_tmp;
  142. char *gNid = NULL;
  143. char *salt = NULL;
  144. int len;
  145. cb_tmp.prompt_info = user;
  146. cb_tmp.password = passout;
  147. len = password_callback(password, sizeof(password)-1, 1, &cb_tmp);
  148. if (len > 0) {
  149. password[len] = 0;
  150. if (verbose)
  151. BIO_printf(bio_err, "Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
  152. user, g, N);
  153. if ((gNid = SRP_create_verifier(user, password, &salt,
  154. srp_verifier, N, g)) == NULL) {
  155. BIO_printf(bio_err, "Internal error creating SRP verifier\n");
  156. } else {
  157. *srp_usersalt = salt;
  158. }
  159. OPENSSL_cleanse(password, len);
  160. if (verbose > 1)
  161. BIO_printf(bio_err, "gNid=%s salt =\"%s\"\n verifier =\"%s\"\n",
  162. gNid, salt, *srp_verifier);
  163. }
  164. return gNid;
  165. }
  166. typedef enum OPTION_choice {
  167. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
  168. OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SRPVFILE, OPT_ADD,
  169. OPT_DELETE, OPT_MODIFY, OPT_LIST, OPT_GN, OPT_USERINFO,
  170. OPT_PASSIN, OPT_PASSOUT, OPT_ENGINE, OPT_R_ENUM, OPT_PROV_ENUM
  171. } OPTION_CHOICE;
  172. const OPTIONS srp_options[] = {
  173. {OPT_HELP_STR, 1, '-', "Usage: %s [options] [user...]\n"},
  174. OPT_SECTION("General"),
  175. {"help", OPT_HELP, '-', "Display this summary"},
  176. {"verbose", OPT_VERBOSE, '-', "Talk a lot while doing things"},
  177. {"config", OPT_CONFIG, '<', "A config file"},
  178. {"name", OPT_NAME, 's', "The particular srp definition to use"},
  179. #ifndef OPENSSL_NO_ENGINE
  180. {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
  181. #endif
  182. OPT_SECTION("Action"),
  183. {"add", OPT_ADD, '-', "Add a user and srp verifier"},
  184. {"modify", OPT_MODIFY, '-', "Modify the srp verifier of an existing user"},
  185. {"delete", OPT_DELETE, '-', "Delete user from verifier file"},
  186. {"list", OPT_LIST, '-', "List users"},
  187. OPT_SECTION("Configuration"),
  188. {"srpvfile", OPT_SRPVFILE, '<', "The srp verifier file name"},
  189. {"gn", OPT_GN, 's', "Set g and N values to be used for new verifier"},
  190. {"userinfo", OPT_USERINFO, 's', "Additional info to be set for user"},
  191. {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
  192. {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
  193. OPT_R_OPTIONS,
  194. OPT_PROV_OPTIONS,
  195. OPT_PARAMETERS(),
  196. {"user", 0, 0, "Username(s) to process (optional)"},
  197. {NULL}
  198. };
  199. int srp_main(int argc, char **argv)
  200. {
  201. ENGINE *e = NULL;
  202. CA_DB *db = NULL;
  203. CONF *conf = NULL;
  204. int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose = 0, i;
  205. int doupdatedb = 0, mode = OPT_ERR;
  206. char *user = NULL, *passinarg = NULL, *passoutarg = NULL;
  207. char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;
  208. char *section = NULL;
  209. char **gNrow = NULL, *configfile = NULL;
  210. char *srpvfile = NULL, **pp, *prog;
  211. OPTION_CHOICE o;
  212. prog = opt_init(argc, argv, srp_options);
  213. while ((o = opt_next()) != OPT_EOF) {
  214. switch (o) {
  215. case OPT_EOF:
  216. case OPT_ERR:
  217. opthelp:
  218. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  219. goto end;
  220. case OPT_HELP:
  221. opt_help(srp_options);
  222. ret = 0;
  223. goto end;
  224. case OPT_VERBOSE:
  225. verbose++;
  226. break;
  227. case OPT_CONFIG:
  228. configfile = opt_arg();
  229. break;
  230. case OPT_NAME:
  231. section = opt_arg();
  232. break;
  233. case OPT_SRPVFILE:
  234. srpvfile = opt_arg();
  235. break;
  236. case OPT_ADD:
  237. case OPT_DELETE:
  238. case OPT_MODIFY:
  239. case OPT_LIST:
  240. if (mode != OPT_ERR) {
  241. BIO_printf(bio_err,
  242. "%s: Only one of -add/-delete/-modify/-list\n",
  243. prog);
  244. goto opthelp;
  245. }
  246. mode = o;
  247. break;
  248. case OPT_GN:
  249. gN = opt_arg();
  250. break;
  251. case OPT_USERINFO:
  252. userinfo = opt_arg();
  253. break;
  254. case OPT_PASSIN:
  255. passinarg = opt_arg();
  256. break;
  257. case OPT_PASSOUT:
  258. passoutarg = opt_arg();
  259. break;
  260. case OPT_ENGINE:
  261. e = setup_engine(opt_arg(), 0);
  262. break;
  263. case OPT_R_CASES:
  264. if (!opt_rand(o))
  265. goto end;
  266. break;
  267. case OPT_PROV_CASES:
  268. if (!opt_provider(o))
  269. goto end;
  270. break;
  271. }
  272. }
  273. /* Optional parameters are usernames. */
  274. argc = opt_num_rest();
  275. argv = opt_rest();
  276. app_RAND_load();
  277. if (srpvfile != NULL && configfile != NULL) {
  278. BIO_printf(bio_err,
  279. "-srpvfile and -configfile cannot be specified together.\n");
  280. goto end;
  281. }
  282. if (mode == OPT_ERR) {
  283. BIO_printf(bio_err,
  284. "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
  285. goto opthelp;
  286. }
  287. if (mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD) {
  288. if (argc == 0) {
  289. BIO_printf(bio_err, "Need at least one user.\n");
  290. goto opthelp;
  291. }
  292. user = *argv++;
  293. }
  294. if ((passinarg != NULL || passoutarg != NULL) && argc != 1) {
  295. BIO_printf(bio_err,
  296. "-passin, -passout arguments only valid with one user.\n");
  297. goto opthelp;
  298. }
  299. if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
  300. BIO_printf(bio_err, "Error getting passwords\n");
  301. goto end;
  302. }
  303. if (srpvfile == NULL) {
  304. if (configfile == NULL)
  305. configfile = default_config_file;
  306. conf = app_load_config_verbose(configfile, verbose);
  307. if (conf == NULL)
  308. goto end;
  309. if (configfile != default_config_file && !app_load_modules(conf))
  310. goto end;
  311. /* Lets get the config section we are using */
  312. if (section == NULL) {
  313. if (verbose)
  314. BIO_printf(bio_err,
  315. "trying to read " ENV_DEFAULT_SRP
  316. " in " BASE_SECTION "\n");
  317. section = lookup_conf(conf, BASE_SECTION, ENV_DEFAULT_SRP);
  318. if (section == NULL)
  319. goto end;
  320. }
  321. app_RAND_load_conf(conf, BASE_SECTION);
  322. if (verbose)
  323. BIO_printf(bio_err,
  324. "trying to read " ENV_DATABASE " in section \"%s\"\n",
  325. section);
  326. srpvfile = lookup_conf(conf, section, ENV_DATABASE);
  327. if (srpvfile == NULL)
  328. goto end;
  329. }
  330. if (verbose)
  331. BIO_printf(bio_err, "Trying to read SRP verifier file \"%s\"\n",
  332. srpvfile);
  333. db = load_index(srpvfile, NULL);
  334. if (db == NULL)
  335. goto end;
  336. /* Lets check some fields */
  337. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  338. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  339. if (pp[DB_srptype][0] == DB_SRP_INDEX) {
  340. maxgN = i;
  341. if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)
  342. gNindex = i;
  343. print_index(db, i, verbose > 1);
  344. }
  345. }
  346. if (verbose)
  347. BIO_printf(bio_err, "Database initialised\n");
  348. if (gNindex >= 0) {
  349. gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);
  350. print_entry(db, gNindex, verbose > 1, "Default g and N");
  351. } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {
  352. BIO_printf(bio_err, "No g and N value for index \"%s\"\n", gN);
  353. goto end;
  354. } else {
  355. if (verbose)
  356. BIO_printf(bio_err, "Database has no g N information.\n");
  357. gNrow = NULL;
  358. }
  359. if (verbose > 1)
  360. BIO_printf(bio_err, "Starting user processing\n");
  361. while (mode == OPT_LIST || user != NULL) {
  362. int userindex = -1;
  363. if (user != NULL && verbose > 1)
  364. BIO_printf(bio_err, "Processing user \"%s\"\n", user);
  365. if ((userindex = get_index(db, user, 'U')) >= 0)
  366. print_user(db, userindex, (verbose > 0) || mode == OPT_LIST);
  367. if (mode == OPT_LIST) {
  368. if (user == NULL) {
  369. BIO_printf(bio_err, "List all users\n");
  370. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++)
  371. print_user(db, i, 1);
  372. } else if (userindex < 0) {
  373. BIO_printf(bio_err,
  374. "user \"%s\" does not exist, ignored. t\n", user);
  375. errors++;
  376. }
  377. } else if (mode == OPT_ADD) {
  378. if (userindex >= 0) {
  379. /* reactivation of a new user */
  380. char **row =
  381. sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  382. BIO_printf(bio_err, "user \"%s\" reactivated.\n", user);
  383. row[DB_srptype][0] = 'V';
  384. doupdatedb = 1;
  385. } else {
  386. char *row[DB_NUMBER];
  387. char *gNid;
  388. row[DB_srpverifier] = NULL;
  389. row[DB_srpsalt] = NULL;
  390. row[DB_srpinfo] = NULL;
  391. if (!
  392. (gNid =
  393. srp_create_user(user, &(row[DB_srpverifier]),
  394. &(row[DB_srpsalt]),
  395. gNrow ? gNrow[DB_srpsalt] : gN,
  396. gNrow ? gNrow[DB_srpverifier] : NULL,
  397. passout, verbose))) {
  398. BIO_printf(bio_err,
  399. "Cannot create srp verifier for user \"%s\", operation abandoned .\n",
  400. user);
  401. errors++;
  402. goto end;
  403. }
  404. row[DB_srpid] = OPENSSL_strdup(user);
  405. row[DB_srptype] = OPENSSL_strdup("v");
  406. row[DB_srpgN] = OPENSSL_strdup(gNid);
  407. if ((row[DB_srpid] == NULL)
  408. || (row[DB_srpgN] == NULL)
  409. || (row[DB_srptype] == NULL)
  410. || (row[DB_srpverifier] == NULL)
  411. || (row[DB_srpsalt] == NULL)
  412. || (userinfo
  413. && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL))
  414. || !update_index(db, row)) {
  415. OPENSSL_free(row[DB_srpid]);
  416. OPENSSL_free(row[DB_srpgN]);
  417. OPENSSL_free(row[DB_srpinfo]);
  418. OPENSSL_free(row[DB_srptype]);
  419. OPENSSL_free(row[DB_srpverifier]);
  420. OPENSSL_free(row[DB_srpsalt]);
  421. goto end;
  422. }
  423. doupdatedb = 1;
  424. }
  425. } else if (mode == OPT_MODIFY) {
  426. if (userindex < 0) {
  427. BIO_printf(bio_err,
  428. "user \"%s\" does not exist, operation ignored.\n",
  429. user);
  430. errors++;
  431. } else {
  432. char **row =
  433. sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  434. char type = row[DB_srptype][0];
  435. if (type == 'v') {
  436. BIO_printf(bio_err,
  437. "user \"%s\" already updated, operation ignored.\n",
  438. user);
  439. errors++;
  440. } else {
  441. char *gNid;
  442. if (row[DB_srptype][0] == 'V') {
  443. int user_gN;
  444. char **irow = NULL;
  445. if (verbose)
  446. BIO_printf(bio_err,
  447. "Verifying password for user \"%s\"\n",
  448. user);
  449. if ((user_gN =
  450. get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)
  451. irow =
  452. sk_OPENSSL_PSTRING_value(db->db->data,
  453. userindex);
  454. if (!srp_verify_user
  455. (user, row[DB_srpverifier], row[DB_srpsalt],
  456. irow ? irow[DB_srpsalt] : row[DB_srpgN],
  457. irow ? irow[DB_srpverifier] : NULL, passin,
  458. verbose)) {
  459. BIO_printf(bio_err,
  460. "Invalid password for user \"%s\", operation abandoned.\n",
  461. user);
  462. errors++;
  463. goto end;
  464. }
  465. }
  466. if (verbose)
  467. BIO_printf(bio_err, "Password for user \"%s\" ok.\n",
  468. user);
  469. if (!
  470. (gNid =
  471. srp_create_user(user, &(row[DB_srpverifier]),
  472. &(row[DB_srpsalt]),
  473. gNrow ? gNrow[DB_srpsalt] : NULL,
  474. gNrow ? gNrow[DB_srpverifier] : NULL,
  475. passout, verbose))) {
  476. BIO_printf(bio_err,
  477. "Cannot create srp verifier for user \"%s\", operation abandoned.\n",
  478. user);
  479. errors++;
  480. goto end;
  481. }
  482. row[DB_srptype][0] = 'v';
  483. row[DB_srpgN] = OPENSSL_strdup(gNid);
  484. if (row[DB_srpid] == NULL
  485. || row[DB_srpgN] == NULL
  486. || row[DB_srptype] == NULL
  487. || row[DB_srpverifier] == NULL
  488. || row[DB_srpsalt] == NULL
  489. || (userinfo
  490. && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo))
  491. == NULL)))
  492. goto end;
  493. doupdatedb = 1;
  494. }
  495. }
  496. } else if (mode == OPT_DELETE) {
  497. if (userindex < 0) {
  498. BIO_printf(bio_err,
  499. "user \"%s\" does not exist, operation ignored. t\n",
  500. user);
  501. errors++;
  502. } else {
  503. char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  504. BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
  505. xpp[DB_srptype][0] = 'R';
  506. doupdatedb = 1;
  507. }
  508. }
  509. user = *argv++;
  510. if (user == NULL) {
  511. /* no more processing in any mode if no users left */
  512. break;
  513. }
  514. }
  515. if (verbose)
  516. BIO_printf(bio_err, "User procession done.\n");
  517. if (doupdatedb) {
  518. /* Lets check some fields */
  519. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  520. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  521. if (pp[DB_srptype][0] == 'v') {
  522. pp[DB_srptype][0] = 'V';
  523. print_user(db, i, verbose);
  524. }
  525. }
  526. if (verbose)
  527. BIO_printf(bio_err, "Trying to update srpvfile.\n");
  528. if (!save_index(srpvfile, "new", db))
  529. goto end;
  530. if (verbose)
  531. BIO_printf(bio_err, "Temporary srpvfile created.\n");
  532. if (!rotate_index(srpvfile, "new", "old"))
  533. goto end;
  534. if (verbose)
  535. BIO_printf(bio_err, "srpvfile updated.\n");
  536. }
  537. ret = (errors != 0);
  538. end:
  539. if (errors != 0)
  540. if (verbose)
  541. BIO_printf(bio_err, "User errors %d.\n", errors);
  542. if (verbose)
  543. BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
  544. OPENSSL_free(passin);
  545. OPENSSL_free(passout);
  546. if (ret)
  547. ERR_print_errors(bio_err);
  548. NCONF_free(conf);
  549. free_index(db);
  550. release_engine(e);
  551. return ret;
  552. }