Added support for the new private message key indicator packet.
authorPekka Riikonen <priikone@silcnet.org>
Sat, 28 Feb 2004 22:23:35 +0000 (22:23 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 28 Feb 2004 22:23:35 +0000 (22:23 +0000)
CHANGES
lib/silcclient/client.c
lib/silcclient/client_internal.h
lib/silcclient/client_prvmsg.c
lib/silcclient/protocol.c
lib/silcclient/silcclient.h

diff --git a/CHANGES b/CHANGES
index 62257243ba9bd40fed94686c6c7a309644891219..9616fcc0bd9007058d34752ffdb09ba52c10605c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -22,6 +22,14 @@ Sat Feb 28 16:25:09 EET 2004  Pekka Riikonen <priikone@silcnet.org>
          Affected files lib/silcclient/silcclient.h, command_reply.c
          and client_notify.c.
 
+       * Added support to the new private message key indicator
+         packet.  Added a new function to the client library:
+         silc_client_send_private_message_key_request.  The sender
+         indicates to be initiator, and receiver is responder.
+         Added the indicator to the SilcClientEntry as 'prv_resp'
+         boolean.  Affected files are lib/silcclient/silcclient.h
+         client.[ch], and client_prvmsg.c.
+
 Fri Feb 27 11:25:26 CET 2004  Pekka Riikonen <priikone@silcnet.org>
 
        * Fixed the JOIN command calling when called with both
index 27df40626bc8ef2153264559499b7dcf32293942..ef4e7e0517873371a4b31be243f3ff09ddd82204 100644 (file)
@@ -1167,8 +1167,9 @@ void silc_client_packet_parse_type(SilcClient client,
 
   case SILC_PACKET_PRIVATE_MESSAGE_KEY:
     /*
-     * Received private message key
+     * Received private message key indicator
      */
+    silc_client_private_message_key(client, sock, packet);
     break;
 
   case SILC_PACKET_COMMAND:
index 37558019f236b32718855e5141388bc0c398025b..05b1ff36562571e9ff0d4b9f43a594c60b4b4f23 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2001, 2003 Pekka Riikonen
+  Copyright (C) 1997 - 2004 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
@@ -271,6 +271,9 @@ void silc_client_notify_by_server(SilcClient client,
 void silc_client_private_message(SilcClient client,
                                 SilcSocketConnection sock,
                                 SilcPacketContext *packet);
+void silc_client_private_message_key(SilcClient client,
+                                    SilcSocketConnection sock,
+                                    SilcPacketContext *packet);
 void silc_client_connection_auth_request(SilcClient client,
                                         SilcSocketConnection sock,
                                         SilcPacketContext *packet);
index 65b173fe272db7f26aa3bfe7ba91c66f4e8894c4..fbd5655e0e6416c9a2bb6797f1657a4b1f5c46cf 100644 (file)
@@ -276,22 +276,8 @@ static void silc_client_private_message_key_cb(SilcClient client,
   if (key_len > packet->buffer->len)
     goto out;
 
-  /* Now take the key in use */
-  if (!silc_client_add_private_message_key(client, conn, clients[0],
-                                          cipher, hmac, key, key_len,
-                                          FALSE, TRUE))
-    goto out;
-
-  /* Print some info for application */
-  client->internal->ops->say(
-                    client, conn, SILC_CLIENT_MESSAGE_AUDIT,
-                    "Received private message key from %s%s%s %s%s%s",
-                    clients[0]->nickname,
-                    clients[0]->server ? "@" : "",
-                    clients[0]->server ? clients[0]->server : "",
-                    clients[0]->username ? "(" : "",
-                    clients[0]->username ? clients[0]->username : "",
-                    clients[0]->username ? ")" : "");
+  /* Mark that we are responder */
+  clients[0]->prv_resp = TRUE;
 
  out:
   silc_free(cipher);
@@ -299,8 +285,8 @@ static void silc_client_private_message_key_cb(SilcClient client,
   silc_packet_context_free(packet);
 }
 
-/* Processes incoming Private Message Key payload. The libary always
-   accepts the key and takes it into use. */
+/* Processes incoming Private Message Key payload to indicate that the
+   sender whishes to set up a static private message key. */
 
 void silc_client_private_message_key(SilcClient client,
                                     SilcSocketConnection sock,
@@ -501,20 +487,13 @@ bool silc_client_add_private_message_key_ske(SilcClient client,
   return TRUE;
 }
 
-/* Sends private message key payload to the remote client indicated by
-   the `client_entry'. If the `force_send' is TRUE the packet is sent
-   immediately. Returns FALSE if error occurs, TRUE otherwise. The
-   application should call this function after setting the key to the
-   client.
-
-   Note that the key sent using this function is sent to the remote client
-   through the SILC network. The packet is protected using normal session
-   keys. */
+/* Sends private message key indicator.  The sender of this packet is
+   going to be the initiator, if and when, the users set up a static
+   private message key (not Key Agreement). */
 
-bool silc_client_send_private_message_key(SilcClient client,
-                                        SilcClientConnection conn,
-                                        SilcClientEntry client_entry,
-                                        bool force_send)
+bool silc_client_send_private_message_key_request(SilcClient client,
+                                                 SilcClientConnection conn,
+                                                 SilcClientEntry client_entry)
 {
   SilcSocketConnection sock;
   SilcBuffer buffer;
@@ -527,7 +506,7 @@ bool silc_client_send_private_message_key(SilcClient client,
   if (!client_entry->send_key || !client_entry->key)
     return FALSE;
 
-  SILC_LOG_DEBUG(("Sending private message key"));
+  SILC_LOG_DEBUG(("Sending private message key indicator"));
 
   cipher = silc_cipher_get_name(client_entry->send_key);
   cipher_len = strlen(cipher);
@@ -535,12 +514,8 @@ bool silc_client_send_private_message_key(SilcClient client,
   hmac_len = strlen(hmac);
 
   /* Create private message key payload */
-  buffer = silc_buffer_alloc(2 + client_entry->key_len);
-  silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+  buffer = silc_buffer_alloc_size(4 + cipher_len + hmac_len);
   silc_buffer_format(buffer,
-                    SILC_STR_UI_SHORT(client_entry->key_len),
-                    SILC_STR_UI_XNSTRING(client_entry->key,
-                                         client_entry->key_len),
                     SILC_STR_UI_SHORT(cipher_len),
                     SILC_STR_UI_XNSTRING(cipher,
                                          cipher_len),
@@ -552,7 +527,7 @@ bool silc_client_send_private_message_key(SilcClient client,
   /* Send the packet */
   silc_client_packet_send(client, sock, SILC_PACKET_PRIVATE_MESSAGE_KEY,
                          client_entry->id, SILC_ID_CLIENT, NULL, NULL,
-                         buffer->data, buffer->len, force_send);
+                         buffer->data, buffer->len, TRUE);
   silc_free(buffer);
 
   return TRUE;
index 1f89a4212be7b45b0ea24ec958a3fc83dffb6c37..b3cbe4a53c1b5696cae76c0a938382f27d633970 100644 (file)
@@ -629,7 +629,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_connection_auth)
        */
       unsigned char *auth_data = NULL;
       SilcUInt32 auth_data_len = 0;
-      unsigned char sign[1024];
+      unsigned char sign[2048 + 1];
 
       switch(ctx->auth_meth) {
       case SILC_AUTH_NONE:
index 4fbff8eb094a79adb6ebd6446636e3bf3a91d873..526ea9952b23ae2434f88a9aa6120c0b5521c299 100644 (file)
@@ -228,8 +228,10 @@ struct SilcClientEntryStruct {
   SilcEntryStatus status;      /* Status mask */
   SilcHashTable channels;      /* All channels client has joined */
   SilcUInt16 resolve_cmd_ident;        /* Command identifier when resolving */
-  bool generated;              /* TRUE if library generated `key' */
-  bool valid;                  /* FALSE if this entry is not valid */
+  unsigned int generated   : 1; /* TRUE if library generated `key' */
+  unsigned int valid       : 1;        /* FALSE if this entry is not valid */
+  unsigned int prv_resp    : 1; /* TRUE if private message key indicator
+                                  has been received (responder). */
 
   /* Application specific data.  Application may set here whatever it wants. */
   void *context;
@@ -1996,6 +1998,40 @@ silc_client_list_private_message_keys(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcUInt32 *key_count);
 
+/****f* silcclient/SilcClientAPI/silc_client_send_private_message_key_request
+ *
+ * SYNOPSIS
+ *
+ *    bool
+ *    silc_client_send_private_message_key_request(SilcClient client,
+ *                                               SilcClientConnection conn,
+ *                                               SilcClientEntry client_entry);
+ *
+ * DESCRIPTION
+ *
+ *    This function can be used to send an private message key indicator
+ *    request to the remote client indicated by 'client_entry'.  This can
+ *    be used when setting a static or pre-shared private message key.
+ *    The sender of this packet is the initiator and must set the 'responder'
+ *    argument in silc_client_add_private_message_key function to FALSE.
+ *    The receiver of this indicator request must set it to TRUE, if the
+ *    receiver decides to set a private message key.  By using this
+ *    function applications may automate initiator/responder setting in
+ *    private message key functions, without asking from user which one is
+ *    the initiator and which one is responder.
+ *
+ * NOTES
+ *
+ *    The sender of this packet must set the private message key for
+ *    'client_entry' before calling this function.  The 'responder'
+ *    argument MUST be set to FALSE when setting the key.
+ *
+ ***/
+bool
+silc_client_send_private_message_key_request(SilcClient client,
+                                            SilcClientConnection conn,
+                                            SilcClientEntry client_entry);
+
 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
  *
  * SYNOPSIS