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