From c8ff4cf35991cc9983ff5415609e5c4d1ff65e4a Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 2 Dec 2002 21:48:25 +0000 Subject: [PATCH] Added support for automatically parsing and encoding signature payload for channel and private messages. Redefined the signature payload, updated specs and implemented. --- CHANGES | 15 +++ apps/irssi/docs/help/in/msg.in | 16 ++- apps/irssi/docs/help/in/smsg.in | 18 +++ apps/irssi/src/core/chat-commands.c | 2 +- apps/irssi/src/silc/core/client_ops.c | 24 +++- apps/irssi/src/silc/core/client_ops.h | 2 + apps/irssi/src/silc/core/silc-servers.c | 83 ++++++++++++- apps/silcd/command_reply.c | 2 +- apps/silcd/packet_send.c | 5 +- lib/silcclient/client_channel.c | 15 +-- lib/silcclient/client_ops_example.c | 8 +- lib/silcclient/client_prvmsg.c | 7 +- lib/silcclient/silcclient.h | 11 +- lib/silccore/silcmessage.c | 159 ++++++++++++++++++------ lib/silccore/silcmessage.h | 96 +++++++++----- tutorial/mybot/mybot.c | 4 +- 16 files changed, 370 insertions(+), 97 deletions(-) create mode 100644 apps/irssi/docs/help/in/smsg.in diff --git a/CHANGES b/CHANGES index 68e6cfca..a9cfe404 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,21 @@ Mon Dec 2 20:50:20 EET 2002 Pekka Riikonen notify. Affected file lib/silcclient/client_notify.c. Fixes bug in '@' character handling in a nickname. + * Added support for automatically parsing signature from + the message payload. Added new function + silc_message_get_signature to return the payload to + application. Affected files lib/silccore/silcmessage.[ch]. + + * Changed the private_message and channel_message client + operations to deliver the SilcMessagePayload to the + application too. Application can use it fe. to get the + signature from the message for verification. Affected + file lib/silcclient/silcclient.h, client_channel.c and + client_prvmsg.c. + + * Redefined the signed payload for message payloads. + Updated protocol specs and implemented. + Mon Dec 2 16:28:29 EET 2002 Pekka Riikonen * Fixed wrong invite and ban list handling in server command diff --git a/apps/irssi/docs/help/in/msg.in b/apps/irssi/docs/help/in/msg.in index 153d82e8..fb7c4fc7 100644 --- a/apps/irssi/docs/help/in/msg.in +++ b/apps/irssi/docs/help/in/msg.in @@ -1,10 +1,22 @@ @SYNTAX:msg@ -Sends a private message to someone. +Sends a private message to other user in the network. + +It is possible to digitally sign your messages. The receiver +may then verify the message with your public key. By default +messages are not signed. If you want your private messages +to be signed you SMSG command instead of this MSG command. + +If -channel option is provided then this command actually +send channel message to the specified channel. The message +IS NOT private message, it is normal channel message. It is +also possible to digitally sign channel messages by using +SMSG command or by doing /set sign_channel_messages on, in +which case _all_ channel messages will be signed. Example: /MSG Toni Hi, what's up? -See also: QUERY +See also: QUERY SMSG diff --git a/apps/irssi/docs/help/in/smsg.in b/apps/irssi/docs/help/in/smsg.in new file mode 100644 index 00000000..1bdad4eb --- /dev/null +++ b/apps/irssi/docs/help/in/smsg.in @@ -0,0 +1,18 @@ + +@SYNTAX:smsg@ + +Sends a signed private message to other user in the network. +The message will be digitally signed and the receiver may verify +the message by using your public key. + +If -channel option is provided then this command actually +send channel message to the specified channel. The message +IS NOT private message, it is normal channel message. Also this +message will be signed and can be verified by using your public +key. + +Example: + +/SMSG Foobar Very authenticated message + +See also: MSG QUERY diff --git a/apps/irssi/src/core/chat-commands.c b/apps/irssi/src/core/chat-commands.c index e26df6cd..722d3df5 100644 --- a/apps/irssi/src/core/chat-commands.c +++ b/apps/irssi/src/core/chat-commands.c @@ -319,7 +319,7 @@ static void cmd_join(const char *data, SERVER_REC *server) cmd_params_free(free_arg); } -/* SYNTAX: MSG [-] [-channel | -nick] */ +/* SYNTAX: MSG [-channel] */ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { GHashTable *optlist; diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index a21963ea..41418bc5 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -158,6 +158,7 @@ void silc_say_error(char *msg, ...) void silc_channel_message(SilcClient client, SilcClientConnection conn, SilcClientEntry sender, SilcChannelEntry channel, + SilcMessagePayload payload, SilcMessageFlags flags, const unsigned char *message, SilcUInt32 message_len) { @@ -183,6 +184,18 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn, nick = silc_nicklist_insert(chanrec, chu, FALSE); } + /* If the messages is digitally signed, verify it, if possible. */ + if (flags & SILC_MESSAGE_FLAG_SIGNED) { + SilcMessageSignedPayload sig = silc_message_get_signature(payload); +/* + if (sig) { + if (silc_message_signed_verify(sig, payload, client->public_key, + client->sha1hash) != SILC_AUTH_OK) + silc_say_error(("Could not verify signature in message")); + } +*/ + } + if (flags & SILC_MESSAGE_FLAG_DATA) { /* MIME object received, try to display it as well as we can */ char type[128], enc[128]; @@ -251,7 +264,8 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn, sender received in the packet. */ void silc_private_message(SilcClient client, SilcClientConnection conn, - SilcClientEntry sender, SilcMessageFlags flags, + SilcClientEntry sender, SilcMessagePayload payload, + SilcMessageFlags flags, const unsigned char *message, SilcUInt32 message_len) { @@ -266,6 +280,14 @@ void silc_private_message(SilcClient client, SilcClientConnection conn, snprintf(userhost, sizeof(userhost) - 1, "%s@%s", sender->username, sender->hostname); + /* If the messages is digitally signed, verify it, if possible. */ + if (flags & SILC_MESSAGE_FLAG_SIGNED) { + SilcMessageSignedPayload sig = silc_message_get_signature(payload); + if (sig) { + + } + } + if (flags & SILC_MESSAGE_FLAG_DATA) { /* MIME object received, try to display it as well as we can */ char type[128], enc[128]; diff --git a/apps/irssi/src/silc/core/client_ops.h b/apps/irssi/src/silc/core/client_ops.h index 68e2b09e..8c3f7630 100644 --- a/apps/irssi/src/silc/core/client_ops.h +++ b/apps/irssi/src/silc/core/client_ops.h @@ -27,11 +27,13 @@ void silc_say_error(char *msg, ...); void silc_channel_message(SilcClient client, SilcClientConnection conn, SilcClientEntry sender, SilcChannelEntry channel, + SilcMessagePayload payload, SilcMessageFlags flags, const unsigned char *message, SilcUInt32 message_len); void silc_private_message(SilcClient client, SilcClientConnection conn, SilcClientEntry sender, + SilcMessagePayload payload, SilcMessageFlags flags, const unsigned char *message, SilcUInt32 message_len); diff --git a/apps/irssi/src/silc/core/silc-servers.c b/apps/irssi/src/silc/core/silc-servers.c index 4d68aeb0..ec9addf4 100644 --- a/apps/irssi/src/silc/core/silc-servers.c +++ b/apps/irssi/src/silc/core/silc-servers.c @@ -51,7 +51,8 @@ void silc_servers_reconnect_init(void); void silc_servers_reconnect_deinit(void); static void silc_send_channel(SILC_SERVER_REC *server, - char *channel, char *msg) + char *channel, char *msg, + SilcMessageFlags flags) { SILC_CHANNEL_REC *rec; @@ -62,8 +63,7 @@ static void silc_send_channel(SILC_SERVER_REC *server, } silc_client_send_channel_message(silc_client, server->conn, rec->entry, - NULL, SILC_MESSAGE_FLAG_UTF8, - msg, strlen(msg), TRUE); + NULL, flags, msg, strlen(msg), TRUE); } typedef struct { @@ -135,7 +135,7 @@ static void silc_send_msg_clients(SilcClient client, } static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg, - int msg_len, SilcMessageFlags flags) + int msg_len, SilcMessageFlags flags) { PRIVMSG_REC *rec; SilcClientEntry *clients; @@ -249,7 +249,8 @@ static void send_message(SILC_SERVER_REC *server, char *target, } if (target_type == SEND_TARGET_CHANNEL) - silc_send_channel(server, target, message ? message : msg); + silc_send_channel(server, target, message ? message : msg, + SILC_MESSAGE_FLAG_UTF8); else silc_send_msg(server, target, message ? message : msg, message ? strlen(message) : strlen(msg), @@ -444,6 +445,7 @@ char *silc_server_get_channels(SILC_SERVER_REC *server) /* SYNTAX: WATCH [<-add | -del> ] */ /* SYNTAX: STATS */ /* SYNTAX: ATTR [<-del>