5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2006 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcclient/Client Library Interface
24 * This interface defines the SILC Client Library API for the application.
25 * The client operations are defined first. These are callback functions that
26 * the application MUST implement since the library may call the functions
27 * at any time. At the end of file is the API for the application that
28 * it can use from the library. This is the only file that the application
29 * may include from the SIlC Client Library.
31 * o SILC Client Operations
33 * These functions must be implemented by the application calling the SILC
34 * client library. The client library can call these functions at any time.
36 * To use this structure: define a static SilcClientOperations variable,
37 * fill it and pass its pointer to silc_client_alloc function.
39 * o SILC Client Library API
41 * This is the API that is published by the SILC Client Library for the
42 * applications. These functions are implemented in the SILC Client Library.
43 * Application may freely call these functions from the library.
55 #include "silcclient_entry.h"
57 /* General definitions */
59 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
63 * typedef enum { ... } SilcClientConnectionStatus
67 * This type is returned to the `connect' client operation to indicate
68 * the status of the created connection. It can indicate if it was
69 * successful or whether an error occurred.
74 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
75 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
76 resumed old detached session */
77 SILC_CLIENT_CONN_DISCONNECTED, /* Remote host disconnected */
78 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
79 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */
80 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */
81 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */
82 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */
83 } SilcClientConnectionStatus;
86 /****f* silcclient/SilcClientAPI/SilcClientConnectCallback
90 * void (*SilcClientConnectCallback)(SilcClient client,
91 * SilcClientConnection conn,
92 * SilcClientConnectionStatus status,
94 * const char *message,
99 * Connect callbak given as argument to silc_client_connect_to_server,
100 * silc_client_connect_to_client and silc_client_key_exchange functions.
101 * It is called to indicate the status of the connection, indicated
102 * by the `status'. It is called after the connection has been
103 * established to the remote host and when connection is disconnected
104 * by the remote host. The `context' is the context given as argument
105 * to the connecting function.
107 * When the `status' is SILC_CLIENT_CONN_DISCONNECTED the `error' will
108 * indicate the reason for disconnection. If the `message' is non-NULL
109 * it delivers error or disconnection message.
112 typedef void (*SilcClientConnectCallback)(SilcClient client,
113 SilcClientConnection conn,
114 SilcClientConnectionStatus status,
119 /****s* silcclient/SilcClientAPI/SilcClient
123 * typedef struct SilcClientStruct { ... } *SilcClient
127 * This is the actual SILC Client structure which represents one
128 * SILC Client. It is allocated with the silc_client_alloc function
129 * and given as argument to all SILC Client Library functions. It
130 * is initialized with silc_client_init function, and freed with
131 * silc_client_free function.
133 * This context represents the client. Each connection to remote server
134 * is represented by SilcClientConnection context.
138 struct SilcClientStruct {
139 char *username; /* Username */
140 char *hostname; /* hostname */
141 char *realname; /* Real name */
142 SilcSchedule schedule; /* Client scheduler */
143 SilcRng rng; /* Random number generator */
144 void *application; /* Application specific context, set with
145 silc_client_alloc. */
147 /* Internal data for client library. Application cannot access this. */
148 SilcClientInternal internal;
152 /****s* silcclient/SilcClientAPI/SilcClientConnection
156 * typedef struct SilcClientConnectionStruct { ... }
157 * *SilcClientConnection
161 * This structure represents a connection. It is allocated and freed by
162 * the library. It is returned to application in SilcClientConnectCallback.
163 * It includes all the important data for the session such as local
164 * client entry (which includes current nickname), local and remote IDs,
165 * and other information. All strings in the structure are UTF-8 encoded.
169 struct SilcClientConnectionStruct {
170 SilcClientEntry local_entry; /* Our own Client Entry */
171 SilcClientID *local_id; /* Our current Client ID */
173 char *remote_host; /* Remote host name */
174 int remote_port; /* Remote port */
175 SilcID remote_id; /* Remote ID */
177 SilcChannelEntry current_channel; /* Current joined channel */
178 SilcPublicKey public_key; /* Public key used in this connection */
179 SilcPrivateKey private_key; /* Private key */
180 SilcPacketStream stream; /* Connection to remote host */
181 SilcConnectionType type; /* Connection type */
182 SilcClientConnectCallback callback; /* Connection callback */
183 void *callback_context; /* Connection context */
184 SilcClient client; /* Pointer back to SilcClient */
186 /* Application specific data. Application may set here whatever it wants. */
189 /* Internal data for client library. Application cannot access this. */
190 SilcClientConnectionInternal internal;
194 /****s* silcclient/SilcClientAPI/SilcChannelUser
198 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
202 * This structure represents a client that has joined to a channel.
203 * It shows the client and the channel and the client's mode (channel
204 * user mode) on the channel.
208 struct SilcChannelUserStruct {
209 SilcClientEntry client; /* Client joined on channel */
210 SilcUInt32 mode; /* mode, ChannelUserModes */
211 SilcChannelEntry channel; /* The channel user has joined */
213 /* Application specific data. Application may set here whatever it wants. */
218 /****s* silcclient/SilcClientAPI/SilcClientStats
222 * typedef struct { ... } SilcClientStats;
226 * This structure holds SILC network statistics returned by the
227 * SILC_COMMAND_STATS command reply to the application.
232 SilcUInt32 starttime; /* SILC server start time */
233 SilcUInt32 uptime; /* SILC server uptime*/
234 SilcUInt32 my_clients; /* Number of clients in the server */
235 SilcUInt32 my_channels; /* Number of channel in the server */
236 SilcUInt32 my_server_ops; /* Number of server operators in the server */
237 SilcUInt32 my_router_ops; /* Number of router operators in the router */
238 SilcUInt32 cell_clients; /* Number of clients in the cell */
239 SilcUInt32 cell_channels; /* Number of channels in the cell */
240 SilcUInt32 cell_servers; /* Number of server in the cell */
241 SilcUInt32 clients; /* All clients in SILC network */
242 SilcUInt32 channels; /* All channels in SILC network */
243 SilcUInt32 servers; /* All servers in SILC network */
244 SilcUInt32 routers; /* All routers in SILC network */
245 SilcUInt32 server_ops; /* All server operators in SILC network */
246 SilcUInt32 router_ops; /* All router operators in SILC network */
250 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
254 * typedef enum { ... } SilcKeyAgreementStatus;
258 * Key agreement status types indicating the status of the key
259 * agreement protocol. These types are returned to the application
260 * in the SilcKeyAgreementCallback callback function.
265 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
266 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
267 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
268 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
269 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
270 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
271 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
272 SILC_KEY_AGREEMENT_NO_MEMORY, /* System out of memory */
273 } SilcKeyAgreementStatus;
276 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
280 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
281 * SilcClientConnection conn,
282 * SilcClientEntry client_entry,
283 * SilcKeyAgreementStatus status,
284 * SilcSKEKeyMaterial *key,
289 * Key agreement callback that is called after the key agreement protocol
290 * has been performed. This is called also if error occurred during the
291 * key agreement protocol. The `key' is the allocated key material and
292 * the caller is responsible of freeing it. The `key' is NULL if error
293 * has occurred. The application can freely use the `key' to whatever
294 * purpose it needs. See lib/silcske/silcske.h for the definition of
295 * the SilcSKEKeyMaterial structure.
298 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
299 SilcClientConnection conn,
300 SilcClientEntry client_entry,
301 SilcKeyAgreementStatus status,
302 SilcSKEKeyMaterial key,
305 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
309 * typedef struct { ... } SilcPrivateMessageKeys;
313 * Structure to hold the list of private message keys. The list of these
314 * structures is returned by the silc_client_list_private_message_keys
320 SilcClientEntry client_entry; /* The remote client entry */
321 char *cipher; /* The cipher name */
322 unsigned char *key; /* The original key, If the appliation
323 provided it. This is NULL if
324 the SKE key material was used. */
325 SilcUInt32 key_len; /* The key length */
326 } *SilcPrivateMessageKeys;
329 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
333 * typedef struct SilcChannelPrivateKeyStruct { ... }
334 * *SilcChannelPrivateKey;
338 * Structure to hold one channel private key. The array of this structure
339 * is returned by silc_client_list_channel_private_keys function.
343 struct SilcChannelPrivateKeyStruct {
344 char *name; /* Application given name */
345 SilcCipher cipher; /* The cipher and key */
346 SilcHmac hmac; /* The HMAC and hmac key */
350 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
354 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
355 * SilcUInt32 passphrase_len,
360 * Ask passphrase callback. This is called by the application when the
361 * library calls `ask_passphrase' client operation. The callback delivers
362 * the passphrase to the library. The passphrases in SILC protocol
363 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
364 * encoded, and if it is not then library will attempt to encode it.
367 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
368 SilcUInt32 passphrase_len,
371 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
375 * typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
379 * Public key (or certificate) verification callback. This is called
380 * by the application to indicate that the public key verification was
381 * either success or failure.
384 typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
386 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
390 * typedef void (*SilcGetAuthMeth)(SilcBool success,
391 * SilcAuthMethod auth_meth,
392 * void *auth, SilcUInt32 auth_len,
397 * Authentication method resolving callback. This is called by the
398 * application to return the resolved authentication method. The client
399 * library has called the get_auth_method client operation and given
400 * this function pointer as argument. The `success' will indicate whether
401 * the authentication method could be resolved. The `auth_meth' is the
402 * resolved authentication method. The `auth_data' and the `auth_data_len'
403 * are the resolved authentication data. The `context' is the libary's
404 * context sent to the get_auth_method client operation.
407 typedef void (*SilcGetAuthMeth)(SilcBool success,
408 SilcAuthMethod auth_meth,
409 void *auth, SilcUInt32 auth_len,
412 /****d* silcclient/SilcClientAPI/SilcClientMessageType
416 * typedef enum { ... } SilcClientMessageType;
420 * Different message types for `say' client operation. The application
421 * may filter the message sent by the library according this type.
426 SILC_CLIENT_MESSAGE_INFO, /* Informational */
427 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
428 SILC_CLIENT_MESSAGE_ERROR, /* Error */
429 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
430 } SilcClientMessageType;
433 /****s* silcclient/SilcClientAPI/SilcClientOperations
437 * typedef struct { ... } SilcClientOperations;
441 * SILC Client Operations. These must be implemented by the application.
442 * The Client library may call any of these routines at any time. The
443 * routines are used to deliver certain information to the application
444 * or from the application to the client library.
449 /* Message sent to the application by library. `conn' associates the
450 message to a specific connection. `conn', however, may be NULL.
451 The `type' indicates the type of the message sent by the library.
452 The application can for example filter the message according the
453 type. The variable argument list is arguments to the formatted
454 message that `msg' may be. */
455 void (*say)(SilcClient client, SilcClientConnection conn,
456 SilcClientMessageType type, char *msg, ...);
458 /* Message for a channel. The `sender' is the sender of the message
459 The `channel' is the channel. The `message' is the message. Note
460 that `message' maybe NULL. The `flags' indicates message flags
461 and it is used to determine how the message can be interpreted
462 (like it may tell the message is multimedia message). */
463 void (*channel_message)(SilcClient client, SilcClientConnection conn,
464 SilcClientEntry sender, SilcChannelEntry channel,
465 SilcMessagePayload payload,
466 SilcChannelPrivateKey key, SilcMessageFlags flags,
467 const unsigned char *message,
468 SilcUInt32 message_len);
470 /* Private message to the client. The `sender' is the sender of the
471 message. The message is `message'and maybe NULL. The `flags'
472 indicates message flags and it is used to determine how the message
473 can be interpreted (like it may tell the message is multimedia
475 void (*private_message)(SilcClient client, SilcClientConnection conn,
476 SilcClientEntry sender, SilcMessagePayload payload,
477 SilcMessageFlags flags, const unsigned char *message,
478 SilcUInt32 message_len);
480 /* Notify message to the client. The notify arguments are sent in the
481 same order as servers sends them. The arguments are same as received
482 from the server except for ID's. If ID is received application receives
483 the corresponding entry to the ID. For example, if Client ID is received
484 application receives SilcClientEntry. Also, if the notify type is
485 for channel the channel entry is sent to application (even if server
486 does not send it because client library gets the channel entry from
487 the Channel ID in the packet's header). */
488 void (*notify)(SilcClient client, SilcClientConnection conn,
489 SilcNotifyType type, ...);
491 /* Command handler. This function is called always after application has
492 called a command. It will be called to indicate that the command
493 was processed. It will also be called if error occurs while processing
494 the command. The `success' indicates whether the command was sent
495 or if error occurred. The `status' indicates the actual error.
496 The `argc' and `argv' are the command line arguments sent to the
497 command by application. Note that, this is not reply to the command
498 from server, this is merely and indication to application that the
499 command was processed. */
500 void (*command)(SilcClient client, SilcClientConnection conn,
501 SilcBool success, SilcCommand command, SilcStatus status,
502 SilcUInt32 argc, unsigned char **argv);
504 /* Command reply handler. This function is called always in the command reply
505 function. If error occurs it will be called as well. Normal scenario
506 is that it will be called after the received command data has been parsed
507 and processed. The function is used to pass the received command data to
510 `conn' is the associated client connection. `cmd_payload' is the command
511 payload data received from server and it can be ignored. It is provided
512 if the application would like to re-parse the received command data,
513 however, it must be noted that the data is parsed already by the library
514 thus the payload can be ignored. `success' is FALSE if error occurred.
515 In this case arguments are not sent to the application. The `status' is
516 the command reply status server returned. The `command' is the command
517 reply being processed. The function has variable argument list and each
518 command defines the number and type of arguments it passes to the
519 application (on error they are not sent).
521 The arguments are sent in the same order as servers sends them. The
522 arguments are same as received from the server except for ID's. If
523 ID is received application receives the corresponding entry to the
524 ID. For example, if Client ID is receives application receives
526 void (*command_reply)(SilcClient client, SilcClientConnection conn,
527 SilcCommand command, SilcStatus status,
528 SilcStatus error, va_list ap);
530 /* Find authentication method and authentication data by hostname and
531 port. The hostname may be IP address as well. When the authentication
532 method has been resolved the `completion' callback with the found
533 authentication method and authentication data is called. The `conn'
535 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
536 char *hostname, SilcUInt16 port,
537 SilcGetAuthMeth completion, void *context);
539 /* Verifies received public key. The `conn_type' indicates which entity
540 (server, client etc.) has sent the public key. If user decides to trust
541 the application may save the key as trusted public key for later
542 use. The `completion' must be called after the public key has been
544 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
545 SilcConnectionType conn_type,
546 SilcPublicKey public_key,
547 SilcVerifyPublicKey completion, void *context);
549 /* Ask (interact, that is) a passphrase from user. The passphrase is
550 returned to the library by calling the `completion' callback with
551 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
552 if not then the library will attempt to encode. */
553 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
554 SilcAskPassphrase completion, void *context);
556 /* Called to indicate that incoming key agreement request has been
557 received. If the application wants to perform key agreement it may
558 call silc_client_perform_key_agreement to initiate key agreementn or
559 silc_client_send_key_agreement to provide connection point to the
560 remote client in case the `hostname' is NULL. If key agreement is
561 not desired this request can be ignored. The `protocol' is either
562 value 0 for TCP or value 1 for UDP. */
563 void (*key_agreement)(SilcClient client, SilcClientConnection conn,
564 SilcClientEntry client_entry,
565 const char *hostname, SilcUInt16 protocol,
568 /* Notifies application that file transfer protocol session is being
569 requested by the remote client indicated by the `client_entry' from
570 the `hostname' and `port'. The `session_id' is the file transfer
571 session and it can be used to either accept or reject the file
572 transfer request, by calling the silc_client_file_receive or
573 silc_client_file_close, respectively. */
574 void (*ftp)(SilcClient client, SilcClientConnection conn,
575 SilcClientEntry client_entry, SilcUInt32 session_id,
576 const char *hostname, SilcUInt16 port);
578 /* Delivers SILC session detachment data indicated by `detach_data' to the
579 application. If application has issued SILC_COMMAND_DETACH command
580 the client session in the SILC network is not quit. The client remains
581 in the network but is detached. The detachment data may be used later
582 to resume the session in the SILC Network. The appliation is
583 responsible of saving the `detach_data', to for example in a file.
585 The detachment data can be given as argument to the functions
586 silc_client_connect_to_server or silc_client_key_exchange when creating
587 connection to remote host, inside SilcClientConnectionParams structure.
588 If it is provided the client library will attempt to resume the session
589 in the network. After the connection is created successfully, the
590 application is responsible of setting the user interface for user into
591 the same state it was before detaching (showing same channels, channel
592 modes, etc). It can do this by fetching the information (like joined
593 channels) from the client library. */
594 void (*detach)(SilcClient client, SilcClientConnection conn,
595 const unsigned char *detach_data,
596 SilcUInt32 detach_data_len);
598 /* Called when the client library is up and running. After this callback
599 is called the application may start using the client library APIs. */
600 void (*running)(SilcClient client, void *application);
602 } SilcClientOperations;
605 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
609 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
610 * char **ret_nickname);
614 * A callback function provided by the application for the library in
615 * SilcClientParams structure. This function parses the formatted
616 * nickname string `nickname' and returns the true nickname to the
617 * `ret_nickname' pointer. The library can call this function at
621 typedef void (*SilcNicknameFormatParse)(const char *nickname,
622 char **ret_nickname);
624 /****s* silcclient/SilcClientAPI/SilcClientParams
628 * typedef struct { ... } SilcClientParams;
632 * Client parameters. This can be filled with proper values and
633 * given as argument to the silc_client_alloc function. The structure
634 * hold various parameters which affects the function of the client.
639 /* If this boolean is set to TRUE then the client library will use
640 threads. Any of the callback functions in the SilcClientOperations
641 and other callbacks may be called at any time in a thread. The
642 application may need to employ appropriate concurrency control
643 in the callbacks to protect application specific data. */
646 /* Rekey timeout in seconds. The client will perform rekey in this
647 time interval. If set to zero, the default value will be used. */
648 unsigned int rekey_secs;
650 /* Connection authentication method request timeout. If server does not
651 reply back the current authentication method when we've requested it
652 in this time interval we'll assume the reply will not come at all.
653 If set to zero, the default value (2 seconds) will be used. */
654 unsigned int connauth_request_secs;
656 /* Nickname format string. This can be used to order the client library
657 to save the nicknames in the library in a certain format. Since
658 nicknames are not unique in SILC it is possible to have multiple same
659 nicknames. Using this format string it is possible to order the library
660 to separate the multiple same nicknames from each other. The format
661 types are defined below and they can appear in any order in the format
662 string. If this is NULL then default format is used which is the
663 default nickname without anything else. The string MUST be NULL
666 Following format types are available:
668 %n nickname - the real nickname returned by the server (mandatory)
669 %h hostname - the stripped hostname of the client
670 %H full hostname - the full hostname of the client
671 %s server name - the server name the client is connected
672 %S full server - the full server name the client is connected
673 %a number - ascending number in case there are several
674 same nicknames (fe. nick@host and nick@host2)
676 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
677 "%a!%n@%s" (fe. nick@server, 2!nick@server)
678 "%n@%H" (fe. nick@host.domain.com)
680 By default this format is employed to the nicknames by the libary
681 only when there appears multiple same nicknames. If the library has
682 only one nickname cached the nickname is saved as is and without the
683 defined format. If you want always to save the nickname in the defined
684 format set the boolean field `nickname_force_format' to value TRUE.
686 char nickname_format[32];
688 /* If this is set to TRUE then the `nickname_format' is employed to all
689 saved nicknames even if there are no multiple same nicknames in the
690 cache. By default this is FALSE, which means that the `nickname_format'
691 is employed only if the library will receive a nickname that is
692 already saved in the cache. It is recommended to leave this to FALSE
694 SilcBool nickname_force_format;
696 /* A callback function provided by the application for the library to
697 parse the nickname from the formatted nickname string. Even though
698 the libary formats the nicknames the application knows generally the
699 format better so this function should be provided for the library
700 if the application sets the `nickname_format' field. The library
701 will call this to get the true nickname from the provided formatted
702 nickname string whenever it needs the true nickname. */
703 SilcNicknameFormatParse nickname_parse;
705 /* If this is set to TRUE then the client will ignore all incoming
706 Requested Attributes queries and does not reply anything back. This
707 usually leads into situation where server does not anymore send
708 the queries after seeing that client does not reply anything back.
709 If your application does not support Requested Attributes or you do
710 not want to use them set this to TRUE. See SilcAttribute and
711 silc_client_attribute_add for more information on attributes. */
712 SilcBool ignore_requested_attributes;
714 /* If this is set to TRUE, the silcclient library will not register and
715 deregister the cipher, pkcs, hash and hmac algorithms. The application
716 itself will need to handle that. */
717 SilcBool dont_register_crypto_library;
723 /* Initialization functions (client.c) */
725 /****f* silcclient/SilcClientAPI/silc_client_alloc
729 * SilcClient silc_client_alloc(SilcClientOperations *ops,
730 * SilcClientParams *params,
732 * const char *silc_version);
736 * Allocates new client object. This has to be done before client may
737 * work. After calling this one must call silc_client_init to initialize
738 * the client. The `application' is application specific user data pointer
739 * and caller must free it. The `silc_version' is the application version
740 * that will be used to compare against remote host's (usually a server)
741 * version string. The `application' context is accessible by the
742 * application by client->application, client being SilcClient.
745 SilcClient silc_client_alloc(SilcClientOperations *ops,
746 SilcClientParams *params,
748 const char *version_string);
750 /****f* silcclient/SilcClientAPI/silc_client_free
754 * void silc_client_free(SilcClient client);
758 * Frees client object and its internals. The execution of the client
759 * should be stopped with silc_client_stop function before calling
763 void silc_client_free(SilcClient client);
765 /****f* silcclient/SilcClientAPI/silc_client_init
769 * SilcBool silc_client_init(SilcClient client, const char *username,
770 * const char *hostname, const char *realname);
774 * Initializes the client. This makes all the necessary steps to make
775 * the client ready to be run. One must call silc_client_run to run the
776 * client. Returns FALSE if error occurred, TRUE otherwise.
778 * The `username', `hostname' and `realname' strings must be given and
779 * they must be UTF-8 encoded. The `username' is the client's username
780 * in the operating system, `hostname' is the client's host name and
781 * the `realname' is the user's real name.
784 SilcBool silc_client_init(SilcClient client, const char *username,
785 const char *hostname, const char *realname);
787 /****f* silcclient/SilcClientAPI/silc_client_run
791 * void silc_client_run(SilcClient client);
795 * Runs the client. This starts the scheduler from the utility library.
796 * When this functions returns the execution of the application is over.
797 * The client must be initialized before calling this.
800 void silc_client_run(SilcClient client);
802 /****f* silcclient/SilcClientAPI/silc_client_run_one
806 * void silc_client_run_one(SilcClient client);
810 * Runs the client and returns immeadiately. This function is used when
811 * the SILC Client object indicated by the `client' is run under some
812 * other scheduler, or event loop or main loop. On GUI applications,
813 * for example this may be desired to used to run the client under the
814 * GUI application's main loop. Typically the GUI application would
815 * register an idle task that calls this function multiple times in
816 * a second to quickly process the SILC specific data.
819 void silc_client_run_one(SilcClient client);
821 /****f* silcclient/SilcClientAPI/silc_client_stop
825 * void silc_client_stop(SilcClient client);
829 * Stops the client. This is called to stop the client and thus to stop
830 * the program. The client context must be freed with the silc_client_free
834 void silc_client_stop(SilcClient client);
837 /* Connecting functions */
839 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
843 * typedef struct { ... } SilcClientConnectionParams;
847 * Client connection parameters. This can be filled by the application
848 * and given as argument to silc_client_connect_to_server,
849 * silc_client_connect_to_client, silc_client_key_exchange or
850 * silc_client_send_key_agreement.
855 /* If this is provided the user's nickname in the network will be the
856 string given here. If it is given, it must be UTF-8 encoded. If this
857 string is not given, the user's username by default is used as nickname.
858 The nickname may later be changed by using NICK command. The maximum
859 length for the nickname string is 128 bytes. */
862 /* If this key repository pointer is non-NULL then public key received in
863 the key exchange protocol will be verified from this repository. If
864 this is not provided then the `verify_public_key' client operation will
865 be called back to application. If the boolean `verify_notfound' is set
866 to TRUE then the `verify_public_key' client operation will be called
867 in case the public key is not found in `repository'. Only public keys
868 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
869 be checked, other keys will be ignored. */
871 SilcBool verify_notfound;
873 /* Authentication data. Application may set here the authentication data
874 and authentication method to be used in connecting. If `auth_set'
875 boolean is TRUE then authentication data is provided by application.
876 If the authentication method is public key authentication then the key
877 pair given as argument when connecting will be used and `auth' field
878 is NULL. If it is passphrase authentication, it can be provided in
879 `auth' and `auth_len' fields. If `auth_set' is FALSE
880 the `get_auth_method' client operation will be called to get the
881 authentication method and data from application. */
883 SilcAuthMethod auth_method;
887 /* If this boolean is set to TRUE then the connection will use UDP instead
888 of TCP. If UDP is set the also the next `local_ip' and `local_port'
892 /* The `local_ip' specifies the local IP address used with the connection.
893 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
894 non-zero it will be used as local port with UDP connection. The remote
895 host will also send packets to the specified address and port. If the
896 `bind_ip' is non-NULL a listener is bound to that address instead of
902 /* If this boolean is set to TRUE then the key exchange is done with
903 perfect forward secrecy. */
906 /* If this boolean is set to TRUE then connection authentication protocol
907 is not performed during connecting. Only key exchange protocol is
908 performed. This usually must be set to TRUE when connecting to another
909 client, but must be FALSE with server connections. */
910 SilcBool no_authentication;
912 /* The SILC session detachment data that was returned by `detach' client
913 operation when the application detached from the network. Application
914 is responsible of saving the data and giving it as argument here
915 for resuming the session in the SILC network.
917 If this is provided here the client library will attempt to resume
918 the session in the network. After the connection is created
919 successfully, the application is responsible of setting the user
920 interface for user into the same state it was before detaching (showing
921 same channels, channel modes, etc). It can do this by fetching the
922 information (like joined channels) from the client library. */
923 unsigned char *detach_data;
924 SilcUInt32 detach_data_len;
926 /* Connection timeout. If non-zero, the connection will timeout unless
927 the SILC connection is completed in the specified amount of time. */
928 SilcUInt32 timeout_secs;
929 } SilcClientConnectionParams;
932 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
937 * silc_client_connect_to_server(SilcClient client,
938 * SilcClientConnectionParams *params,
939 * SilcPublicKey public_key,
940 * char *remote_host, int port,
941 * SilcClientConnectCallback callback,
946 * Connects to remote server `remote_host' at port `port'. This function
947 * can be used to create connection to remote SILC server and start
948 * SILC session in the SILC network. The `params' may be provided
949 * to provide various connection parameters. The `public_key' and the
950 * `private_key' is your identity used in this connection. When
951 * authentication method is based on digital signatures, this key pair
952 * will be used. The `callback' with `context' will be called after the
953 * connection has been created. It will also be called later when remote
956 * If application wishes to create the network connection itself, use
957 * the silc_client_key_exchange after creating the connection to start
958 * key exchange and authentication with the server.
960 * Returns when connecting is started and FALSE if connection was not
964 SilcBool silc_client_connect_to_server(SilcClient client,
965 SilcClientConnectionParams *params,
966 SilcPublicKey public_key,
967 SilcPrivateKey private_key,
968 char *remote_host, int port,
969 SilcClientConnectCallback callback,
972 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
977 * silc_client_connect_to_client(SilcClient client,
978 * SilcClientConnectionParams *params,
979 * SilcPublicKey public_key,
980 * char *remote_host, int port,
981 * SilcClientConnectCallback callback,
986 * Connects to remote client `remote_host' at port `port'. This function
987 * can be used to create peer-to-peer connection to another SILC client,
988 * for example, for direct conferencing, or file transfer or for other
989 * purposes. The `params' may be provided to provide various connection
990 * parameters. The `public_key' and the `private_key' is your identity
991 * used in this connection. The `callback' with `context' will be called
992 * after the connection has been created. It will also be called later
993 * when remote host disconnects.
995 * If application wishes to create the network connection itself, use
996 * the silc_client_key_exchange after creating the connection to start
997 * key exchange with the client.
999 * Returns when connecting is started and FALSE if connection was not
1003 SilcBool silc_client_connect_to_client(SilcClient client,
1004 SilcClientConnectionParams *params,
1005 SilcPublicKey public_key,
1006 SilcPrivateKey private_key,
1007 char *remote_host, int port,
1008 SilcClientConnectCallback callback,
1011 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1016 * silc_client_key_exchange(SilcClient client,
1017 * SilcClientConnectionParams *params,
1018 * SilcPublicKey public_key,
1019 * SilcPrivateKey private_key,
1020 * SilcStream stream,
1021 * SilcConnectionType conn_type,
1022 * SilcClientConnectCallback callback,
1027 * Starts key exchange protocol and authentication protocol in the
1028 * connection indicated by `stream'. This function can be be used to
1029 * start SILC session with remote host (usually server) when the caller
1030 * has itself created the connection, instead of calling the function
1031 * silc_client_connect_to_server or silc_client_connect_to_client. If
1032 * one of those functions was used this function must not be called as
1033 * in that case the key exchange is performed automatically.
1035 * Use this function only if you have created the connection by yourself.
1036 * After creating the connection the socket must be wrapped into a
1037 * socket stream. See silcsocketstream.h for more information. Note that
1038 * the `stream' must have valid remote IP address (and optionally also
1039 * hostname) and port set.
1041 * The `params' may be provided to provide various connection parameters.
1042 * The `public_key' and the `private_key' is your identity used in this
1043 * session. The `callback' with `context' will be called after the session
1044 * has been set up. It will also be called later when remote host
1045 * disconnects. The `conn_type' is the type of session this is going to
1048 * Returns TRUE when key exchange is started and FALSE if it is not started
1055 * // Create remote connection stream. Resolve hostname and IP also.
1056 * sock = create_connection(remote_host, port);
1057 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1058 * stream_create_cb, app);
1060 * // Stream callback delivers our new SilcStream context
1061 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1065 * if (status != SILC_SOCKET_OK)
1068 * // Start key exchange
1069 * silc_client_key_exchange(client, NULL, public_key, private_key,
1070 * stream, SILC_CONN_SERVER, connection_cb, app);
1075 SilcBool silc_client_key_exchange(SilcClient client,
1076 SilcClientConnectionParams *params,
1077 SilcPublicKey public_key,
1078 SilcPrivateKey private_key,
1080 SilcConnectionType conn_type,
1081 SilcClientConnectCallback callback,
1084 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1088 * void silc_client_close_connection(SilcClient client,
1089 * SilcClientConnection conn);
1093 * Closes the remote connection `conn'. The `conn' will become invalid
1094 * after this call. Usually this function is called only when explicitly
1095 * closing connection for example in case of error, or when the remote
1096 * connection was created by the application or when the remote is client
1097 * connection. Server connections are usually closed by sending QUIT
1098 * command to the server. However, this call may also be used.
1101 void silc_client_close_connection(SilcClient client,
1102 SilcClientConnection conn);
1104 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1106 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1110 * SilcBool silc_client_send_channel_message(SilcClient client,
1111 * SilcClientConnection conn,
1112 * SilcChannelEntry channel,
1113 * SilcChannelPrivateKey key,
1114 * SilcMessageFlags flags,
1116 * unsigned char *data,
1117 * SilcUInt32 data_len);
1121 * Sends packet to the `channel'. Packet to channel is always encrypted
1122 * differently from "normal" packets. SILC header of the packet is
1123 * encrypted with the next receiver's key and the rest of the packet is
1124 * encrypted with the channel specific key. Padding and HMAC is computed
1125 * with the next receiver's key. The `data' is the channel message.
1127 * If `key' is provided then that private key is used to encrypt the
1128 * channel message. If it is not provided, private keys has not been
1129 * set at all, the normal channel key is used automatically. If private
1130 * keys are set then the first key (the key that was added first as
1131 * private key) is used.
1133 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1134 * digitally signed with the SILC key pair.
1136 * Returns TRUE if the message was sent, and FALSE if error occurred or
1137 * the sending is not allowed due to channel modes (like sending is
1138 * blocked). This function is thread safe and private messages can be
1139 * sent from multiple threads.
1142 SilcBool silc_client_send_channel_message(SilcClient client,
1143 SilcClientConnection conn,
1144 SilcChannelEntry channel,
1145 SilcChannelPrivateKey key,
1146 SilcMessageFlags flags,
1148 unsigned char *data,
1149 SilcUInt32 data_len);
1151 /* Block process until channel message from `channel' is received */
1153 silc_client_receive_channel_message(SilcClient client,
1154 SilcClientConnection conn,
1155 SilcChannelEntry channel,
1156 SilcClientEntry *return_sender,
1157 SilcMessageFlags *return_flags,
1158 const unsigned char **return_message,
1159 SilcUInt32 *return_message_len);
1161 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1165 * SilcBool silc_client_send_private_message(SilcClient client,
1166 * SilcClientConnection conn,
1167 * SilcClientEntry client_entry,
1168 * SilcMessageFlags flags,
1170 * unsigned char *data,
1171 * SilcUInt32 data_len);
1175 * Sends private message to remote client. If private message key has
1176 * not been set with this client then the message will be encrypted using
1177 * normal session keys. If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
1178 * the message will be digitally signed with the SILC key pair. In this
1179 * case the caller must also provide the `hash' pointer. By default, the
1180 * hash function must be SHA-1.
1182 * Returns TRUE if the message was sent, and FALSE if error occurred.
1183 * This function is thread safe and private messages can be sent from
1187 SilcBool silc_client_send_private_message(SilcClient client,
1188 SilcClientConnection conn,
1189 SilcClientEntry client_entry,
1190 SilcMessageFlags flags,
1192 unsigned char *data,
1193 SilcUInt32 data_len);
1195 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1199 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1200 * SilcClientEntry client_entry);
1204 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1205 * channel indicated by the `channel'. NULL if client is not joined on
1209 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1210 SilcClientEntry client_entry);
1213 /* Command management */
1215 /****f* silcclient/SilcClientAPI/silc_client_command_call
1219 * SilcUInt16 silc_client_command_call(SilcClient client,
1220 * SilcClientConnection conn,
1221 * const char *command_line, ...);
1225 * Calls and executes the command indicated by the `command_name'.
1226 * The `command_line' is a string which includes the command's name and
1227 * its arguments separated with whitespaces (' '). If `command_line'
1228 * is non-NULL then all variable arguments are ignored by default.
1230 * If `command_line' is NULL, then the variable arguments define the
1231 * command's name and its arguments. The first variable argument must
1232 * be the command name. The variable argument list must be terminated
1235 * Returns FALSE if the command is not known and TRUE after command.
1236 * execution. The "command" client operation is called when the
1237 * command is executed to indicate whether the command executed
1238 * successfully or not.
1240 * The "command_reply" client operation will be called when reply is
1241 * received from the server to the command. Application may also use
1242 * the silc_client_command_pending to attach to the command reply.
1243 * The command identifier for silc_client_command_pending function after
1244 * this function call is conn->cmd_ident, which application may use.
1248 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1250 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1254 * This command executes the commands implemented inside the client
1255 * library. These commands are designed for command line applications,
1256 * but GUI application may call them too if needed. Alternatively
1257 * application may override the library and use silc_client_command_send
1261 SilcUInt16 silc_client_command_call(SilcClient client,
1262 SilcClientConnection conn,
1263 const char *command_line, ...);
1265 /* If FALSE is returned the callback will not be called again, even if there
1266 is more data coming in in the command reply. If there are other pending
1267 commands waiting for the reply, they will receive it even if some other
1268 command reply has returned FALSE. */
1269 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1270 SilcClientConnection conn,
1271 SilcCommand command,
1277 /****f* silcclient/SilcClientAPI/silc_client_command_send
1281 * SilcUInt16 silc_client_command_send(SilcClient client,
1282 * SilcClientConnection conn,
1283 * SilcCommand command,
1284 * SilcClientCommandReply reply,
1285 * void *reply_context,
1286 * SilcUInt32 argc, ...);
1290 * Generic function to send any command. The arguments must be given
1291 * already encoded into correct format and in correct order. If application
1292 * wants to perform the commands by itself, it can do so and send the data
1293 * directly to the server using this function. If application is using
1294 * the silc_client_command_call, this function is usually not used.
1295 * Programmer should get familiar with the SILC protocol commands
1296 * specification when using this function, as the arguments needs to
1297 * be encoded as specified in the protocol.
1299 * The variable arguments are a set of { type, data, data_length },
1300 * and the `argc' is the number of these sets.
1302 * The `reply' callback must be provided, and it is called when the
1303 * command reply is received from the server. Note that, when using this
1304 * function the default `command_reply' client operation will not be
1305 * called, when reply is received. Note however that, `reply' is almost
1306 * identical with `command_reply' callback, and application may forward
1307 * the reply from `reply' to `command_reply' callback, if desired.
1309 * Returns command identifier for this sent command. It can be used
1310 * to additionally attach to the command reply using the function
1311 * silc_client_command_pending, if needed. Returns 0 on error,
1315 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1316 * my_whois_command_reply, cmd_ctx,
1317 * 1, 1, nickname, strlen(nickname));
1320 SilcUInt16 silc_client_command_send(SilcClient client,
1321 SilcClientConnection conn,
1322 SilcCommand command,
1323 SilcClientCommandReply reply,
1324 void *reply_context,
1325 SilcUInt32 argc, ...);
1327 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1331 * void silc_client_command_pending(SilcClientConnection conn,
1332 * SilcCommand reply_cmd,
1333 * SilcUInt16 cmd-ident,
1334 * SilcCommandCb callback,
1339 * This function can be used to add pending command callback to be
1340 * called when an command reply is received to an earlier sent command.
1341 * The `reply_cmd' is the command that must be received in order for
1342 * the pending command callback indicated by `callback' to be called.
1343 * The `callback' will deliver the `context' and
1344 * SilcClientCommandReplyContext which includes the internals of the
1347 * The `cmd_ident' is a command identifier which was set for the earlier
1348 * sent command. The command reply will include the same identifier
1349 * and pending command callback will be called when the reply is
1350 * received with the same command identifier. It is possible to
1351 * add multiple pending command callbacks for same command and for
1354 * Application may use this function to add its own command reply
1355 * handlers if it wishes not to use the standard `command_reply'
1356 * client operation. However, note that the pending command callback
1357 * does not deliver parsed command reply, but application must parse
1360 * Note also that the application is notified about the received command
1361 * reply through the `command_reply' client operation before calling
1362 * the `callback` pending command callback. That is the normal
1363 * command reply handling, and is called regardless whether pending
1364 * command callbacks are used or not.
1366 * Commands that application calls with silc_client_command_call
1367 * will use a command identifier from conn->cmd_ident variable. After
1368 * calling the silc_client_command_call, the conn->cmd_ident includes
1369 * the command identifier that was used for the command sending.
1373 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1374 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1375 * my_ping_handler, my_ping_context);
1378 SilcBool silc_client_command_pending(SilcClientConnection conn,
1379 SilcCommand command,
1380 SilcUInt16 cmd_ident,
1381 SilcClientCommandReply reply,
1385 /* Private Message key management (client_prvmsg.c) */
1387 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1392 * silc_client_add_private_message_key(SilcClient client,
1393 * SilcClientConnection conn,
1394 * SilcClientEntry client_entry,
1395 * const char *cipher,
1397 * unsigned char *key,
1398 * SilcUInt32 key_len);
1402 * Adds a static private message key to the client library. The key
1403 * will be used to encrypt all private message between the client and
1404 * the remote client indicated by the `client_entry'. The `key' can
1405 * be for example a pre-shared-key, passphrase or similar shared secret
1406 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1407 * to assure that the requirements of the SILC protocol are met. The
1408 * API, however, allows to allocate any cipher and HMAC.
1410 * If the private message key is added to client without first receiving
1411 * a request for it from the remote `client_entry' this function will
1412 * send the request to `client_entry'. Note that, the actual key is
1413 * not sent to the network.
1415 * It is not necessary to set key for normal private message usage. If the
1416 * key is not set then the private messages are encrypted using normal
1417 * session keys. Setting the private key, however, increases the security.
1419 * Returns FALSE if the key is already set for the `client_entry', TRUE
1423 SilcBool silc_client_add_private_message_key(SilcClient client,
1424 SilcClientConnection conn,
1425 SilcClientEntry client_entry,
1429 SilcUInt32 key_len);
1431 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1436 * silc_client_add_private_message_key_ske(SilcClient client,
1437 * SilcClientConnection conn,
1438 * SilcClientEntry client_entry,
1439 * const char *cipher,
1441 * SilcSKEKeyMaterial key);
1445 * Same as silc_client_add_private_message_key but takes the key material
1446 * from the SKE key material structure. This structure is received if
1447 * the application uses the silc_client_send_key_agreement to negotiate
1448 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1449 * negotiated also in the SKE protocol.
1452 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1453 SilcClientConnection conn,
1454 SilcClientEntry client_entry,
1457 SilcSKEKeyMaterial key);
1459 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1463 * SilcBool silc_client_del_private_message_key(SilcClient client,
1464 * SilcClientConnection conn,
1465 * SilcClientEntry client_entry);
1469 * Removes the private message from the library. The key won't be used
1470 * after this to protect the private messages with the remote `client_entry'
1471 * client. Returns FALSE on error, TRUE otherwise.
1474 SilcBool silc_client_del_private_message_key(SilcClient client,
1475 SilcClientConnection conn,
1476 SilcClientEntry client_entry);
1478 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1482 * SilcPrivateMessageKeys
1483 * silc_client_list_private_message_keys(SilcClient client,
1484 * SilcClientConnection conn,
1485 * SilcUInt32 *key_count);
1489 * Returns array of set private message keys associated to the connection
1490 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1491 * count to the `key_count' argument. The array must be freed by the caller
1492 * by calling the silc_client_free_private_message_keys function. Note:
1493 * the keys returned in the array is in raw format. It might not be desired
1494 * to show the keys as is. The application might choose not to show the keys
1495 * at all or to show the fingerprints of the keys.
1498 SilcPrivateMessageKeys
1499 silc_client_list_private_message_keys(SilcClient client,
1500 SilcClientConnection conn,
1501 SilcUInt32 *key_count);
1503 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1507 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1508 * SilcUInt32 key_count);
1512 * Frees the SilcPrivateMessageKeys array returned by the function
1513 * silc_client_list_private_message_keys.
1516 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1517 SilcUInt32 key_count);
1520 /* Channel private key management (client_channel.c,
1521 SilcChannelPrivateKey is defined in idlist.h) */
1523 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1527 * SilcBool silc_client_add_channel_private_key(SilcClient client,
1528 * SilcClientConnection conn,
1529 * SilcChannelEntry channel,
1533 * unsigned char *key,
1534 * SilcUInt32 key_len,
1535 * SilcChannelPrivateKey *ret_key);
1539 * Adds private key for channel. When channel has private key then the
1540 * messages are encrypted using that key. All clients on the channel
1541 * must also know the key in order to decrypt the messages. However,
1542 * it is possible to have several private keys per one channel. In this
1543 * case only some of the clients on the channel may know the one key
1544 * and only some the other key. The `name' can be application given
1545 * name for the key. This returns the created key to the 'ret_key'
1546 * pointer if it is non-NULL;
1548 * If `cipher' and/or `hmac' is NULL then default values will be used
1549 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1551 * The private key for channel is optional. If it is not set then the
1552 * channel messages are encrypted using the channel key generated by the
1553 * server. However, setting the private key (or keys) for the channel
1554 * significantly adds security. If more than one key is set the library
1555 * will automatically try all keys at the message decryption phase. Note:
1556 * setting many keys slows down the decryption phase as all keys has to
1557 * be tried in order to find the correct decryption key. However, setting
1558 * a few keys does not have big impact to the decryption performace.
1562 * NOTE: This is entirely local setting. The key set using this function
1563 * is not sent to the network at any phase.
1565 * NOTE: If the key material was originated by the SKE protocol (using
1566 * silc_client_send_key_agreement) then the `key' MUST be the
1567 * key->send_enc_key as this is dictated by the SILC protocol. However,
1568 * currently it is not expected that the SKE key material would be used
1569 * as channel private key. However, this API allows it.
1572 SilcBool silc_client_add_channel_private_key(SilcClient client,
1573 SilcClientConnection conn,
1574 SilcChannelEntry channel,
1580 SilcChannelPrivateKey *ret_key);
1582 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1586 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1587 * SilcClientConnection conn,
1588 * SilcChannelEntry channel);
1592 * Removes all private keys from the `channel'. The old channel key is used
1593 * after calling this to protect the channel messages. Returns FALSE on
1594 * on error, TRUE otherwise.
1597 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1598 SilcClientConnection conn,
1599 SilcChannelEntry channel);
1601 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1605 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1606 * SilcClientConnection conn,
1607 * SilcChannelEntry channel,
1608 * SilcChannelPrivateKey key);
1612 * Removes and frees private key `key' from the channel `channel'.
1613 * The `key' is retrieved by calling the function
1614 * silc_client_list_channel_private_keys. The key is not used after
1615 * this. If the key was last private key then the old channel key is
1616 * used hereafter to protect the channel messages. This returns FALSE
1617 * on error, TRUE otherwise.
1620 SilcBool silc_client_del_channel_private_key(SilcClient client,
1621 SilcClientConnection conn,
1622 SilcChannelEntry channel,
1623 SilcChannelPrivateKey key);
1625 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1630 * silc_client_list_channel_private_keys(SilcClient client,
1631 * SilcClientConnection conn,
1632 * SilcChannelEntry channel);
1636 * Returns list of private keys associated to the `channel'. The caller
1637 * must free the returned list. The pointers in the list may be
1638 * used to delete the specific key by giving the pointer as argument to the
1639 * function silc_client_del_channel_private_key. Each entry in the list
1640 * is SilcChannelPrivateKey.
1643 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1644 SilcClientConnection conn,
1645 SilcChannelEntry channel);
1647 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1651 * void silc_client_current_channel_private_key(SilcClient client,
1652 * SilcClientConnection conn,
1653 * SilcChannelEntry channel,
1654 * SilcChannelPrivateKey key);
1658 * Sets the `key' to be used as current channel private key on the
1659 * `channel'. Packet sent after calling this function will be secured
1663 void silc_client_current_channel_private_key(SilcClient client,
1664 SilcClientConnection conn,
1665 SilcChannelEntry channel,
1666 SilcChannelPrivateKey key);
1669 /* Key Agreement routines */
1671 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1675 * void silc_client_send_key_agreement(SilcClient client,
1676 * SilcClientConnection conn,
1677 * SilcClientEntry client_entry,
1678 * SilcClientConnectionParams *params,
1679 * SilcPublicKey public_key,
1680 * SilcPrivateKey private_key,
1681 * SilcKeyAgreementCallback completion,
1686 * Sends key agreement request to the remote client indicated by the
1689 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1690 * the caller will provide the connection endpoint for the key agreement
1691 * connection. The `bind_ip' can be used to bind to that IP instead of
1692 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1693 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1694 * and `timeout_secs' fields in `params'. Other fields are ignored.
1695 * If `params' is NULL, then the `client_entry' is expected to provide
1696 * the connection endpoint for us. It is recommended the `timeout_secs'
1697 * is specified in case the remote client does not reply anything to
1700 * The `public_key' and `private_key' is our identity in the key agreement.
1702 * In case we do not provide the connection endpoint, we will receive
1703 * the `key_agreement' client operation when the remote send its own
1704 * key agreement request packet. We may then there start the key
1705 * agreement with silc_client_perform_key_agreement. If we provided the
1706 * the connection endpoint, the client operation will not be called.
1708 * There can be only one active key agreement for `client_entry'. Old
1709 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1712 void silc_client_send_key_agreement(SilcClient client,
1713 SilcClientConnection conn,
1714 SilcClientEntry client_entry,
1715 SilcClientConnectionParams *params,
1716 SilcPublicKey public_key,
1717 SilcPrivateKey private_key,
1718 SilcKeyAgreementCallback completion,
1721 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1726 * silc_client_perform_key_agreement(SilcClient client,
1727 * SilcClientConnection conn,
1728 * SilcClientEntry client_entry,
1729 * SilcClientConnectionParams *params,
1730 * SilcPublicKey public_key,
1731 * SilcPrivateKey private_key,
1732 * char *hostname, int port,
1733 * SilcKeyAgreementCallback completion,
1738 * Performs the key agreement protocol. Application may use this to
1739 * initiate the key agreement protocol. Usually this is called after
1740 * receiving the `key_agreement' client operation.
1742 * The `hostname' is the remote hostname (or IP address) and the `port'
1743 * is the remote port. The `completion' callback with the `context' will
1744 * be called after the key agreement protocol.
1746 * The `params' is connection parameters and it may be used to define
1747 * the key agreement connection related parameters. It may be NULL.
1750 void silc_client_perform_key_agreement(SilcClient client,
1751 SilcClientConnection conn,
1752 SilcClientEntry client_entry,
1753 SilcClientConnectionParams *params,
1754 SilcPublicKey public_key,
1755 SilcPrivateKey private_key,
1756 char *hostname, int port,
1757 SilcKeyAgreementCallback completion,
1760 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1765 * silc_client_perform_key_agreement_stream(
1766 * SilcClient client,
1767 * SilcClientConnection conn,
1768 * SilcClientEntry client_entry,
1769 * SilcClientConnectionParams *params,
1770 * SilcPublicKey public_key,
1771 * SilcPrivateKey private_key,
1772 * SilcStream stream,
1773 * SilcKeyAgreementCallback completion,
1778 * Same as silc_client_perform_key_agreement but the caller has created
1779 * the connection. The `stream' is the created connection.
1783 silc_client_perform_key_agreement_stream(SilcClient client,
1784 SilcClientConnection conn,
1785 SilcClientEntry client_entry,
1786 SilcClientConnectionParams *params,
1787 SilcPublicKey public_key,
1788 SilcPrivateKey private_key,
1790 SilcKeyAgreementCallback completion,
1793 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1797 * void silc_client_abort_key_agreement(SilcClient client,
1798 * SilcClientConnection conn,
1799 * SilcClientEntry client_entry);
1803 * This function can be called to unbind the hostname and the port for
1804 * the key agreement protocol. However, this function has effect only
1805 * before the key agreement protocol has been performed. After it has
1806 * been performed the library will automatically unbind the port. The
1807 * `client_entry' is the client to which we sent the key agreement
1808 * request. The key agreement completion callback will be called
1809 * with SILC_KEY_AGREEMENT_ABORTED status.
1812 void silc_client_abort_key_agreement(SilcClient client,
1813 SilcClientConnection conn,
1814 SilcClientEntry client_entry);
1817 /* Misc functions */
1819 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1823 * void silc_client_set_away_message(SilcClient client,
1824 * SilcClientConnection conn,
1829 * Sets away `message'. The away message may be set when the client's
1830 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1831 * to anyone who sends private message. The `message' will be sent
1832 * automatically back to the the client who send private message. If
1833 * away message is already set this replaces the old message with the
1834 * new one. If `message' is NULL the old away message is removed.
1835 * The sender may freely free the memory of the `message'.
1838 void silc_client_set_away_message(SilcClient client,
1839 SilcClientConnection conn,
1842 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1846 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1847 * SilcClientConnection conn,
1848 * SilcAuthMethod auth_meth,
1853 * Connection authentication method request callback. This is called
1854 * by the client library after it has received the authentication method
1855 * that the application requested by calling the function
1856 * silc_client_request_authentication_method.
1859 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1860 SilcClientConnection conn,
1861 SilcAuthMethod auth_meth,
1864 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1869 * silc_client_request_authentication_method(SilcClient client,
1870 * SilcClientConnection conn,
1871 * SilcConnectionAuthRequest
1877 * This function can be used to request the current authentication method
1878 * from the server. This may be called when connecting to the server
1879 * and the client library requests the authentication data from the
1880 * application. If the application does not know the current authentication
1881 * method it can request it from the server using this function.
1882 * The `callback' with `context' will be called after the server has
1883 * replied back with the current authentication method.
1887 silc_client_request_authentication_method(SilcClient client,
1888 SilcClientConnection conn,
1889 SilcConnectionAuthRequest callback,
1892 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1896 * typedef enum { ... } SilcClientMonitorStatus;
1900 * File transmission session status types. These will indicate
1901 * the status of the file transmission session.
1906 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1907 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1908 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1909 SILC_CLIENT_FILE_MONITOR_GET,
1910 SILC_CLIENT_FILE_MONITOR_PUT,
1911 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1912 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1913 } SilcClientMonitorStatus;
1916 /****d* silcclient/SilcClientAPI/SilcClientFileError
1920 * typedef enum { ... } SilcClientFileError;
1924 * File transmission error types. These types are returned by
1925 * some of the file transmission functions, and by the monitor
1926 * callback to indicate error.
1931 SILC_CLIENT_FILE_OK,
1932 SILC_CLIENT_FILE_ERROR,
1933 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1934 SILC_CLIENT_FILE_ALREADY_STARTED,
1935 SILC_CLIENT_FILE_NO_SUCH_FILE,
1936 SILC_CLIENT_FILE_PERMISSION_DENIED,
1937 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1938 } SilcClientFileError;
1941 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1945 * typedef void (*SilcClientFileMonitor)(SilcClient client,
1946 * SilcClientConnection conn,
1947 * SilcClientMonitorStatus status,
1948 * SilcClientFileError error,
1949 * SilcUInt64 offset,
1950 * SilcUInt64 filesize,
1951 * SilcClientEntry client_entry,
1952 * SilcUInt32 session_id,
1953 * const char *filepath,
1958 * Monitor callback that is called during the file transmission to
1959 * monitor the transmission process. The `status' indicates the current
1960 * monitoring process. The `error' will indicate the error type
1961 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
1962 * currently transmitted amount of total `filesize'. The `client_entry'
1963 * indicates the remote client, and the transmission session ID is the
1964 * `session_id'. The filename being transmitted is indicated by the
1968 typedef void (*SilcClientFileMonitor)(SilcClient client,
1969 SilcClientConnection conn,
1970 SilcClientMonitorStatus status,
1971 SilcClientFileError error,
1973 SilcUInt64 filesize,
1974 SilcClientEntry client_entry,
1975 SilcUInt32 session_id,
1976 const char *filepath,
1979 /****f* silcclient/SilcClientAPI/SilcClientFileName
1983 * typedef void (*SilcClientFileName)(const char *filepath,
1988 * Completion callback for the SilcClientFileAskName callback function.
1989 * Application calls this to deliver the filepath and filename where
1990 * the downloaded file is to be saved.
1993 typedef void (*SilcClientFileName)(const char *filepath,
1996 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2000 * typedef void (*SilcClientFileAskName)(SilcClient client,
2001 * SilcClientConnection conn,
2002 * SilcUInt32 session_id,
2003 * const char *remote_filename,
2004 * SilcClientFileName completion,
2005 * void *completion_context,
2010 * File name asking callback, that is called if it is given to the
2011 * silc_client_file_receive and the path given to that as argument was
2012 * NULL. The library calls this to ask the filename and filepath to
2013 * where the file is to be saved. The 'remote_filename' is the file
2014 * that is being downloaded. Application must call the 'completion'
2015 * with 'completion_context' to continue with the file downloading.
2016 * It is not mandatory to provide this to the silc_client_file_receive.
2019 typedef void (*SilcClientFileAskName)(SilcClient client,
2020 SilcClientConnection conn,
2021 SilcUInt32 session_id,
2022 const char *remote_filename,
2023 SilcClientFileName completion,
2024 void *completion_context,
2027 /****f* silcclient/SilcClientAPI/silc_client_file_send
2031 * SilcClientFileError
2032 * silc_client_file_send(SilcClient client,
2033 * SilcClientConnection conn,
2034 * SilcClientFileMonitor monitor,
2035 * void *monitor_context,
2036 * const char *local_ip,
2037 * SilcUInt32 local_port,
2038 * SilcBool do_not_bind,
2039 * SilcClientEntry client_entry,
2040 * const char *filepath);
2041 * SilcUInt32 *session_id);
2045 * Sends a file indicated by the `filepath' to the remote client
2046 * indicated by the `client_entry'. This will negotiate a secret key
2047 * with the remote client before actually starting the transmission of
2048 * the file. The `monitor' callback will be called to monitor the
2049 * transmission of the file.
2051 * This returns a file session ID for the file transmission to the
2052 * `session_id' pointer. It can be used to close the session (and
2053 * abort the file transmission) by calling the silc_client_file_close
2054 * function. The session ID is also returned in the `monitor' callback.
2056 * If the `local_ip' is provided then this will try to bind the
2057 * listener for key exchange protocol to that IP. If `local_port' is
2058 * non-zero that port is used. If `local_ip' is NULL then this will
2059 * automatically attempt to bind it to local IP address of the machine.
2060 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2061 * ignored and it is expected that the receiver will provide the
2062 * point of contact. This is usefull if the sender is behind NAT.
2064 * If error will occur during the file transfer process the error
2065 * status will be returned in the monitor callback. In this case
2066 * the application must call silc_client_file_close to close the
2071 silc_client_file_send(SilcClient client,
2072 SilcClientConnection conn,
2073 SilcClientFileMonitor monitor,
2074 void *monitor_context,
2075 const char *local_ip,
2076 SilcUInt32 local_port,
2077 SilcBool do_not_bind,
2078 SilcClientEntry client_entry,
2079 const char *filepath,
2080 SilcUInt32 *session_id);
2082 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2086 * SilcClientFileError
2087 * silc_client_file_receive(SilcClient client,
2088 * SilcClientConnection conn,
2089 * SilcClientFileMonitor monitor,
2090 * void *monitor_context,
2092 * SilcUInt32 session_id,
2093 * SilcClientFileAskName ask_name,
2094 * void *ask_name_context);
2098 * Receives a file from a client indicated by the `client_entry'. The
2099 * `session_id' indicates the file transmission session and it has been
2100 * received in the `ftp' client operation function. This will actually
2101 * perform the key agreement protocol with the remote client before
2102 * actually starting the file transmission. The `monitor' callback
2103 * will be called to monitor the transmission. If `path' is non-NULL
2104 * the file will be saved into that directory. If NULL the file is
2105 * saved in the current working directory, unless the 'ask_name'
2106 * callback is non-NULL. In this case the callback is called to ask
2107 * the path and filename from application.
2109 * If error will occur during the file transfer process the error
2110 * status will be returned in the monitor callback. In this case
2111 * the application must call silc_client_file_close to close the
2116 silc_client_file_receive(SilcClient client,
2117 SilcClientConnection conn,
2118 SilcClientFileMonitor monitor,
2119 void *monitor_context,
2121 SilcUInt32 session_id,
2122 SilcClientFileAskName ask_name,
2123 void *ask_name_context);
2125 /****f* silcclient/SilcClientAPI/silc_client_file_close
2129 * SilcClientFileError silc_client_file_close(SilcClient client,
2130 * SilcClientConnection conn,
2131 * SilcUInt32 session_id);
2135 * Closes file transmission session indicated by the `session_id'.
2136 * If file transmission is being conducted it will be aborted
2137 * automatically. This function is also used to close the session
2138 * after successful file transmission. This function can be used
2139 * also to reject incoming file transmission request. If the
2140 * session was already started and the monitor callback was set
2141 * the monitor callback will be called with the monitor status
2142 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2145 SilcClientFileError silc_client_file_close(SilcClient client,
2146 SilcClientConnection conn,
2147 SilcUInt32 session_id);
2149 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2153 * SilcAttributePayload
2154 * silc_client_attribute_add(SilcClient client,
2155 * SilcClientConnection conn,
2156 * SilcAttribute attribute,
2158 * SilcUInt32 object_size);
2162 * Add new Requsted Attribute for WHOIS command to the client library.
2163 * The `attribute' object indicated by `object' is added and allocated
2164 * SilcAttributePayload is returned. The `object' must be of correct
2165 * type and of correct size. See the SilcAttribute for object types
2166 * for different attributes. You may also get all added attributes
2167 * from the client with silc_client_attributes_get function.
2169 * Requested Attributes are different personal information about the
2170 * user, status information and other information which other users
2171 * may query with WHOIS command. Application may set these so that
2172 * if someone sends WHOIS query these attributes will be replied back
2173 * to the sender. The library always puts the public key to the
2174 * Requested Attributes, but if application wishes to add additional
2175 * public keys (or certificates) it can be done with this interface.
2176 * Library also always computes digital signature of the attributes
2177 * automatically, so application does not need to do that.
2180 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2181 SilcClientConnection conn,
2182 SilcAttribute attribute,
2184 SilcUInt32 object_size);
2186 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2190 * SilcBool silc_client_attribute_del(SilcClient client,
2191 * SilcClientConnection conn,
2192 * SilcAttribute attribute,
2193 * SilcAttributePayload attr);
2197 * Delete a Requested Attribute from the client. If the `attribute'
2198 * is non-zero then all attributes of that type are deleted and the
2199 * `attr' is ignored. If `attr' is non-NULL then that specific
2200 * attribute is deleted and `attribute' is ignored.
2202 * You may get all added attributes with the function
2203 * silc_client_attributes_get and to get the SilcAttributePayload.
2204 * This function Returns TRUE if the attribute was found and deleted.
2207 SilcBool silc_client_attribute_del(SilcClient client,
2208 SilcClientConnection conn,
2209 SilcAttribute attribute,
2210 SilcAttributePayload attr);
2212 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2216 * const SilcHashTable
2217 * silc_client_attributes_get(SilcClient client,
2218 * SilcClientConnection conn);
2222 * Returns pointer to the SilcHashTable which includes all the added
2223 * Requested Attributes. The caller must not free the hash table.
2224 * The caller may use SilcHashTableList and silc_hash_table_list to
2225 * traverse the table. Each entry in the hash table is one added
2226 * SilcAttributePayload. It is possible to delete a attribute
2227 * payload while traversing the table.
2230 SilcHashTable silc_client_attributes_get(SilcClient client,
2231 SilcClientConnection conn);
2233 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2237 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2241 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2242 * then all attributes are requested. Alternatively, `attribute' and
2243 * all variable arguments can each be requested attribute. In this case
2244 * the last must be set to zero (0) to complete the variable list of
2245 * requested attributes. See SilcAttribute for all attributes.
2246 * You can give the returned buffer as argument to for example
2247 * silc_client_get_client_by_id_resolve function.
2251 * Request all attributes
2252 * buffer = silc_client_attributes_request(0);
2254 * Request only the following attributes
2255 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2256 * SILC_ATTRIBUTE_SERVICE,
2257 * SILC_ATTRIBUTE_MOOD, 0);
2260 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2266 #endif /* SILCCLIENT_H */