Merged silc_1_0_branch to trunk.
[crypto.git] / apps / irssi / src / silc / core / clientutil.c
index cdc0fc9ee3bb9fdd9bbccc4e33dcf3ae9991210a..7118e5ccaf086509f2746eb3765abe064028dae4 100644 (file)
@@ -83,9 +83,8 @@ void silc_client_list_pkcs()
 /* This checks stats for various SILC files and directories. First it 
    checks if ~/.silc directory exist and is owned by the correct user. If 
    it doesn't exist, it will create the directory. After that it checks if
-   user's Public and Private key files exists and that they aren't expired.
-   If they doesn't exist or they are expired, they will be (re)created
-   after return. */
+   user's Public and Private key files exists. If they doesn't exist they 
+   will be created after return. */
 
 int silc_client_check_silc_dir()
 {
@@ -93,7 +92,6 @@ int silc_client_check_silc_dir()
   char servfilename[256], clientfilename[256], friendsfilename[256];
   struct stat st;
   struct passwd *pw;
-  time_t curtime, modtime;
 
   SILC_LOG_DEBUG(("Checking ~./silc directory"));
 
@@ -238,7 +236,7 @@ int silc_client_check_silc_dir()
       silc_create_key_pair(SILC_CLIENT_DEF_PKCS,
                           SILC_CLIENT_DEF_PKCS_LEN,
                           file_public_key, file_private_key, NULL,
-                          NULL, NULL, NULL, FALSE);
+                          NULL, NULL, NULL, NULL, FALSE);
       printf("Press <Enter> to continue...\n");
       getchar();
     } else {
@@ -260,7 +258,7 @@ int silc_client_check_silc_dir()
       silc_create_key_pair(SILC_CLIENT_DEF_PKCS,
                           SILC_CLIENT_DEF_PKCS_LEN,
                           file_public_key, file_private_key, NULL,
-                          NULL, NULL, NULL, FALSE);
+                          NULL, NULL, NULL, NULL, FALSE);
       printf("Press <Enter> to continue...\n");
       getchar();
     } else {
@@ -288,44 +286,6 @@ int silc_client_check_silc_dir()
     fprintf(stderr, "Done.\n\n");
   }
 
-  /* See if the key has expired. */
-  modtime = st.st_mtime;       /* last modified */
-  curtime = time(0) - modtime;
-    
-  /* 86400 is seconds in a day. */
-  if (curtime >= (86400 * SILC_CLIENT_KEY_EXPIRES)) {
-    char *answer;
-
-    fprintf(stdout, 
-           "----------------------------------------------------\n"
-           "Your private key has expired and needs to be\n" 
-           "recreated.  Would you like to create a new key pair\n"
-           "now?  If you answer Yes, the new key will expire in\n"
-           "%d days from today.  If you answer No, the old key\n"
-           "will expire again in %d days from today.\n"
-           "----------------------------------------------------\n",
-           SILC_CLIENT_KEY_EXPIRES, SILC_CLIENT_KEY_EXPIRES);
-
-    answer = silc_get_input("Would you like to create a new key pair "
-                           "([y]/n)?: ", FALSE);
-    if (!answer || answer[0] == 'Y' || answer[0] == 'y') {
-      silc_create_key_pair(SILC_CLIENT_DEF_PKCS,
-                          SILC_CLIENT_DEF_PKCS_LEN,
-                          file_public_key, file_private_key, NULL,
-                          NULL, NULL, NULL, FALSE);
-      printf("Press <Enter> to continue...\n");
-      getchar();
-    } else {
-#ifdef HAVE_UTIME
-      struct utimbuf utim;
-      utim.actime = time(NULL);
-      utim.modtime = time(NULL);
-      utime(file_private_key, &utim);
-#endif
-    }
-    silc_free(answer);
-  }
-  
   return TRUE;
 }
 
@@ -335,6 +295,7 @@ int silc_client_load_keys(SilcClient client)
 {
   char pub[256], prv[256];
   struct passwd *pw;
+  bool ret;
 
   SILC_LOG_DEBUG(("Loading public and private keys"));
 
@@ -350,6 +311,13 @@ int silc_client_load_keys(SilcClient client)
   snprintf(pub, sizeof(pub) - 1, "%s/%s",
           get_irssi_dir(), SILC_CLIENT_PUBLIC_KEY_NAME);
   
-  return silc_load_key_pair(pub, prv, &client->pkcs, &client->public_key,
-                           &client->private_key);
+  /* Try loading first with "" passphrase, for those that didn't set
+     passphrase for private key, and only if that fails let it prompt
+     for passphrase. */
+  ret = silc_load_key_pair(pub, prv, "", &client->pkcs, &client->public_key,
+                          &client->private_key);
+  if (!ret)
+    ret = silc_load_key_pair(pub, prv, NULL, &client->pkcs,
+                            &client->public_key, &client->private_key);
+  return ret;
 }