srp.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Written by Peter Sylvester (peter.sylvester@edelweb.fr) for the EdelKey
  3. * project and contributed to the OpenSSL project 2004.
  4. */
  5. /* ====================================================================
  6. * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. All advertising materials mentioning features or use of this
  21. * software must display the following acknowledgment:
  22. * "This product includes software developed by the OpenSSL Project
  23. * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  24. *
  25. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  26. * endorse or promote products derived from this software without
  27. * prior written permission. For written permission, please contact
  28. * licensing@OpenSSL.org.
  29. *
  30. * 5. Products derived from this software may not be called "OpenSSL"
  31. * nor may "OpenSSL" appear in their names without prior written
  32. * permission of the OpenSSL Project.
  33. *
  34. * 6. Redistributions of any form whatsoever must retain the following
  35. * acknowledgment:
  36. * "This product includes software developed by the OpenSSL Project
  37. * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  38. *
  39. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  40. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  41. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  43. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  44. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  45. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  46. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  48. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  50. * OF THE POSSIBILITY OF SUCH DAMAGE.
  51. * ====================================================================
  52. *
  53. * This product includes cryptographic software written by Eric Young
  54. * (eay@cryptsoft.com). This product includes software written by Tim
  55. * Hudson (tjh@cryptsoft.com).
  56. *
  57. */
  58. #include <openssl/opensslconf.h>
  59. #ifndef OPENSSL_NO_SRP
  60. #include <stdio.h>
  61. #include <stdlib.h>
  62. #include <string.h>
  63. #include <openssl/conf.h>
  64. #include <openssl/bio.h>
  65. #include <openssl/err.h>
  66. #include <openssl/txt_db.h>
  67. #include <openssl/buffer.h>
  68. #include <openssl/srp.h>
  69. #include "apps.h"
  70. # define BASE_SECTION "srp"
  71. # define CONFIG_FILE "openssl.cnf"
  72. # define ENV_RANDFILE "RANDFILE"
  73. # define ENV_DATABASE "srpvfile"
  74. # define ENV_DEFAULT_SRP "default_srp"
  75. static int get_index(CA_DB *db, char *id, char type)
  76. {
  77. char **pp;
  78. int i;
  79. if (id == NULL)
  80. return -1;
  81. if (type == DB_SRP_INDEX)
  82. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  83. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  84. if (pp[DB_srptype][0] == DB_SRP_INDEX
  85. && strcmp(id, pp[DB_srpid]) == 0)
  86. return i;
  87. } else
  88. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  89. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  90. if (pp[DB_srptype][0] != DB_SRP_INDEX
  91. && strcmp(id, pp[DB_srpid]) == 0)
  92. return i;
  93. }
  94. return -1;
  95. }
  96. static void print_entry(CA_DB *db, int indx, int verbose, char *s)
  97. {
  98. if (indx >= 0 && verbose) {
  99. int j;
  100. char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
  101. BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
  102. for (j = 0; j < DB_NUMBER; j++) {
  103. BIO_printf(bio_err, " %d = \"%s\"\n", j, pp[j]);
  104. }
  105. }
  106. }
  107. static void print_index(CA_DB *db, int indexindex, int verbose)
  108. {
  109. print_entry(db, indexindex, verbose, "g N entry");
  110. }
  111. static void print_user(CA_DB *db, int userindex, int verbose)
  112. {
  113. if (verbose > 0) {
  114. char **pp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  115. if (pp[DB_srptype][0] != 'I') {
  116. print_entry(db, userindex, verbose, "User entry");
  117. print_entry(db, get_index(db, pp[DB_srpgN], 'I'), verbose,
  118. "g N entry");
  119. }
  120. }
  121. }
  122. static int update_index(CA_DB *db, char **row)
  123. {
  124. char **irow;
  125. int i;
  126. irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");
  127. for (i = 0; i < DB_NUMBER; i++) {
  128. irow[i] = row[i];
  129. row[i] = NULL;
  130. }
  131. irow[DB_NUMBER] = NULL;
  132. if (!TXT_DB_insert(db->db, irow)) {
  133. BIO_printf(bio_err, "failed to update srpvfile\n");
  134. BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
  135. OPENSSL_free(irow);
  136. return 0;
  137. }
  138. return 1;
  139. }
  140. static void lookup_fail(const char *name, const char *tag)
  141. {
  142. BIO_printf(bio_err, "variable lookup failed for %s::%s\n", name, tag);
  143. }
  144. static char *srp_verify_user(const char *user, const char *srp_verifier,
  145. char *srp_usersalt, const char *g, const char *N,
  146. const char *passin, int verbose)
  147. {
  148. char password[1024];
  149. PW_CB_DATA cb_tmp;
  150. char *verifier = NULL;
  151. char *gNid = NULL;
  152. cb_tmp.prompt_info = user;
  153. cb_tmp.password = passin;
  154. if (password_callback(password, 1024, 0, &cb_tmp) > 0) {
  155. if (verbose)
  156. BIO_printf(bio_err,
  157. "Validating\n user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
  158. user, srp_verifier, srp_usersalt, g, N);
  159. BIO_printf(bio_err, "Pass %s\n", password);
  160. OPENSSL_assert(srp_usersalt != NULL);
  161. if (!
  162. (gNid =
  163. SRP_create_verifier(user, password, &srp_usersalt, &verifier, N,
  164. g))) {
  165. BIO_printf(bio_err, "Internal error validating SRP verifier\n");
  166. } else {
  167. if (strcmp(verifier, srp_verifier))
  168. gNid = NULL;
  169. OPENSSL_free(verifier);
  170. }
  171. }
  172. return gNid;
  173. }
  174. static char *srp_create_user(char *user, char **srp_verifier,
  175. char **srp_usersalt, char *g, char *N,
  176. char *passout, int verbose)
  177. {
  178. char password[1024];
  179. PW_CB_DATA cb_tmp;
  180. char *gNid = NULL;
  181. char *salt = NULL;
  182. cb_tmp.prompt_info = user;
  183. cb_tmp.password = passout;
  184. if (password_callback(password, 1024, 1, &cb_tmp) > 0) {
  185. if (verbose)
  186. BIO_printf(bio_err, "Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
  187. user, g, N);
  188. if (!
  189. (gNid =
  190. SRP_create_verifier(user, password, &salt, srp_verifier, N,
  191. g))) {
  192. BIO_printf(bio_err, "Internal error creating SRP verifier\n");
  193. } else
  194. *srp_usersalt = salt;
  195. if (verbose > 1)
  196. BIO_printf(bio_err, "gNid=%s salt =\"%s\"\n verifier =\"%s\"\n", gNid,
  197. salt, *srp_verifier);
  198. }
  199. return gNid;
  200. }
  201. typedef enum OPTION_choice {
  202. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
  203. OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SRPVFILE, OPT_ADD,
  204. OPT_DELETE, OPT_MODIFY, OPT_LIST, OPT_GN, OPT_USERINFO,
  205. OPT_PASSIN, OPT_PASSOUT, OPT_ENGINE
  206. } OPTION_CHOICE;
  207. OPTIONS srp_options[] = {
  208. {"help", OPT_HELP, '-', "Display this summary"},
  209. {"verbose", OPT_VERBOSE, '-', "Talk a lot while doing things"},
  210. {"config", OPT_CONFIG, '<', "A config file"},
  211. {"name", OPT_NAME, 's', "The particular srp definition to use"},
  212. {"srpvfile", OPT_SRPVFILE, '<', "The srp verifier file name"},
  213. {"add", OPT_ADD, '-', "Add a user and srp verifier"},
  214. {"modify", OPT_MODIFY, '-',
  215. "Modify the srp verifier of an existing user"},
  216. {"delete", OPT_DELETE, '-', "Delete user from verifier file"},
  217. {"list", OPT_LIST, '-', "List users"},
  218. {"gn", OPT_GN, 's', "Set g and N values to be used for new verifier"},
  219. {"userinfo", OPT_USERINFO, 's', "Additional info to be set for user"},
  220. {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
  221. {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
  222. # ifndef OPENSSL_NO_ENGINE
  223. {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
  224. # endif
  225. {NULL}
  226. };
  227. int srp_main(int argc, char **argv)
  228. {
  229. CA_DB *db = NULL;
  230. DB_ATTR db_attr;
  231. CONF *conf = NULL;
  232. int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose = 0, i;
  233. int doupdatedb = 0, mode = OPT_ERR;
  234. char *user = NULL, *passinarg = NULL, *passoutarg = NULL;
  235. char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;
  236. char *randfile = NULL, *tofree = NULL, *section = NULL;
  237. char **gNrow = NULL, *configfile = NULL;
  238. char *srpvfile = NULL, **pp, *prog;
  239. OPTION_CHOICE o;
  240. prog = opt_init(argc, argv, srp_options);
  241. while ((o = opt_next()) != OPT_EOF) {
  242. switch (o) {
  243. case OPT_EOF:
  244. case OPT_ERR:
  245. opthelp:
  246. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  247. goto end;
  248. case OPT_HELP:
  249. opt_help(srp_options);
  250. ret = 0;
  251. goto end;
  252. case OPT_VERBOSE:
  253. verbose++;
  254. break;
  255. case OPT_CONFIG:
  256. configfile = opt_arg();
  257. break;
  258. case OPT_NAME:
  259. section = opt_arg();
  260. break;
  261. case OPT_SRPVFILE:
  262. srpvfile = opt_arg();
  263. break;
  264. case OPT_ADD:
  265. case OPT_DELETE:
  266. case OPT_MODIFY:
  267. case OPT_LIST:
  268. if (mode != OPT_ERR) {
  269. BIO_printf(bio_err,
  270. "%s: Only one of -add/delete-modify/-list\n",
  271. prog);
  272. goto opthelp;
  273. }
  274. mode = o;
  275. break;
  276. case OPT_GN:
  277. gN = opt_arg();
  278. break;
  279. case OPT_USERINFO:
  280. userinfo = opt_arg();
  281. break;
  282. case OPT_PASSIN:
  283. passinarg = opt_arg();
  284. break;
  285. case OPT_PASSOUT:
  286. passoutarg = opt_arg();
  287. break;
  288. case OPT_ENGINE:
  289. (void)setup_engine(opt_arg(), 0);
  290. break;
  291. }
  292. }
  293. argc = opt_num_rest();
  294. argv = opt_rest();
  295. if (srpvfile && configfile) {
  296. BIO_printf(bio_err,
  297. "-srpvfile and -configfile cannot be specified together.\n");
  298. goto end;
  299. }
  300. if (mode == OPT_ERR) {
  301. BIO_printf(bio_err,
  302. "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
  303. goto opthelp;
  304. }
  305. if ((mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD)
  306. && argc < 1) {
  307. BIO_printf(bio_err,
  308. "Need at least one user for options -add, -delete, -modify. \n");
  309. goto opthelp;
  310. }
  311. if ((passin || passout) && argc != 1) {
  312. BIO_printf(bio_err,
  313. "-passin, -passout arguments only valid with one user.\n");
  314. goto opthelp;
  315. }
  316. if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
  317. BIO_printf(bio_err, "Error getting passwords\n");
  318. goto end;
  319. }
  320. if (!srpvfile) {
  321. if (!configfile)
  322. configfile = default_config_file;
  323. if (verbose)
  324. BIO_printf(bio_err, "Using configuration from %s\n",
  325. configfile);
  326. conf = app_load_config(configfile);
  327. if (conf == NULL)
  328. goto end;
  329. if (!app_load_modules(conf))
  330. goto end;
  331. /* Lets get the config section we are using */
  332. if (section == NULL) {
  333. if (verbose)
  334. BIO_printf(bio_err,
  335. "trying to read " ENV_DEFAULT_SRP
  336. " in " BASE_SECTION "\n");
  337. section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_SRP);
  338. if (section == NULL) {
  339. lookup_fail(BASE_SECTION, ENV_DEFAULT_SRP);
  340. goto end;
  341. }
  342. }
  343. if (randfile == NULL && conf)
  344. randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");
  345. if (verbose)
  346. BIO_printf(bio_err,
  347. "trying to read " ENV_DATABASE " in section \"%s\"\n",
  348. section);
  349. if ((srpvfile = NCONF_get_string(conf, section, ENV_DATABASE))
  350. == NULL) {
  351. lookup_fail(section, ENV_DATABASE);
  352. goto end;
  353. }
  354. }
  355. if (randfile == NULL)
  356. ERR_clear_error();
  357. else
  358. app_RAND_load_file(randfile, 0);
  359. if (verbose)
  360. BIO_printf(bio_err, "Trying to read SRP verifier file \"%s\"\n",
  361. srpvfile);
  362. db = load_index(srpvfile, &db_attr);
  363. if (db == NULL)
  364. goto end;
  365. /* Lets check some fields */
  366. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  367. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  368. if (pp[DB_srptype][0] == DB_SRP_INDEX) {
  369. maxgN = i;
  370. if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)
  371. gNindex = i;
  372. print_index(db, i, verbose > 1);
  373. }
  374. }
  375. if (verbose)
  376. BIO_printf(bio_err, "Database initialised\n");
  377. if (gNindex >= 0) {
  378. gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);
  379. print_entry(db, gNindex, verbose > 1, "Default g and N");
  380. } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {
  381. BIO_printf(bio_err, "No g and N value for index \"%s\"\n", gN);
  382. goto end;
  383. } else {
  384. if (verbose)
  385. BIO_printf(bio_err, "Database has no g N information.\n");
  386. gNrow = NULL;
  387. }
  388. if (verbose > 1)
  389. BIO_printf(bio_err, "Starting user processing\n");
  390. if (argc > 0)
  391. user = *(argv++);
  392. while (mode == OPT_LIST || user) {
  393. int userindex = -1;
  394. if (user)
  395. if (verbose > 1)
  396. BIO_printf(bio_err, "Processing user \"%s\"\n", user);
  397. if ((userindex = get_index(db, user, 'U')) >= 0) {
  398. print_user(db, userindex, (verbose > 0)
  399. || mode == OPT_LIST);
  400. }
  401. if (mode == OPT_LIST) {
  402. if (user == NULL) {
  403. BIO_printf(bio_err, "List all users\n");
  404. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  405. print_user(db, i, 1);
  406. }
  407. } else if (userindex < 0) {
  408. BIO_printf(bio_err,
  409. "user \"%s\" does not exist, ignored. t\n", user);
  410. errors++;
  411. }
  412. } else if (mode == OPT_ADD) {
  413. if (userindex >= 0) {
  414. /* reactivation of a new user */
  415. char **row =
  416. sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  417. BIO_printf(bio_err, "user \"%s\" reactivated.\n", user);
  418. row[DB_srptype][0] = 'V';
  419. doupdatedb = 1;
  420. } else {
  421. char *row[DB_NUMBER];
  422. char *gNid;
  423. row[DB_srpverifier] = NULL;
  424. row[DB_srpsalt] = NULL;
  425. row[DB_srpinfo] = NULL;
  426. if (!
  427. (gNid =
  428. srp_create_user(user, &(row[DB_srpverifier]),
  429. &(row[DB_srpsalt]),
  430. gNrow ? gNrow[DB_srpsalt] : gN,
  431. gNrow ? gNrow[DB_srpverifier] : NULL,
  432. passout, verbose))) {
  433. BIO_printf(bio_err,
  434. "Cannot create srp verifier for user \"%s\", operation abandoned .\n",
  435. user);
  436. errors++;
  437. goto end;
  438. }
  439. row[DB_srpid] = OPENSSL_strdup(user);
  440. row[DB_srptype] = OPENSSL_strdup("v");
  441. row[DB_srpgN] = OPENSSL_strdup(gNid);
  442. if ((row[DB_srpid] == NULL)
  443. || (row[DB_srpgN] == NULL)
  444. || (row[DB_srptype] == NULL)
  445. || (row[DB_srpverifier] == NULL)
  446. || (row[DB_srpsalt] == NULL)
  447. || (userinfo
  448. && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL))
  449. || !update_index(db, row)) {
  450. OPENSSL_free(row[DB_srpid]);
  451. OPENSSL_free(row[DB_srpgN]);
  452. OPENSSL_free(row[DB_srpinfo]);
  453. OPENSSL_free(row[DB_srptype]);
  454. OPENSSL_free(row[DB_srpverifier]);
  455. OPENSSL_free(row[DB_srpsalt]);
  456. goto end;
  457. }
  458. doupdatedb = 1;
  459. }
  460. } else if (mode == OPT_MODIFY) {
  461. if (userindex < 0) {
  462. BIO_printf(bio_err,
  463. "user \"%s\" does not exist, operation ignored.\n",
  464. user);
  465. errors++;
  466. } else {
  467. char **row =
  468. sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  469. char type = row[DB_srptype][0];
  470. if (type == 'v') {
  471. BIO_printf(bio_err,
  472. "user \"%s\" already updated, operation ignored.\n",
  473. user);
  474. errors++;
  475. } else {
  476. char *gNid;
  477. if (row[DB_srptype][0] == 'V') {
  478. int user_gN;
  479. char **irow = NULL;
  480. if (verbose)
  481. BIO_printf(bio_err,
  482. "Verifying password for user \"%s\"\n",
  483. user);
  484. if ((user_gN =
  485. get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)
  486. irow =
  487. sk_OPENSSL_PSTRING_value(db->db->data,
  488. userindex);
  489. if (!srp_verify_user
  490. (user, row[DB_srpverifier], row[DB_srpsalt],
  491. irow ? irow[DB_srpsalt] : row[DB_srpgN],
  492. irow ? irow[DB_srpverifier] : NULL, passin,
  493. verbose)) {
  494. BIO_printf(bio_err,
  495. "Invalid password for user \"%s\", operation abandoned.\n",
  496. user);
  497. errors++;
  498. goto end;
  499. }
  500. }
  501. if (verbose)
  502. BIO_printf(bio_err, "Password for user \"%s\" ok.\n",
  503. user);
  504. if (!
  505. (gNid =
  506. srp_create_user(user, &(row[DB_srpverifier]),
  507. &(row[DB_srpsalt]),
  508. gNrow ? gNrow[DB_srpsalt] : NULL,
  509. gNrow ? gNrow[DB_srpverifier] : NULL,
  510. passout, verbose))) {
  511. BIO_printf(bio_err,
  512. "Cannot create srp verifier for user \"%s\", operation abandoned.\n",
  513. user);
  514. errors++;
  515. goto end;
  516. }
  517. row[DB_srptype][0] = 'v';
  518. row[DB_srpgN] = OPENSSL_strdup(gNid);
  519. if (row[DB_srpid] == NULL
  520. || row[DB_srpgN] == NULL
  521. || row[DB_srptype] == NULL
  522. || row[DB_srpverifier] == NULL
  523. || row[DB_srpsalt] == NULL
  524. || (userinfo
  525. && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo))
  526. == NULL)))
  527. goto end;
  528. doupdatedb = 1;
  529. }
  530. }
  531. } else if (mode == OPT_DELETE) {
  532. if (userindex < 0) {
  533. BIO_printf(bio_err,
  534. "user \"%s\" does not exist, operation ignored. t\n",
  535. user);
  536. errors++;
  537. } else {
  538. char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
  539. BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
  540. xpp[DB_srptype][0] = 'R';
  541. doupdatedb = 1;
  542. }
  543. }
  544. if (--argc > 0)
  545. user = *(argv++);
  546. else {
  547. user = NULL;
  548. }
  549. }
  550. if (verbose)
  551. BIO_printf(bio_err, "User procession done.\n");
  552. if (doupdatedb) {
  553. /* Lets check some fields */
  554. for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
  555. pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
  556. if (pp[DB_srptype][0] == 'v') {
  557. pp[DB_srptype][0] = 'V';
  558. print_user(db, i, verbose);
  559. }
  560. }
  561. if (verbose)
  562. BIO_printf(bio_err, "Trying to update srpvfile.\n");
  563. if (!save_index(srpvfile, "new", db))
  564. goto end;
  565. if (verbose)
  566. BIO_printf(bio_err, "Temporary srpvfile created.\n");
  567. if (!rotate_index(srpvfile, "new", "old"))
  568. goto end;
  569. if (verbose)
  570. BIO_printf(bio_err, "srpvfile updated.\n");
  571. }
  572. ret = (errors != 0);
  573. end:
  574. if (errors != 0)
  575. if (verbose)
  576. BIO_printf(bio_err, "User errors %d.\n", errors);
  577. if (verbose)
  578. BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
  579. OPENSSL_free(tofree);
  580. if (ret)
  581. ERR_print_errors(bio_err);
  582. if (randfile)
  583. app_RAND_write_file(randfile);
  584. NCONF_free(conf);
  585. free_index(db);
  586. OBJ_cleanup();
  587. return (ret);
  588. }
  589. #else
  590. # if PEDANTIC
  591. static void *dummy = &dummy;
  592. # endif
  593. #endif