From 2dff80cc91b1fa388de1e6f5866beab377014683 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sat, 28 Feb 2004 22:23:35 +0000 Subject: [PATCH] Added support for the new private message key indicator packet. --- CHANGES | 8 +++++ lib/silcclient/client.c | 3 +- lib/silcclient/client_internal.h | 5 +++- lib/silcclient/client_prvmsg.c | 51 ++++++++------------------------ lib/silcclient/protocol.c | 2 +- lib/silcclient/silcclient.h | 40 +++++++++++++++++++++++-- 6 files changed, 66 insertions(+), 43 deletions(-) diff --git a/CHANGES b/CHANGES index 62257243..9616fcc0 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,14 @@ Sat Feb 28 16:25:09 EET 2004 Pekka Riikonen 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 * Fixed the JOIN command calling when called with both diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 27df4062..ef4e7e05 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -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: diff --git a/lib/silcclient/client_internal.h b/lib/silcclient/client_internal.h index 37558019..05b1ff36 100644 --- a/lib/silcclient/client_internal.h +++ b/lib/silcclient/client_internal.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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); diff --git a/lib/silcclient/client_prvmsg.c b/lib/silcclient/client_prvmsg.c index 65b173fe..fbd5655e 100644 --- a/lib/silcclient/client_prvmsg.c +++ b/lib/silcclient/client_prvmsg.c @@ -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; diff --git a/lib/silcclient/protocol.c b/lib/silcclient/protocol.c index 1f89a421..b3cbe4a5 100644 --- a/lib/silcclient/protocol.c +++ b/lib/silcclient/protocol.c @@ -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: diff --git a/lib/silcclient/silcclient.h b/lib/silcclient/silcclient.h index 4fbff8eb..526ea995 100644 --- a/lib/silcclient/silcclient.h +++ b/lib/silcclient/silcclient.h @@ -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 -- 2.24.0