1ebfedea0SLionel Sambuc /* apps/srp.c */
2*0a6a1f1dSLionel Sambuc /*
3*0a6a1f1dSLionel Sambuc * Written by Peter Sylvester (peter.sylvester@edelweb.fr) for the EdelKey
4*0a6a1f1dSLionel Sambuc * project and contributed to the OpenSSL project 2004.
5ebfedea0SLionel Sambuc */
6ebfedea0SLionel Sambuc /* ====================================================================
7ebfedea0SLionel Sambuc * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
8ebfedea0SLionel Sambuc *
9ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
10ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
11ebfedea0SLionel Sambuc * are met:
12ebfedea0SLionel Sambuc *
13ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
14ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
15ebfedea0SLionel Sambuc *
16ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
17ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in
18ebfedea0SLionel Sambuc * the documentation and/or other materials provided with the
19ebfedea0SLionel Sambuc * distribution.
20ebfedea0SLionel Sambuc *
21ebfedea0SLionel Sambuc * 3. All advertising materials mentioning features or use of this
22ebfedea0SLionel Sambuc * software must display the following acknowledgment:
23ebfedea0SLionel Sambuc * "This product includes software developed by the OpenSSL Project
24ebfedea0SLionel Sambuc * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25ebfedea0SLionel Sambuc *
26ebfedea0SLionel Sambuc * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27ebfedea0SLionel Sambuc * endorse or promote products derived from this software without
28ebfedea0SLionel Sambuc * prior written permission. For written permission, please contact
29ebfedea0SLionel Sambuc * licensing@OpenSSL.org.
30ebfedea0SLionel Sambuc *
31ebfedea0SLionel Sambuc * 5. Products derived from this software may not be called "OpenSSL"
32ebfedea0SLionel Sambuc * nor may "OpenSSL" appear in their names without prior written
33ebfedea0SLionel Sambuc * permission of the OpenSSL Project.
34ebfedea0SLionel Sambuc *
35ebfedea0SLionel Sambuc * 6. Redistributions of any form whatsoever must retain the following
36ebfedea0SLionel Sambuc * acknowledgment:
37ebfedea0SLionel Sambuc * "This product includes software developed by the OpenSSL Project
38ebfedea0SLionel Sambuc * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39ebfedea0SLionel Sambuc *
40ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41ebfedea0SLionel Sambuc * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43ebfedea0SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44ebfedea0SLionel Sambuc * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45ebfedea0SLionel Sambuc * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46ebfedea0SLionel Sambuc * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47ebfedea0SLionel Sambuc * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49ebfedea0SLionel Sambuc * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50ebfedea0SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51ebfedea0SLionel Sambuc * OF THE POSSIBILITY OF SUCH DAMAGE.
52ebfedea0SLionel Sambuc * ====================================================================
53ebfedea0SLionel Sambuc *
54ebfedea0SLionel Sambuc * This product includes cryptographic software written by Eric Young
55ebfedea0SLionel Sambuc * (eay@cryptsoft.com). This product includes software written by Tim
56ebfedea0SLionel Sambuc * Hudson (tjh@cryptsoft.com).
57ebfedea0SLionel Sambuc *
58ebfedea0SLionel Sambuc */
59ebfedea0SLionel Sambuc #include <openssl/opensslconf.h>
60ebfedea0SLionel Sambuc
61ebfedea0SLionel Sambuc #ifndef OPENSSL_NO_SRP
62ebfedea0SLionel Sambuc # include <stdio.h>
63ebfedea0SLionel Sambuc # include <stdlib.h>
64ebfedea0SLionel Sambuc # include <string.h>
65ebfedea0SLionel Sambuc # include <openssl/conf.h>
66ebfedea0SLionel Sambuc # include <openssl/bio.h>
67ebfedea0SLionel Sambuc # include <openssl/err.h>
68ebfedea0SLionel Sambuc # include <openssl/txt_db.h>
69ebfedea0SLionel Sambuc # include <openssl/buffer.h>
70ebfedea0SLionel Sambuc # include <openssl/srp.h>
71ebfedea0SLionel Sambuc
72ebfedea0SLionel Sambuc # include "apps.h"
73ebfedea0SLionel Sambuc
74ebfedea0SLionel Sambuc # undef PROG
75ebfedea0SLionel Sambuc # define PROG srp_main
76ebfedea0SLionel Sambuc
77ebfedea0SLionel Sambuc # define BASE_SECTION "srp"
78ebfedea0SLionel Sambuc # define CONFIG_FILE "openssl.cnf"
79ebfedea0SLionel Sambuc
80ebfedea0SLionel Sambuc # define ENV_RANDFILE "RANDFILE"
81ebfedea0SLionel Sambuc
82ebfedea0SLionel Sambuc # define ENV_DATABASE "srpvfile"
83ebfedea0SLionel Sambuc # define ENV_DEFAULT_SRP "default_srp"
84ebfedea0SLionel Sambuc
85ebfedea0SLionel Sambuc static char *srp_usage[] = {
86ebfedea0SLionel Sambuc "usage: srp [args] [user] \n",
87ebfedea0SLionel Sambuc "\n",
88ebfedea0SLionel Sambuc " -verbose Talk alot while doing things\n",
89ebfedea0SLionel Sambuc " -config file A config file\n",
90ebfedea0SLionel Sambuc " -name arg The particular srp definition to use\n",
91ebfedea0SLionel Sambuc " -srpvfile arg The srp verifier file name\n",
92ebfedea0SLionel Sambuc " -add add an user and srp verifier\n",
93ebfedea0SLionel Sambuc " -modify modify the srp verifier of an existing user\n",
94ebfedea0SLionel Sambuc " -delete delete user from verifier file\n",
95ebfedea0SLionel Sambuc " -list list user\n",
96ebfedea0SLionel Sambuc " -gn arg g and N values to be used for new verifier\n",
97ebfedea0SLionel Sambuc " -userinfo arg additional info to be set for user\n",
98ebfedea0SLionel Sambuc " -passin arg input file pass phrase source\n",
99ebfedea0SLionel Sambuc " -passout arg output file pass phrase source\n",
100ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
101ebfedea0SLionel Sambuc " -engine e - use engine e, possibly a hardware device.\n",
102ebfedea0SLionel Sambuc # endif
103ebfedea0SLionel Sambuc NULL
104ebfedea0SLionel Sambuc };
105ebfedea0SLionel Sambuc
106ebfedea0SLionel Sambuc # ifdef EFENCE
107ebfedea0SLionel Sambuc extern int EF_PROTECT_FREE;
108ebfedea0SLionel Sambuc extern int EF_PROTECT_BELOW;
109ebfedea0SLionel Sambuc extern int EF_ALIGNMENT;
110ebfedea0SLionel Sambuc # endif
111ebfedea0SLionel Sambuc
112ebfedea0SLionel Sambuc static CONF *conf = NULL;
113ebfedea0SLionel Sambuc static char *section = NULL;
114ebfedea0SLionel Sambuc
115ebfedea0SLionel Sambuc # define VERBOSE if (verbose)
116ebfedea0SLionel Sambuc # define VVERBOSE if (verbose>1)
117ebfedea0SLionel Sambuc
118ebfedea0SLionel Sambuc int MAIN(int, char **);
119ebfedea0SLionel Sambuc
get_index(CA_DB * db,char * id,char type)120ebfedea0SLionel Sambuc static int get_index(CA_DB *db, char *id, char type)
121ebfedea0SLionel Sambuc {
122ebfedea0SLionel Sambuc char **pp;
123ebfedea0SLionel Sambuc int i;
124*0a6a1f1dSLionel Sambuc if (id == NULL)
125*0a6a1f1dSLionel Sambuc return -1;
126ebfedea0SLionel Sambuc if (type == DB_SRP_INDEX)
127*0a6a1f1dSLionel Sambuc for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
128ebfedea0SLionel Sambuc pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
129*0a6a1f1dSLionel Sambuc if (pp[DB_srptype][0] == DB_SRP_INDEX
130*0a6a1f1dSLionel Sambuc && !strcmp(id, pp[DB_srpid]))
131ebfedea0SLionel Sambuc return i;
132*0a6a1f1dSLionel Sambuc } else
133*0a6a1f1dSLionel Sambuc for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
134ebfedea0SLionel Sambuc pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
135ebfedea0SLionel Sambuc
136*0a6a1f1dSLionel Sambuc if (pp[DB_srptype][0] != DB_SRP_INDEX
137*0a6a1f1dSLionel Sambuc && !strcmp(id, pp[DB_srpid]))
138ebfedea0SLionel Sambuc return i;
139ebfedea0SLionel Sambuc }
140ebfedea0SLionel Sambuc
141ebfedea0SLionel Sambuc return -1;
142ebfedea0SLionel Sambuc }
143ebfedea0SLionel Sambuc
print_entry(CA_DB * db,BIO * bio,int indx,int verbose,char * s)144ebfedea0SLionel Sambuc static void print_entry(CA_DB *db, BIO *bio, int indx, int verbose, char *s)
145ebfedea0SLionel Sambuc {
146*0a6a1f1dSLionel Sambuc if (indx >= 0 && verbose) {
147ebfedea0SLionel Sambuc int j;
148ebfedea0SLionel Sambuc char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
149ebfedea0SLionel Sambuc BIO_printf(bio, "%s \"%s\"\n", s, pp[DB_srpid]);
150*0a6a1f1dSLionel Sambuc for (j = 0; j < DB_NUMBER; j++) {
151ebfedea0SLionel Sambuc BIO_printf(bio_err, " %d = \"%s\"\n", j, pp[j]);
152ebfedea0SLionel Sambuc }
153ebfedea0SLionel Sambuc }
154ebfedea0SLionel Sambuc }
155ebfedea0SLionel Sambuc
print_index(CA_DB * db,BIO * bio,int indexindex,int verbose)156ebfedea0SLionel Sambuc static void print_index(CA_DB *db, BIO *bio, int indexindex, int verbose)
157ebfedea0SLionel Sambuc {
158ebfedea0SLionel Sambuc print_entry(db, bio, indexindex, verbose, "g N entry");
159ebfedea0SLionel Sambuc }
160ebfedea0SLionel Sambuc
print_user(CA_DB * db,BIO * bio,int userindex,int verbose)161ebfedea0SLionel Sambuc static void print_user(CA_DB *db, BIO *bio, int userindex, int verbose)
162ebfedea0SLionel Sambuc {
163*0a6a1f1dSLionel Sambuc if (verbose > 0) {
164ebfedea0SLionel Sambuc char **pp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
165ebfedea0SLionel Sambuc
166*0a6a1f1dSLionel Sambuc if (pp[DB_srptype][0] != 'I') {
167ebfedea0SLionel Sambuc print_entry(db, bio, userindex, verbose, "User entry");
168*0a6a1f1dSLionel Sambuc print_entry(db, bio, get_index(db, pp[DB_srpgN], 'I'), verbose,
169*0a6a1f1dSLionel Sambuc "g N entry");
170ebfedea0SLionel Sambuc }
171ebfedea0SLionel Sambuc
172ebfedea0SLionel Sambuc }
173ebfedea0SLionel Sambuc }
174ebfedea0SLionel Sambuc
update_index(CA_DB * db,BIO * bio,char ** row)175ebfedea0SLionel Sambuc static int update_index(CA_DB *db, BIO *bio, char **row)
176ebfedea0SLionel Sambuc {
177ebfedea0SLionel Sambuc char **irow;
178ebfedea0SLionel Sambuc int i;
179ebfedea0SLionel Sambuc
180*0a6a1f1dSLionel Sambuc if ((irow =
181*0a6a1f1dSLionel Sambuc (char **)OPENSSL_malloc(sizeof(char *) * (DB_NUMBER + 1))) == NULL) {
182ebfedea0SLionel Sambuc BIO_printf(bio_err, "Memory allocation failure\n");
183ebfedea0SLionel Sambuc return 0;
184ebfedea0SLionel Sambuc }
185ebfedea0SLionel Sambuc
186*0a6a1f1dSLionel Sambuc for (i = 0; i < DB_NUMBER; i++) {
187ebfedea0SLionel Sambuc irow[i] = row[i];
188ebfedea0SLionel Sambuc row[i] = NULL;
189ebfedea0SLionel Sambuc }
190ebfedea0SLionel Sambuc irow[DB_NUMBER] = NULL;
191ebfedea0SLionel Sambuc
192*0a6a1f1dSLionel Sambuc if (!TXT_DB_insert(db->db, irow)) {
193ebfedea0SLionel Sambuc BIO_printf(bio, "failed to update srpvfile\n");
194ebfedea0SLionel Sambuc BIO_printf(bio, "TXT_DB error number %ld\n", db->db->error);
195ebfedea0SLionel Sambuc OPENSSL_free(irow);
196ebfedea0SLionel Sambuc return 0;
197ebfedea0SLionel Sambuc }
198ebfedea0SLionel Sambuc return 1;
199ebfedea0SLionel Sambuc }
200ebfedea0SLionel Sambuc
lookup_fail(const char * name,char * tag)201ebfedea0SLionel Sambuc static void lookup_fail(const char *name, char *tag)
202ebfedea0SLionel Sambuc {
203ebfedea0SLionel Sambuc BIO_printf(bio_err, "variable lookup failed for %s::%s\n", name, tag);
204ebfedea0SLionel Sambuc }
205ebfedea0SLionel Sambuc
srp_verify_user(const char * user,const char * srp_verifier,char * srp_usersalt,const char * g,const char * N,const char * passin,BIO * bio,int verbose)206ebfedea0SLionel Sambuc static char *srp_verify_user(const char *user, const char *srp_verifier,
207ebfedea0SLionel Sambuc char *srp_usersalt, const char *g, const char *N,
208ebfedea0SLionel Sambuc const char *passin, BIO *bio, int verbose)
209ebfedea0SLionel Sambuc {
210ebfedea0SLionel Sambuc char password[1024];
211ebfedea0SLionel Sambuc PW_CB_DATA cb_tmp;
212ebfedea0SLionel Sambuc char *verifier = NULL;
213ebfedea0SLionel Sambuc char *gNid = NULL;
214ebfedea0SLionel Sambuc
215ebfedea0SLionel Sambuc cb_tmp.prompt_info = user;
216ebfedea0SLionel Sambuc cb_tmp.password = passin;
217ebfedea0SLionel Sambuc
218*0a6a1f1dSLionel Sambuc if (password_callback(password, 1024, 0, &cb_tmp) > 0) {
219*0a6a1f1dSLionel Sambuc VERBOSE BIO_printf(bio,
220*0a6a1f1dSLionel Sambuc "Validating\n user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
221*0a6a1f1dSLionel Sambuc user, srp_verifier, srp_usersalt, g, N);
222ebfedea0SLionel Sambuc BIO_printf(bio, "Pass %s\n", password);
223ebfedea0SLionel Sambuc
224*0a6a1f1dSLionel Sambuc if (!
225*0a6a1f1dSLionel Sambuc (gNid =
226*0a6a1f1dSLionel Sambuc SRP_create_verifier(user, password, &srp_usersalt, &verifier, N,
227*0a6a1f1dSLionel Sambuc g))) {
228ebfedea0SLionel Sambuc BIO_printf(bio, "Internal error validating SRP verifier\n");
229*0a6a1f1dSLionel Sambuc } else {
230ebfedea0SLionel Sambuc if (strcmp(verifier, srp_verifier))
231ebfedea0SLionel Sambuc gNid = NULL;
232ebfedea0SLionel Sambuc OPENSSL_free(verifier);
233ebfedea0SLionel Sambuc }
234ebfedea0SLionel Sambuc }
235ebfedea0SLionel Sambuc return gNid;
236ebfedea0SLionel Sambuc }
237ebfedea0SLionel Sambuc
srp_create_user(char * user,char ** srp_verifier,char ** srp_usersalt,char * g,char * N,char * passout,BIO * bio,int verbose)238ebfedea0SLionel Sambuc static char *srp_create_user(char *user, char **srp_verifier,
239ebfedea0SLionel Sambuc char **srp_usersalt, char *g, char *N,
240ebfedea0SLionel Sambuc char *passout, BIO *bio, int verbose)
241ebfedea0SLionel Sambuc {
242ebfedea0SLionel Sambuc char password[1024];
243ebfedea0SLionel Sambuc PW_CB_DATA cb_tmp;
244ebfedea0SLionel Sambuc char *gNid = NULL;
245ebfedea0SLionel Sambuc char *salt = NULL;
246ebfedea0SLionel Sambuc cb_tmp.prompt_info = user;
247ebfedea0SLionel Sambuc cb_tmp.password = passout;
248ebfedea0SLionel Sambuc
249*0a6a1f1dSLionel Sambuc if (password_callback(password, 1024, 1, &cb_tmp) > 0) {
250*0a6a1f1dSLionel Sambuc VERBOSE BIO_printf(bio,
251*0a6a1f1dSLionel Sambuc "Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
252*0a6a1f1dSLionel Sambuc user, g, N);
253*0a6a1f1dSLionel Sambuc if (!
254*0a6a1f1dSLionel Sambuc (gNid =
255*0a6a1f1dSLionel Sambuc SRP_create_verifier(user, password, &salt, srp_verifier, N,
256*0a6a1f1dSLionel Sambuc g))) {
257ebfedea0SLionel Sambuc BIO_printf(bio, "Internal error creating SRP verifier\n");
258*0a6a1f1dSLionel Sambuc } else
259ebfedea0SLionel Sambuc *srp_usersalt = salt;
260*0a6a1f1dSLionel Sambuc VVERBOSE BIO_printf(bio, "gNid=%s salt =\"%s\"\n verifier =\"%s\"\n",
261*0a6a1f1dSLionel Sambuc gNid, salt, *srp_verifier);
262ebfedea0SLionel Sambuc
263ebfedea0SLionel Sambuc }
264ebfedea0SLionel Sambuc return gNid;
265ebfedea0SLionel Sambuc }
266ebfedea0SLionel Sambuc
MAIN(int argc,char ** argv)267ebfedea0SLionel Sambuc int MAIN(int argc, char **argv)
268ebfedea0SLionel Sambuc {
269ebfedea0SLionel Sambuc int add_user = 0;
270ebfedea0SLionel Sambuc int list_user = 0;
271ebfedea0SLionel Sambuc int delete_user = 0;
272ebfedea0SLionel Sambuc int modify_user = 0;
273ebfedea0SLionel Sambuc char *user = NULL;
274ebfedea0SLionel Sambuc
275ebfedea0SLionel Sambuc char *passargin = NULL, *passargout = NULL;
276ebfedea0SLionel Sambuc char *passin = NULL, *passout = NULL;
277ebfedea0SLionel Sambuc char *gN = NULL;
278ebfedea0SLionel Sambuc int gNindex = -1;
279ebfedea0SLionel Sambuc char **gNrow = NULL;
280ebfedea0SLionel Sambuc int maxgN = -1;
281ebfedea0SLionel Sambuc
282ebfedea0SLionel Sambuc char *userinfo = NULL;
283ebfedea0SLionel Sambuc
284ebfedea0SLionel Sambuc int badops = 0;
285ebfedea0SLionel Sambuc int ret = 1;
286ebfedea0SLionel Sambuc int errors = 0;
287ebfedea0SLionel Sambuc int verbose = 0;
288ebfedea0SLionel Sambuc int doupdatedb = 0;
289ebfedea0SLionel Sambuc char *configfile = NULL;
290ebfedea0SLionel Sambuc char *dbfile = NULL;
291ebfedea0SLionel Sambuc CA_DB *db = NULL;
292ebfedea0SLionel Sambuc char **pp;
293ebfedea0SLionel Sambuc int i;
294ebfedea0SLionel Sambuc long errorline = -1;
295ebfedea0SLionel Sambuc char *randfile = NULL;
296ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
297ebfedea0SLionel Sambuc char *engine = NULL;
298ebfedea0SLionel Sambuc # endif
299ebfedea0SLionel Sambuc char *tofree = NULL;
300ebfedea0SLionel Sambuc DB_ATTR db_attr;
301ebfedea0SLionel Sambuc
302ebfedea0SLionel Sambuc # ifdef EFENCE
303ebfedea0SLionel Sambuc EF_PROTECT_FREE = 1;
304ebfedea0SLionel Sambuc EF_PROTECT_BELOW = 1;
305ebfedea0SLionel Sambuc EF_ALIGNMENT = 0;
306ebfedea0SLionel Sambuc # endif
307ebfedea0SLionel Sambuc
308ebfedea0SLionel Sambuc apps_startup();
309ebfedea0SLionel Sambuc
310ebfedea0SLionel Sambuc conf = NULL;
311ebfedea0SLionel Sambuc section = NULL;
312ebfedea0SLionel Sambuc
313ebfedea0SLionel Sambuc if (bio_err == NULL)
314ebfedea0SLionel Sambuc if ((bio_err = BIO_new(BIO_s_file())) != NULL)
315ebfedea0SLionel Sambuc BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
316ebfedea0SLionel Sambuc
317ebfedea0SLionel Sambuc argc--;
318ebfedea0SLionel Sambuc argv++;
319*0a6a1f1dSLionel Sambuc while (argc >= 1 && badops == 0) {
320ebfedea0SLionel Sambuc if (strcmp(*argv, "-verbose") == 0)
321ebfedea0SLionel Sambuc verbose++;
322*0a6a1f1dSLionel Sambuc else if (strcmp(*argv, "-config") == 0) {
323*0a6a1f1dSLionel Sambuc if (--argc < 1)
324*0a6a1f1dSLionel Sambuc goto bad;
325ebfedea0SLionel Sambuc configfile = *(++argv);
326*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-name") == 0) {
327*0a6a1f1dSLionel Sambuc if (--argc < 1)
328*0a6a1f1dSLionel Sambuc goto bad;
329ebfedea0SLionel Sambuc section = *(++argv);
330*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-srpvfile") == 0) {
331*0a6a1f1dSLionel Sambuc if (--argc < 1)
332*0a6a1f1dSLionel Sambuc goto bad;
333ebfedea0SLionel Sambuc dbfile = *(++argv);
334*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-add") == 0)
335ebfedea0SLionel Sambuc add_user = 1;
336ebfedea0SLionel Sambuc else if (strcmp(*argv, "-delete") == 0)
337ebfedea0SLionel Sambuc delete_user = 1;
338ebfedea0SLionel Sambuc else if (strcmp(*argv, "-modify") == 0)
339ebfedea0SLionel Sambuc modify_user = 1;
340ebfedea0SLionel Sambuc else if (strcmp(*argv, "-list") == 0)
341ebfedea0SLionel Sambuc list_user = 1;
342*0a6a1f1dSLionel Sambuc else if (strcmp(*argv, "-gn") == 0) {
343*0a6a1f1dSLionel Sambuc if (--argc < 1)
344*0a6a1f1dSLionel Sambuc goto bad;
345ebfedea0SLionel Sambuc gN = *(++argv);
346*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-userinfo") == 0) {
347*0a6a1f1dSLionel Sambuc if (--argc < 1)
348*0a6a1f1dSLionel Sambuc goto bad;
349ebfedea0SLionel Sambuc userinfo = *(++argv);
350*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-passin") == 0) {
351*0a6a1f1dSLionel Sambuc if (--argc < 1)
352*0a6a1f1dSLionel Sambuc goto bad;
353ebfedea0SLionel Sambuc passargin = *(++argv);
354*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-passout") == 0) {
355*0a6a1f1dSLionel Sambuc if (--argc < 1)
356*0a6a1f1dSLionel Sambuc goto bad;
357ebfedea0SLionel Sambuc passargout = *(++argv);
358ebfedea0SLionel Sambuc }
359ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
360*0a6a1f1dSLionel Sambuc else if (strcmp(*argv, "-engine") == 0) {
361*0a6a1f1dSLionel Sambuc if (--argc < 1)
362*0a6a1f1dSLionel Sambuc goto bad;
363ebfedea0SLionel Sambuc engine = *(++argv);
364ebfedea0SLionel Sambuc }
365ebfedea0SLionel Sambuc # endif
366ebfedea0SLionel Sambuc
367*0a6a1f1dSLionel Sambuc else if (**argv == '-') {
368ebfedea0SLionel Sambuc bad:
369ebfedea0SLionel Sambuc BIO_printf(bio_err, "unknown option %s\n", *argv);
370ebfedea0SLionel Sambuc badops = 1;
371ebfedea0SLionel Sambuc break;
372*0a6a1f1dSLionel Sambuc } else
373ebfedea0SLionel Sambuc break;
374ebfedea0SLionel Sambuc
375ebfedea0SLionel Sambuc argc--;
376ebfedea0SLionel Sambuc argv++;
377ebfedea0SLionel Sambuc }
378ebfedea0SLionel Sambuc
379*0a6a1f1dSLionel Sambuc if (dbfile && configfile) {
380*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
381*0a6a1f1dSLionel Sambuc "-dbfile and -configfile cannot be specified together.\n");
382ebfedea0SLionel Sambuc badops = 1;
383ebfedea0SLionel Sambuc }
384*0a6a1f1dSLionel Sambuc if (add_user + delete_user + modify_user + list_user != 1) {
385*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
386*0a6a1f1dSLionel Sambuc "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
387ebfedea0SLionel Sambuc badops = 1;
388ebfedea0SLionel Sambuc }
389*0a6a1f1dSLionel Sambuc if (delete_user + modify_user + delete_user == 1 && argc <= 0) {
390*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
391*0a6a1f1dSLionel Sambuc "Need at least one user for options -add, -delete, -modify. \n");
392ebfedea0SLionel Sambuc badops = 1;
393ebfedea0SLionel Sambuc }
394*0a6a1f1dSLionel Sambuc if ((passin || passout) && argc != 1) {
395*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
396*0a6a1f1dSLionel Sambuc "-passin, -passout arguments only valid with one user.\n");
397ebfedea0SLionel Sambuc badops = 1;
398ebfedea0SLionel Sambuc }
399ebfedea0SLionel Sambuc
400*0a6a1f1dSLionel Sambuc if (badops) {
401ebfedea0SLionel Sambuc for (pp = srp_usage; (*pp != NULL); pp++)
402ebfedea0SLionel Sambuc BIO_printf(bio_err, "%s", *pp);
403ebfedea0SLionel Sambuc
404*0a6a1f1dSLionel Sambuc BIO_printf(bio_err, " -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR,
405*0a6a1f1dSLionel Sambuc LIST_SEPARATOR_CHAR);
406*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
407*0a6a1f1dSLionel Sambuc " load the file (or the files in the directory) into\n");
408ebfedea0SLionel Sambuc BIO_printf(bio_err, " the random number generator\n");
409ebfedea0SLionel Sambuc goto err;
410ebfedea0SLionel Sambuc }
411ebfedea0SLionel Sambuc
412ebfedea0SLionel Sambuc ERR_load_crypto_strings();
413ebfedea0SLionel Sambuc
414ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
415ebfedea0SLionel Sambuc setup_engine(bio_err, engine, 0);
416ebfedea0SLionel Sambuc # endif
417ebfedea0SLionel Sambuc
418*0a6a1f1dSLionel Sambuc if (!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
419ebfedea0SLionel Sambuc BIO_printf(bio_err, "Error getting passwords\n");
420ebfedea0SLionel Sambuc goto err;
421ebfedea0SLionel Sambuc }
422ebfedea0SLionel Sambuc
423*0a6a1f1dSLionel Sambuc if (!dbfile) {
424ebfedea0SLionel Sambuc
425ebfedea0SLionel Sambuc /*****************************************************************/
426ebfedea0SLionel Sambuc tofree = NULL;
427ebfedea0SLionel Sambuc if (configfile == NULL)
428*0a6a1f1dSLionel Sambuc configfile = getenv("OPENSSL_CONF");
429*0a6a1f1dSLionel Sambuc if (configfile == NULL)
430*0a6a1f1dSLionel Sambuc configfile = getenv("SSLEAY_CONF");
431*0a6a1f1dSLionel Sambuc if (configfile == NULL) {
432ebfedea0SLionel Sambuc const char *s = X509_get_default_cert_area();
433ebfedea0SLionel Sambuc size_t len;
434ebfedea0SLionel Sambuc
435ebfedea0SLionel Sambuc # ifdef OPENSSL_SYS_VMS
436ebfedea0SLionel Sambuc len = strlen(s) + sizeof(CONFIG_FILE);
437ebfedea0SLionel Sambuc tofree = OPENSSL_malloc(len);
438*0a6a1f1dSLionel Sambuc if (!tofree) {
439*0a6a1f1dSLionel Sambuc BIO_printf(bio_err, "Out of memory\n");
440*0a6a1f1dSLionel Sambuc goto err;
441*0a6a1f1dSLionel Sambuc }
442ebfedea0SLionel Sambuc strcpy(tofree, s);
443ebfedea0SLionel Sambuc # else
444ebfedea0SLionel Sambuc len = strlen(s) + sizeof(CONFIG_FILE) + 1;
445ebfedea0SLionel Sambuc tofree = OPENSSL_malloc(len);
446*0a6a1f1dSLionel Sambuc if (!tofree) {
447*0a6a1f1dSLionel Sambuc BIO_printf(bio_err, "Out of memory\n");
448*0a6a1f1dSLionel Sambuc goto err;
449*0a6a1f1dSLionel Sambuc }
450ebfedea0SLionel Sambuc BUF_strlcpy(tofree, s, len);
451ebfedea0SLionel Sambuc BUF_strlcat(tofree, "/", len);
452ebfedea0SLionel Sambuc # endif
453ebfedea0SLionel Sambuc BUF_strlcat(tofree, CONFIG_FILE, len);
454ebfedea0SLionel Sambuc configfile = tofree;
455ebfedea0SLionel Sambuc }
456ebfedea0SLionel Sambuc
457*0a6a1f1dSLionel Sambuc VERBOSE BIO_printf(bio_err, "Using configuration from %s\n",
458*0a6a1f1dSLionel Sambuc configfile);
459ebfedea0SLionel Sambuc conf = NCONF_new(NULL);
460*0a6a1f1dSLionel Sambuc if (NCONF_load(conf, configfile, &errorline) <= 0) {
461ebfedea0SLionel Sambuc if (errorline <= 0)
462ebfedea0SLionel Sambuc BIO_printf(bio_err, "error loading the config file '%s'\n",
463ebfedea0SLionel Sambuc configfile);
464ebfedea0SLionel Sambuc else
465*0a6a1f1dSLionel Sambuc BIO_printf(bio_err, "error on line %ld of config file '%s'\n",
466*0a6a1f1dSLionel Sambuc errorline, configfile);
467ebfedea0SLionel Sambuc goto err;
468ebfedea0SLionel Sambuc }
469*0a6a1f1dSLionel Sambuc if (tofree) {
470ebfedea0SLionel Sambuc OPENSSL_free(tofree);
471ebfedea0SLionel Sambuc tofree = NULL;
472ebfedea0SLionel Sambuc }
473ebfedea0SLionel Sambuc
474ebfedea0SLionel Sambuc if (!load_config(bio_err, conf))
475ebfedea0SLionel Sambuc goto err;
476ebfedea0SLionel Sambuc
477ebfedea0SLionel Sambuc /* Lets get the config section we are using */
478*0a6a1f1dSLionel Sambuc if (section == NULL) {
479*0a6a1f1dSLionel Sambuc VERBOSE BIO_printf(bio_err,
480*0a6a1f1dSLionel Sambuc "trying to read " ENV_DEFAULT_SRP
481*0a6a1f1dSLionel Sambuc " in \" BASE_SECTION \"\n");
482ebfedea0SLionel Sambuc
483ebfedea0SLionel Sambuc section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_SRP);
484*0a6a1f1dSLionel Sambuc if (section == NULL) {
485ebfedea0SLionel Sambuc lookup_fail(BASE_SECTION, ENV_DEFAULT_SRP);
486ebfedea0SLionel Sambuc goto err;
487ebfedea0SLionel Sambuc }
488ebfedea0SLionel Sambuc }
489ebfedea0SLionel Sambuc
490ebfedea0SLionel Sambuc if (randfile == NULL && conf)
491ebfedea0SLionel Sambuc randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");
492ebfedea0SLionel Sambuc
493*0a6a1f1dSLionel Sambuc VERBOSE BIO_printf(bio_err,
494*0a6a1f1dSLionel Sambuc "trying to read " ENV_DATABASE
495*0a6a1f1dSLionel Sambuc " in section \"%s\"\n", section);
496ebfedea0SLionel Sambuc
497*0a6a1f1dSLionel Sambuc if ((dbfile = NCONF_get_string(conf, section, ENV_DATABASE)) == NULL) {
498ebfedea0SLionel Sambuc lookup_fail(section, ENV_DATABASE);
499ebfedea0SLionel Sambuc goto err;
500ebfedea0SLionel Sambuc }
501ebfedea0SLionel Sambuc
502ebfedea0SLionel Sambuc }
503ebfedea0SLionel Sambuc if (randfile == NULL)
504ebfedea0SLionel Sambuc ERR_clear_error();
505ebfedea0SLionel Sambuc else
506ebfedea0SLionel Sambuc app_RAND_load_file(randfile, bio_err, 0);
507ebfedea0SLionel Sambuc
508*0a6a1f1dSLionel Sambuc VERBOSE BIO_printf(bio_err, "Trying to read SRP verifier file \"%s\"\n",
509*0a6a1f1dSLionel Sambuc dbfile);
510ebfedea0SLionel Sambuc
511ebfedea0SLionel Sambuc db = load_index(dbfile, &db_attr);
512*0a6a1f1dSLionel Sambuc if (db == NULL)
513*0a6a1f1dSLionel Sambuc goto err;
514ebfedea0SLionel Sambuc
515ebfedea0SLionel Sambuc /* Lets check some fields */
516*0a6a1f1dSLionel Sambuc for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
517ebfedea0SLionel Sambuc pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
518ebfedea0SLionel Sambuc
519*0a6a1f1dSLionel Sambuc if (pp[DB_srptype][0] == DB_SRP_INDEX) {
520ebfedea0SLionel Sambuc maxgN = i;
521ebfedea0SLionel Sambuc if (gNindex < 0 && gN != NULL && !strcmp(gN, pp[DB_srpid]))
522ebfedea0SLionel Sambuc gNindex = i;
523ebfedea0SLionel Sambuc
524ebfedea0SLionel Sambuc print_index(db, bio_err, i, verbose > 1);
525ebfedea0SLionel Sambuc }
526ebfedea0SLionel Sambuc }
527ebfedea0SLionel Sambuc
528ebfedea0SLionel Sambuc VERBOSE BIO_printf(bio_err, "Database initialised\n");
529ebfedea0SLionel Sambuc
530*0a6a1f1dSLionel Sambuc if (gNindex >= 0) {
531ebfedea0SLionel Sambuc gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);
532ebfedea0SLionel Sambuc print_entry(db, bio_err, gNindex, verbose > 1, "Default g and N");
533*0a6a1f1dSLionel Sambuc } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {
534ebfedea0SLionel Sambuc BIO_printf(bio_err, "No g and N value for index \"%s\"\n", gN);
535ebfedea0SLionel Sambuc goto err;
536*0a6a1f1dSLionel Sambuc } else {
537ebfedea0SLionel Sambuc VERBOSE BIO_printf(bio_err, "Database has no g N information.\n");
538ebfedea0SLionel Sambuc gNrow = NULL;
539ebfedea0SLionel Sambuc }
540ebfedea0SLionel Sambuc
541ebfedea0SLionel Sambuc VVERBOSE BIO_printf(bio_err, "Starting user processing\n");
542ebfedea0SLionel Sambuc
543ebfedea0SLionel Sambuc if (argc > 0)
544ebfedea0SLionel Sambuc user = *(argv++);
545ebfedea0SLionel Sambuc
546*0a6a1f1dSLionel Sambuc while (list_user || user) {
547ebfedea0SLionel Sambuc int userindex = -1;
548ebfedea0SLionel Sambuc if (user)
549ebfedea0SLionel Sambuc VVERBOSE BIO_printf(bio_err, "Processing user \"%s\"\n", user);
550*0a6a1f1dSLionel Sambuc if ((userindex = get_index(db, user, 'U')) >= 0) {
551ebfedea0SLionel Sambuc print_user(db, bio_err, userindex, (verbose > 0) || list_user);
552ebfedea0SLionel Sambuc }
553ebfedea0SLionel Sambuc
554*0a6a1f1dSLionel Sambuc if (list_user) {
555*0a6a1f1dSLionel Sambuc if (user == NULL) {
556ebfedea0SLionel Sambuc BIO_printf(bio_err, "List all users\n");
557ebfedea0SLionel Sambuc
558*0a6a1f1dSLionel Sambuc for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
559ebfedea0SLionel Sambuc print_user(db, bio_err, i, 1);
560ebfedea0SLionel Sambuc }
561ebfedea0SLionel Sambuc list_user = 0;
562*0a6a1f1dSLionel Sambuc } else if (userindex < 0) {
563*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
564*0a6a1f1dSLionel Sambuc "user \"%s\" does not exist, ignored. t\n", user);
565ebfedea0SLionel Sambuc errors++;
566ebfedea0SLionel Sambuc }
567*0a6a1f1dSLionel Sambuc } else if (add_user) {
568*0a6a1f1dSLionel Sambuc if (userindex >= 0) {
569ebfedea0SLionel Sambuc /* reactivation of a new user */
570*0a6a1f1dSLionel Sambuc char **row =
571*0a6a1f1dSLionel Sambuc sk_OPENSSL_PSTRING_value(db->db->data, userindex);
572ebfedea0SLionel Sambuc BIO_printf(bio_err, "user \"%s\" reactivated.\n", user);
573ebfedea0SLionel Sambuc row[DB_srptype][0] = 'V';
574ebfedea0SLionel Sambuc
575ebfedea0SLionel Sambuc doupdatedb = 1;
576*0a6a1f1dSLionel Sambuc } else {
577*0a6a1f1dSLionel Sambuc char *row[DB_NUMBER];
578*0a6a1f1dSLionel Sambuc char *gNid;
579ebfedea0SLionel Sambuc row[DB_srpverifier] = NULL;
580ebfedea0SLionel Sambuc row[DB_srpsalt] = NULL;
581ebfedea0SLionel Sambuc row[DB_srpinfo] = NULL;
582*0a6a1f1dSLionel Sambuc if (!
583*0a6a1f1dSLionel Sambuc (gNid =
584*0a6a1f1dSLionel Sambuc srp_create_user(user, &(row[DB_srpverifier]),
585*0a6a1f1dSLionel Sambuc &(row[DB_srpsalt]),
586*0a6a1f1dSLionel Sambuc gNrow ? gNrow[DB_srpsalt] : gN,
587*0a6a1f1dSLionel Sambuc gNrow ? gNrow[DB_srpverifier] : NULL,
588*0a6a1f1dSLionel Sambuc passout, bio_err, verbose))) {
589*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
590*0a6a1f1dSLionel Sambuc "Cannot create srp verifier for user \"%s\", operation abandoned .\n",
591*0a6a1f1dSLionel Sambuc user);
592ebfedea0SLionel Sambuc errors++;
593ebfedea0SLionel Sambuc goto err;
594ebfedea0SLionel Sambuc }
595ebfedea0SLionel Sambuc row[DB_srpid] = BUF_strdup(user);
596ebfedea0SLionel Sambuc row[DB_srptype] = BUF_strdup("v");
597ebfedea0SLionel Sambuc row[DB_srpgN] = BUF_strdup(gNid);
598ebfedea0SLionel Sambuc
599*0a6a1f1dSLionel Sambuc if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype]
600*0a6a1f1dSLionel Sambuc || !row[DB_srpverifier] || !row[DB_srpsalt] || (userinfo
601*0a6a1f1dSLionel Sambuc &&
602*0a6a1f1dSLionel Sambuc (!(row
603*0a6a1f1dSLionel Sambuc [DB_srpinfo]
604*0a6a1f1dSLionel Sambuc =
605*0a6a1f1dSLionel Sambuc BUF_strdup
606*0a6a1f1dSLionel Sambuc (userinfo))))
607*0a6a1f1dSLionel Sambuc || !update_index(db, bio_err, row)) {
608*0a6a1f1dSLionel Sambuc if (row[DB_srpid])
609*0a6a1f1dSLionel Sambuc OPENSSL_free(row[DB_srpid]);
610*0a6a1f1dSLionel Sambuc if (row[DB_srpgN])
611*0a6a1f1dSLionel Sambuc OPENSSL_free(row[DB_srpgN]);
612*0a6a1f1dSLionel Sambuc if (row[DB_srpinfo])
613*0a6a1f1dSLionel Sambuc OPENSSL_free(row[DB_srpinfo]);
614*0a6a1f1dSLionel Sambuc if (row[DB_srptype])
615*0a6a1f1dSLionel Sambuc OPENSSL_free(row[DB_srptype]);
616*0a6a1f1dSLionel Sambuc if (row[DB_srpverifier])
617*0a6a1f1dSLionel Sambuc OPENSSL_free(row[DB_srpverifier]);
618*0a6a1f1dSLionel Sambuc if (row[DB_srpsalt])
619*0a6a1f1dSLionel Sambuc OPENSSL_free(row[DB_srpsalt]);
620ebfedea0SLionel Sambuc goto err;
621ebfedea0SLionel Sambuc }
622ebfedea0SLionel Sambuc doupdatedb = 1;
623ebfedea0SLionel Sambuc }
624*0a6a1f1dSLionel Sambuc } else if (modify_user) {
625*0a6a1f1dSLionel Sambuc if (userindex < 0) {
626*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
627*0a6a1f1dSLionel Sambuc "user \"%s\" does not exist, operation ignored.\n",
628*0a6a1f1dSLionel Sambuc user);
629ebfedea0SLionel Sambuc errors++;
630*0a6a1f1dSLionel Sambuc } else {
631ebfedea0SLionel Sambuc
632*0a6a1f1dSLionel Sambuc char **row =
633*0a6a1f1dSLionel Sambuc sk_OPENSSL_PSTRING_value(db->db->data, userindex);
634ebfedea0SLionel Sambuc char type = row[DB_srptype][0];
635*0a6a1f1dSLionel Sambuc if (type == 'v') {
636*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
637*0a6a1f1dSLionel Sambuc "user \"%s\" already updated, operation ignored.\n",
638*0a6a1f1dSLionel Sambuc user);
639ebfedea0SLionel Sambuc errors++;
640*0a6a1f1dSLionel Sambuc } else {
641ebfedea0SLionel Sambuc char *gNid;
642ebfedea0SLionel Sambuc
643*0a6a1f1dSLionel Sambuc if (row[DB_srptype][0] == 'V') {
644ebfedea0SLionel Sambuc int user_gN;
645ebfedea0SLionel Sambuc char **irow = NULL;
646*0a6a1f1dSLionel Sambuc VERBOSE BIO_printf(bio_err,
647*0a6a1f1dSLionel Sambuc "Verifying password for user \"%s\"\n",
648*0a6a1f1dSLionel Sambuc user);
649*0a6a1f1dSLionel Sambuc if ((user_gN =
650*0a6a1f1dSLionel Sambuc get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)
651*0a6a1f1dSLionel Sambuc irow =
652*0a6a1f1dSLionel Sambuc (char **)sk_OPENSSL_PSTRING_value(db->
653*0a6a1f1dSLionel Sambuc db->data,
654*0a6a1f1dSLionel Sambuc userindex);
655ebfedea0SLionel Sambuc
656*0a6a1f1dSLionel Sambuc if (!srp_verify_user
657*0a6a1f1dSLionel Sambuc (user, row[DB_srpverifier], row[DB_srpsalt],
658*0a6a1f1dSLionel Sambuc irow ? irow[DB_srpsalt] : row[DB_srpgN],
659*0a6a1f1dSLionel Sambuc irow ? irow[DB_srpverifier] : NULL, passin,
660*0a6a1f1dSLionel Sambuc bio_err, verbose)) {
661*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
662*0a6a1f1dSLionel Sambuc "Invalid password for user \"%s\", operation abandoned.\n",
663*0a6a1f1dSLionel Sambuc user);
664ebfedea0SLionel Sambuc errors++;
665ebfedea0SLionel Sambuc goto err;
666ebfedea0SLionel Sambuc }
667ebfedea0SLionel Sambuc }
668*0a6a1f1dSLionel Sambuc VERBOSE BIO_printf(bio_err,
669*0a6a1f1dSLionel Sambuc "Password for user \"%s\" ok.\n",
670*0a6a1f1dSLionel Sambuc user);
671ebfedea0SLionel Sambuc
672*0a6a1f1dSLionel Sambuc if (!
673*0a6a1f1dSLionel Sambuc (gNid =
674*0a6a1f1dSLionel Sambuc srp_create_user(user, &(row[DB_srpverifier]),
675*0a6a1f1dSLionel Sambuc &(row[DB_srpsalt]),
676*0a6a1f1dSLionel Sambuc gNrow ? gNrow[DB_srpsalt] : NULL,
677*0a6a1f1dSLionel Sambuc gNrow ? gNrow[DB_srpverifier] : NULL,
678*0a6a1f1dSLionel Sambuc passout, bio_err, verbose))) {
679*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
680*0a6a1f1dSLionel Sambuc "Cannot create srp verifier for user \"%s\", operation abandoned.\n",
681*0a6a1f1dSLionel Sambuc user);
682ebfedea0SLionel Sambuc errors++;
683ebfedea0SLionel Sambuc goto err;
684ebfedea0SLionel Sambuc }
685ebfedea0SLionel Sambuc
686ebfedea0SLionel Sambuc row[DB_srptype][0] = 'v';
687ebfedea0SLionel Sambuc row[DB_srpgN] = BUF_strdup(gNid);
688ebfedea0SLionel Sambuc
689*0a6a1f1dSLionel Sambuc if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype]
690*0a6a1f1dSLionel Sambuc || !row[DB_srpverifier] || !row[DB_srpsalt]
691*0a6a1f1dSLionel Sambuc || (userinfo
692*0a6a1f1dSLionel Sambuc && (!(row[DB_srpinfo] = BUF_strdup(userinfo)))))
693ebfedea0SLionel Sambuc goto err;
694ebfedea0SLionel Sambuc
695ebfedea0SLionel Sambuc doupdatedb = 1;
696ebfedea0SLionel Sambuc }
697ebfedea0SLionel Sambuc }
698*0a6a1f1dSLionel Sambuc } else if (delete_user) {
699*0a6a1f1dSLionel Sambuc if (userindex < 0) {
700*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
701*0a6a1f1dSLionel Sambuc "user \"%s\" does not exist, operation ignored. t\n",
702*0a6a1f1dSLionel Sambuc user);
703ebfedea0SLionel Sambuc errors++;
704*0a6a1f1dSLionel Sambuc } else {
705*0a6a1f1dSLionel Sambuc char **xpp =
706*0a6a1f1dSLionel Sambuc sk_OPENSSL_PSTRING_value(db->db->data, userindex);
707ebfedea0SLionel Sambuc BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
708ebfedea0SLionel Sambuc
709ebfedea0SLionel Sambuc xpp[DB_srptype][0] = 'R';
710ebfedea0SLionel Sambuc
711ebfedea0SLionel Sambuc doupdatedb = 1;
712ebfedea0SLionel Sambuc }
713ebfedea0SLionel Sambuc }
714ebfedea0SLionel Sambuc if (--argc > 0)
715ebfedea0SLionel Sambuc user = *(argv++);
716*0a6a1f1dSLionel Sambuc else {
717ebfedea0SLionel Sambuc user = NULL;
718ebfedea0SLionel Sambuc list_user = 0;
719ebfedea0SLionel Sambuc }
720ebfedea0SLionel Sambuc }
721ebfedea0SLionel Sambuc
722ebfedea0SLionel Sambuc VERBOSE BIO_printf(bio_err, "User procession done.\n");
723ebfedea0SLionel Sambuc
724*0a6a1f1dSLionel Sambuc if (doupdatedb) {
725ebfedea0SLionel Sambuc /* Lets check some fields */
726*0a6a1f1dSLionel Sambuc for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
727ebfedea0SLionel Sambuc pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
728ebfedea0SLionel Sambuc
729*0a6a1f1dSLionel Sambuc if (pp[DB_srptype][0] == 'v') {
730ebfedea0SLionel Sambuc pp[DB_srptype][0] = 'V';
731ebfedea0SLionel Sambuc print_user(db, bio_err, i, verbose);
732ebfedea0SLionel Sambuc }
733ebfedea0SLionel Sambuc }
734ebfedea0SLionel Sambuc
735ebfedea0SLionel Sambuc VERBOSE BIO_printf(bio_err, "Trying to update srpvfile.\n");
736*0a6a1f1dSLionel Sambuc if (!save_index(dbfile, "new", db))
737*0a6a1f1dSLionel Sambuc goto err;
738ebfedea0SLionel Sambuc
739ebfedea0SLionel Sambuc VERBOSE BIO_printf(bio_err, "Temporary srpvfile created.\n");
740*0a6a1f1dSLionel Sambuc if (!rotate_index(dbfile, "new", "old"))
741*0a6a1f1dSLionel Sambuc goto err;
742ebfedea0SLionel Sambuc
743ebfedea0SLionel Sambuc VERBOSE BIO_printf(bio_err, "srpvfile updated.\n");
744ebfedea0SLionel Sambuc }
745ebfedea0SLionel Sambuc
746ebfedea0SLionel Sambuc ret = (errors != 0);
747ebfedea0SLionel Sambuc err:
748ebfedea0SLionel Sambuc if (errors != 0)
749ebfedea0SLionel Sambuc VERBOSE BIO_printf(bio_err, "User errors %d.\n", errors);
750ebfedea0SLionel Sambuc
751ebfedea0SLionel Sambuc VERBOSE BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
752ebfedea0SLionel Sambuc if (tofree)
753ebfedea0SLionel Sambuc OPENSSL_free(tofree);
754*0a6a1f1dSLionel Sambuc if (ret)
755*0a6a1f1dSLionel Sambuc ERR_print_errors(bio_err);
756*0a6a1f1dSLionel Sambuc if (randfile)
757*0a6a1f1dSLionel Sambuc app_RAND_write_file(randfile, bio_err);
758*0a6a1f1dSLionel Sambuc if (conf)
759*0a6a1f1dSLionel Sambuc NCONF_free(conf);
760*0a6a1f1dSLionel Sambuc if (db)
761*0a6a1f1dSLionel Sambuc free_index(db);
762ebfedea0SLionel Sambuc
763ebfedea0SLionel Sambuc OBJ_cleanup();
764ebfedea0SLionel Sambuc apps_shutdown();
765ebfedea0SLionel Sambuc OPENSSL_EXIT(ret);
766ebfedea0SLionel Sambuc }
767ebfedea0SLionel Sambuc
768ebfedea0SLionel Sambuc #endif
769