Merged silc_1_0_branch to trunk.
[silc.git] / lib / silcutil / silcapputil.c
index 723ca37f777d26057bbac8777b92815c6315eb4a..415d591fd22691142a3d606bc02deff916ce7554 100644 (file)
@@ -1,10 +1,10 @@
 /*
 
-  silcapputil.c 
+  silcapputil.c
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2002 Pekka Riikonen
+  Copyright (C) 2002 - 2005 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@ static char *silc_create_pk_identifier(void)
   char *username = NULL, *realname = NULL;
   char *hostname, email[256];
   char *ident;
-  
+
   /* Get realname */
   realname = silc_get_real_name();
 
@@ -89,7 +89,7 @@ New pair of keys will be created.  Please, answer to following questions.\n\
        alg = silc_get_input("PKCS name (l to list names) [rsa]: ", FALSE);
        if (!alg)
          alg = strdup("rsa");
-    
+
        if (*alg == 'l' || *alg == 'L') {
          char *list = silc_pkcs_get_supported();
          printf("%s\n", list);
@@ -175,19 +175,24 @@ New pair of keys will be created.  Please, answer to following questions.\n\
   }
 
   if (!pass) {
-    char *pass2 = NULL;
-    pass = silc_get_input("Private key passphrase: ", TRUE);
-    if (!pass) {
-      pass = strdup("");
-    } else {
-      while (TRUE) {
+    while (TRUE) {
+      char *pass2 = NULL;
+      pass = silc_get_input("Private key passphrase: ", TRUE);
+      if (!pass) {
+        pass = strdup("");
+       break;
+      } else {
+       bool match;
        printf("\n");
        pass2 = silc_get_input("Retype private key passphrase: ", TRUE);
-       if (!strcmp(pass, pass2))
+       if (!pass2)
+         pass2 = strdup("");
+       match = !strcmp(pass, pass2);
+       silc_free(pass2);
+       if (match)
          break;
-       fprintf(stderr, "\nPassphrases do not match");
+       fprintf(stderr, "\nPassphrases do not match\n\n");
       }
-      silc_free(pass2);
     }
   }
 
@@ -342,8 +347,8 @@ bool silc_show_public_key(const char *pub_filename)
     printf("Organization       : %s\n", ident->org);
   if (ident->country)
     printf("Country            : %s\n", ident->country);
-  printf("Fingerprint (SHA1) : %s\n", fingerprint); 
-  printf("Babbleprint (SHA1) : %s\n", babbleprint); 
+  printf("Fingerprint (SHA1) : %s\n", fingerprint);
+  printf("Babbleprint (SHA1) : %s\n", babbleprint);
 
   fflush(stdout);
 
@@ -401,6 +406,8 @@ bool silc_change_private_key_passphrase(const char *prv_filename,
       while (TRUE) {
        printf("\n");
        pass2 = silc_get_input("Retype new passphrase: ", TRUE);
+       if (!pass2)
+         pass2 = strdup("");
        if (!strcmp(pass, pass2))
          break;
        fprintf(stderr, "\nPassphrases do not match");