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 * 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 * 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 * 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.
320 SilcClient silc_client_alloc(SilcClientOperations *ops, void *application);
322 /****f* silcclient/SilcClientAPI/silc_client_free
326 * void silc_client_free(SilcClient client);
330 * Frees client object and its internals. The execution of the client
331 * should be stopped with silc_client_stop function before calling
335 void silc_client_free(SilcClient client);
337 /****f* silcclient/SilcClientAPI/silc_client_init
341 * int silc_client_init(SilcClient client);
345 * Initializes the client. This makes all the necessary steps to make
346 * the client ready to be run. One must call silc_client_run to run the
347 * client. Returns FALSE if error occurred, TRUE otherwise.
350 int silc_client_init(SilcClient client);
352 /****f* silcclient/SilcClientAPI/silc_client_run
356 * void silc_client_run(SilcClient client);
360 * Runs the client. This starts the scheduler from the utility library.
361 * When this functions returns the execution of the appliation is over.
364 void silc_client_run(SilcClient client);
366 /****f* silcclient/SilcClientAPI/silc_client_stop
370 * void silc_client_stop(SilcClient client);
374 * Stops the client. This is called to stop the client and thus to stop
375 * the program. The client context must be freed with the silc_client_free
379 void silc_client_stop(SilcClient client);
382 /* Connecting functions (client.c) */
384 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
388 * int silc_client_connect_to_server(SilcClient client, int port,
389 * char *host, void *context);
393 * Connects to remote server. This is the main routine used to connect
394 * to SILC server. Returns -1 on error and the created socket otherwise.
395 * The `context' is user context that is saved into the SilcClientConnection
396 * that is created after the connection is created. Note that application
397 * may handle the connecting process outside the library. If this is the
398 * case then this function is not used at all. When the connecting is
399 * done the `connect' client operation is called.
402 int silc_client_connect_to_server(SilcClient client, int port,
403 char *host, void *context);
405 /****f* silcclient/SilcClientAPI/silc_client_add_connection
409 * SilcClientConnection silc_client_add_connection(SilcClient client,
416 * Allocates and adds new connection to the client. This adds the allocated
417 * connection to the connection table and returns a pointer to it. A client
418 * can have multiple connections to multiple servers. Every connection must
419 * be added to the client using this function. User data `context' may
420 * be sent as argument. This function is normally used only if the
421 * application performed the connecting outside the library. The library
422 * however may use this internally.
425 SilcClientConnection silc_client_add_connection(SilcClient client,
430 /****f* silcclient/SilcClientAPI/silc_client_del_connection
434 * void silc_client_del_connection(SilcClient client,
435 * SilcClientConnection conn);
439 * Removes connection from client. Frees all memory. The library
440 * call this function automatically for all connection contexts.
441 * The application however may free the connection contexts it has
445 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
447 /****f* silcclient/SilcClientAPI/silc_client_add_socket
451 * void silc_client_add_socket(SilcClient client,
452 * SilcSocketConnection sock);
456 * Adds listener socket to the listener sockets table. This function is
457 * used to add socket objects that are listeners to the client. This should
458 * not be used to add other connection objects.
461 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
463 /****f* silcclient/SilcClientAPI/silc_client_del_socket
467 * void silc_client_del_socket(SilcClient client,
468 * SilcSocketConnection sock);
472 * Deletes listener socket from the listener sockets table. If the
473 * application has added a socket with silc_client_add_socket it must
474 * also free it using this function.
477 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
479 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
483 * int silc_client_start_key_exchange(SilcClient client,
484 * SilcClientConnection conn,
489 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
490 * key material between client and server. This function can be called
491 * directly if application is performing its own connecting and does not
492 * use the connecting provided by this library. This function is normally
493 * used only if the application performed the connecting outside the
494 * library. The library however may use this internally.
497 int silc_client_start_key_exchange(SilcClient client,
498 SilcClientConnection conn,
501 /****f* silcclient/SilcClientAPI/silc_client_close_connection
505 * void silc_client_close_connection(SilcClient client,
506 * SilcSocketConnection sock,
507 * SilcClientConnection conn);
511 * Closes connection to remote end. Free's all allocated data except
512 * for some information such as nickname etc. that are valid at all time.
513 * If the `sock' is NULL then the conn->sock will be used. If `sock' is
514 * provided it will be checked whether the sock and `conn->sock' are the
515 * same (they can be different, ie. a socket can use `conn' as its
516 * connection but `conn->sock' might be actually a different connection
520 void silc_client_close_connection(SilcClient client,
521 SilcSocketConnection sock,
522 SilcClientConnection conn);
525 /* Message sending functions (client_channel.c and client_prvmsg.c) */
527 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
531 * void silc_client_send_channel_message(SilcClient client,
532 * SilcClientConnection conn,
533 * SilcChannelEntry channel,
534 * SilcChannelPrivateKey key,
535 * SilcMessageFlags flags,
536 * unsigned char *data,
542 * Sends packet to the `channel'. Packet to channel is always encrypted
543 * differently from "normal" packets. SILC header of the packet is
544 * encrypted with the next receiver's key and the rest of the packet is
545 * encrypted with the channel specific key. Padding and HMAC is computed
546 * with the next receiver's key. The `data' is the channel message. If
547 * the `force_send' is TRUE then the packet is sent immediately.
549 * If `key' is provided then that private key is used to encrypt the
550 * channel message. If it is not provided, private keys has not been
551 * set at all, the normal channel key is used automatically. If private
552 * keys are set then the first key (the key that was added first as
553 * private key) is used.
556 void silc_client_send_channel_message(SilcClient client,
557 SilcClientConnection conn,
558 SilcChannelEntry channel,
559 SilcChannelPrivateKey key,
560 SilcMessageFlags flags,
565 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
569 * void silc_client_send_private_message(SilcClient client,
570 * SilcClientConnection conn,
571 * SilcClientEntry client_entry,
572 * SilcMessageFlags flags,
573 * unsigned char *data,
579 * Sends private message to remote client. If private message key has
580 * not been set with this client then the message will be encrypted using
581 * normal session keys. Private messages are special packets in SILC
582 * network hence we need this own function for them. This is similar
583 * to silc_client_packet_send_to_channel except that we send private
584 * message. The `data' is the private message. If the `force_send' is
585 * TRUE the packet is sent immediately.
588 void silc_client_send_private_message(SilcClient client,
589 SilcClientConnection conn,
590 SilcClientEntry client_entry,
591 SilcMessageFlags flags,
597 /* Client and Channel entry retrieval (idlist.c) */
599 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
603 * typedef void (*SilcGetClientCallback)(SilcClient client,
604 * SilcClientConnection conn,
605 * SilcClientEntry *clients,
606 * uint32 clients_count,
611 * Callback function given to the silc_client_get_client function. The
612 * found entries are allocated into the `clients' array. The array must
613 * not be freed by the caller, the library will free it later. If the
614 * `clients' is NULL, no such clients exist in the SILC Network.
617 typedef void (*SilcGetClientCallback)(SilcClient client,
618 SilcClientConnection conn,
619 SilcClientEntry *clients,
620 uint32 clients_count,
623 /****f* silcclient/SilcClientAPI/silc_client_get_clients
627 * void silc_client_get_clients(SilcClient client,
628 * SilcClientConnection conn,
631 * SilcGetClientCallback completion,
636 * Finds client entry or entries by the `nickname' and `server'. The
637 * completion callback will be called when the client entries has been
642 * NOTE: This function is always asynchronous and resolves the client
643 * information from the server. Thus, if you already know the client
644 * information then use the silc_client_get_client_by_id function to
645 * get the client entry since this function may be very slow and should
646 * be used only to initially get the client entries.
649 void silc_client_get_clients(SilcClient client,
650 SilcClientConnection conn,
653 SilcGetClientCallback completion,
656 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
660 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
661 * SilcClientConnection conn,
664 * uint32 *clients_count);
668 * Same as silc_client_get_clients function but does not resolve anything
669 * from the server. This checks local cache and returns all clients from
673 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
674 SilcClientConnection conn,
677 uint32 *clients_count);
679 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
683 * void silc_client_get_clients_by_list(SilcClient client,
684 * SilcClientConnection conn,
686 * SilcBuffer client_id_list,
687 * SilcGetClientCallback completion,
692 * Gets client entries by the list of client ID's `client_id_list'. This
693 * always resolves those client ID's it does not know yet from the server
694 * so this function might take a while. The `client_id_list' is a list
695 * of ID Payloads added one after other. JOIN command reply and USERS
696 * command reply for example returns this sort of list. The `completion'
697 * will be called after the entries are available.
700 void silc_client_get_clients_by_list(SilcClient client,
701 SilcClientConnection conn,
703 SilcBuffer client_id_list,
704 SilcGetClientCallback completion,
707 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
711 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
712 * SilcClientConnection conn,
713 * SilcClientID *client_id);
717 * Find entry for client by the client's ID. Returns the entry or NULL
718 * if the entry was not found.
721 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
722 SilcClientConnection conn,
723 SilcClientID *client_id);
725 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
730 * silc_client_get_client_by_id_resolve(SilcClient client,
731 * SilcClientConnection conn,
732 * SilcClientID *client_id,
733 * SilcGetClientCallback completion,
738 * Same as silc_client_get_client_by_id but will always resolve the
739 * information from the server. Use this only if you know that you
740 * do not have the entry and the only thing you know about the client
744 void silc_client_get_client_by_id_resolve(SilcClient client,
745 SilcClientConnection conn,
746 SilcClientID *client_id,
747 SilcGetClientCallback completion,
750 /****f* silcclient/SilcClientAPI/silc_client_get_channel
754 * SilcChannelEntry silc_client_get_channel(SilcClient client,
755 * SilcClientConnection conn,
760 * Finds entry for channel by the channel name. Returns the entry or NULL
761 * if the entry was not found. It is found only if the client is joined
765 SilcChannelEntry silc_client_get_channel(SilcClient client,
766 SilcClientConnection conn,
770 /* Command management (command.c) */
772 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
776 * SilcClientCommandContext silc_client_command_alloc();
780 * Allocate Command Context. The context is defined in `command.h' file.
781 * The context is used by the library commands and applications should use
782 * it as well. However, application may choose to use some own context
783 * for its local commands. All library commands, however, must use this
787 SilcClientCommandContext silc_client_command_alloc();
789 /****f* silcclient/SilcClientAPI/silc_client_command_free
793 * void silc_client_command_free(SilcClientCommandContext ctx);
797 * Free command context and its internals. If the contex was duplicated
798 * with silc_client_command_dup this may not actually free the data,
799 * instead it will decrease the reference counter of the context. The
800 * context will be freed when the reference counter hits zero.
803 void silc_client_command_free(SilcClientCommandContext ctx);
805 /****f* silcclient/SilcClientAPI/silc_client_command_dup
809 * SilcClientCommandContext
810 * silc_client_command_dup(SilcClientCommandContext ctx);
814 * Duplicate Command Context by adding reference counter. The context won't
815 * be free'd untill it hits zero.
818 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
820 /****f* silcclient/SilcClientAPI/silc_client_command_find
824 * SilcClientCommand *silc_client_command_find(const char *name);
828 * Finds and returns a pointer to the command list. Return NULL if the
829 * command is not found. See the `command.[ch]' for the command list.
832 SilcClientCommand *silc_client_command_find(const char *name);
834 /****f* silcclient/SilcClientAPI/silc_client_send_command
838 * void silc_client_send_command(SilcClient client,
839 * SilcClientConnection conn,
840 * SilcCommand command, uint16 ident,
845 * Generic function to send any command. The arguments must be sent already
846 * encoded into correct form and in correct order.
849 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
850 SilcCommand command, uint16 ident,
853 /****f* silcclient/SilcClientAPI/SilcClientPendingDestructor
857 * typedef void (*SilcClientPendingDestructor)(void *context);
861 * Pending Command callback destructor. This is called after calling the
862 * pending callback or if error occurs while processing the pending command.
863 * If error occurs then the callback won't be called at all, and only this
864 * destructor is called. The `context' is the context given for the function
865 * silc_client_command_pending.
868 typedef void (*SilcClientPendingDestructor)(void *context);
870 /****f* silcclient/SilcClientAPI/silc_client_command_pending
874 * void silc_client_command_pending(SilcClientConnection conn,
875 * SilcCommand reply_cmd,
877 * SilcClientPendingDestructor destructor,
878 * SilcCommandCb callback,
883 * Add new pending command to be executed when reply to a command has been
884 * received. The `reply_cmd' is the command that will call the `callback'
885 * with `context' when reply has been received. If `ident is non-zero
886 * the `callback' will be executed when received reply with command
887 * identifier `ident'.
890 void silc_client_command_pending(SilcClientConnection conn,
891 SilcCommand reply_cmd,
893 SilcClientPendingDestructor destructor,
894 SilcCommandCb callback,
898 /* Private Message key management (client_prvmsg.c) */
900 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
904 * int silc_client_add_private_message_key(SilcClient client,
905 * SilcClientConnection conn,
906 * SilcClientEntry client_entry,
908 * unsigned char *key,
914 * Adds private message key to the client library. The key will be used to
915 * encrypt all private message between the client and the remote client
916 * indicated by the `client_entry'. If the `key' is NULL and the boolean
917 * value `generate_key' is TRUE the library will generate random key.
918 * The `key' maybe for example pre-shared-key, passphrase or similar.
919 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
920 * requirements of the SILC protocol are met. The API, however, allows
921 * to allocate any cipher.
923 * It is not necessary to set key for normal private message usage. If the
924 * key is not set then the private messages are encrypted using normal
925 * session keys. Setting the private key, however, increases the security.
927 * Returns FALSE if the key is already set for the `client_entry', TRUE
931 int silc_client_add_private_message_key(SilcClient client,
932 SilcClientConnection conn,
933 SilcClientEntry client_entry,
939 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
943 * int silc_client_add_private_message_key_ske(SilcClient client,
944 * SilcClientConnection conn,
945 * SilcClientEntry client_entry,
947 * SilcSKEKeyMaterial *key);
951 * Same as above but takes the key material from the SKE key material
952 * structure. This structure is received if the application uses the
953 * silc_client_send_key_agreement to negotiate the key material. The
954 * `cipher' SHOULD be provided as it is negotiated also in the SKE
958 int silc_client_add_private_message_key_ske(SilcClient client,
959 SilcClientConnection conn,
960 SilcClientEntry client_entry,
962 SilcSKEKeyMaterial *key);
964 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
968 * int silc_client_send_private_message_key(SilcClient client,
969 * SilcClientConnection conn,
970 * SilcClientEntry client_entry,
975 * Sends private message key payload to the remote client indicated by
976 * the `client_entry'. If the `force_send' is TRUE the packet is sent
977 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
978 * application should call this function after setting the key to the
981 * Note that the key sent using this function is sent to the remote client
982 * through the SILC network. The packet is protected using normal session
986 int silc_client_send_private_message_key(SilcClient client,
987 SilcClientConnection conn,
988 SilcClientEntry client_entry,
991 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
995 * int silc_client_del_private_message_key(SilcClient client,
996 * SilcClientConnection conn,
997 * SilcClientEntry client_entry);
1001 * Removes the private message from the library. The key won't be used
1002 * after this to protect the private messages with the remote `client_entry'
1003 * client. Returns FALSE on error, TRUE otherwise.
1006 int silc_client_del_private_message_key(SilcClient client,
1007 SilcClientConnection conn,
1008 SilcClientEntry client_entry);
1010 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1014 * SilcPrivateMessageKeys
1015 * silc_client_list_private_message_keys(SilcClient client,
1016 * SilcClientConnection conn,
1017 * uint32 *key_count);
1021 * Returns array of set private message keys associated to the connection
1022 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1023 * count to the `key_count' argument. The array must be freed by the caller
1024 * by calling the silc_client_free_private_message_keys function. Note:
1025 * the keys returned in the array is in raw format. It might not be desired
1026 * to show the keys as is. The application might choose not to show the keys
1027 * at all or to show the fingerprints of the keys.
1030 SilcPrivateMessageKeys
1031 silc_client_list_private_message_keys(SilcClient client,
1032 SilcClientConnection conn,
1035 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1039 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1040 * uint32 key_count);
1044 * Frees the SilcPrivateMessageKeys array returned by the function
1045 * silc_client_list_private_message_keys.
1048 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1052 /* Channel private key management (client_channel.c,
1053 SilcChannelPrivateKey is defined in idlist.h) */
1055 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1059 * int silc_client_add_channel_private_key(SilcClient client,
1060 * SilcClientConnection conn,
1061 * SilcChannelEntry channel,
1064 * unsigned char *key,
1069 * Adds private key for channel. This may be set only if the channel's mode
1070 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1071 * mode is not set. When channel has private key then the messages are
1072 * encrypted using that key. All clients on the channel must also know the
1073 * key in order to decrypt the messages. However, it is possible to have
1074 * several private keys per one channel. In this case only some of the
1075 * clients on the channel may know the one key and only some the other key.
1077 * The private key for channel is optional. If it is not set then the
1078 * channel messages are encrypted using the channel key generated by the
1079 * server. However, setting the private key (or keys) for the channel
1080 * significantly adds security. If more than one key is set the library
1081 * will automatically try all keys at the message decryption phase. Note:
1082 * setting many keys slows down the decryption phase as all keys has to
1083 * be tried in order to find the correct decryption key. However, setting
1084 * a few keys does not have big impact to the decryption performace.
1088 * NOTE: This is entirely local setting. The key set using this function
1089 * is not sent to the network at any phase.
1091 * NOTE: If the key material was originated by the SKE protocol (using
1092 * silc_client_send_key_agreement) then the `key' MUST be the
1093 * key->send_enc_key as this is dictated by the SILC protocol. However,
1094 * currently it is not expected that the SKE key material would be used
1095 * as channel private key. However, this API allows it.
1098 int silc_client_add_channel_private_key(SilcClient client,
1099 SilcClientConnection conn,
1100 SilcChannelEntry channel,
1106 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1110 * int silc_client_del_channel_private_keys(SilcClient client,
1111 * SilcClientConnection conn,
1112 * SilcChannelEntry channel);
1116 * Removes all private keys from the `channel'. The old channel key is used
1117 * after calling this to protect the channel messages. Returns FALSE on
1118 * on error, TRUE otherwise.
1121 int silc_client_del_channel_private_keys(SilcClient client,
1122 SilcClientConnection conn,
1123 SilcChannelEntry channel);
1125 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1129 * int silc_client_del_channel_private_key(SilcClient client,
1130 * SilcClientConnection conn,
1131 * SilcChannelEntry channel,
1132 * SilcChannelPrivateKey key);
1136 * Removes and frees private key `key' from the channel `channel'.
1137 * The `key' is retrieved by calling the function
1138 * silc_client_list_channel_private_keys. The key is not used after
1139 * this. If the key was last private key then the old channel key is
1140 * used hereafter to protect the channel messages. This returns FALSE
1141 * on error, TRUE otherwise.
1144 int silc_client_del_channel_private_key(SilcClient client,
1145 SilcClientConnection conn,
1146 SilcChannelEntry channel,
1147 SilcChannelPrivateKey key);
1149 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1153 * SilcChannelPrivateKey *
1154 * silc_client_list_channel_private_keys(SilcClient client,
1155 * SilcClientConnection conn,
1156 * SilcChannelEntry channel,
1157 * uint32 *key_count);
1161 * Returns array (pointers) of private keys associated to the `channel'.
1162 * The caller must free the array by calling the function
1163 * silc_client_free_channel_private_keys. The pointers in the array may be
1164 * used to delete the specific key by giving the pointer as argument to the
1165 * function silc_client_del_channel_private_key.
1168 SilcChannelPrivateKey *
1169 silc_client_list_channel_private_keys(SilcClient client,
1170 SilcClientConnection conn,
1171 SilcChannelEntry channel,
1174 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1178 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1179 * uint32 key_count);
1183 * Frees the SilcChannelPrivateKey array.
1186 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1190 /* Key Agreement routines (client_keyagr.c) */
1192 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1196 * void silc_client_send_key_agreement(SilcClient client,
1197 * SilcClientConnection conn,
1198 * SilcClientEntry client_entry,
1201 * uint32 timeout_secs,
1202 * SilcKeyAgreementCallback completion,
1207 * Sends key agreement request to the remote client indicated by the
1208 * `client_entry'. If the caller provides the `hostname' and the `port'
1209 * arguments then the library will bind the client to that hostname and
1210 * that port for the key agreement protocol. It also sends the `hostname'
1211 * and the `port' in the key agreement packet to the remote client. This
1212 * would indicate that the remote client may initiate the key agreement
1213 * protocol to the `hostname' on the `port'. If port is zero then the
1214 * bound port is undefined (the operating system defines it).
1216 * If the `hostname' and `port' is not provided then empty key agreement
1217 * packet is sent to the remote client. The remote client may reply with
1218 * the same packet including its hostname and port. If the library receives
1219 * the reply from the remote client the `key_agreement' client operation
1220 * callback will be called to verify whether the user wants to perform the
1221 * key agreement or not.
1225 * NOTE: If the application provided the `hostname' and the `port' and the
1226 * remote side initiates the key agreement protocol it is not verified
1227 * from the user anymore whether the protocol should be executed or not.
1228 * By setting the `hostname' and `port' the user gives permission to
1229 * perform the protocol (we are responder in this case).
1231 * NOTE: If the remote side decides not to initiate the key agreement
1232 * or decides not to reply with the key agreement packet then we cannot
1233 * perform the key agreement at all. If the key agreement protocol is
1234 * performed the `completion' callback with the `context' will be called.
1235 * If remote side decides to ignore the request the `completion' will be
1236 * called after the specified timeout, `timeout_secs'.
1238 * NOTE: There can be only one active key agreement for one client entry.
1239 * Before setting new one, the old one must be finished (it is finished
1240 * after calling the completion callback) or the function
1241 * silc_client_abort_key_agreement must be called.
1244 void silc_client_send_key_agreement(SilcClient client,
1245 SilcClientConnection conn,
1246 SilcClientEntry client_entry,
1249 uint32 timeout_secs,
1250 SilcKeyAgreementCallback completion,
1253 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1258 * silc_client_perform_key_agreement(SilcClient client,
1259 * SilcClientConnection conn,
1260 * SilcClientEntry client_entry,
1263 * SilcKeyAgreementCallback completion,
1268 * Performs the actual key agreement protocol. Application may use this
1269 * to initiate the key agreement protocol. This can be called for example
1270 * after the application has received the `key_agreement' client operation,
1271 * and did not return TRUE from it.
1273 * The `hostname' is the remote hostname (or IP address) and the `port'
1274 * is the remote port. The `completion' callback with the `context' will
1275 * be called after the key agreement protocol.
1279 * NOTE: If the application returns TRUE in the `key_agreement' client
1280 * operation the library will automatically start the key agreement. In this
1281 * case the application must not call this function. However, application
1282 * may choose to just ignore the `key_agreement' client operation (and
1283 * merely just print information about it on the screen) and call this
1284 * function when the user whishes to do so (by, for example, giving some
1285 * specific command). Thus, the API provides both, automatic and manual
1286 * initiation of the key agreement. Calling this function is the manual
1287 * initiation and returning TRUE in the `key_agreement' client operation
1288 * is the automatic initiation.
1291 void silc_client_perform_key_agreement(SilcClient client,
1292 SilcClientConnection conn,
1293 SilcClientEntry client_entry,
1296 SilcKeyAgreementCallback completion,
1299 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1304 * silc_client_perform_key_agreement_fd(SilcClient client,
1305 * SilcClientConnection conn,
1306 * SilcClientEntry client_entry,
1309 * SilcKeyAgreementCallback completion,
1314 * Same as above but application has created already the connection to
1315 * the remote host. The `sock' is the socket to the remote connection.
1316 * Application can use this function if it does not want the client library
1317 * to create the connection.
1320 void silc_client_perform_key_agreement_fd(SilcClient client,
1321 SilcClientConnection conn,
1322 SilcClientEntry client_entry,
1325 SilcKeyAgreementCallback completion,
1328 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1332 * void silc_client_abort_key_agreement(SilcClient client,
1333 * SilcClientConnection conn,
1334 * SilcClientEntry client_entry);
1338 * This function can be called to unbind the hostname and the port for
1339 * the key agreement protocol. However, this function has effect only
1340 * before the key agreement protocol has been performed. After it has
1341 * been performed the library will automatically unbind the port. The
1342 * `client_entry' is the client to which we sent the key agreement
1346 void silc_client_abort_key_agreement(SilcClient client,
1347 SilcClientConnection conn,
1348 SilcClientEntry client_entry);
1351 /* Misc functions */
1353 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1357 * void silc_client_set_away_message(SilcClient client,
1358 * SilcClientConnection conn,
1363 * Sets away `message'. The away message may be set when the client's
1364 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1365 * to anyone who sends private message. The `message' will be sent
1366 * automatically back to the the client who send private message. If
1367 * away message is already set this replaces the old message with the
1368 * new one. If `message' is NULL the old away message is removed.
1369 * The sender may freely free the memory of the `message'.
1372 void silc_client_set_away_message(SilcClient client,
1373 SilcClientConnection conn,