silc-client: target public key verification better
[silc.git] / apps / irssi / src / silc / core / client_ops.c
index 0b0396496a13d3cc1889fbefc3dc9e9a3d0c30a9..9ad989e29ff80b58638ffe5fa24b6c2b78cf0f93 100644 (file)
@@ -1434,15 +1434,8 @@ void silc_getkey_cb(SilcBool success, void *context)
   silc_pubkey = silc_pkcs_get_context(SILC_PKCS_SILC, public_key);
 
   if (success) {
-    if (getkey->id_type == SILC_ID_CLIENT)
-      printformat_module("fe-common/silc", NULL, NULL,
-                        MSGLEVEL_CRAP, SILCTXT_PUBKEY_VERIFIED_CLIENT,
-                        name,
-                        silc_pubkey->identifier.realname ?
-                        silc_pubkey->identifier.realname : "",
-                        silc_pubkey->identifier.email ?
-                        silc_pubkey->identifier.email : "");
-    else
+    /* Client's verification notice was showed in verify_internal() */
+    if (getkey->id_type != SILC_ID_CLIENT)
       printformat_module("fe-common/silc", NULL, NULL,
                         MSGLEVEL_CRAP, SILCTXT_PUBKEY_VERIFIED,
                         entity, name);
@@ -2476,7 +2469,7 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
   SilcPublicKey local_pubkey;
   SilcSILCPublicKey silc_pubkey;
   SilcUInt16 port;
-  SILC_SERVER_REC *server;
+  SILC_SERVER_REC *server = NULL;
   const char *hostname, *ip;
   unsigned char *pk;
   SilcUInt32 pk_len;
@@ -2487,8 +2480,8 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                  "server" : "client");
   int i;
 
+  server = (SILC_SERVER_REC*)conn->context;
   if (conn_type != SILC_CONN_CLIENT) {
-    server = (SILC_SERVER_REC*)conn->context;
     SILC_VERIFY(server);
     if (!server) {
       if (completion)
@@ -2497,6 +2490,12 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
     }
   }
 
+  /* If we have pending public key prompt already up */
+  if (server && server->prompt_op) {
+    silc_async_abort(server->prompt_op, NULL, NULL);
+    server->prompt_op = NULL;
+  }
+
   if (silc_pkcs_get_type(public_key) != SILC_PKCS_SILC) {
     printformat_module("fe-common/silc", NULL, NULL,
                       MSGLEVEL_CRAP, SILCTXT_PUBKEY_UNSUPPORTED,
@@ -2573,6 +2572,9 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
   fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
   babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
 
+  if (!name && conn->context_type == SILC_ID_CLIENT)
+    name = conn->client_entry->nickname;
+
   verify = silc_calloc(1, sizeof(*verify));
   verify->client = client;
   verify->conn = conn;
@@ -2751,6 +2753,21 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
       return;
     }
 
+    if (conn_type == SILC_CONN_CLIENT)
+      printformat_module("fe-common/silc", NULL, NULL,
+                        MSGLEVEL_CRAP, SILCTXT_PUBKEY_VERIFIED_CLIENT,
+                        (name
+                         ? name
+                         : (silc_pubkey->identifier.realname
+                            ? silc_pubkey->identifier.realname
+                            : (silc_pubkey->identifier.email
+                               ? silc_pubkey->identifier.email
+                               : ""))),
+                        silc_pubkey->identifier.realname ?
+                        silc_pubkey->identifier.realname : "",
+                        silc_pubkey->identifier.email ?
+                        silc_pubkey->identifier.email : "");
+
     /* Local copy matched */
     if (completion)
       completion(TRUE, context);
@@ -2863,7 +2880,7 @@ void silc_get_auth_method(SilcClient client, SilcClientConnection conn,
 
   /* Check whether we find the password for this server in our
      configuration.  If it's set, always send it server. */
-  setup = server_setup_find_port(hostname, port);
+  setup = server_setup_find(hostname, port, "silcnet");
   if (setup && setup->password) {
     completion(SILC_AUTH_PASSWORD, setup->password, strlen(setup->password),
               context);