60 #ifndef OPENSSL_NO_SRP
76 #define BASE_SECTION "srp"
77 #define CONFIG_FILE "openssl.cnf"
79 #define ENV_RANDFILE "RANDFILE"
81 #define ENV_DATABASE "srpvfile"
82 #define ENV_DEFAULT_SRP "default_srp"
84 static char *srp_usage[]={
85 "usage: srp [args] [user] \n",
87 " -verbose Talk alot while doing things\n",
88 " -config file A config file\n",
89 " -name arg The particular srp definition to use\n",
90 " -srpvfile arg The srp verifier file name\n",
91 " -add add an user and srp verifier\n",
92 " -modify modify the srp verifier of an existing user\n",
93 " -delete delete user from verifier file\n",
95 " -gn arg g and N values to be used for new verifier\n",
96 " -userinfo arg additional info to be set for user\n",
97 " -passin arg input file pass phrase source\n",
98 " -passout arg output file pass phrase source\n",
99 #ifndef OPENSSL_NO_ENGINE
100 " -engine e - use engine e, possibly a hardware device.\n",
106 extern int EF_PROTECT_FREE;
107 extern int EF_PROTECT_BELOW;
108 extern int EF_ALIGNMENT;
111 static CONF *conf=NULL;
112 static char *section=NULL;
114 #define VERBOSE if (verbose)
115 #define VVERBOSE if (verbose>1)
118 int MAIN(
int,
char **);
120 static int get_index(
CA_DB *db,
char*
id,
char type)
124 if (
id == NULL)
return -1;
143 static void print_entry(
CA_DB *db,
BIO *bio,
int indx,
int verbose,
char *s)
145 if (indx >= 0 && verbose)
157 static void print_index(
CA_DB *db,
BIO *bio,
int indexindex,
int verbose)
159 print_entry(db, bio, indexindex, verbose,
"g N entry") ;
162 static void print_user(
CA_DB *db,
BIO *bio,
int userindex,
int verbose)
170 print_entry(db, bio, userindex, verbose,
"User entry");
171 print_entry(db, bio, get_index(db, pp[
DB_srpgN],
'I'), verbose,
"g N entry");
177 static int update_index(
CA_DB *db,
BIO *bio,
char **row)
197 BIO_printf(bio,
"failed to update srpvfile\n");
205 static void lookup_fail(
const char *name,
char *tag)
211 static char *srp_verify_user(
const char *user,
const char *srp_verifier,
212 char *srp_usersalt,
const char *g,
const char *
N,
213 const char *passin,
BIO *bio,
int verbose)
217 char *verifier = NULL;
225 VERBOSE BIO_printf(bio,
"Validating\n user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",user,srp_verifier,srp_usersalt, g, N);
230 BIO_printf(bio,
"Internal error validating SRP verifier\n");
234 if (strcmp(verifier, srp_verifier))
242 static char *srp_create_user(
char *user,
char **srp_verifier,
243 char **srp_usersalt,
char *g,
char *N,
244 char *passout,
BIO *bio,
int verbose)
255 VERBOSE BIO_printf(bio,
"Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",user,g,N);
258 BIO_printf(bio,
"Internal error creating SRP verifier\n");
261 *srp_usersalt = salt;
262 VVERBOSE BIO_printf(bio,
"gNid=%s salt =\"%s\"\n verifier =\"%s\"\n", gNid,salt, *srp_verifier);
268 int MAIN(
int argc,
char **argv)
276 char *passargin = NULL, *passargout = NULL;
277 char *passin = NULL, *passout = NULL;
280 char ** gNrow = NULL;
283 char * userinfo = NULL;
290 char *configfile=NULL;
297 #ifndef OPENSSL_NO_ENGINE
320 while (argc >= 1 && badops == 0)
322 if (strcmp(*argv,
"-verbose") == 0)
324 else if (strcmp(*argv,
"-config") == 0)
326 if (--argc < 1)
goto bad;
327 configfile= *(++argv);
329 else if (strcmp(*argv,
"-name") == 0)
331 if (--argc < 1)
goto bad;
334 else if (strcmp(*argv,
"-srpvfile") == 0)
336 if (--argc < 1)
goto bad;
339 else if (strcmp(*argv,
"-add") == 0)
341 else if (strcmp(*argv,
"-delete") == 0)
343 else if (strcmp(*argv,
"-modify") == 0)
345 else if (strcmp(*argv,
"-list") == 0)
347 else if (strcmp(*argv,
"-gn") == 0)
349 if (--argc < 1)
goto bad;
352 else if (strcmp(*argv,
"-userinfo") == 0)
354 if (--argc < 1)
goto bad;
357 else if (strcmp(*argv,
"-passin") == 0)
359 if (--argc < 1)
goto bad;
360 passargin= *(++argv);
362 else if (strcmp(*argv,
"-passout") == 0)
364 if (--argc < 1)
goto bad;
365 passargout= *(++argv);
367 #ifndef OPENSSL_NO_ENGINE
368 else if (strcmp(*argv,
"-engine") == 0)
370 if (--argc < 1)
goto bad;
375 else if (**argv ==
'-')
389 if (dbfile && configfile)
394 if (add_user+delete_user+modify_user+list_user != 1)
396 BIO_printf(
bio_err,
"Exactly one of the options -add, -delete, -modify -list must be specified.\n");
399 if (delete_user+modify_user+delete_user== 1 && argc <= 0)
401 BIO_printf(
bio_err,
"Need at least one user for options -add, -delete, -modify. \n");
404 if ((passin || passout) && argc != 1 )
412 for (pp=srp_usage; (*pp != NULL); pp++)
423 #ifndef OPENSSL_NO_ENGINE
439 if (configfile == NULL) configfile = getenv(
"OPENSSL_CONF");
440 if (configfile == NULL) configfile = getenv(
"SSLEAY_CONF");
441 if (configfile == NULL)
446 #ifdef OPENSSL_SYS_VMS
462 if (
NCONF_load(conf,configfile,&errorline) <= 0)
469 ,errorline,configfile);
494 if (randfile == NULL && conf)
507 if (randfile == NULL)
515 if (db == NULL)
goto err;
525 if (gNindex < 0 && gN != NULL && !strcmp(gN, pp[
DB_srpid]))
528 print_index(db,
bio_err, i, verbose > 1);
537 print_entry(db,
bio_err, gNindex, verbose > 1,
"Default g and N") ;
556 while (list_user || user)
561 if ((userindex = get_index(db, user,
'U')) >= 0)
563 print_user(db,
bio_err, userindex, (verbose > 0) || list_user);
578 else if (userindex < 0)
602 if (!(gNid = srp_create_user(user,&(row[
DB_srpverifier]), &(row[
DB_srpsalt]),gNrow?gNrow[DB_srpsalt]:gN,gNrow?gNrow[DB_srpverifier]:NULL, passout,
bio_err,verbose)))
604 BIO_printf(
bio_err,
"Cannot create srp verifier for user \"%s\", operation abandoned .\n", user);
614 !update_index(db,
bio_err, row))
620 if (row[DB_srpverifier])
OPENSSL_free(row[DB_srpverifier]);
627 else if (modify_user)
653 if ( (user_gN = get_index(db, row[DB_srpgN],
DB_SRP_INDEX)) >= 0)
656 if (!srp_verify_user(user, row[DB_srpverifier], row[DB_srpsalt], irow ? irow[DB_srpsalt] : row[DB_srpgN], irow ? irow[DB_srpverifier] : NULL, passin,
bio_err, verbose))
658 BIO_printf(
bio_err,
"Invalid password for user \"%s\", operation abandoned.\n", user);
665 if (!(gNid=srp_create_user(user,&(row[DB_srpverifier]), &(row[DB_srpsalt]),gNrow?gNrow[DB_srpsalt]:NULL, gNrow?gNrow[DB_srpverifier]:NULL, passout,
bio_err,verbose)))
667 BIO_printf(
bio_err,
"Cannot create srp verifier for user \"%s\", operation abandoned.\n", user);
675 if (!row[DB_srpid] || !row[DB_srpgN] || !row[
DB_srptype] || !row[DB_srpverifier] || !row[DB_srpsalt] ||
676 (userinfo && (!(row[DB_srpinfo] =
BUF_strdup(userinfo)))))
683 else if (delete_user)
722 print_user(db,
bio_err, i, verbose);