key mode on the channel being set.
The channel private key used to decrypt message is now develired
to channel_message client operation.
Affected files are lib/silcclient/silcclient.h and
client_channel.c.
+ * Added support for using channel private keys in SILC
+ Client Library even if the private key mode is not set
+ on the channel. Affected file lib/silcclient/client_channel.c.
+
+ * The channel private key used to decrypt message is now
+ delivered to the application in the 'channel_messageÃ' client
+ operation. Affected files are lib/silcclient/silcclient.h
+ and client_channel.c.
+
Fri Feb 27 11:25:26 CET 2004 Pekka Riikonen <priikone@silcnet.org>
* Fixed the JOIN command calling when called with both
channel, newnick, MSGLEVEL_NICKS))
return;
- signal_emit("message silc appears", 5, server, channel,
+ signal_emit("message silc appears", 5, server, channel,
oldnick, newnick, address);
}
void silc_channel_message(SilcClient client, SilcClientConnection conn,
SilcClientEntry sender, SilcChannelEntry channel,
SilcMessagePayload payload,
+ SilcChannelPrivateKey key,
SilcMessageFlags flags, const unsigned char *message,
SilcUInt32 message_len)
{
silc_utf8_decode(message, message_len, SILC_STRING_LANGUAGE,
cp, message_len);
if (flags & SILC_MESSAGE_FLAG_SIGNED)
- signal_emit("message silc signed_private_action", 6, server, cp,
+ signal_emit("message silc signed_private_action", 6, server, cp,
sender->nickname ? sender->nickname : "[<unknown>]",
- sender->username ? userhost : NULL,
+ sender->username ? userhost : NULL,
NULL, verified);
else
- signal_emit("message silc private_action", 5, server, cp,
+ signal_emit("message silc private_action", 5, server, cp,
sender->nickname ? sender->nickname : "[<unknown>]",
sender->username ? userhost : NULL, NULL);
silc_free(dm);
} else {
if (flags & SILC_MESSAGE_FLAG_SIGNED)
- signal_emit("message silc signed_private_action", 6, server, message,
+ signal_emit("message silc signed_private_action", 6, server, message,
sender->nickname ? sender->nickname : "[<unknown>]",
- sender->username ? userhost : NULL,
+ sender->username ? userhost : NULL,
NULL, verified);
else
- signal_emit("message silc private_action", 5, server, message,
+ signal_emit("message silc private_action", 5, server, message,
sender->nickname ? sender->nickname : "[<unknown>]",
sender->username ? userhost : NULL, NULL);
}
silc_utf8_decode(message, message_len, SILC_STRING_LANGUAGE,
cp, message_len);
if (flags & SILC_MESSAGE_FLAG_SIGNED)
- signal_emit("message silc signed_private_notice", 6, server, cp,
+ signal_emit("message silc signed_private_notice", 6, server, cp,
sender->nickname ? sender->nickname : "[<unknown>]",
- sender->username ? userhost : NULL,
+ sender->username ? userhost : NULL,
NULL, verified);
else
- signal_emit("message silc private_notice", 5, server, cp,
+ signal_emit("message silc private_notice", 5, server, cp,
sender->nickname ? sender->nickname : "[<unknown>]",
sender->username ? userhost : NULL, NULL);
silc_free(dm);
} else {
if (flags & SILC_MESSAGE_FLAG_SIGNED)
- signal_emit("message silc signed_private_notice", 6, server, message,
+ signal_emit("message silc signed_private_notice", 6, server, message,
sender->nickname ? sender->nickname : "[<unknown>]",
- sender->username ? userhost : NULL,
+ sender->username ? userhost : NULL,
NULL, verified);
else
- signal_emit("message silc private_notice", 5, server, message,
+ signal_emit("message silc private_notice", 5, server, message,
sender->nickname ? sender->nickname : "[<unknown>]",
sender->username ? userhost : NULL, NULL);
}
sender->username ? userhost : NULL);
silc_free(dm);
return;
- }
+ }
if (flags & SILC_MESSAGE_FLAG_SIGNED)
signal_emit("message signed_private", 5, server, message,
signal_emit("message private", 4, server, message,
sender->nickname ? sender->nickname : "[<unknown>]",
sender->username ? userhost : NULL);
- }
+ }
}
/* Notify message to the client. The notify arguments are sent in the
client_entry = va_arg(va, SilcClientEntry);
channel = va_arg(va, SilcChannelEntry);
-
+
memset(buf, 0, sizeof(buf));
if (client_entry->username)
snprintf(buf, sizeof(buf) - 1, "%s@%s",
/*
* Changed topic.
*/
-
+
SILC_LOG_DEBUG(("Notify: TOPIC_SET"));
-
+
idtype = va_arg(va, int);
entry = va_arg(va, void *);
tmp = va_arg(va, char *);
chanrec = silc_channel_find_entry(server, channel);
if (chanrec != NULL) {
-
+
g_free_not_null(chanrec->topic);
-
+
chanrec->topic = *tmp == '\0' ? NULL : g_strdup(tmp);
signal_emit("channel topic changed", 1, chanrec);
-
+
}
-
+
if (idtype == SILC_ID_CLIENT) {
client_entry = (SilcClientEntry)entry;
memset(buf, 0, sizeof(buf));
signal_emit("message topic", 5, server, channel->channel_name,
tmp, channel->channel_name, channel->channel_name);
}
-
+
silc_free(tmp);
break;
switch (status) {
case SILC_CLIENT_CONN_SUCCESS:
/* We have successfully connected to server */
- if ((client->nickname != NULL) &&
+ if ((client->nickname != NULL) &&
(strcmp(client->nickname, client->username)))
silc_queue_enable(conn); /* enable queueing until we have our nick */
server->connected = TRUE;
return;
/* Print the channel public key list */
- signal_emit("message silc pubkeys", 3,
+ signal_emit("message silc pubkeys", 3,
server, channel_entry, channel_pubkeys);
}
break;
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#include "silc-servers.h"
-void silc_say(SilcClient client, SilcClientConnection conn,
+void silc_say(SilcClient client, SilcClientConnection conn,
SilcClientMessageType type, char *msg, ...);
void silc_say_error(char *msg, ...);
void silc_channel_message(SilcClient client, SilcClientConnection conn,
- SilcClientEntry sender,
- SilcChannelEntry channel,
+ SilcClientEntry sender,
+ SilcChannelEntry channel,
SilcMessagePayload payload,
- SilcMessageFlags flags,
+ SilcChannelPrivateKey key,
+ SilcMessageFlags flags,
const unsigned char *message,
SilcUInt32 message_len);
void silc_private_message(SilcClient client, SilcClientConnection conn,
- SilcClientEntry sender,
+ SilcClientEntry sender,
SilcMessagePayload payload,
- SilcMessageFlags flags,
+ SilcMessageFlags flags,
const unsigned char *message,
SilcUInt32 message_len);
-void silc_notify(SilcClient client, SilcClientConnection conn,
+void silc_notify(SilcClient client, SilcClientConnection conn,
SilcNotifyType type, ...);
-void silc_command(SilcClient client, SilcClientConnection conn,
+void silc_command(SilcClient client, SilcClientConnection conn,
SilcClientCommandContext cmd_context, bool success,
SilcCommand command, SilcStatus status);
void silc_command_reply(SilcClient client, SilcClientConnection conn,
void silc_ask_passphrase(SilcClient client, SilcClientConnection conn,
SilcAskPassphrase completion, void *context);
void silc_verify_public_key(SilcClient client, SilcClientConnection conn,
- SilcSocketType conn_type, unsigned char *pk,
+ SilcSocketType conn_type, unsigned char *pk,
SilcUInt32 pk_len, SilcSKEPKType pk_type,
SilcVerifyPublicKey completion, void *context);
void silc_get_auth_method(SilcClient client, SilcClientConnection conn,
char *hostname, SilcUInt16 port,
SilcGetAuthMeth completion, void *context);
-void silc_failure(SilcClient client, SilcClientConnection conn,
+void silc_failure(SilcClient client, SilcClientConnection conn,
SilcProtocol protocol, void *failure);
bool silc_key_agreement(SilcClient client, SilcClientConnection conn,
SilcClientEntry client_entry, const char *hostname,
const unsigned char *detach_data, SilcUInt32 detach_data_len);
char *
silc_unescape_data(const char *escaped_data, SilcUInt32 *length);
-char *
+char *
silc_escape_data(const char *data, SilcUInt32 len);
char *
return FALSE;
/* Take the key to be used */
- if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY) {
+ if (channel->private_keys) {
if (key) {
/* Use key application specified */
cipher = key->cipher;
hmac = key->hmac;
- } else if (channel->curr_key) {
+ } else if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY &&
+ channel->curr_key) {
/* Use current private key */
cipher = channel->curr_key->cipher;
hmac = channel->curr_key->hmac;
- } else if (!channel->curr_key && channel->private_keys) {
+ } else if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY &&
+ !channel->curr_key && channel->private_keys) {
/* Use just some private key since we don't know what to use
and private keys are set. */
silc_dlist_start(channel->private_keys);
typedef struct {
SilcMessagePayload payload;
SilcChannelID *channel_id;
+ SilcChannelPrivateKey key;
} *SilcChannelClientResolve;
static void silc_client_channel_message_cb(SilcClient client,
/* Pass the message to application */
client->internal->ops->channel_message(
client, conn, clients[0], channel, res->payload,
- silc_message_get_flags(res->payload),
+ res->key, silc_message_get_flags(res->payload),
message, message_len);
}
SilcClientID *client_id = NULL;
unsigned char *message;
SilcUInt32 message_len;
+ SilcChannelPrivateKey key = NULL;
SILC_LOG_DEBUG(("Received channel message"));
/* If there is no channel private key then just decrypt the message
with the channel key. If private keys are set then just go through
all private keys and check what decrypts correctly. */
- if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
+ if (!channel->private_keys) {
/* Parse the channel message payload. This also decrypts the payload */
payload = silc_message_payload_parse(buffer->data, buffer->len, FALSE,
FALSE, channel->channel_key,
if (!payload)
goto out;
}
- } else if (channel->private_keys) {
- SilcChannelPrivateKey entry;
-
- silc_dlist_start(channel->private_keys);
- while ((entry = silc_dlist_get(channel->private_keys)) != SILC_LIST_END) {
- /* Parse the message payload. This also decrypts the payload */
- payload = silc_message_payload_parse(buffer->data, buffer->len,
- FALSE, FALSE,
- entry->cipher, entry->hmac);
- if (payload)
- break;
- }
- if (entry == SILC_LIST_END)
- goto out;
} else {
- goto out;
+ /* If the private key mode, however is not set on the channel then
+ try the actual channel key first before trying private keys. */
+ if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY))
+ payload = silc_message_payload_parse(buffer->data, buffer->len, FALSE,
+ FALSE, channel->channel_key,
+ channel->hmac);
+
+ if (!payload) {
+ silc_dlist_start(channel->private_keys);
+ while ((key = silc_dlist_get(channel->private_keys))
+ != SILC_LIST_END) {
+ /* Parse the message payload. This also decrypts the payload */
+ payload = silc_message_payload_parse(buffer->data, buffer->len,
+ FALSE, FALSE,
+ key->cipher, key->hmac);
+ if (payload)
+ break;
+ }
+ if (key == SILC_LIST_END)
+ goto out;
+ }
}
/* Find client entry */
SilcChannelClientResolve res = silc_calloc(1, sizeof(*res));
res->payload = payload;
res->channel_id = id;
+ res->key = key;
silc_client_get_client_by_id_resolve(client, conn, client_id, NULL,
silc_client_channel_message_cb,
res);
/* Pass the message to application */
client->internal->ops->channel_message(
client, conn, client_entry, channel, payload,
- silc_message_get_flags(payload),
+ key, silc_message_get_flags(payload),
message, message_len);
out:
silc_client_save_channel_key(client, sock->user_data, packet, NULL);
}
-/* Adds private key for channel. This may be set only if the channel's mode
- mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
- mode is not set. When channel has private key then the messages are
- encrypted using that key. All clients on the channel must also know the
- key in order to decrypt the messages. However, it is possible to have
- several private keys per one channel. In this case only some of the
- clients on the channel may know the one key and only some the other key.
+/* Adds private key for channel. When channel has private key then the
+ messages are encrypted using that key. All clients on the channel must
+ also know the key in order to decrypt the messages. However, it is
+ possible to have several private keys per one channel. In this case
+ only some of the clients on the channel may know the one key and only
+ some the other key.
If `cipher' and/or `hmac' is NULL then default values will be used
(aes-256-cbc for cipher and hmac-sha1-96 for hmac).
assert(client && channel);
- if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY))
- return FALSE;
-
if (!cipher)
cipher = SILC_DEFAULT_CIPHER;
if (!hmac)
!= SILC_SKE_STATUS_OK)
return FALSE;
- /* Remove the current key, if it exists. */
- if (channel->channel_key) {
- silc_cipher_free(channel->channel_key);
- memset(channel->key, 0, channel->key_len / 8);
- silc_free(channel->key);
- channel->channel_key = NULL;
- channel->key = NULL;
- channel->key_len = 0;
- }
- if (channel->hmac) {
- silc_hmac_free(channel->hmac);
- channel->hmac = NULL;
- }
-
if (!channel->private_keys)
channel->private_keys = silc_dlist_init();
static void
silc_channel_message(SilcClient client, SilcClientConnection conn,
SilcClientEntry sender, SilcChannelEntry channel,
- SilcMessagePayload payload, SilcMessageFlags flags,
- const unsigned char *message, SilcUInt32 message_len)
+ SilcMessagePayload payload, SilcChannelPrivateKey key,
+ SilcMessageFlags flags, const unsigned char *message,
+ SilcUInt32 message_len)
{
}
/* Private message to the client. The `sender' is the sender of the
- message. The message is `message'and maybe NULL. The `flags'
+ message. The message is `message'and maybe NULL. The `flags'
indicates message flags and it is used to determine how the message
can be interpreted (like it may tell the message is multimedia
message). */
client_mode_list->head);
/* Save channel key */
- if (keyp && !(channel->mode & SILC_CHANNEL_MODE_PRIVKEY))
+ if (keyp)
silc_client_save_channel_key(cmd->client, conn, keyp, channel);
/* Get founder key */
(like it may tell the message is multimedia message). */
void (*channel_message)(SilcClient client, SilcClientConnection conn,
SilcClientEntry sender, SilcChannelEntry channel,
- SilcMessagePayload payload, SilcMessageFlags flags,
+ SilcMessagePayload payload,
+ SilcChannelPrivateKey key, SilcMessageFlags flags,
const unsigned char *message,
SilcUInt32 message_len);
*
* DESCRIPTION
*
- * Adds private key for channel. This may be set only if the channel's mode
- * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
- * mode is not set. When channel has private key then the messages are
- * encrypted using that key. All clients on the channel must also know the
- * key in order to decrypt the messages. However, it is possible to have
- * several private keys per one channel. In this case only some of the
- * clients on the channel may know the one key and only some the other key.
- * The `name' can be application given name for the key. This returns
- * the created key to the 'ret_key' pointer if it is non-NULL;
+ * Adds private key for channel. When channel has private key then the
+ * messages are encrypted using that key. All clients on the channel
+ * must also know the key in order to decrypt the messages. However,
+ * it is possible to have several private keys per one channel. In this
+ * case only some of the clients on the channel may know the one key
+ * and only some the other key. The `name' can be application given
+ * name for the key. This returns the created key to the 'ret_key'
+ * pointer if it is non-NULL;
*
* If `cipher' and/or `hmac' is NULL then default values will be used
* (aes-256-cbc for cipher and hmac-sha1-96 for hmac).