Added support for auto-passphrase authentication from the config
authorPekka Riikonen <priikone@silcnet.org>
Fri, 18 Oct 2002 07:55:32 +0000 (07:55 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 18 Oct 2002 07:55:32 +0000 (07:55 +0000)
file during connecting.
Fixed auth protocol failure handling in Client library.

CHANGES
TODO
apps/irssi/src/silc/core/client_ops.c
lib/silcclient/client.c
lib/silcclient/protocol.c

diff --git a/CHANGES b/CHANGES
index 398b47dd42caa66369cf8706d2204f8758f5e4bf..96a78a9a66a2e6eaaabc7d08e9989f5259c3d970 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,13 @@
+Fri Oct 18 10:51:04 EEST 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added support for auto-passphrase authentication from the
+         config file during connecting which was not implemented
+         yet.  Affected file irssi/src/silc/core/client_ops.c.
+
+       * Fixed a bug in authentication protocol failure handling which
+         was processing wrong callback context.  Affected files
+         are lib/silcclient/client.c and protocol.c.
+
 Thu Oct 17 23:45:12 EEST 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * Fixed string formatting crashbug in lib/silccore/silcattrs.c.
diff --git a/TODO b/TODO
index 15a34e5bc6147b8ef19c02aa628a4fb024032459..d1af4714fa878a2d2c6e80a4bc5b6a742a1f997a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,12 +1,6 @@
 TODO/bugs in Irssi SILC client
 ==============================
 
- o Server password is not used at all.  It is not possible to automize
-   the password authentication currently.  The silc_get_auth_method
-   in irssi/src/silc/core/client_ops.c should find the connection's
-   password, only if not found then continue resolving the auth method.
-   Alternatively it can do it after resolving in the callback.
-
  o UTF-8 encode/decode WHOIS userinfos, topic, etc.
 
  o Manaul file for silc(1) and silc.conf.
index c450af86070a08b350affacf2455fe6f2e7e19ec..297272ef8902e27d32022d9216326aa3cebd56d0 100644 (file)
@@ -2072,9 +2072,20 @@ static void silc_get_auth_method_callback(SilcClient client,
     (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
     break;
   case SILC_AUTH_PASSWORD:
-    /* Do not ask the passphrase from user, the library will ask it if
-       we do not provide it here. */
-    (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
+    {
+      /* Check whether we find the password for this server in our
+        configuration.  If not, then don't provide so library will ask
+        it from the user. */
+      SERVER_SETUP_REC *setup = server_setup_find_port(conn->remote_host,
+                                                      conn->remote_port);
+      if (!setup || !setup->password) {
+       (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
+       break;
+      }
+      
+      (*internal->completion)(TRUE, auth_meth, setup->password,
+                             strlen(setup->password), internal->context);
+    }
     break;
   case SILC_AUTH_PUBLIC_KEY:
     /* Do not get the authentication data now, the library will generate
@@ -2102,9 +2113,6 @@ void silc_get_auth_method(SilcClient client, SilcClientConnection conn,
 
   SILC_LOG_DEBUG(("Start"));
 
-  /* XXX must resolve from configuration whether this connection has
-     any specific authentication data */
-
   /* If we do not have this connection configured by the user in a
      configuration file then resolve the authentication method from the
      server for this session. */
index 8b50fa4ac84d03be13fb5bcaa09f15888ee756d9..e5ad7feda4699575e5cf7b9bfd1316316bbc64b0 100644 (file)
@@ -461,8 +461,8 @@ void silc_client_start_key_exchange(SilcClient client,
                          conn, client->schedule);
 }
 
-/* Callback called when error has occurred during connecting to the server.
-   The `connect' client operation will be called. */
+/* Callback called when error has occurred during connecting (KE) to
+   the server.  The `connect' client operation will be called. */
 
 SILC_TASK_CALLBACK(silc_client_connect_failure)
 {
@@ -477,6 +477,20 @@ SILC_TASK_CALLBACK(silc_client_connect_failure)
   silc_free(ctx);
 }
 
+/* Callback called when error has occurred during connecting (auth) to
+   the server.  The `connect' client operation will be called. */
+
+SILC_TASK_CALLBACK(silc_client_connect_failure_auth)
+{
+  SilcClientConnAuthInternalContext *ctx =
+    (SilcClientConnAuthInternalContext *)context;
+  SilcClient client = (SilcClient)ctx->client;
+
+  client->internal->ops->connect(client, ctx->sock->user_data, 
+                                SILC_CLIENT_CONN_ERROR);
+  silc_free(ctx);
+}
+
 /* Start of the connection to the remote server. This is called after
    succesful TCP/IP connection has been established to the remote host. */
 
@@ -593,6 +607,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_second)
   silc_protocol_free(protocol);
   if (ctx->packet)
     silc_packet_context_free(ctx->packet);
+  ctx->packet = NULL;
   silc_free(ctx);
   sock->protocol = NULL;
 
@@ -625,7 +640,21 @@ void silc_client_resolve_auth_method(bool success,
 
   proto_ctx->auth_meth = auth_meth;
 
-  if (auth_data && auth_data_len) {
+  if (success && auth_data && auth_data_len) {
+
+    /* Passphrase must be UTF-8 encoded, if it isn't encode it */
+    if (auth_meth == SILC_AUTH_PASSWORD && 
+       !silc_utf8_valid(auth_data, auth_data_len)) {
+      int payload_len = 0;
+      unsigned char *autf8 = NULL;
+      payload_len = silc_utf8_encoded_len(auth_data, auth_data_len, 
+                                         SILC_STRING_ASCII);
+      autf8 = silc_calloc(payload_len, sizeof(*autf8));
+      auth_data_len = silc_utf8_encode(auth_data, auth_data_len, 
+                                      SILC_STRING_ASCII, autf8, payload_len);
+      auth_data = autf8;
+    }
+
     proto_ctx->auth_data = silc_memdup(auth_data, auth_data_len);
     proto_ctx->auth_data_len = auth_data_len;
   }
@@ -761,7 +790,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_final)
 
   /* Notify application of failure */
   silc_schedule_task_add(client->schedule, ctx->sock->sock,
-                        silc_client_connect_failure, ctx,
+                        silc_client_connect_failure_auth, ctx,
                         0, 1, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
 }
 
index e2f6454cab852c34ae93d1eb0f9a543a0ed8dab1..b8d4c3df2dd323aa7d46e2b869413bf349b61b3a 100644 (file)
@@ -574,7 +574,7 @@ silc_client_conn_auth_continue(unsigned char *auth_data,
   int payload_len = 0;
   unsigned char *autf8 = NULL;
 
-  SILC_LOG_DEBUG(("Start"));
+  SILC_LOG_DEBUG(("Sending authentication to server"));
 
   /* Passphrase must be UTF-8 encoded, if it isn't encode it */
   if (ctx->auth_meth == SILC_AUTH_PASSWORD &&