srp.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*
  2. * Copyright 2004-2020 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. #include <openssl/opensslconf.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <openssl/conf.h>
  18. #include <openssl/bio.h>
  19. #include <openssl/err.h>
  20. #include <openssl/txt_db.h>
  21. #include <openssl/buffer.h>
  22. #include <openssl/srp.h>
  23. #include "apps.h"
  24. #include "progs.h"
  25. #define BASE_SECTION "srp"
  26. #define CONFIG_FILE "openssl.cnf"
  27. #define ENV_DATABASE "srpvfile"
  28. #define ENV_DEFAULT_SRP "default_srp"
  29. static int get_index(CA_DB *db, char *id, char type)
  30. {
  31. char **pp;
  32. int i;
  33. if (id == NULL)
  34. return -1;
  35. if (type == DB_SRP_INDEX) {
  36. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  37. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  38. if (pp[DB_srptype][0] == DB_SRP_INDEX
  39. && strcmp(id, pp[DB_srpid]) == 0)
  40. return i;
  41. }
  42. } else {
  43. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  44. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  45. if (pp[DB_srptype][0] != DB_SRP_INDEX
  46. && strcmp(id, pp[DB_srpid]) == 0)
  47. return i;
  48. }
  49. }
  50. return -1;
  51. }
  52. static void print_entry(CA_DB *db, int indx, int verbose, char *s)
  53. {
  54. if (indx >= 0 && verbose) {
  55. int j;
  56. char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
  57. BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
  58. for (j = 0; j < DB_NUMBER; j++) {
  59. BIO_printf(bio_err, " %d = \"%s\"\n", j, pp[j]);
  60. }
  61. }
  62. }
  63. static void print_index(CA_DB *db, int indexindex, int verbose)
  64. {
  65. print_entry(db, indexindex, verbose, "g N entry");
  66. }
  67. static void print_user(CA_DB *db, int userindex, int verbose)
  68. {
  69. if (verbose > 0) {
  70. char **pp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  71. if (pp[DB_srptype][0] != 'I') {
  72. print_entry(db, userindex, verbose, "User entry");
  73. print_entry(db, get_index(db, pp[DB_srpgN], 'I'), verbose,
  74. "g N entry");
  75. }
  76. }
  77. }
  78. static int update_index(CA_DB *db, char **row)
  79. {
  80. char **irow;
  81. int i;
  82. irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");
  83. for (i = 0; i < DB_NUMBER; i++)
  84. irow[i] = row[i];
  85. irow[DB_NUMBER] = NULL;
  86. if (!TXT_DB_insert(db->db, irow)) {
  87. BIO_printf(bio_err, "failed to update srpvfile\n");
  88. BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
  89. OPENSSL_free(irow);
  90. return 0;
  91. }
  92. return 1;
  93. }
  94. static char *lookup_conf(const CONF *conf, const char *section, const char *tag)
  95. {
  96. char *entry = NCONF_get_string(conf, section, tag);
  97. if (entry == NULL)
  98. BIO_printf(bio_err, "variable lookup failed for %s::%s\n", section, tag);
  99. return entry;
  100. }
  101. static char *srp_verify_user(const char *user, const char *srp_verifier,
  102. char *srp_usersalt, const char *g, const char *N,
  103. const char *passin, int verbose)
  104. {
  105. char password[1025];
  106. PW_CB_DATA cb_tmp;
  107. char *verifier = NULL;
  108. char *gNid = NULL;
  109. int len;
  110. cb_tmp.prompt_info = user;
  111. cb_tmp.password = passin;
  112. len = password_callback(password, sizeof(password)-1, 0, &cb_tmp);
  113. if (len > 0) {
  114. password[len] = 0;
  115. if (verbose)
  116. BIO_printf(bio_err,
  117. "Validating\n user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
  118. user, srp_verifier, srp_usersalt, g, N);
  119. if (verbose > 1)
  120. BIO_printf(bio_err, "Pass %s\n", password);
  121. OPENSSL_assert(srp_usersalt != NULL);
  122. if ((gNid = SRP_create_verifier(user, password, &srp_usersalt,
  123. &verifier, N, g)) == NULL) {
  124. BIO_printf(bio_err, "Internal error validating SRP verifier\n");
  125. } else {
  126. if (strcmp(verifier, srp_verifier))
  127. gNid = NULL;
  128. OPENSSL_free(verifier);
  129. }
  130. OPENSSL_cleanse(password, len);
  131. }
  132. return gNid;
  133. }
  134. static char *srp_create_user(char *user, char **srp_verifier,
  135. char **srp_usersalt, char *g, char *N,
  136. char *passout, int verbose)
  137. {
  138. char password[1025];
  139. PW_CB_DATA cb_tmp;
  140. char *gNid = NULL;
  141. char *salt = NULL;
  142. int len;
  143. cb_tmp.prompt_info = user;
  144. cb_tmp.password = passout;
  145. len = password_callback(password, sizeof(password)-1, 1, &cb_tmp);
  146. if (len > 0) {
  147. password[len] = 0;
  148. if (verbose)
  149. BIO_printf(bio_err, "Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
  150. user, g, N);
  151. if ((gNid = SRP_create_verifier(user, password, &salt,
  152. srp_verifier, N, g)) == NULL) {
  153. BIO_printf(bio_err, "Internal error creating SRP verifier\n");
  154. } else {
  155. *srp_usersalt = salt;
  156. }
  157. OPENSSL_cleanse(password, len);
  158. if (verbose > 1)
  159. BIO_printf(bio_err, "gNid=%s salt =\"%s\"\n verifier =\"%s\"\n",
  160. gNid, salt, *srp_verifier);
  161. }
  162. return gNid;
  163. }
  164. typedef enum OPTION_choice {
  165. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
  166. OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SRPVFILE, OPT_ADD,
  167. OPT_DELETE, OPT_MODIFY, OPT_LIST, OPT_GN, OPT_USERINFO,
  168. OPT_PASSIN, OPT_PASSOUT, OPT_ENGINE, OPT_R_ENUM, OPT_PROV_ENUM
  169. } OPTION_CHOICE;
  170. const OPTIONS srp_options[] = {
  171. {OPT_HELP_STR, 1, '-', "Usage: %s [options] [user...]\n"},
  172. OPT_SECTION("General"),
  173. {"help", OPT_HELP, '-', "Display this summary"},
  174. {"verbose", OPT_VERBOSE, '-', "Talk a lot while doing things"},
  175. {"config", OPT_CONFIG, '<', "A config file"},
  176. {"name", OPT_NAME, 's', "The particular srp definition to use"},
  177. #ifndef OPENSSL_NO_ENGINE
  178. {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
  179. #endif
  180. OPT_SECTION("Action"),
  181. {"add", OPT_ADD, '-', "Add a user and srp verifier"},
  182. {"modify", OPT_MODIFY, '-', "Modify the srp verifier of an existing user"},
  183. {"delete", OPT_DELETE, '-', "Delete user from verifier file"},
  184. {"list", OPT_LIST, '-', "List users"},
  185. OPT_SECTION("Configuration"),
  186. {"srpvfile", OPT_SRPVFILE, '<', "The srp verifier file name"},
  187. {"gn", OPT_GN, 's', "Set g and N values to be used for new verifier"},
  188. {"userinfo", OPT_USERINFO, 's', "Additional info to be set for user"},
  189. {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
  190. {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
  191. OPT_R_OPTIONS,
  192. OPT_PROV_OPTIONS,
  193. OPT_PARAMETERS(),
  194. {"user", 0, 0, "Username(s) to process (optional)"},
  195. {NULL}
  196. };
  197. int srp_main(int argc, char **argv)
  198. {
  199. ENGINE *e = NULL;
  200. CA_DB *db = NULL;
  201. CONF *conf = NULL;
  202. int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose = 0, i;
  203. int doupdatedb = 0, mode = OPT_ERR;
  204. char *user = NULL, *passinarg = NULL, *passoutarg = NULL;
  205. char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;
  206. char *section = NULL;
  207. char **gNrow = NULL, *configfile = NULL;
  208. char *srpvfile = NULL, **pp, *prog;
  209. OPTION_CHOICE o;
  210. prog = opt_init(argc, argv, srp_options);
  211. while ((o = opt_next()) != OPT_EOF) {
  212. switch (o) {
  213. case OPT_EOF:
  214. case OPT_ERR:
  215. opthelp:
  216. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  217. goto end;
  218. case OPT_HELP:
  219. opt_help(srp_options);
  220. ret = 0;
  221. goto end;
  222. case OPT_VERBOSE:
  223. verbose++;
  224. break;
  225. case OPT_CONFIG:
  226. configfile = opt_arg();
  227. break;
  228. case OPT_NAME:
  229. section = opt_arg();
  230. break;
  231. case OPT_SRPVFILE:
  232. srpvfile = opt_arg();
  233. break;
  234. case OPT_ADD:
  235. case OPT_DELETE:
  236. case OPT_MODIFY:
  237. case OPT_LIST:
  238. if (mode != OPT_ERR) {
  239. BIO_printf(bio_err,
  240. "%s: Only one of -add/-delete/-modify/-list\n",
  241. prog);
  242. goto opthelp;
  243. }
  244. mode = o;
  245. break;
  246. case OPT_GN:
  247. gN = opt_arg();
  248. break;
  249. case OPT_USERINFO:
  250. userinfo = opt_arg();
  251. break;
  252. case OPT_PASSIN:
  253. passinarg = opt_arg();
  254. break;
  255. case OPT_PASSOUT:
  256. passoutarg = opt_arg();
  257. break;
  258. case OPT_ENGINE:
  259. e = setup_engine(opt_arg(), 0);
  260. break;
  261. case OPT_R_CASES:
  262. if (!opt_rand(o))
  263. goto end;
  264. break;
  265. case OPT_PROV_CASES:
  266. if (!opt_provider(o))
  267. goto end;
  268. break;
  269. }
  270. }
  271. /* Optional parameters are usernames. */
  272. argc = opt_num_rest();
  273. argv = opt_rest();
  274. if (srpvfile != NULL && configfile != NULL) {
  275. BIO_printf(bio_err,
  276. "-srpvfile and -configfile cannot be specified together.\n");
  277. goto end;
  278. }
  279. if (mode == OPT_ERR) {
  280. BIO_printf(bio_err,
  281. "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
  282. goto opthelp;
  283. }
  284. if (mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD) {
  285. if (argc == 0) {
  286. BIO_printf(bio_err, "Need at least one user.\n");
  287. goto opthelp;
  288. }
  289. user = *argv++;
  290. }
  291. if ((passinarg != NULL || passoutarg != NULL) && argc != 1) {
  292. BIO_printf(bio_err,
  293. "-passin, -passout arguments only valid with one user.\n");
  294. goto opthelp;
  295. }
  296. if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
  297. BIO_printf(bio_err, "Error getting passwords\n");
  298. goto end;
  299. }
  300. if (srpvfile == NULL) {
  301. if (configfile == NULL)
  302. configfile = default_config_file;
  303. if (verbose)
  304. BIO_printf(bio_err, "Using configuration from %s\n",
  305. configfile);
  306. conf = app_load_config(configfile);
  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. }