1 /****h* silcclient/silcapi.h
9 * Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
11 * Copyright (C) 2000 - 2001 Pekka Riikonen
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
25 * This file defines the SILC Client Library API for the application. The
26 * client operations are defined first. These are callback functions that
27 * the application MUST implement since the library may call the functions
28 * at any time. At the end of file is the API for the application that
29 * it can use from the library. This is the only file that the application
30 * may include from the SIlC Client Library.
32 * o SILC Client Operations
34 * These functions must be implemented by the application calling the SILC
35 * client library. The client library can call these functions at any time.
37 * To use this structure: define a static SilcClientOperations variable,
38 * fill it and pass its pointer to silc_client_alloc function.
40 * o SILC Client Library API
42 * This is the API that is published by the SILC Client Library for the
43 * applications. These functions are implemented in the SILC Client Library.
44 * Application may freely call these functions from the library.
46 * Please, refer to the README file in this directory for the directions
47 * of how to use the SILC Client Library.
54 #include "clientlibincludes.h"
56 /* General definitions */
58 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
62 * typedef enum { ... } SilcKeyAgreementStatus;
66 * Key agreement status types indicating the status of the key
67 * agreement protocol. These types are returned to the application
68 * in the SilcKeyAgreementCallback callback function.
73 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
74 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
75 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
76 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
77 } SilcKeyAgreementStatus;
80 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
84 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
85 * SilcClientConnection conn,
86 * SilcClientEntry client_entry,
87 * SilcKeyAgreementStatus status,
88 * SilcSKEKeyMaterial *key,
93 * Key agreement callback that is called after the key agreement protocol
94 * has been performed. This is called also if error occurred during the
95 * key agreement protocol. The `key' is the allocated key material and
96 * the caller is responsible of freeing it. The `key' is NULL if error
97 * has occurred. The application can freely use the `key' to whatever
98 * purpose it needs. See lib/silcske/silcske.h for the definition of
99 * the SilcSKEKeyMaterial structure.
102 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
103 SilcClientConnection conn,
104 SilcClientEntry client_entry,
105 SilcKeyAgreementStatus status,
106 SilcSKEKeyMaterial *key,
109 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
113 * typedef struct { ... } SilcPrivateMessageKeys;
117 * Structure to hold the list of private message keys. The array of this
118 * structure is returned by the silc_client_list_private_message_keys
124 SilcClientEntry client_entry; /* The remote client entry */
125 char *cipher; /* The cipher name */
126 unsigned char *key; /* The original key, If the appliation
127 provided it. This is NULL if the
128 library generated the key or if
129 the SKE key material was used. */
130 uint32 key_len; /* The key length */
131 } *SilcPrivateMessageKeys;
135 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
139 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
140 * uint32 passphrase_len,
145 * Ask passphrase callback. This is called by the application when the
146 * library calls `ask_passphrase' client operation. The callback delivers
147 * the passphrase to the library.
150 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
151 uint32 passphrase_len,
154 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
158 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
162 * Public key (or certificate) verification callback. This is called
163 * by the application to indicate that the public key verification was
164 * either success or failure.
167 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
169 /****s* silcclient/SilcClientAPI/SilcClientOperations
173 * typedef struct { ... } SilcClientOperations;
177 * SILC Client Operations. These must be implemented by the application.
178 * The Client library may call any of these routines at any time. The
179 * routines are used to deliver certain information to the application
180 * or from the application to the client library.
185 /* Message sent to the application by library. `conn' associates the
186 message to a specific connection. `conn', however, may be NULL. */
187 void (*say)(SilcClient client, SilcClientConnection conn, char *msg, ...);
189 /* Message for a channel. The `sender' is the sender of the message
190 The `channel' is the channel. */
191 void (*channel_message)(SilcClient client, SilcClientConnection conn,
192 SilcClientEntry sender, SilcChannelEntry channel,
193 SilcMessageFlags flags, char *msg);
195 /* Private message to the client. The `sender' is the sender of the
197 void (*private_message)(SilcClient client, SilcClientConnection conn,
198 SilcClientEntry sender, SilcMessageFlags flags,
201 /* Notify message to the client. The notify arguments are sent in the
202 same order as servers sends them. The arguments are same as received
203 from the server except for ID's. If ID is received application receives
204 the corresponding entry to the ID. For example, if Client ID is received
205 application receives SilcClientEntry. Also, if the notify type is
206 for channel the channel entry is sent to application (even if server
207 does not send it because client library gets the channel entry from
208 the Channel ID in the packet's header). */
209 void (*notify)(SilcClient client, SilcClientConnection conn,
210 SilcNotifyType type, ...);
212 /* Command handler. This function is called always in the command function.
213 If error occurs it will be called as well. `conn' is the associated
214 client connection. `cmd_context' is the command context that was
215 originally sent to the command. `success' is FALSE if error occurred
216 during command. `command' is the command being processed. It must be
217 noted that this is not reply from server. This is merely called just
218 after application has called the command. Just to tell application
219 that the command really was processed. */
220 void (*command)(SilcClient client, SilcClientConnection conn,
221 SilcClientCommandContext cmd_context, int success,
222 SilcCommand command);
224 /* Command reply handler. This function is called always in the command reply
225 function. If error occurs it will be called as well. Normal scenario
226 is that it will be called after the received command data has been parsed
227 and processed. The function is used to pass the received command data to
230 `conn' is the associated client connection. `cmd_payload' is the command
231 payload data received from server and it can be ignored. It is provided
232 if the application would like to re-parse the received command data,
233 however, it must be noted that the data is parsed already by the library
234 thus the payload can be ignored. `success' is FALSE if error occurred.
235 In this case arguments are not sent to the application. The `status' is
236 the command reply status server returned. The `command' is the command
237 reply being processed. The function has variable argument list and each
238 command defines the number and type of arguments it passes to the
239 application (on error they are not sent). */
240 void (*command_reply)(SilcClient client, SilcClientConnection conn,
241 SilcCommandPayload cmd_payload, int success,
242 SilcCommand command, SilcCommandStatus status, ...);
244 /* Called to indicate that connection was either successfully established
245 or connecting failed. This is also the first time application receives
246 the SilcClientConnection objecet which it should save somewhere. */
247 void (*connect)(SilcClient client, SilcClientConnection conn, int success);
249 /* Called to indicate that connection was disconnected to the server. */
250 void (*disconnect)(SilcClient client, SilcClientConnection conn);
252 /* Find authentication method and authentication data by hostname and
253 port. The hostname may be IP address as well. The found authentication
254 method and authentication data is returned to `auth_meth', `auth_data'
255 and `auth_data_len'. The function returns TRUE if authentication method
256 is found and FALSE if not. `conn' may be NULL. */
257 int (*get_auth_method)(SilcClient client, SilcClientConnection conn,
258 char *hostname, uint16 port,
259 SilcProtocolAuthMeth *auth_meth,
260 unsigned char **auth_data,
261 uint32 *auth_data_len);
263 /* Verifies received public key. The `conn_type' indicates which entity
264 (server, client etc.) has sent the public key. If user decides to trust
265 the key may be saved as trusted public key for later use. The
266 `completion' must be called after the public key has been verified. */
267 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
268 SilcSocketType conn_type, unsigned char *pk,
269 uint32 pk_len, SilcSKEPKType pk_type,
270 SilcVerifyPublicKey completion, void *context);
272 /* Ask (interact, that is) a passphrase from user. The passphrase is
273 returned to the library by calling the `completion' callback with
275 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
276 SilcAskPassphrase completion, void *context);
278 /* Notifies application that failure packet was received. This is called
279 if there is some protocol active in the client. The `protocol' is the
280 protocol context. The `failure' is opaque pointer to the failure
281 indication. Note, that the `failure' is protocol dependant and
282 application must explicitly cast it to correct type. Usually `failure'
283 is 32 bit failure type (see protocol specs for all protocol failure
285 void (*failure)(SilcClient client, SilcClientConnection conn,
286 SilcProtocol protocol, void *failure);
288 /* Asks whether the user would like to perform the key agreement protocol.
289 This is called after we have received an key agreement packet or an
290 reply to our key agreement packet. This returns TRUE if the user wants
291 the library to perform the key agreement protocol and FALSE if it is not
292 desired (application may start it later by calling the function
293 silc_client_perform_key_agreement). If TRUE is returned also the
294 `completion' and `context' arguments must be set by the application. */
295 int (*key_agreement)(SilcClient client, SilcClientConnection conn,
296 SilcClientEntry client_entry, char *hostname,
298 SilcKeyAgreementCallback *completion,
300 } SilcClientOperations;
303 /* Initialization functions (client.c) */
305 /****f* silcclient/SilcClientAPI/silc_client_alloc
309 * SilcClient silc_client_alloc(SilcClientOperations *ops,
310 * void *application);
314 * Allocates new client object. This has to be done before client may
315 * work. After calling this one must call silc_client_init to initialize
316 * the client. The `application' is application specific user data pointer
317 * and caller must free it. The `silc_version' is the application version
318 * that will be used to compare against remote host's (usually a server)
322 SilcClient silc_client_alloc(SilcClientOperations *ops, void *application,
323 const char *silc_version);
325 /****f* silcclient/SilcClientAPI/silc_client_free
329 * void silc_client_free(SilcClient client);
333 * Frees client object and its internals. The execution of the client
334 * should be stopped with silc_client_stop function before calling
338 void silc_client_free(SilcClient client);
340 /****f* silcclient/SilcClientAPI/silc_client_init
344 * int silc_client_init(SilcClient client);
348 * Initializes the client. This makes all the necessary steps to make
349 * the client ready to be run. One must call silc_client_run to run the
350 * client. Returns FALSE if error occurred, TRUE otherwise.
353 int silc_client_init(SilcClient client);
355 /****f* silcclient/SilcClientAPI/silc_client_run
359 * void silc_client_run(SilcClient client);
363 * Runs the client. This starts the scheduler from the utility library.
364 * When this functions returns the execution of the appliation is over.
367 void silc_client_run(SilcClient client);
369 /****f* silcclient/SilcClientAPI/silc_client_stop
373 * void silc_client_stop(SilcClient client);
377 * Stops the client. This is called to stop the client and thus to stop
378 * the program. The client context must be freed with the silc_client_free
382 void silc_client_stop(SilcClient client);
385 /* Connecting functions (client.c) */
387 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
391 * int silc_client_connect_to_server(SilcClient client, int port,
392 * char *host, void *context);
396 * Connects to remote server. This is the main routine used to connect
397 * to SILC server. Returns -1 on error and the created socket otherwise.
398 * The `context' is user context that is saved into the SilcClientConnection
399 * that is created after the connection is created. Note that application
400 * may handle the connecting process outside the library. If this is the
401 * case then this function is not used at all. When the connecting is
402 * done the `connect' client operation is called.
405 int silc_client_connect_to_server(SilcClient client, int port,
406 char *host, void *context);
408 /****f* silcclient/SilcClientAPI/silc_client_add_connection
412 * SilcClientConnection silc_client_add_connection(SilcClient client,
419 * Allocates and adds new connection to the client. This adds the allocated
420 * connection to the connection table and returns a pointer to it. A client
421 * can have multiple connections to multiple servers. Every connection must
422 * be added to the client using this function. User data `context' may
423 * be sent as argument. This function is normally used only if the
424 * application performed the connecting outside the library. The library
425 * however may use this internally.
428 SilcClientConnection silc_client_add_connection(SilcClient client,
433 /****f* silcclient/SilcClientAPI/silc_client_del_connection
437 * void silc_client_del_connection(SilcClient client,
438 * SilcClientConnection conn);
442 * Removes connection from client. Frees all memory. The library
443 * call this function automatically for all connection contexts.
444 * The application however may free the connection contexts it has
448 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
450 /****f* silcclient/SilcClientAPI/silc_client_add_socket
454 * void silc_client_add_socket(SilcClient client,
455 * SilcSocketConnection sock);
459 * Adds listener socket to the listener sockets table. This function is
460 * used to add socket objects that are listeners to the client. This should
461 * not be used to add other connection objects.
464 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
466 /****f* silcclient/SilcClientAPI/silc_client_del_socket
470 * void silc_client_del_socket(SilcClient client,
471 * SilcSocketConnection sock);
475 * Deletes listener socket from the listener sockets table. If the
476 * application has added a socket with silc_client_add_socket it must
477 * also free it using this function.
480 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
482 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
486 * int silc_client_start_key_exchange(SilcClient client,
487 * SilcClientConnection conn,
492 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
493 * key material between client and server. This function can be called
494 * directly if application is performing its own connecting and does not
495 * use the connecting provided by this library. This function is normally
496 * used only if the application performed the connecting outside the
497 * library. The library however may use this internally.
500 int silc_client_start_key_exchange(SilcClient client,
501 SilcClientConnection conn,
504 /****f* silcclient/SilcClientAPI/silc_client_close_connection
508 * void silc_client_close_connection(SilcClient client,
509 * SilcSocketConnection sock,
510 * SilcClientConnection conn);
514 * Closes connection to remote end. Free's all allocated data except
515 * for some information such as nickname etc. that are valid at all time.
516 * If the `sock' is NULL then the conn->sock will be used. If `sock' is
517 * provided it will be checked whether the sock and `conn->sock' are the
518 * same (they can be different, ie. a socket can use `conn' as its
519 * connection but `conn->sock' might be actually a different connection
523 void silc_client_close_connection(SilcClient client,
524 SilcSocketConnection sock,
525 SilcClientConnection conn);
528 /* Message sending functions (client_channel.c and client_prvmsg.c) */
530 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
534 * void silc_client_send_channel_message(SilcClient client,
535 * SilcClientConnection conn,
536 * SilcChannelEntry channel,
537 * SilcChannelPrivateKey key,
538 * SilcMessageFlags flags,
539 * unsigned char *data,
545 * Sends packet to the `channel'. Packet to channel is always encrypted
546 * differently from "normal" packets. SILC header of the packet is
547 * encrypted with the next receiver's key and the rest of the packet is
548 * encrypted with the channel specific key. Padding and HMAC is computed
549 * with the next receiver's key. The `data' is the channel message. If
550 * the `force_send' is TRUE then the packet is sent immediately.
552 * If `key' is provided then that private key is used to encrypt the
553 * channel message. If it is not provided, private keys has not been
554 * set at all, the normal channel key is used automatically. If private
555 * keys are set then the first key (the key that was added first as
556 * private key) is used.
559 void silc_client_send_channel_message(SilcClient client,
560 SilcClientConnection conn,
561 SilcChannelEntry channel,
562 SilcChannelPrivateKey key,
563 SilcMessageFlags flags,
568 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
572 * void silc_client_send_private_message(SilcClient client,
573 * SilcClientConnection conn,
574 * SilcClientEntry client_entry,
575 * SilcMessageFlags flags,
576 * unsigned char *data,
582 * Sends private message to remote client. If private message key has
583 * not been set with this client then the message will be encrypted using
584 * normal session keys. Private messages are special packets in SILC
585 * network hence we need this own function for them. This is similar
586 * to silc_client_packet_send_to_channel except that we send private
587 * message. The `data' is the private message. If the `force_send' is
588 * TRUE the packet is sent immediately.
591 void silc_client_send_private_message(SilcClient client,
592 SilcClientConnection conn,
593 SilcClientEntry client_entry,
594 SilcMessageFlags flags,
600 /* Client and Channel entry retrieval (idlist.c) */
602 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
606 * typedef void (*SilcGetClientCallback)(SilcClient client,
607 * SilcClientConnection conn,
608 * SilcClientEntry *clients,
609 * uint32 clients_count,
614 * Callback function given to the silc_client_get_client function. The
615 * found entries are allocated into the `clients' array. The array must
616 * not be freed by the caller, the library will free it later. If the
617 * `clients' is NULL, no such clients exist in the SILC Network.
620 typedef void (*SilcGetClientCallback)(SilcClient client,
621 SilcClientConnection conn,
622 SilcClientEntry *clients,
623 uint32 clients_count,
626 /****f* silcclient/SilcClientAPI/silc_client_get_clients
630 * void silc_client_get_clients(SilcClient client,
631 * SilcClientConnection conn,
634 * SilcGetClientCallback completion,
639 * Finds client entry or entries by the `nickname' and `server'. The
640 * completion callback will be called when the client entries has been
645 * NOTE: This function is always asynchronous and resolves the client
646 * information from the server. Thus, if you already know the client
647 * information then use the silc_client_get_client_by_id function to
648 * get the client entry since this function may be very slow and should
649 * be used only to initially get the client entries.
652 void silc_client_get_clients(SilcClient client,
653 SilcClientConnection conn,
656 SilcGetClientCallback completion,
659 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
663 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
664 * SilcClientConnection conn,
667 * uint32 *clients_count);
671 * Same as silc_client_get_clients function but does not resolve anything
672 * from the server. This checks local cache and returns all clients from
676 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
677 SilcClientConnection conn,
680 uint32 *clients_count);
682 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
686 * void silc_client_get_clients_by_list(SilcClient client,
687 * SilcClientConnection conn,
689 * SilcBuffer client_id_list,
690 * SilcGetClientCallback completion,
695 * Gets client entries by the list of client ID's `client_id_list'. This
696 * always resolves those client ID's it does not know yet from the server
697 * so this function might take a while. The `client_id_list' is a list
698 * of ID Payloads added one after other. JOIN command reply and USERS
699 * command reply for example returns this sort of list. The `completion'
700 * will be called after the entries are available.
703 void silc_client_get_clients_by_list(SilcClient client,
704 SilcClientConnection conn,
706 SilcBuffer client_id_list,
707 SilcGetClientCallback completion,
710 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
714 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
715 * SilcClientConnection conn,
716 * SilcClientID *client_id);
720 * Find entry for client by the client's ID. Returns the entry or NULL
721 * if the entry was not found.
724 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
725 SilcClientConnection conn,
726 SilcClientID *client_id);
728 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
733 * silc_client_get_client_by_id_resolve(SilcClient client,
734 * SilcClientConnection conn,
735 * SilcClientID *client_id,
736 * SilcGetClientCallback completion,
741 * Same as silc_client_get_client_by_id but will always resolve the
742 * information from the server. Use this only if you know that you
743 * do not have the entry and the only thing you know about the client
747 void silc_client_get_client_by_id_resolve(SilcClient client,
748 SilcClientConnection conn,
749 SilcClientID *client_id,
750 SilcGetClientCallback completion,
753 /****f* silcclient/SilcClientAPI/silc_client_get_channel
757 * SilcChannelEntry silc_client_get_channel(SilcClient client,
758 * SilcClientConnection conn,
763 * Finds entry for channel by the channel name. Returns the entry or NULL
764 * if the entry was not found. It is found only if the client is joined
768 SilcChannelEntry silc_client_get_channel(SilcClient client,
769 SilcClientConnection conn,
773 /* Command management (command.c) */
775 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
779 * SilcClientCommandContext silc_client_command_alloc();
783 * Allocate Command Context. The context is defined in `command.h' file.
784 * The context is used by the library commands and applications should use
785 * it as well. However, application may choose to use some own context
786 * for its local commands. All library commands, however, must use this
790 SilcClientCommandContext silc_client_command_alloc();
792 /****f* silcclient/SilcClientAPI/silc_client_command_free
796 * void silc_client_command_free(SilcClientCommandContext ctx);
800 * Free command context and its internals. If the contex was duplicated
801 * with silc_client_command_dup this may not actually free the data,
802 * instead it will decrease the reference counter of the context. The
803 * context will be freed when the reference counter hits zero.
806 void silc_client_command_free(SilcClientCommandContext ctx);
808 /****f* silcclient/SilcClientAPI/silc_client_command_dup
812 * SilcClientCommandContext
813 * silc_client_command_dup(SilcClientCommandContext ctx);
817 * Duplicate Command Context by adding reference counter. The context won't
818 * be free'd untill it hits zero.
821 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
823 /****f* silcclient/SilcClientAPI/silc_client_command_find
827 * SilcClientCommand *silc_client_command_find(const char *name);
831 * Finds and returns a pointer to the command list. Return NULL if the
832 * command is not found. See the `command.[ch]' for the command list.
835 SilcClientCommand *silc_client_command_find(const char *name);
837 /****f* silcclient/SilcClientAPI/silc_client_send_command
841 * void silc_client_send_command(SilcClient client,
842 * SilcClientConnection conn,
843 * SilcCommand command, uint16 ident,
848 * Generic function to send any command. The arguments must be sent already
849 * encoded into correct form and in correct order.
852 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
853 SilcCommand command, uint16 ident,
856 /****f* silcclient/SilcClientAPI/SilcClientPendingDestructor
860 * typedef void (*SilcClientPendingDestructor)(void *context);
864 * Pending Command callback destructor. This is called after calling the
865 * pending callback or if error occurs while processing the pending command.
866 * If error occurs then the callback won't be called at all, and only this
867 * destructor is called. The `context' is the context given for the function
868 * silc_client_command_pending.
871 typedef void (*SilcClientPendingDestructor)(void *context);
873 /****f* silcclient/SilcClientAPI/silc_client_command_pending
877 * void silc_client_command_pending(SilcClientConnection conn,
878 * SilcCommand reply_cmd,
880 * SilcClientPendingDestructor destructor,
881 * SilcCommandCb callback,
886 * Add new pending command to be executed when reply to a command has been
887 * received. The `reply_cmd' is the command that will call the `callback'
888 * with `context' when reply has been received. If `ident is non-zero
889 * the `callback' will be executed when received reply with command
890 * identifier `ident'.
893 void silc_client_command_pending(SilcClientConnection conn,
894 SilcCommand reply_cmd,
896 SilcClientPendingDestructor destructor,
897 SilcCommandCb callback,
901 /* Private Message key management (client_prvmsg.c) */
903 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
907 * int silc_client_add_private_message_key(SilcClient client,
908 * SilcClientConnection conn,
909 * SilcClientEntry client_entry,
911 * unsigned char *key,
918 * Adds private message key to the client library. The key will be used to
919 * encrypt all private message between the client and the remote client
920 * indicated by the `client_entry'. If the `key' is NULL and the boolean
921 * value `generate_key' is TRUE the library will generate random key.
922 * The `key' maybe for example pre-shared-key, passphrase or similar.
923 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
924 * requirements of the SILC protocol are met. The API, however, allows
925 * to allocate any cipher.
927 * If `responder' is TRUE then the sending and receiving keys will be
928 * set according the client being the receiver of the private key. If
929 * FALSE the client is being the sender (or negotiator) of the private
932 * It is not necessary to set key for normal private message usage. If the
933 * key is not set then the private messages are encrypted using normal
934 * session keys. Setting the private key, however, increases the security.
936 * Returns FALSE if the key is already set for the `client_entry', TRUE
940 int silc_client_add_private_message_key(SilcClient client,
941 SilcClientConnection conn,
942 SilcClientEntry client_entry,
949 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
953 * int silc_client_add_private_message_key_ske(SilcClient client,
954 * SilcClientConnection conn,
955 * SilcClientEntry client_entry,
957 * SilcSKEKeyMaterial *key);
961 * Same as silc_client_add_private_message_key but takes the key material
962 * from the SKE key material structure. This structure is received if
963 * the application uses the silc_client_send_key_agreement to negotiate
964 * the key material. The `cipher' SHOULD be provided as it is negotiated
965 * also in the SKE protocol.
968 int silc_client_add_private_message_key_ske(SilcClient client,
969 SilcClientConnection conn,
970 SilcClientEntry client_entry,
972 SilcSKEKeyMaterial *key,
975 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
979 * int silc_client_send_private_message_key(SilcClient client,
980 * SilcClientConnection conn,
981 * SilcClientEntry client_entry,
986 * Sends private message key payload to the remote client indicated by
987 * the `client_entry'. If the `force_send' is TRUE the packet is sent
988 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
989 * application should call this function after setting the key to the
992 * Note that the key sent using this function is sent to the remote client
993 * through the SILC network. The packet is protected using normal session
997 int silc_client_send_private_message_key(SilcClient client,
998 SilcClientConnection conn,
999 SilcClientEntry client_entry,
1002 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1006 * int silc_client_del_private_message_key(SilcClient client,
1007 * SilcClientConnection conn,
1008 * SilcClientEntry client_entry);
1012 * Removes the private message from the library. The key won't be used
1013 * after this to protect the private messages with the remote `client_entry'
1014 * client. Returns FALSE on error, TRUE otherwise.
1017 int silc_client_del_private_message_key(SilcClient client,
1018 SilcClientConnection conn,
1019 SilcClientEntry client_entry);
1021 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1025 * SilcPrivateMessageKeys
1026 * silc_client_list_private_message_keys(SilcClient client,
1027 * SilcClientConnection conn,
1028 * uint32 *key_count);
1032 * Returns array of set private message keys associated to the connection
1033 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1034 * count to the `key_count' argument. The array must be freed by the caller
1035 * by calling the silc_client_free_private_message_keys function. Note:
1036 * the keys returned in the array is in raw format. It might not be desired
1037 * to show the keys as is. The application might choose not to show the keys
1038 * at all or to show the fingerprints of the keys.
1041 SilcPrivateMessageKeys
1042 silc_client_list_private_message_keys(SilcClient client,
1043 SilcClientConnection conn,
1046 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1050 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1051 * uint32 key_count);
1055 * Frees the SilcPrivateMessageKeys array returned by the function
1056 * silc_client_list_private_message_keys.
1059 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1063 /* Channel private key management (client_channel.c,
1064 SilcChannelPrivateKey is defined in idlist.h) */
1066 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1070 * int silc_client_add_channel_private_key(SilcClient client,
1071 * SilcClientConnection conn,
1072 * SilcChannelEntry channel,
1075 * unsigned char *key,
1080 * Adds private key for channel. This may be set only if the channel's mode
1081 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1082 * mode is not set. When channel has private key then the messages are
1083 * encrypted using that key. All clients on the channel must also know the
1084 * key in order to decrypt the messages. However, it is possible to have
1085 * several private keys per one channel. In this case only some of the
1086 * clients on the channel may know the one key and only some the other key.
1088 * The private key for channel is optional. If it is not set then the
1089 * channel messages are encrypted using the channel key generated by the
1090 * server. However, setting the private key (or keys) for the channel
1091 * significantly adds security. If more than one key is set the library
1092 * will automatically try all keys at the message decryption phase. Note:
1093 * setting many keys slows down the decryption phase as all keys has to
1094 * be tried in order to find the correct decryption key. However, setting
1095 * a few keys does not have big impact to the decryption performace.
1099 * NOTE: This is entirely local setting. The key set using this function
1100 * is not sent to the network at any phase.
1102 * NOTE: If the key material was originated by the SKE protocol (using
1103 * silc_client_send_key_agreement) then the `key' MUST be the
1104 * key->send_enc_key as this is dictated by the SILC protocol. However,
1105 * currently it is not expected that the SKE key material would be used
1106 * as channel private key. However, this API allows it.
1109 int silc_client_add_channel_private_key(SilcClient client,
1110 SilcClientConnection conn,
1111 SilcChannelEntry channel,
1117 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1121 * int silc_client_del_channel_private_keys(SilcClient client,
1122 * SilcClientConnection conn,
1123 * SilcChannelEntry channel);
1127 * Removes all private keys from the `channel'. The old channel key is used
1128 * after calling this to protect the channel messages. Returns FALSE on
1129 * on error, TRUE otherwise.
1132 int silc_client_del_channel_private_keys(SilcClient client,
1133 SilcClientConnection conn,
1134 SilcChannelEntry channel);
1136 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1140 * int silc_client_del_channel_private_key(SilcClient client,
1141 * SilcClientConnection conn,
1142 * SilcChannelEntry channel,
1143 * SilcChannelPrivateKey key);
1147 * Removes and frees private key `key' from the channel `channel'.
1148 * The `key' is retrieved by calling the function
1149 * silc_client_list_channel_private_keys. The key is not used after
1150 * this. If the key was last private key then the old channel key is
1151 * used hereafter to protect the channel messages. This returns FALSE
1152 * on error, TRUE otherwise.
1155 int silc_client_del_channel_private_key(SilcClient client,
1156 SilcClientConnection conn,
1157 SilcChannelEntry channel,
1158 SilcChannelPrivateKey key);
1160 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1164 * SilcChannelPrivateKey *
1165 * silc_client_list_channel_private_keys(SilcClient client,
1166 * SilcClientConnection conn,
1167 * SilcChannelEntry channel,
1168 * uint32 *key_count);
1172 * Returns array (pointers) of private keys associated to the `channel'.
1173 * The caller must free the array by calling the function
1174 * silc_client_free_channel_private_keys. The pointers in the array may be
1175 * used to delete the specific key by giving the pointer as argument to the
1176 * function silc_client_del_channel_private_key.
1179 SilcChannelPrivateKey *
1180 silc_client_list_channel_private_keys(SilcClient client,
1181 SilcClientConnection conn,
1182 SilcChannelEntry channel,
1185 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1189 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1190 * uint32 key_count);
1194 * Frees the SilcChannelPrivateKey array.
1197 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1201 /* Key Agreement routines (client_keyagr.c) */
1203 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1207 * void silc_client_send_key_agreement(SilcClient client,
1208 * SilcClientConnection conn,
1209 * SilcClientEntry client_entry,
1212 * uint32 timeout_secs,
1213 * SilcKeyAgreementCallback completion,
1218 * Sends key agreement request to the remote client indicated by the
1219 * `client_entry'. If the caller provides the `hostname' and the `port'
1220 * arguments then the library will bind the client to that hostname and
1221 * that port for the key agreement protocol. It also sends the `hostname'
1222 * and the `port' in the key agreement packet to the remote client. This
1223 * would indicate that the remote client may initiate the key agreement
1224 * protocol to the `hostname' on the `port'. If port is zero then the
1225 * bound port is undefined (the operating system defines it).
1227 * If the `hostname' and `port' is not provided then empty key agreement
1228 * packet is sent to the remote client. The remote client may reply with
1229 * the same packet including its hostname and port. If the library receives
1230 * the reply from the remote client the `key_agreement' client operation
1231 * callback will be called to verify whether the user wants to perform the
1232 * key agreement or not.
1236 * NOTE: If the application provided the `hostname' and the `port' and the
1237 * remote side initiates the key agreement protocol it is not verified
1238 * from the user anymore whether the protocol should be executed or not.
1239 * By setting the `hostname' and `port' the user gives permission to
1240 * perform the protocol (we are responder in this case).
1242 * NOTE: If the remote side decides not to initiate the key agreement
1243 * or decides not to reply with the key agreement packet then we cannot
1244 * perform the key agreement at all. If the key agreement protocol is
1245 * performed the `completion' callback with the `context' will be called.
1246 * If remote side decides to ignore the request the `completion' will be
1247 * called after the specified timeout, `timeout_secs'.
1249 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1250 * will not be called at all since this does nothing more than sending
1251 * a packet to the remote host.
1253 * NOTE: There can be only one active key agreement for one client entry.
1254 * Before setting new one, the old one must be finished (it is finished
1255 * after calling the completion callback) or the function
1256 * silc_client_abort_key_agreement must be called.
1259 void silc_client_send_key_agreement(SilcClient client,
1260 SilcClientConnection conn,
1261 SilcClientEntry client_entry,
1264 uint32 timeout_secs,
1265 SilcKeyAgreementCallback completion,
1268 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1273 * silc_client_perform_key_agreement(SilcClient client,
1274 * SilcClientConnection conn,
1275 * SilcClientEntry client_entry,
1278 * SilcKeyAgreementCallback completion,
1283 * Performs the actual key agreement protocol. Application may use this
1284 * to initiate the key agreement protocol. This can be called for example
1285 * after the application has received the `key_agreement' client operation,
1286 * and did not return TRUE from it.
1288 * The `hostname' is the remote hostname (or IP address) and the `port'
1289 * is the remote port. The `completion' callback with the `context' will
1290 * be called after the key agreement protocol.
1294 * NOTE: If the application returns TRUE in the `key_agreement' client
1295 * operation the library will automatically start the key agreement. In this
1296 * case the application must not call this function. However, application
1297 * may choose to just ignore the `key_agreement' client operation (and
1298 * merely just print information about it on the screen) and call this
1299 * function when the user whishes to do so (by, for example, giving some
1300 * specific command). Thus, the API provides both, automatic and manual
1301 * initiation of the key agreement. Calling this function is the manual
1302 * initiation and returning TRUE in the `key_agreement' client operation
1303 * is the automatic initiation.
1306 void silc_client_perform_key_agreement(SilcClient client,
1307 SilcClientConnection conn,
1308 SilcClientEntry client_entry,
1311 SilcKeyAgreementCallback completion,
1314 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1319 * silc_client_perform_key_agreement_fd(SilcClient client,
1320 * SilcClientConnection conn,
1321 * SilcClientEntry client_entry,
1324 * SilcKeyAgreementCallback completion,
1329 * Same as above but application has created already the connection to
1330 * the remote host. The `sock' is the socket to the remote connection.
1331 * Application can use this function if it does not want the client library
1332 * to create the connection.
1335 void silc_client_perform_key_agreement_fd(SilcClient client,
1336 SilcClientConnection conn,
1337 SilcClientEntry client_entry,
1340 SilcKeyAgreementCallback completion,
1343 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1347 * void silc_client_abort_key_agreement(SilcClient client,
1348 * SilcClientConnection conn,
1349 * SilcClientEntry client_entry);
1353 * This function can be called to unbind the hostname and the port for
1354 * the key agreement protocol. However, this function has effect only
1355 * before the key agreement protocol has been performed. After it has
1356 * been performed the library will automatically unbind the port. The
1357 * `client_entry' is the client to which we sent the key agreement
1361 void silc_client_abort_key_agreement(SilcClient client,
1362 SilcClientConnection conn,
1363 SilcClientEntry client_entry);
1366 /* Misc functions */
1368 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1372 * void silc_client_set_away_message(SilcClient client,
1373 * SilcClientConnection conn,
1378 * Sets away `message'. The away message may be set when the client's
1379 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1380 * to anyone who sends private message. The `message' will be sent
1381 * automatically back to the the client who send private message. If
1382 * away message is already set this replaces the old message with the
1383 * new one. If `message' is NULL the old away message is removed.
1384 * The sender may freely free the memory of the `message'.
1387 void silc_client_set_away_message(SilcClient client,
1388 SilcClientConnection conn,