]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/srp.c
Make SRP work with -www
[thirdparty/openssl.git] / apps / srp.c
CommitLineData
0f113f3e
MC
1/*
2 * Written by Peter Sylvester (peter.sylvester@edelweb.fr) for the EdelKey
3 * project and contributed to the OpenSSL project 2004.
edc032b5
BL
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
0f113f3e 13 * notice, this list of conditions and the following disclaimer.
edc032b5
BL
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
60#ifndef OPENSSL_NO_SRP
a7f82a1a
MC
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64#include <openssl/conf.h>
65#include <openssl/bio.h>
66#include <openssl/err.h>
67#include <openssl/txt_db.h>
68#include <openssl/buffer.h>
69#include <openssl/srp.h>
70#include "apps.h"
6e81b270 71
6e81b270
AP
72# define BASE_SECTION "srp"
73# define CONFIG_FILE "openssl.cnf"
74
75# define ENV_RANDFILE "RANDFILE"
76
77# define ENV_DATABASE "srpvfile"
78# define ENV_DEFAULT_SRP "default_srp"
79
6e81b270
AP
80static int get_index(CA_DB *db, char *id, char type)
81{
82 char **pp;
83 int i;
84 if (id == NULL)
85 return -1;
86 if (type == DB_SRP_INDEX)
87 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
88 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
89 if (pp[DB_srptype][0] == DB_SRP_INDEX
86885c28 90 && strcmp(id, pp[DB_srpid]) == 0)
6e81b270
AP
91 return i;
92 } else
93 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
94 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
95
96 if (pp[DB_srptype][0] != DB_SRP_INDEX
86885c28 97 && strcmp(id, pp[DB_srpid]) == 0)
6e81b270
AP
98 return i;
99 }
100
101 return -1;
102}
edc032b5 103
ecf3a1fb 104static void print_entry(CA_DB *db, int indx, int verbose, char *s)
6e81b270
AP
105{
106 if (indx >= 0 && verbose) {
107 int j;
108 char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
ecf3a1fb 109 BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
6e81b270
AP
110 for (j = 0; j < DB_NUMBER; j++) {
111 BIO_printf(bio_err, " %d = \"%s\"\n", j, pp[j]);
112 }
113 }
114}
edc032b5 115
ecf3a1fb 116static void print_index(CA_DB *db, int indexindex, int verbose)
6e81b270 117{
ecf3a1fb 118 print_entry(db, indexindex, verbose, "g N entry");
6e81b270 119}
edc032b5 120
ecf3a1fb 121static void print_user(CA_DB *db, int userindex, int verbose)
6e81b270
AP
122{
123 if (verbose > 0) {
124 char **pp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
edc032b5 125
6e81b270 126 if (pp[DB_srptype][0] != 'I') {
ecf3a1fb
RS
127 print_entry(db, userindex, verbose, "User entry");
128 print_entry(db, get_index(db, pp[DB_srpgN], 'I'), verbose,
6e81b270
AP
129 "g N entry");
130 }
edc032b5 131
6e81b270
AP
132 }
133}
edc032b5 134
ecf3a1fb 135static int update_index(CA_DB *db, char **row)
6e81b270
AP
136{
137 char **irow;
138 int i;
139
b4faea50 140 irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");
6e81b270
AP
141 for (i = 0; i < DB_NUMBER; i++) {
142 irow[i] = row[i];
143 row[i] = NULL;
144 }
145 irow[DB_NUMBER] = NULL;
146
147 if (!TXT_DB_insert(db->db, irow)) {
ecf3a1fb
RS
148 BIO_printf(bio_err, "failed to update srpvfile\n");
149 BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
6e81b270
AP
150 OPENSSL_free(irow);
151 return 0;
152 }
153 return 1;
154}
edc032b5
BL
155
156static void lookup_fail(const char *name, const char *tag)
6e81b270
AP
157{
158 BIO_printf(bio_err, "variable lookup failed for %s::%s\n", name, tag);
159}
edc032b5
BL
160
161static char *srp_verify_user(const char *user, const char *srp_verifier,
6e81b270 162 char *srp_usersalt, const char *g, const char *N,
ecf3a1fb 163 const char *passin, int verbose)
6e81b270
AP
164{
165 char password[1024];
166 PW_CB_DATA cb_tmp;
167 char *verifier = NULL;
168 char *gNid = NULL;
169
170 cb_tmp.prompt_info = user;
171 cb_tmp.password = passin;
172
173 if (password_callback(password, 1024, 0, &cb_tmp) > 0) {
7e1b7485 174 if (verbose)
ecf3a1fb 175 BIO_printf(bio_err,
7e1b7485
RS
176 "Validating\n user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
177 user, srp_verifier, srp_usersalt, g, N);
ecf3a1fb 178 BIO_printf(bio_err, "Pass %s\n", password);
6e81b270
AP
179
180 OPENSSL_assert(srp_usersalt != NULL);
7e1b7485
RS
181 if (!
182 (gNid =
183 SRP_create_verifier(user, password, &srp_usersalt, &verifier, N,
184 g))) {
ecf3a1fb 185 BIO_printf(bio_err, "Internal error validating SRP verifier\n");
6e81b270
AP
186 } else {
187 if (strcmp(verifier, srp_verifier))
188 gNid = NULL;
189 OPENSSL_free(verifier);
190 }
191 }
192 return gNid;
193}
edc032b5 194
71fa4513 195static char *srp_create_user(char *user, char **srp_verifier,
6e81b270 196 char **srp_usersalt, char *g, char *N,
ecf3a1fb 197 char *passout, int verbose)
6e81b270
AP
198{
199 char password[1024];
200 PW_CB_DATA cb_tmp;
201 char *gNid = NULL;
202 char *salt = NULL;
203 cb_tmp.prompt_info = user;
204 cb_tmp.password = passout;
205
206 if (password_callback(password, 1024, 1, &cb_tmp) > 0) {
7e1b7485 207 if (verbose)
ecf3a1fb 208 BIO_printf(bio_err, "Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
7e1b7485
RS
209 user, g, N);
210 if (!
211 (gNid =
212 SRP_create_verifier(user, password, &salt, srp_verifier, N,
213 g))) {
ecf3a1fb 214 BIO_printf(bio_err, "Internal error creating SRP verifier\n");
6e81b270
AP
215 } else
216 *srp_usersalt = salt;
7e1b7485 217 if (verbose > 1)
ecf3a1fb 218 BIO_printf(bio_err, "gNid=%s salt =\"%s\"\n verifier =\"%s\"\n", gNid,
7e1b7485 219 salt, *srp_verifier);
6e81b270
AP
220
221 }
222 return gNid;
223}
edc032b5 224
7e1b7485
RS
225typedef enum OPTION_choice {
226 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
227 OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SRPVFILE, OPT_ADD,
228 OPT_DELETE, OPT_MODIFY, OPT_LIST, OPT_GN, OPT_USERINFO,
229 OPT_PASSIN, OPT_PASSOUT, OPT_ENGINE
230} OPTION_CHOICE;
231
232OPTIONS srp_options[] = {
233 {"help", OPT_HELP, '-', "Display this summary"},
234 {"verbose", OPT_VERBOSE, '-', "Talk a lot while doing things"},
235 {"config", OPT_CONFIG, '<', "A config file"},
236 {"name", OPT_NAME, 's', "The particular srp definition to use"},
237 {"srpvfile", OPT_SRPVFILE, '<', "The srp verifier file name"},
238 {"add", OPT_ADD, '-', "Add a user and srp verifier"},
239 {"modify", OPT_MODIFY, '-',
240 "Modify the srp verifier of an existing user"},
241 {"delete", OPT_DELETE, '-', "Delete user from verifier file"},
242 {"list", OPT_LIST, '-', "List users"},
243 {"gn", OPT_GN, 's', "Set g and N values to be used for new verifier"},
244 {"userinfo", OPT_USERINFO, 's', "Additional info to be set for user"},
245 {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
246 {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
6e81b270 247# ifndef OPENSSL_NO_ENGINE
7e1b7485 248 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
6e81b270 249# endif
7e1b7485
RS
250 {NULL}
251};
252
253int srp_main(int argc, char **argv)
254{
255 CA_DB *db = NULL;
6e81b270 256 DB_ATTR db_attr;
7e1b7485 257 CONF *conf = NULL;
cc01d217
RS
258 int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose = 0, i;
259 int doupdatedb = 0, mode = OPT_ERR;
7e1b7485
RS
260 char *user = NULL, *passinarg = NULL, *passoutarg = NULL;
261 char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;
333b070e 262 char *randfile = NULL, *tofree = NULL, *section = NULL;
cc01d217
RS
263 char **gNrow = NULL, *configfile = default_config_file;
264 char *dbfile = NULL, **pp, *prog;
7e1b7485 265 OPTION_CHOICE o;
6e81b270 266
7e1b7485
RS
267 prog = opt_init(argc, argv, srp_options);
268 while ((o = opt_next()) != OPT_EOF) {
269 switch (o) {
270 case OPT_EOF:
271 case OPT_ERR:
272 opthelp:
273 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
274 goto end;
275 case OPT_HELP:
276 opt_help(srp_options);
277 ret = 0;
278 goto end;
279 case OPT_VERBOSE:
6e81b270 280 verbose++;
6e81b270 281 break;
7e1b7485
RS
282 case OPT_CONFIG:
283 configfile = opt_arg();
6e81b270 284 break;
7e1b7485
RS
285 case OPT_NAME:
286 section = opt_arg();
287 break;
288 case OPT_SRPVFILE:
289 dbfile = opt_arg();
290 break;
291 case OPT_ADD:
292 case OPT_DELETE:
293 case OPT_MODIFY:
294 case OPT_LIST:
295 if (mode != OPT_ERR) {
296 BIO_printf(bio_err,
297 "%s: Only one of -add/delete-modify/-list\n",
298 prog);
299 goto opthelp;
300 }
301 mode = o;
302 break;
303 case OPT_GN:
304 gN = opt_arg();
305 break;
306 case OPT_USERINFO:
307 userinfo = opt_arg();
308 break;
309 case OPT_PASSIN:
310 passinarg = opt_arg();
311 break;
312 case OPT_PASSOUT:
313 passoutarg = opt_arg();
314 break;
315 case OPT_ENGINE:
333b070e 316 (void)setup_engine(opt_arg(), 0);
7e1b7485
RS
317 break;
318 }
6e81b270 319 }
7e1b7485
RS
320 argc = opt_num_rest();
321 argv = opt_rest();
6e81b270
AP
322
323 if (dbfile && configfile) {
324 BIO_printf(bio_err,
325 "-dbfile and -configfile cannot be specified together.\n");
7e1b7485 326 goto end;
6e81b270 327 }
7e1b7485
RS
328 if (mode == OPT_ERR) {
329 BIO_printf(bio_err,
330 "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
331 goto opthelp;
6e81b270 332 }
5a80d9fb
RS
333 if ((mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD)
334 && argc < 1) {
7e1b7485
RS
335 BIO_printf(bio_err,
336 "Need at least one user for options -add, -delete, -modify. \n");
337 goto opthelp;
6e81b270
AP
338 }
339 if ((passin || passout) && argc != 1) {
340 BIO_printf(bio_err,
341 "-passin, -passout arguments only valid with one user.\n");
7e1b7485 342 goto opthelp;
6e81b270 343 }
6e81b270 344
7e1b7485 345 if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
6e81b270 346 BIO_printf(bio_err, "Error getting passwords\n");
7e1b7485 347 goto end;
6e81b270
AP
348 }
349
350 if (!dbfile) {
7e1b7485 351 if (verbose)
cc01d217
RS
352 BIO_printf(bio_err, "Using configuration from %s\n",
353 configfile);
354 conf = app_load_config(configfile);
355 if (conf == NULL)
7e1b7485 356 goto end;
296f54ee
RL
357 if (!app_load_modules(conf))
358 goto end;
6e81b270 359
6e81b270
AP
360 /* Lets get the config section we are using */
361 if (section == NULL) {
7e1b7485
RS
362 if (verbose)
363 BIO_printf(bio_err,
364 "trying to read " ENV_DEFAULT_SRP
365 " in \" BASE_SECTION \"\n");
6e81b270
AP
366
367 section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_SRP);
368 if (section == NULL) {
369 lookup_fail(BASE_SECTION, ENV_DEFAULT_SRP);
7e1b7485 370 goto end;
6e81b270
AP
371 }
372 }
373
374 if (randfile == NULL && conf)
375 randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");
376
7e1b7485
RS
377 if (verbose)
378 BIO_printf(bio_err,
379 "trying to read " ENV_DATABASE " in section \"%s\"\n",
380 section);
6e81b270
AP
381
382 if ((dbfile = NCONF_get_string(conf, section, ENV_DATABASE)) == NULL) {
383 lookup_fail(section, ENV_DATABASE);
7e1b7485 384 goto end;
6e81b270
AP
385 }
386
387 }
388 if (randfile == NULL)
389 ERR_clear_error();
390 else
7e1b7485 391 app_RAND_load_file(randfile, 0);
6e81b270 392
7e1b7485
RS
393 if (verbose)
394 BIO_printf(bio_err, "Trying to read SRP verifier file \"%s\"\n",
395 dbfile);
6e81b270
AP
396
397 db = load_index(dbfile, &db_attr);
398 if (db == NULL)
7e1b7485 399 goto end;
6e81b270
AP
400
401 /* Lets check some fields */
402 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
403 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
404
405 if (pp[DB_srptype][0] == DB_SRP_INDEX) {
406 maxgN = i;
86885c28 407 if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)
6e81b270
AP
408 gNindex = i;
409
ecf3a1fb 410 print_index(db, i, verbose > 1);
6e81b270
AP
411 }
412 }
413
7e1b7485
RS
414 if (verbose)
415 BIO_printf(bio_err, "Database initialised\n");
6e81b270
AP
416
417 if (gNindex >= 0) {
418 gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);
ecf3a1fb 419 print_entry(db, gNindex, verbose > 1, "Default g and N");
6e81b270
AP
420 } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {
421 BIO_printf(bio_err, "No g and N value for index \"%s\"\n", gN);
7e1b7485 422 goto end;
6e81b270 423 } else {
7e1b7485
RS
424 if (verbose)
425 BIO_printf(bio_err, "Database has no g N information.\n");
6e81b270
AP
426 gNrow = NULL;
427 }
428
7e1b7485
RS
429 if (verbose > 1)
430 BIO_printf(bio_err, "Starting user processing\n");
6e81b270
AP
431
432 if (argc > 0)
433 user = *(argv++);
434
7e1b7485 435 while (mode == OPT_LIST || user) {
6e81b270
AP
436 int userindex = -1;
437 if (user)
7e1b7485
RS
438 if (verbose > 1)
439 BIO_printf(bio_err, "Processing user \"%s\"\n", user);
6e81b270 440 if ((userindex = get_index(db, user, 'U')) >= 0) {
ecf3a1fb 441 print_user(db, userindex, (verbose > 0)
7e1b7485 442 || mode == OPT_LIST);
6e81b270
AP
443 }
444
7e1b7485 445 if (mode == OPT_LIST) {
6e81b270
AP
446 if (user == NULL) {
447 BIO_printf(bio_err, "List all users\n");
448
449 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
ecf3a1fb 450 print_user(db, i, 1);
6e81b270 451 }
6e81b270
AP
452 } else if (userindex < 0) {
453 BIO_printf(bio_err,
454 "user \"%s\" does not exist, ignored. t\n", user);
455 errors++;
456 }
7e1b7485 457 } else if (mode == OPT_ADD) {
6e81b270
AP
458 if (userindex >= 0) {
459 /* reactivation of a new user */
460 char **row =
461 sk_OPENSSL_PSTRING_value(db->db->data, userindex);
462 BIO_printf(bio_err, "user \"%s\" reactivated.\n", user);
463 row[DB_srptype][0] = 'V';
464
465 doupdatedb = 1;
466 } else {
467 char *row[DB_NUMBER];
468 char *gNid;
469 row[DB_srpverifier] = NULL;
470 row[DB_srpsalt] = NULL;
471 row[DB_srpinfo] = NULL;
7e1b7485
RS
472 if (!
473 (gNid =
474 srp_create_user(user, &(row[DB_srpverifier]),
475 &(row[DB_srpsalt]),
476 gNrow ? gNrow[DB_srpsalt] : gN,
477 gNrow ? gNrow[DB_srpverifier] : NULL,
ecf3a1fb 478 passout, verbose))) {
6e81b270 479 BIO_printf(bio_err,
7e1b7485
RS
480 "Cannot create srp verifier for user \"%s\", operation abandoned .\n",
481 user);
6e81b270 482 errors++;
7e1b7485 483 goto end;
6e81b270
AP
484 }
485 row[DB_srpid] = BUF_strdup(user);
486 row[DB_srptype] = BUF_strdup("v");
487 row[DB_srpgN] = BUF_strdup(gNid);
488
75ebbd9a
RS
489 if ((row[DB_srpid] == NULL)
490 || (row[DB_srpgN] == NULL)
491 || (row[DB_srptype] == NULL)
492 || (row[DB_srpverifier] == NULL)
493 || (row[DB_srpsalt] == NULL)
494 || (userinfo
495 && ((row[DB_srpinfo] = BUF_strdup(userinfo)) == NULL))
ecf3a1fb 496 || !update_index(db, row)) {
b548a1f1
RS
497 OPENSSL_free(row[DB_srpid]);
498 OPENSSL_free(row[DB_srpgN]);
499 OPENSSL_free(row[DB_srpinfo]);
500 OPENSSL_free(row[DB_srptype]);
501 OPENSSL_free(row[DB_srpverifier]);
502 OPENSSL_free(row[DB_srpsalt]);
7e1b7485 503 goto end;
6e81b270
AP
504 }
505 doupdatedb = 1;
506 }
7e1b7485 507 } else if (mode == OPT_MODIFY) {
6e81b270
AP
508 if (userindex < 0) {
509 BIO_printf(bio_err,
510 "user \"%s\" does not exist, operation ignored.\n",
511 user);
512 errors++;
513 } else {
514
515 char **row =
516 sk_OPENSSL_PSTRING_value(db->db->data, userindex);
517 char type = row[DB_srptype][0];
518 if (type == 'v') {
519 BIO_printf(bio_err,
520 "user \"%s\" already updated, operation ignored.\n",
521 user);
522 errors++;
523 } else {
524 char *gNid;
525
526 if (row[DB_srptype][0] == 'V') {
527 int user_gN;
528 char **irow = NULL;
7e1b7485
RS
529 if (verbose)
530 BIO_printf(bio_err,
531 "Verifying password for user \"%s\"\n",
532 user);
6e81b270
AP
533 if ((user_gN =
534 get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)
535 irow =
536 sk_OPENSSL_PSTRING_value(db->db->data,
537 userindex);
538
539 if (!srp_verify_user
540 (user, row[DB_srpverifier], row[DB_srpsalt],
541 irow ? irow[DB_srpsalt] : row[DB_srpgN],
542 irow ? irow[DB_srpverifier] : NULL, passin,
ecf3a1fb 543 verbose)) {
6e81b270
AP
544 BIO_printf(bio_err,
545 "Invalid password for user \"%s\", operation abandoned.\n",
546 user);
547 errors++;
7e1b7485 548 goto end;
6e81b270
AP
549 }
550 }
7e1b7485
RS
551 if (verbose)
552 BIO_printf(bio_err, "Password for user \"%s\" ok.\n",
553 user);
554
555 if (!
556 (gNid =
557 srp_create_user(user, &(row[DB_srpverifier]),
558 &(row[DB_srpsalt]),
559 gNrow ? gNrow[DB_srpsalt] : NULL,
560 gNrow ? gNrow[DB_srpverifier] : NULL,
ecf3a1fb 561 passout, verbose))) {
6e81b270 562 BIO_printf(bio_err,
7e1b7485
RS
563 "Cannot create srp verifier for user \"%s\", operation abandoned.\n",
564 user);
6e81b270 565 errors++;
7e1b7485 566 goto end;
6e81b270
AP
567 }
568
569 row[DB_srptype][0] = 'v';
570 row[DB_srpgN] = BUF_strdup(gNid);
571
75ebbd9a
RS
572 if (row[DB_srpid] == NULL
573 || row[DB_srpgN] == NULL
574 || row[DB_srptype] == NULL
575 || row[DB_srpverifier] == NULL
576 || row[DB_srpsalt] == NULL
6e81b270 577 || (userinfo
75ebbd9a
RS
578 && ((row[DB_srpinfo] = BUF_strdup(userinfo))
579 == NULL)))
7e1b7485 580 goto end;
6e81b270
AP
581
582 doupdatedb = 1;
583 }
584 }
7e1b7485 585 } else if (mode == OPT_DELETE) {
6e81b270
AP
586 if (userindex < 0) {
587 BIO_printf(bio_err,
588 "user \"%s\" does not exist, operation ignored. t\n",
589 user);
590 errors++;
591 } else {
75ebbd9a 592 char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
6e81b270 593
75ebbd9a 594 BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
6e81b270 595 xpp[DB_srptype][0] = 'R';
6e81b270
AP
596 doupdatedb = 1;
597 }
598 }
599 if (--argc > 0)
600 user = *(argv++);
601 else {
602 user = NULL;
6e81b270
AP
603 }
604 }
605
7e1b7485
RS
606 if (verbose)
607 BIO_printf(bio_err, "User procession done.\n");
6e81b270
AP
608
609 if (doupdatedb) {
610 /* Lets check some fields */
611 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
612 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
613
614 if (pp[DB_srptype][0] == 'v') {
615 pp[DB_srptype][0] = 'V';
ecf3a1fb 616 print_user(db, i, verbose);
6e81b270
AP
617 }
618 }
619
7e1b7485
RS
620 if (verbose)
621 BIO_printf(bio_err, "Trying to update srpvfile.\n");
6e81b270 622 if (!save_index(dbfile, "new", db))
7e1b7485 623 goto end;
6e81b270 624
7e1b7485
RS
625 if (verbose)
626 BIO_printf(bio_err, "Temporary srpvfile created.\n");
6e81b270 627 if (!rotate_index(dbfile, "new", "old"))
7e1b7485 628 goto end;
6e81b270 629
7e1b7485
RS
630 if (verbose)
631 BIO_printf(bio_err, "srpvfile updated.\n");
6e81b270
AP
632 }
633
634 ret = (errors != 0);
7e1b7485 635 end:
6e81b270 636 if (errors != 0)
7e1b7485
RS
637 if (verbose)
638 BIO_printf(bio_err, "User errors %d.\n", errors);
6e81b270 639
7e1b7485
RS
640 if (verbose)
641 BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
b548a1f1 642 OPENSSL_free(tofree);
6e81b270
AP
643 if (ret)
644 ERR_print_errors(bio_err);
645 if (randfile)
7e1b7485 646 app_RAND_write_file(randfile);
25aaa98a
RS
647 NCONF_free(conf);
648 free_index(db);
6e81b270 649 OBJ_cleanup();
7e1b7485 650 return (ret);
6e81b270 651}
edc032b5 652
857048a7
RS
653#else
654
655# if PEDANTIC
656static void *dummy = &dummy;
657# endif
658
edc032b5 659#endif