Default RSA key length is 2048 bits (old 1024 bits).
[silc.git] / apps / irssi / src / silc / core / clientutil.c
index 59fb2bac7d82346128528c37fc7095b87c837e67..f660af3bff5bc2df25dd2ec4c3731626d8d49b78 100644 (file)
@@ -157,9 +157,9 @@ New pair of keys will be created.  Please, answer to following questions.\n\
 
   if (!bits) {
     char *length = NULL;
-    length = silc_get_input("Key length in bits [1024]: ", FALSE);
+    length = silc_get_input("Key length in bits [2048]: ", FALSE);
     if (!length)
-      bits = 1024;
+      bits = 2048;
     else
       bits = atoi(length);
   }
@@ -217,7 +217,7 @@ New pair of keys will be created.  Please, answer to following questions.\n\
 
   /* Save public key into file */
   key = silc_pkcs_get_public_key(pkcs, &key_len);
-  pub_key = silc_pkcs_public_key_alloc(pkcs->pkcs->name, identifier,
+  pub_key = silc_pkcs_public_key_alloc(silc_pkcs_get_name(pkcs), identifier,
                                       key, key_len);
   silc_pkcs_save_public_key(pkfile, pub_key, SILC_PKCS_FILE_PEM);
   if (ret_pub_key)
@@ -228,8 +228,8 @@ New pair of keys will be created.  Please, answer to following questions.\n\
 
   /* Save private key into file */
   key = silc_pkcs_get_private_key(pkcs, &key_len);
-  prv_key = silc_pkcs_private_key_alloc(pkcs->pkcs->name, key, key_len);
-
+  prv_key = silc_pkcs_private_key_alloc(silc_pkcs_get_name(pkcs),
+                                       key, key_len);
   silc_pkcs_save_private_key(prvfile, prv_key, NULL, SILC_PKCS_FILE_BIN);
   if (ret_prv_key)
     *ret_prv_key = prv_key;
@@ -408,6 +408,12 @@ int silc_client_check_silc_dir()
     }
   }
 
+  /* Check the owner of the public key */
+  if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { 
+    fprintf(stderr, "You don't seem to own your public key!?\n");
+    return FALSE;
+  }
+  
   if ((stat(file_private_key, &st)) == -1) {
     /* If file doesn't exist */
     if (errno == ENOENT) {
@@ -422,12 +428,6 @@ int silc_client_check_silc_dir()
     }
   }
     
-  /* Check the owner of the public key */
-  if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { 
-    fprintf(stderr, "You don't seem to own your public key!?\n");
-    return FALSE;
-  }
-  
   /* Check the owner of the private key */
   if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { 
     fprintf(stderr, "You don't seem to own your private key!?\n");
@@ -453,18 +453,34 @@ int silc_client_check_silc_dir()
     
   /* 86400 is seconds in a day. */
   if (curtime >= (86400 * SILC_CLIENT_KEY_EXPIRES)) {
+    char *answer;
+
     fprintf(stdout, 
-           "--------------------------------------------------\n"
+           "----------------------------------------------------\n"
            "Your private key has expired and needs to be\n" 
-           "recreated.  This will be done automatically now.\n"
-           "Your new key will expire in %d days from today.\n"
-           "--------------------------------------------------\n",
-           SILC_CLIENT_KEY_EXPIRES);
-
-    silc_client_create_key_pair(SILC_CLIENT_DEF_PKCS, 
-                               SILC_CLIENT_DEF_PKCS_LEN,
-                               file_public_key, 
-                               file_private_key, identifier, NULL, NULL);
+           "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_client_create_key_pair(SILC_CLIENT_DEF_PKCS, 
+                                 SILC_CLIENT_DEF_PKCS_LEN,
+                                 file_public_key, 
+                                 file_private_key, identifier, NULL, NULL);
+    } else {
+#ifdef HAVE_UTIME
+      struct utimbuf utim;
+      utim.actime = time(NULL);
+      utim.modtime = time(NULL);
+      utime(file_private_key, &utim);
+#endif
+    }
+    silc_free(answer);
   }
   
   if (identifier)