srp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. argc = opt_num_rest();
  272. argv = opt_rest();
  273. if (srpvfile != NULL && configfile != NULL) {
  274. BIO_printf(bio_err,
  275. "-srpvfile and -configfile cannot be specified together.\n");
  276. goto end;
  277. }
  278. if (mode == OPT_ERR) {
  279. BIO_printf(bio_err,
  280. "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
  281. goto opthelp;
  282. }
  283. if (mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD) {
  284. if (argc == 0) {
  285. BIO_printf(bio_err, "Need at least one user.\n");
  286. goto opthelp;
  287. }
  288. user = *argv++;
  289. }
  290. if ((passinarg != NULL || passoutarg != NULL) && argc != 1) {
  291. BIO_printf(bio_err,
  292. "-passin, -passout arguments only valid with one user.\n");
  293. goto opthelp;
  294. }
  295. if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
  296. BIO_printf(bio_err, "Error getting passwords\n");
  297. goto end;
  298. }
  299. if (srpvfile == NULL) {
  300. if (configfile == NULL)
  301. configfile = default_config_file;
  302. if (verbose)
  303. BIO_printf(bio_err, "Using configuration from %s\n",
  304. configfile);
  305. conf = app_load_config(configfile);
  306. if (conf == NULL)
  307. goto end;
  308. if (configfile != default_config_file && !app_load_modules(conf))
  309. goto end;
  310. /* Lets get the config section we are using */
  311. if (section == NULL) {
  312. if (verbose)
  313. BIO_printf(bio_err,
  314. "trying to read " ENV_DEFAULT_SRP
  315. " in " BASE_SECTION "\n");
  316. section = lookup_conf(conf, BASE_SECTION, ENV_DEFAULT_SRP);
  317. if (section == NULL)
  318. goto end;
  319. }
  320. app_RAND_load_conf(conf, BASE_SECTION);
  321. if (verbose)
  322. BIO_printf(bio_err,
  323. "trying to read " ENV_DATABASE " in section \"%s\"\n",
  324. section);
  325. srpvfile = lookup_conf(conf, section, ENV_DATABASE);
  326. if (srpvfile == NULL)
  327. goto end;
  328. }
  329. if (verbose)
  330. BIO_printf(bio_err, "Trying to read SRP verifier file \"%s\"\n",
  331. srpvfile);
  332. db = load_index(srpvfile, NULL);
  333. if (db == NULL)
  334. goto end;
  335. /* Lets check some fields */
  336. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  337. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  338. if (pp[DB_srptype][0] == DB_SRP_INDEX) {
  339. maxgN = i;
  340. if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)
  341. gNindex = i;
  342. print_index(db, i, verbose > 1);
  343. }
  344. }
  345. if (verbose)
  346. BIO_printf(bio_err, "Database initialised\n");
  347. if (gNindex >= 0) {
  348. gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);
  349. print_entry(db, gNindex, verbose > 1, "Default g and N");
  350. } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {
  351. BIO_printf(bio_err, "No g and N value for index \"%s\"\n", gN);
  352. goto end;
  353. } else {
  354. if (verbose)
  355. BIO_printf(bio_err, "Database has no g N information.\n");
  356. gNrow = NULL;
  357. }
  358. if (verbose > 1)
  359. BIO_printf(bio_err, "Starting user processing\n");
  360. while (mode == OPT_LIST || user != NULL) {
  361. int userindex = -1;
  362. if (user != NULL && verbose > 1)
  363. BIO_printf(bio_err, "Processing user \"%s\"\n", user);
  364. if ((userindex = get_index(db, user, 'U')) >= 0)
  365. print_user(db, userindex, (verbose > 0) || mode == OPT_LIST);
  366. if (mode == OPT_LIST) {
  367. if (user == NULL) {
  368. BIO_printf(bio_err, "List all users\n");
  369. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++)
  370. print_user(db, i, 1);
  371. } else if (userindex < 0) {
  372. BIO_printf(bio_err,
  373. "user \"%s\" does not exist, ignored. t\n", user);
  374. errors++;
  375. }
  376. } else if (mode == OPT_ADD) {
  377. if (userindex >= 0) {
  378. /* reactivation of a new user */
  379. char **row =
  380. sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  381. BIO_printf(bio_err, "user \"%s\" reactivated.\n", user);
  382. row[DB_srptype][0] = 'V';
  383. doupdatedb = 1;
  384. } else {
  385. char *row[DB_NUMBER];
  386. char *gNid;
  387. row[DB_srpverifier] = NULL;
  388. row[DB_srpsalt] = NULL;
  389. row[DB_srpinfo] = NULL;
  390. if (!
  391. (gNid =
  392. srp_create_user(user, &(row[DB_srpverifier]),
  393. &(row[DB_srpsalt]),
  394. gNrow ? gNrow[DB_srpsalt] : gN,
  395. gNrow ? gNrow[DB_srpverifier] : NULL,
  396. passout, verbose))) {
  397. BIO_printf(bio_err,
  398. "Cannot create srp verifier for user \"%s\", operation abandoned .\n",
  399. user);
  400. errors++;
  401. goto end;
  402. }
  403. row[DB_srpid] = OPENSSL_strdup(user);
  404. row[DB_srptype] = OPENSSL_strdup("v");
  405. row[DB_srpgN] = OPENSSL_strdup(gNid);
  406. if ((row[DB_srpid] == NULL)
  407. || (row[DB_srpgN] == NULL)
  408. || (row[DB_srptype] == NULL)
  409. || (row[DB_srpverifier] == NULL)
  410. || (row[DB_srpsalt] == NULL)
  411. || (userinfo
  412. && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL))
  413. || !update_index(db, row)) {
  414. OPENSSL_free(row[DB_srpid]);
  415. OPENSSL_free(row[DB_srpgN]);
  416. OPENSSL_free(row[DB_srpinfo]);
  417. OPENSSL_free(row[DB_srptype]);
  418. OPENSSL_free(row[DB_srpverifier]);
  419. OPENSSL_free(row[DB_srpsalt]);
  420. goto end;
  421. }
  422. doupdatedb = 1;
  423. }
  424. } else if (mode == OPT_MODIFY) {
  425. if (userindex < 0) {
  426. BIO_printf(bio_err,
  427. "user \"%s\" does not exist, operation ignored.\n",
  428. user);
  429. errors++;
  430. } else {
  431. char **row =
  432. sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  433. char type = row[DB_srptype][0];
  434. if (type == 'v') {
  435. BIO_printf(bio_err,
  436. "user \"%s\" already updated, operation ignored.\n",
  437. user);
  438. errors++;
  439. } else {
  440. char *gNid;
  441. if (row[DB_srptype][0] == 'V') {
  442. int user_gN;
  443. char **irow = NULL;
  444. if (verbose)
  445. BIO_printf(bio_err,
  446. "Verifying password for user \"%s\"\n",
  447. user);
  448. if ((user_gN =
  449. get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)
  450. irow =
  451. sk_OPENSSL_PSTRING_value(db->db->data,
  452. userindex);
  453. if (!srp_verify_user
  454. (user, row[DB_srpverifier], row[DB_srpsalt],
  455. irow ? irow[DB_srpsalt] : row[DB_srpgN],
  456. irow ? irow[DB_srpverifier] : NULL, passin,
  457. verbose)) {
  458. BIO_printf(bio_err,
  459. "Invalid password for user \"%s\", operation abandoned.\n",
  460. user);
  461. errors++;
  462. goto end;
  463. }
  464. }
  465. if (verbose)
  466. BIO_printf(bio_err, "Password for user \"%s\" ok.\n",
  467. user);
  468. if (!
  469. (gNid =
  470. srp_create_user(user, &(row[DB_srpverifier]),
  471. &(row[DB_srpsalt]),
  472. gNrow ? gNrow[DB_srpsalt] : NULL,
  473. gNrow ? gNrow[DB_srpverifier] : NULL,
  474. passout, verbose))) {
  475. BIO_printf(bio_err,
  476. "Cannot create srp verifier for user \"%s\", operation abandoned.\n",
  477. user);
  478. errors++;
  479. goto end;
  480. }
  481. row[DB_srptype][0] = 'v';
  482. row[DB_srpgN] = OPENSSL_strdup(gNid);
  483. if (row[DB_srpid] == NULL
  484. || row[DB_srpgN] == NULL
  485. || row[DB_srptype] == NULL
  486. || row[DB_srpverifier] == NULL
  487. || row[DB_srpsalt] == NULL
  488. || (userinfo
  489. && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo))
  490. == NULL)))
  491. goto end;
  492. doupdatedb = 1;
  493. }
  494. }
  495. } else if (mode == OPT_DELETE) {
  496. if (userindex < 0) {
  497. BIO_printf(bio_err,
  498. "user \"%s\" does not exist, operation ignored. t\n",
  499. user);
  500. errors++;
  501. } else {
  502. char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  503. BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
  504. xpp[DB_srptype][0] = 'R';
  505. doupdatedb = 1;
  506. }
  507. }
  508. user = *argv++;
  509. if (user == NULL) {
  510. /* no more processing in any mode if no users left */
  511. break;
  512. }
  513. }
  514. if (verbose)
  515. BIO_printf(bio_err, "User procession done.\n");
  516. if (doupdatedb) {
  517. /* Lets check some fields */
  518. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  519. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  520. if (pp[DB_srptype][0] == 'v') {
  521. pp[DB_srptype][0] = 'V';
  522. print_user(db, i, verbose);
  523. }
  524. }
  525. if (verbose)
  526. BIO_printf(bio_err, "Trying to update srpvfile.\n");
  527. if (!save_index(srpvfile, "new", db))
  528. goto end;
  529. if (verbose)
  530. BIO_printf(bio_err, "Temporary srpvfile created.\n");
  531. if (!rotate_index(srpvfile, "new", "old"))
  532. goto end;
  533. if (verbose)
  534. BIO_printf(bio_err, "srpvfile updated.\n");
  535. }
  536. ret = (errors != 0);
  537. end:
  538. if (errors != 0)
  539. if (verbose)
  540. BIO_printf(bio_err, "User errors %d.\n", errors);
  541. if (verbose)
  542. BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
  543. OPENSSL_free(passin);
  544. OPENSSL_free(passout);
  545. if (ret)
  546. ERR_print_errors(bio_err);
  547. NCONF_free(conf);
  548. free_index(db);
  549. release_engine(e);
  550. return ret;
  551. }