srp.c (238405) | srp.c (246772) |
---|---|
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. 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 --- 111 unchanged lines hidden (view full) --- 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 { | 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. 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 --- 111 unchanged lines hidden (view full) --- 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 = (char **)sk_OPENSSL_PSTRING_value(db->db->data, i); 129 if (pp[DB_srptype][0] == DB_SRP_INDEX && !strcmp(id, pp[DB_srpid])) | 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 { | 130 return i; 131 } 132 else for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) 133 { |
134 pp = (char **)sk_OPENSSL_PSTRING_value(db->db->data, i); | 134 pp = sk_OPENSSL_PSTRING_value(db->db->data,i); |
135 136 if (pp[DB_srptype][0] != DB_SRP_INDEX && !strcmp(id,pp[DB_srpid])) 137 return i; 138 } 139 140 return -1 ; 141 } 142 143static void print_entry(CA_DB *db, BIO *bio, int indx, int verbose, char *s) 144 { 145 if (indx >= 0 && verbose) 146 { 147 int j; | 135 136 if (pp[DB_srptype][0] != DB_SRP_INDEX && !strcmp(id,pp[DB_srpid])) 137 return i; 138 } 139 140 return -1 ; 141 } 142 143static 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 = (char **)sk_OPENSSL_PSTRING_value(db->db->data, indx); | 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 } 156 157static void print_index(CA_DB *db, BIO *bio, int indexindex, int verbose) 158 { 159 print_entry(db, bio, indexindex, verbose, "g N entry") ; 160 } 161 162static void print_user(CA_DB *db, BIO *bio, int userindex, int verbose) 163 { 164 if (verbose > 0) 165 { | 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 } 156 157static void print_index(CA_DB *db, BIO *bio, int indexindex, int verbose) 158 { 159 print_entry(db, bio, indexindex, verbose, "g N entry") ; 160 } 161 162static void print_user(CA_DB *db, BIO *bio, int userindex, int verbose) 163 { 164 if (verbose > 0) 165 { |
166 char **pp = (char **)sk_OPENSSL_PSTRING_value(db->db->data, userindex); | 166 char **pp = sk_OPENSSL_PSTRING_value(db->db->data,userindex); |
167 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 } 173 174 } --- 337 unchanged lines hidden (view full) --- 512 VERBOSE BIO_printf(bio_err,"Trying to read SRP verifier file \"%s\"\n",dbfile); 513 514 db = load_index(dbfile, &db_attr); 515 if (db == NULL) goto err; 516 517 /* Lets check some fields */ 518 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) 519 { | 167 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 } 173 174 } --- 337 unchanged lines hidden (view full) --- 512 VERBOSE BIO_printf(bio_err,"Trying to read SRP verifier file \"%s\"\n",dbfile); 513 514 db = load_index(dbfile, &db_attr); 515 if (db == NULL) goto err; 516 517 /* Lets check some fields */ 518 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) 519 { |
520 pp = (char **)sk_OPENSSL_PSTRING_value(db->db->data, i); | 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; 527 528 print_index(db, bio_err, i, verbose > 1); 529 } 530 } 531 532 VERBOSE BIO_printf(bio_err, "Database initialised\n"); 533 534 if (gNindex >= 0) 535 { | 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; 527 528 print_index(db, bio_err, i, verbose > 1); 529 } 530 } 531 532 VERBOSE BIO_printf(bio_err, "Database initialised\n"); 533 534 if (gNindex >= 0) 535 { |
536 gNrow = (char **)sk_OPENSSL_PSTRING_value(db->db->data, gNindex); 537 print_entry(db, bio_err, gNindex, verbose > 1, "Default g and N") ; | 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 { --- 36 unchanged lines hidden (view full) --- 582 errors++; 583 } 584 } 585 else if (add_user) 586 { 587 if (userindex >= 0) 588 { 589 /* reactivation of a new user */ | 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 { --- 36 unchanged lines hidden (view full) --- 582 errors++; 583 } 584 } 585 else if (add_user) 586 { 587 if (userindex >= 0) 588 { 589 /* reactivation of a new user */ |
590 char **row = (char **)sk_OPENSSL_PSTRING_value(db->db->data, userindex); | 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'; 593 594 doupdatedb = 1; 595 } 596 else 597 { 598 char *row[DB_NUMBER] ; char *gNid; --- 30 unchanged lines hidden (view full) --- 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 { 636 | 591 BIO_printf(bio_err, "user \"%s\" reactivated.\n", user); 592 row[DB_srptype][0] = 'V'; 593 594 doupdatedb = 1; 595 } 596 else 597 { 598 char *row[DB_NUMBER] ; char *gNid; --- 30 unchanged lines hidden (view full) --- 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 { 636 |
637 char **row = (char **)sk_OPENSSL_PSTRING_value(db->db->data, userindex); | 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 { --- 13 unchanged lines hidden (view full) --- 659 errors++; 660 goto err; 661 } 662 } 663 VERBOSE BIO_printf(bio_err,"Password for user \"%s\" ok.\n",user); 664 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 { | 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 { --- 13 unchanged lines hidden (view full) --- 659 errors++; 660 goto err; 661 } 662 } 663 VERBOSE BIO_printf(bio_err,"Password for user \"%s\" ok.\n",user); 664 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; | 667 BIO_printf(bio_err, "Cannot create srp verifier for user \"%s\", operation abandoned.\n", user); 668 errors++; 669 goto err; |
670 } 671 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; --- 6 unchanged lines hidden (view full) --- 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 { | 670 } 671 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; --- 6 unchanged lines hidden (view full) --- 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 = (char **)sk_OPENSSL_PSTRING_value(db->db->data, userindex); | 692 char **xpp = sk_OPENSSL_PSTRING_value(db->db->data,userindex); |
693 BIO_printf(bio_err, "user \"%s\" revoked. t\n", user); 694 695 xpp[DB_srptype][0] = 'R'; 696 697 doupdatedb = 1; 698 } 699 } 700 if (--argc > 0) --- 8 unchanged lines hidden (view full) --- 709 VERBOSE BIO_printf(bio_err,"User procession done.\n"); 710 711 712 if (doupdatedb) 713 { 714 /* Lets check some fields */ 715 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) 716 { | 693 BIO_printf(bio_err, "user \"%s\" revoked. t\n", user); 694 695 xpp[DB_srptype][0] = 'R'; 696 697 doupdatedb = 1; 698 } 699 } 700 if (--argc > 0) --- 8 unchanged lines hidden (view full) --- 709 VERBOSE BIO_printf(bio_err,"User procession done.\n"); 710 711 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 = (char **)sk_OPENSSL_PSTRING_value(db->db->data, i); | 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 } 725 --- 31 unchanged lines hidden --- | 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 } 725 --- 31 unchanged lines hidden --- |