silc-client: handle key load error correctly
[silc.git] / apps / irssi / src / silc / core / clientutil.c
index 66c8eb9a987e9c617ac9eef0d0836f1ff9dee1c2..56854526514bc5988148243e6b9c869dbe04d026 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2006, 2008 Pekka Riikonen
+  Copyright (C) 1997 - 2014 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
@@ -363,9 +363,19 @@ int silc_client_load_keys(SilcClient client)
   ret = silc_load_key_pair(pub, prv, "", &irssi_pubkey, &irssi_privkey);
   if (!ret)
     ret = silc_load_key_pair(pub, prv, NULL, &irssi_pubkey, &irssi_privkey);
-
-  if (!ret)
+  if (!ret) {
     SILC_LOG_ERROR(("Could not load key pair"));
+    return ret;
+  }
+
+  if (silc_pkcs_private_key_get_len(irssi_privkey) < 4096) {
+    fprintf(stdout,
+            "warning: Your private key %s length is under 4096 bits. It is "
+           "recommended to use at least 4096 bits. Consider generating a "
+           "new key pair.\n", prv);
+    printf("Press <Enter> to continue...\n");
+    getchar();
+  }
 
   return ret;
 }
@@ -402,6 +412,14 @@ static void silc_keyboard_entry_redirect_abort(SilcAsyncOperation op,
    * the operation has been aborted.
    */
   ctx->user_prompt_proc(NULL, ctx->user_context, KeyboardCompletionAborted);
+
+  /*
+   * Allow new prompt after we've abored despite us leaking Irssi prompt
+   * data.  It's more important to get new prompt up and this abort
+   * guarantees we handle things correctly towards silcclient library by
+   * calling the callback above.
+   */
+  silc_keyboard_prompt_pending = FALSE;
 }
 
 static void silc_keyboard_entry_redirect_completion(const char *line,
@@ -536,7 +554,8 @@ SilcBool silc_keyboard_entry_redirect(SILC_KEYBOARD_PROMPT_PROC prompt_func,
    * assuming that it doesn't as there's already many other things that seem
    * to make this assumption.
    */
-  *async = ctx->async_context;
+  if (async)
+    *async = ctx->async_context;
 
   /*
    * All done.  Irssi will invoke the callback on this thread at a later point