/*
- client_prvmsg.c
+ client_prvmsg.c
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2002 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
message. The `data' is the private message. If the `force_send' is
TRUE the packet is sent immediately. */
-void silc_client_send_private_message(SilcClient client,
+SilcBool silc_client_send_private_message(SilcClient client,
SilcClientConnection conn,
SilcClientEntry client_entry,
SilcMessageFlags flags,
- unsigned char *data,
- SilcUInt32 data_len,
- bool force_send)
+ unsigned char *data,
+ SilcUInt32 data_len,
+ SilcBool force_send)
{
SilcSocketConnection sock;
SilcBuffer buffer;
SilcCipher cipher;
SilcHmac hmac;
int block_len;
+ SilcBool ret = FALSE;
assert(client && conn && client_entry);
sock = conn->sock;
!client_entry->generated,
TRUE, client_entry->send_key,
client_entry->hmac_send,
- client->rng);
+ client->rng, NULL, client->private_key,
+ client->sha1hash);
+ if (!buffer) {
+ SILC_LOG_ERROR(("Error encoding private message"));
+ return FALSE;
+ }
/* If we don't have private message specific key then private messages
are just as any normal packet thus call normal packet sending. If
silc_client_packet_send(client, sock, SILC_PACKET_PRIVATE_MESSAGE,
client_entry->id, SILC_ID_CLIENT, NULL, NULL,
buffer->data, buffer->len, force_send);
+ ret = TRUE;
goto out;
}
data_len = SILC_PACKET_DATALEN(data_len, SILC_PACKET_HEADER_LEN +
packetdata.src_id_len +
packetdata.dst_id_len);
- packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
+ packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
packetdata.src_id_len + packetdata.dst_id_len;
SILC_PACKET_PADLEN((SILC_PACKET_HEADER_LEN +
packetdata.src_id_len +
packetdata.dst_id_len), block_len, packetdata.padlen);
/* Create the outgoing packet */
- if (!silc_packet_assemble(&packetdata, client->rng, cipher, hmac, sock,
+ if (!silc_packet_assemble(&packetdata, client->rng, cipher, hmac, sock,
data, data_len, (const SilcBuffer)&packet)) {
SILC_LOG_ERROR(("Error assembling packet"));
goto out;
silc_free(packetdata.dst_id);
+ ret = TRUE;
+
out:
silc_buffer_free(buffer);
-}
+
+ return ret;
+}
static void silc_client_private_message_cb(SilcClient client,
SilcClientConnection conn,
/* Private message received. This processes the private message and
finally displays it on the screen. */
-void silc_client_private_message(SilcClient client,
- SilcSocketConnection sock,
+void silc_client_private_message(SilcClient client,
+ SilcSocketConnection sock,
SilcPacketContext *packet)
{
SilcClientConnection conn = (SilcClientConnection)sock->user_data;
if (packet->src_id_type != SILC_ID_CLIENT)
goto out;
- remote_id = silc_id_str2id(packet->src_id, packet->src_id_len,
+ remote_id = silc_id_str2id(packet->src_id, packet->src_id_len,
SILC_ID_CLIENT);
if (!remote_id)
goto out;
/* Pass the private message to application */
message = silc_message_get_data(payload, &message_len);
- client->internal->ops->private_message(client, conn, remote_client, flags,
- message, message_len);
+ client->internal->ops->private_message(client, conn, remote_client, payload,
+ flags, message, message_len);
/* See if we are away (gone). If we are away we will reply to the
sender with the set away message. */
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);
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,
if (packet->src_id_type != SILC_ID_CLIENT)
return;
- remote_id = silc_id_str2id(packet->src_id, packet->src_id_len,
+ remote_id = silc_id_str2id(packet->src_id, packet->src_id_len,
SILC_ID_CLIENT);
if (!remote_id)
return;
It is not necessary to set key for normal private message usage. If the
key is not set then the private messages are encrypted using normal
- session keys. Setting the private key, however, increases the security.
+ session keys. Setting the private key, however, increases the security.
Returns FALSE if the key is already set for the `client_entry', TRUE
otherwise. */
-bool silc_client_add_private_message_key(SilcClient client,
+SilcBool silc_client_add_private_message_key(SilcClient client,
SilcClientConnection conn,
SilcClientEntry client_entry,
const char *cipher,
const char *hmac,
unsigned char *key,
SilcUInt32 key_len,
- bool generate_key,
- bool responder)
+ SilcBool generate_key,
+ SilcBool responder)
{
unsigned char private_key[32];
SilcUInt32 len;
/* Produce the key material as the protocol defines */
keymat = silc_calloc(1, sizeof(*keymat));
- if (silc_ske_process_key_material_data(key, key_len, 16, 256, 16,
- client->md5hash, keymat)
+ if (silc_ske_process_key_material_data(key, key_len, 16, 256, 16,
+ client->sha1hash, keymat)
!= SILC_SKE_STATUS_OK)
return FALSE;
`cipher' and `hmac' SHOULD be provided as it is negotiated also in
the SKE protocol. */
-bool silc_client_add_private_message_key_ske(SilcClient client,
+SilcBool silc_client_add_private_message_key_ske(SilcClient client,
SilcClientConnection conn,
SilcClientEntry client_entry,
const char *cipher,
const char *hmac,
SilcSKEKeyMaterial *key,
- bool responder)
+ SilcBool responder)
{
assert(client && client_entry);
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)
+SilcBool silc_client_send_private_message_key_request(SilcClient client,
+ SilcClientConnection conn,
+ SilcClientEntry client_entry)
{
SilcSocketConnection sock;
SilcBuffer buffer;
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);
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),
/* 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;
after this to protect the private messages with the remote `client_entry'
client. Returns FALSE on error, TRUE otherwise. */
-bool silc_client_del_private_message_key(SilcClient client,
+SilcBool silc_client_del_private_message_key(SilcClient client,
SilcClientConnection conn,
SilcClientEntry client_entry)
{
/* Returns array of set private message keys associated to the connection
`conn'. Returns allocated SilcPrivateMessageKeys array and the array
count to the `key_count' argument. The array must be freed by the caller
- by calling the silc_client_free_private_message_keys function. Note:
+ by calling the silc_client_free_private_message_keys function. Note:
the keys returned in the array is in raw format. It might not be desired
to show the keys as is. The application might choose not to show the keys
at all or to show the fingerprints of the keys. */
to anyone who sends private message. The `message' will be sent
automatically back to the the client who send private message. If
away message is already set this replaces the old message with the
- new one. If `message' is NULL the old away message is removed.
+ new one. If `message' is NULL the old away message is removed.
The sender may freely free the memory of the `message'. */
void silc_client_set_away_message(SilcClient client,