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 /* Connection authentication method request timeout. If server does not
647 reply back the current authentication method when we've requested it
648 in this time interval we'll assume the reply will not come at all.
649 If set to zero, the default value (2 seconds) will be used. */
650 unsigned int connauth_request_secs;
652 /* Nickname format string. This can be used to order the client library
653 to save the nicknames in the library in a certain format. Since
654 nicknames are not unique in SILC it is possible to have multiple same
655 nicknames. Using this format string it is possible to order the library
656 to separate the multiple same nicknames from each other. The format
657 types are defined below and they can appear in any order in the format
658 string. If this is NULL then default format is used which is the
659 default nickname without anything else. The string MUST be NULL
662 Following format types are available:
664 %n nickname - the real nickname returned by the server (mandatory)
665 %h hostname - the stripped hostname of the client
666 %H full hostname - the full hostname of the client
667 %s server name - the server name the client is connected
668 %S full server - the full server name the client is connected
669 %a number - ascending number in case there are several
670 same nicknames (fe. nick@host and nick@host2)
672 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
673 "%a!%n@%s" (fe. nick@server, 2!nick@server)
674 "%n@%H" (fe. nick@host.domain.com)
676 By default this format is employed to the nicknames by the libary
677 only when there appears multiple same nicknames. If the library has
678 only one nickname cached the nickname is saved as is and without the
679 defined format. If you want always to save the nickname in the defined
680 format set the boolean field `nickname_force_format' to value TRUE.
682 char nickname_format[32];
684 /* If this is set to TRUE then the `nickname_format' is employed to all
685 saved nicknames even if there are no multiple same nicknames in the
686 cache. By default this is FALSE, which means that the `nickname_format'
687 is employed only if the library will receive a nickname that is
688 already saved in the cache. It is recommended to leave this to FALSE
690 SilcBool nickname_force_format;
692 /* A callback function provided by the application for the library to
693 parse the nickname from the formatted nickname string. Even though
694 the libary formats the nicknames the application knows generally the
695 format better so this function should be provided for the library
696 if the application sets the `nickname_format' field. The library
697 will call this to get the true nickname from the provided formatted
698 nickname string whenever it needs the true nickname. */
699 SilcNicknameFormatParse nickname_parse;
701 /* If this is set to TRUE then the client will ignore all incoming
702 Requested Attributes queries and does not reply anything back. This
703 usually leads into situation where server does not anymore send
704 the queries after seeing that client does not reply anything back.
705 If your application does not support Requested Attributes or you do
706 not want to use them set this to TRUE. See SilcAttribute and
707 silc_client_attribute_add for more information on attributes. */
708 SilcBool ignore_requested_attributes;
710 /* If this is set to TRUE, the silcclient library will not register and
711 deregister the cipher, pkcs, hash and hmac algorithms. The application
712 itself will need to handle that. */
713 SilcBool dont_register_crypto_library;
719 /* Initialization functions (client.c) */
721 /****f* silcclient/SilcClientAPI/silc_client_alloc
725 * SilcClient silc_client_alloc(SilcClientOperations *ops,
726 * SilcClientParams *params,
728 * const char *silc_version);
732 * Allocates new client object. This has to be done before client may
733 * work. After calling this one must call silc_client_init to initialize
734 * the client. The `application' is application specific user data pointer
735 * and caller must free it. The `silc_version' is the application version
736 * that will be used to compare against remote host's (usually a server)
737 * version string. The `application' context is accessible by the
738 * application by client->application, client being SilcClient.
741 SilcClient silc_client_alloc(SilcClientOperations *ops,
742 SilcClientParams *params,
744 const char *version_string);
746 /****f* silcclient/SilcClientAPI/silc_client_free
750 * void silc_client_free(SilcClient client);
754 * Frees client object and its internals. The execution of the client
755 * should be stopped with silc_client_stop function before calling
759 void silc_client_free(SilcClient client);
761 /****f* silcclient/SilcClientAPI/silc_client_init
765 * SilcBool silc_client_init(SilcClient client, const char *username,
766 * const char *hostname, const char *realname);
770 * Initializes the client. This makes all the necessary steps to make
771 * the client ready to be run. One must call silc_client_run to run the
772 * client. Returns FALSE if error occurred, TRUE otherwise.
774 * The `username', `hostname' and `realname' strings must be given and
775 * they must be UTF-8 encoded. The `username' is the client's username
776 * in the operating system, `hostname' is the client's host name and
777 * the `realname' is the user's real name.
780 SilcBool silc_client_init(SilcClient client, const char *username,
781 const char *hostname, const char *realname);
783 /****f* silcclient/SilcClientAPI/silc_client_run
787 * void silc_client_run(SilcClient client);
791 * Runs the client. This starts the scheduler from the utility library.
792 * When this functions returns the execution of the application is over.
793 * The client must be initialized before calling this.
796 void silc_client_run(SilcClient client);
798 /****f* silcclient/SilcClientAPI/silc_client_run_one
802 * void silc_client_run_one(SilcClient client);
806 * Runs the client and returns immeadiately. This function is used when
807 * the SILC Client object indicated by the `client' is run under some
808 * other scheduler, or event loop or main loop. On GUI applications,
809 * for example this may be desired to used to run the client under the
810 * GUI application's main loop. Typically the GUI application would
811 * register an idle task that calls this function multiple times in
812 * a second to quickly process the SILC specific data.
815 void silc_client_run_one(SilcClient client);
817 /****f* silcclient/SilcClientAPI/silc_client_stop
821 * void silc_client_stop(SilcClient client);
825 * Stops the client. This is called to stop the client and thus to stop
826 * the program. The client context must be freed with the silc_client_free
830 void silc_client_stop(SilcClient client);
833 /* Connecting functions */
835 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
839 * typedef struct { ... } SilcClientConnectionParams;
843 * Client connection parameters. This can be filled by the application
844 * and given as argument to silc_client_connect_to_server,
845 * silc_client_connect_to_client, silc_client_key_exchange or
846 * silc_client_send_key_agreement.
851 /* If this is provided the user's nickname in the network will be the
852 string given here. If it is given, it must be UTF-8 encoded. If this
853 string is not given, the user's username by default is used as nickname.
854 The nickname may later be changed by using NICK command. The maximum
855 length for the nickname string is 128 bytes. */
858 /* If this key repository pointer is non-NULL then public key received in
859 the key exchange protocol will be verified from this repository. If
860 this is not provided then the `verify_public_key' client operation will
861 be called back to application. If the boolean `verify_notfound' is set
862 to TRUE then the `verify_public_key' client operation will be called
863 in case the public key is not found in `repository'. Only public keys
864 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
865 be checked, other keys will be ignored. */
867 SilcBool verify_notfound;
869 /* Authentication data. Application may set here the authentication data
870 and authentication method to be used in connecting. If `auth_set'
871 boolean is TRUE then authentication data is provided by application.
872 If the authentication method is public key authentication then the key
873 pair given as argument when connecting will be used and `auth' field
874 is NULL. If it is passphrase authentication, it can be provided in
875 `auth' and `auth_len' fields. If `auth_set' is FALSE
876 the `get_auth_method' client operation will be called to get the
877 authentication method and data from application. */
879 SilcAuthMethod auth_method;
883 /* If this boolean is set to TRUE then the connection will use UDP instead
884 of TCP. If UDP is set the also the next `local_ip' and `local_port'
888 /* The `local_ip' specifies the local IP address used with the connection.
889 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
890 non-zero it will be used as local port with UDP connection. The remote
891 host will also send packets to the specified address and port. If the
892 `bind_ip' is non-NULL a listener is bound to that address instead of
898 /* If this boolean is set to TRUE then the key exchange is done with
899 perfect forward secrecy. */
902 /* If this boolean is set to TRUE then connection authentication protocol
903 is not performed during connecting. Only key exchange protocol is
904 performed. This usually must be set to TRUE when connecting to another
905 client, but must be FALSE with server connections. */
906 SilcBool no_authentication;
908 /* The SILC session detachment data that was returned by `detach' client
909 operation when the application detached from the network. Application
910 is responsible of saving the data and giving it as argument here
911 for resuming the session in the SILC network.
913 If this is provided here the client library will attempt to resume
914 the session in the network. After the connection is created
915 successfully, the application is responsible of setting the user
916 interface for user into the same state it was before detaching (showing
917 same channels, channel modes, etc). It can do this by fetching the
918 information (like joined channels) from the client library. */
919 unsigned char *detach_data;
920 SilcUInt32 detach_data_len;
922 /* Connection timeout. If non-zero, the connection will timeout unless
923 the SILC connection is completed in the specified amount of time. */
924 SilcUInt32 timeout_secs;
926 /* Rekey timeout in seconds. The client will perform rekey in this
927 time interval. If set to zero, the default value will be used
928 (3600 seconds, 1 hour). */
929 unsigned int rekey_secs;
931 } SilcClientConnectionParams;
934 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
939 * silc_client_connect_to_server(SilcClient client,
940 * SilcClientConnectionParams *params,
941 * SilcPublicKey public_key,
942 * char *remote_host, int port,
943 * SilcClientConnectCallback callback,
948 * Connects to remote server `remote_host' at port `port'. This function
949 * can be used to create connection to remote SILC server and start
950 * SILC session in the SILC network. The `params' may be provided
951 * to provide various connection parameters. The `public_key' and the
952 * `private_key' is your identity used in this connection. When
953 * authentication method is based on digital signatures, this key pair
954 * will be used. The `callback' with `context' will be called after the
955 * connection has been created. It will also be called later when remote
958 * If application wishes to create the network connection itself, use
959 * the silc_client_key_exchange after creating the connection to start
960 * key exchange and authentication with the server.
962 * Returns when connecting is started and FALSE if connection was not
966 SilcBool silc_client_connect_to_server(SilcClient client,
967 SilcClientConnectionParams *params,
968 SilcPublicKey public_key,
969 SilcPrivateKey private_key,
970 char *remote_host, int port,
971 SilcClientConnectCallback callback,
974 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
979 * silc_client_connect_to_client(SilcClient client,
980 * SilcClientConnectionParams *params,
981 * SilcPublicKey public_key,
982 * char *remote_host, int port,
983 * SilcClientConnectCallback callback,
988 * Connects to remote client `remote_host' at port `port'. This function
989 * can be used to create peer-to-peer connection to another SILC client,
990 * for example, for direct conferencing, or file transfer or for other
991 * purposes. The `params' may be provided to provide various connection
992 * parameters. The `public_key' and the `private_key' is your identity
993 * used in this connection. The `callback' with `context' will be called
994 * after the connection has been created. It will also be called later
995 * when remote host disconnects.
997 * If application wishes to create the network connection itself, use
998 * the silc_client_key_exchange after creating the connection to start
999 * key exchange with the client.
1001 * Returns when connecting is started and FALSE if connection was not
1005 SilcBool silc_client_connect_to_client(SilcClient client,
1006 SilcClientConnectionParams *params,
1007 SilcPublicKey public_key,
1008 SilcPrivateKey private_key,
1009 char *remote_host, int port,
1010 SilcClientConnectCallback callback,
1013 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1018 * silc_client_key_exchange(SilcClient client,
1019 * SilcClientConnectionParams *params,
1020 * SilcPublicKey public_key,
1021 * SilcPrivateKey private_key,
1022 * SilcStream stream,
1023 * SilcConnectionType conn_type,
1024 * SilcClientConnectCallback callback,
1029 * Starts key exchange protocol and authentication protocol in the
1030 * connection indicated by `stream'. This function can be be used to
1031 * start SILC session with remote host (usually server) when the caller
1032 * has itself created the connection, instead of calling the function
1033 * silc_client_connect_to_server or silc_client_connect_to_client. If
1034 * one of those functions was used this function must not be called as
1035 * in that case the key exchange is performed automatically.
1037 * Use this function only if you have created the connection by yourself.
1038 * After creating the connection the socket must be wrapped into a
1039 * socket stream. See silcsocketstream.h for more information. Note that
1040 * the `stream' must have valid remote IP address (and optionally also
1041 * hostname) and port set.
1043 * The `params' may be provided to provide various connection parameters.
1044 * The `public_key' and the `private_key' is your identity used in this
1045 * session. The `callback' with `context' will be called after the session
1046 * has been set up. It will also be called later when remote host
1047 * disconnects. The `conn_type' is the type of session this is going to
1050 * Returns TRUE when key exchange is started and FALSE if it is not started
1057 * // Create remote connection stream. Resolve hostname and IP also.
1058 * sock = create_connection(remote_host, port);
1059 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1060 * stream_create_cb, app);
1062 * // Stream callback delivers our new SilcStream context
1063 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1067 * if (status != SILC_SOCKET_OK)
1070 * // Start key exchange
1071 * silc_client_key_exchange(client, NULL, public_key, private_key,
1072 * stream, SILC_CONN_SERVER, connection_cb, app);
1077 SilcBool silc_client_key_exchange(SilcClient client,
1078 SilcClientConnectionParams *params,
1079 SilcPublicKey public_key,
1080 SilcPrivateKey private_key,
1082 SilcConnectionType conn_type,
1083 SilcClientConnectCallback callback,
1086 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1090 * void silc_client_close_connection(SilcClient client,
1091 * SilcClientConnection conn);
1095 * Closes the remote connection `conn'. The `conn' will become invalid
1096 * after this call. Usually this function is called only when explicitly
1097 * closing connection for example in case of error, or when the remote
1098 * connection was created by the application or when the remote is client
1099 * connection. Server connections are usually closed by sending QUIT
1100 * command to the server. However, this call may also be used.
1103 void silc_client_close_connection(SilcClient client,
1104 SilcClientConnection conn);
1106 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1108 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1112 * SilcBool silc_client_send_channel_message(SilcClient client,
1113 * SilcClientConnection conn,
1114 * SilcChannelEntry channel,
1115 * SilcChannelPrivateKey key,
1116 * SilcMessageFlags flags,
1118 * unsigned char *data,
1119 * SilcUInt32 data_len);
1123 * Sends packet to the `channel'. Packet to channel is always encrypted
1124 * differently from "normal" packets. SILC header of the packet is
1125 * encrypted with the next receiver's key and the rest of the packet is
1126 * encrypted with the channel specific key. Padding and HMAC is computed
1127 * with the next receiver's key. The `data' is the channel message.
1129 * If `key' is provided then that private key is used to encrypt the
1130 * channel message. If it is not provided, private keys has not been
1131 * set at all, the normal channel key is used automatically. If private
1132 * keys are set then the first key (the key that was added first as
1133 * private key) is used.
1135 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1136 * digitally signed with the SILC key pair.
1138 * Returns TRUE if the message was sent, and FALSE if error occurred or
1139 * the sending is not allowed due to channel modes (like sending is
1140 * blocked). This function is thread safe and private messages can be
1141 * sent from multiple threads.
1144 SilcBool silc_client_send_channel_message(SilcClient client,
1145 SilcClientConnection conn,
1146 SilcChannelEntry channel,
1147 SilcChannelPrivateKey key,
1148 SilcMessageFlags flags,
1150 unsigned char *data,
1151 SilcUInt32 data_len);
1153 /* Block process until channel message from `channel' is received */
1155 silc_client_receive_channel_message(SilcClient client,
1156 SilcClientConnection conn,
1157 SilcChannelEntry channel,
1158 SilcClientEntry *return_sender,
1159 SilcMessageFlags *return_flags,
1160 const unsigned char **return_message,
1161 SilcUInt32 *return_message_len);
1163 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1167 * SilcBool silc_client_send_private_message(SilcClient client,
1168 * SilcClientConnection conn,
1169 * SilcClientEntry client_entry,
1170 * SilcMessageFlags flags,
1172 * unsigned char *data,
1173 * SilcUInt32 data_len);
1177 * Sends private message to remote client. If private message key has
1178 * not been set with this client then the message will be encrypted using
1179 * normal session keys. If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
1180 * the message will be digitally signed with the SILC key pair. In this
1181 * case the caller must also provide the `hash' pointer. By default, the
1182 * hash function must be SHA-1.
1184 * Returns TRUE if the message was sent, and FALSE if error occurred.
1185 * This function is thread safe and private messages can be sent from
1189 SilcBool silc_client_send_private_message(SilcClient client,
1190 SilcClientConnection conn,
1191 SilcClientEntry client_entry,
1192 SilcMessageFlags flags,
1194 unsigned char *data,
1195 SilcUInt32 data_len);
1197 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1201 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1202 * SilcClientEntry client_entry);
1206 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1207 * channel indicated by the `channel'. NULL if client is not joined on
1211 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1212 SilcClientEntry client_entry);
1215 /* Command management */
1217 /****f* silcclient/SilcClientAPI/silc_client_command_call
1221 * SilcUInt16 silc_client_command_call(SilcClient client,
1222 * SilcClientConnection conn,
1223 * const char *command_line, ...);
1227 * Calls and executes the command indicated by the `command_name'.
1228 * The `command_line' is a string which includes the command's name and
1229 * its arguments separated with whitespaces (' '). If `command_line'
1230 * is non-NULL then all variable arguments are ignored by default.
1232 * If `command_line' is NULL, then the variable arguments define the
1233 * command's name and its arguments. The first variable argument must
1234 * be the command name. The variable argument list must be terminated
1237 * Returns FALSE if the command is not known and TRUE after command.
1238 * execution. The "command" client operation is called when the
1239 * command is executed to indicate whether the command executed
1240 * successfully or not.
1242 * The "command_reply" client operation will be called when reply is
1243 * received from the server to the command. Application may also use
1244 * the silc_client_command_pending to attach to the command reply.
1245 * The command identifier for silc_client_command_pending function after
1246 * this function call is conn->cmd_ident, which application may use.
1250 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1252 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1256 * This command executes the commands implemented inside the client
1257 * library. These commands are designed for command line applications,
1258 * but GUI application may call them too if needed. Alternatively
1259 * application may override the library and use silc_client_command_send
1263 SilcUInt16 silc_client_command_call(SilcClient client,
1264 SilcClientConnection conn,
1265 const char *command_line, ...);
1267 /* If FALSE is returned the callback will not be called again, even if there
1268 is more data coming in in the command reply. If there are other pending
1269 commands waiting for the reply, they will receive it even if some other
1270 command reply has returned FALSE. */
1271 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1272 SilcClientConnection conn,
1273 SilcCommand command,
1279 /****f* silcclient/SilcClientAPI/silc_client_command_send
1283 * SilcUInt16 silc_client_command_send(SilcClient client,
1284 * SilcClientConnection conn,
1285 * SilcCommand command,
1286 * SilcClientCommandReply reply,
1287 * void *reply_context,
1288 * SilcUInt32 argc, ...);
1292 * Generic function to send any command. The arguments must be given
1293 * already encoded into correct format and in correct order. If application
1294 * wants to perform the commands by itself, it can do so and send the data
1295 * directly to the server using this function. If application is using
1296 * the silc_client_command_call, this function is usually not used.
1297 * Programmer should get familiar with the SILC protocol commands
1298 * specification when using this function, as the arguments needs to
1299 * be encoded as specified in the protocol.
1301 * The variable arguments are a set of { type, data, data_length },
1302 * and the `argc' is the number of these sets.
1304 * The `reply' callback must be provided, and it is called when the
1305 * command reply is received from the server. Note that, when using this
1306 * function the default `command_reply' client operation will not be
1307 * called, when reply is received. Note however that, `reply' is almost
1308 * identical with `command_reply' callback, and application may forward
1309 * the reply from `reply' to `command_reply' callback, if desired.
1311 * Returns command identifier for this sent command. It can be used
1312 * to additionally attach to the command reply using the function
1313 * silc_client_command_pending, if needed. Returns 0 on error,
1317 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1318 * my_whois_command_reply, cmd_ctx,
1319 * 1, 1, nickname, strlen(nickname));
1322 SilcUInt16 silc_client_command_send(SilcClient client,
1323 SilcClientConnection conn,
1324 SilcCommand command,
1325 SilcClientCommandReply reply,
1326 void *reply_context,
1327 SilcUInt32 argc, ...);
1329 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1333 * void silc_client_command_pending(SilcClientConnection conn,
1334 * SilcCommand reply_cmd,
1335 * SilcUInt16 cmd-ident,
1336 * SilcCommandCb callback,
1341 * This function can be used to add pending command callback to be
1342 * called when an command reply is received to an earlier sent command.
1343 * The `reply_cmd' is the command that must be received in order for
1344 * the pending command callback indicated by `callback' to be called.
1345 * The `callback' will deliver the `context' and
1346 * SilcClientCommandReplyContext which includes the internals of the
1349 * The `cmd_ident' is a command identifier which was set for the earlier
1350 * sent command. The command reply will include the same identifier
1351 * and pending command callback will be called when the reply is
1352 * received with the same command identifier. It is possible to
1353 * add multiple pending command callbacks for same command and for
1356 * Application may use this function to add its own command reply
1357 * handlers if it wishes not to use the standard `command_reply'
1358 * client operation. However, note that the pending command callback
1359 * does not deliver parsed command reply, but application must parse
1362 * Note also that the application is notified about the received command
1363 * reply through the `command_reply' client operation before calling
1364 * the `callback` pending command callback. That is the normal
1365 * command reply handling, and is called regardless whether pending
1366 * command callbacks are used or not.
1368 * Commands that application calls with silc_client_command_call
1369 * will use a command identifier from conn->cmd_ident variable. After
1370 * calling the silc_client_command_call, the conn->cmd_ident includes
1371 * the command identifier that was used for the command sending.
1375 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1376 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1377 * my_ping_handler, my_ping_context);
1380 SilcBool silc_client_command_pending(SilcClientConnection conn,
1381 SilcCommand command,
1382 SilcUInt16 cmd_ident,
1383 SilcClientCommandReply reply,
1387 /* Private Message key management (client_prvmsg.c) */
1389 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1394 * silc_client_add_private_message_key(SilcClient client,
1395 * SilcClientConnection conn,
1396 * SilcClientEntry client_entry,
1397 * const char *cipher,
1399 * unsigned char *key,
1400 * SilcUInt32 key_len);
1404 * Adds a static private message key to the client library. The key
1405 * will be used to encrypt all private message between the client and
1406 * the remote client indicated by the `client_entry'. The `key' can
1407 * be for example a pre-shared-key, passphrase or similar shared secret
1408 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1409 * to assure that the requirements of the SILC protocol are met. The
1410 * API, however, allows to allocate any cipher and HMAC.
1412 * If the private message key is added to client without first receiving
1413 * a request for it from the remote `client_entry' this function will
1414 * send the request to `client_entry'. Note that, the actual key is
1415 * not sent to the network.
1417 * It is not necessary to set key for normal private message usage. If the
1418 * key is not set then the private messages are encrypted using normal
1419 * session keys. Setting the private key, however, increases the security.
1421 * Returns FALSE if the key is already set for the `client_entry', TRUE
1425 SilcBool silc_client_add_private_message_key(SilcClient client,
1426 SilcClientConnection conn,
1427 SilcClientEntry client_entry,
1431 SilcUInt32 key_len);
1433 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1438 * silc_client_add_private_message_key_ske(SilcClient client,
1439 * SilcClientConnection conn,
1440 * SilcClientEntry client_entry,
1441 * const char *cipher,
1443 * SilcSKEKeyMaterial key);
1447 * Same as silc_client_add_private_message_key but takes the key material
1448 * from the SKE key material structure. This structure is received if
1449 * the application uses the silc_client_send_key_agreement to negotiate
1450 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1451 * negotiated also in the SKE protocol.
1454 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1455 SilcClientConnection conn,
1456 SilcClientEntry client_entry,
1459 SilcSKEKeyMaterial key);
1461 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1465 * SilcBool silc_client_del_private_message_key(SilcClient client,
1466 * SilcClientConnection conn,
1467 * SilcClientEntry client_entry);
1471 * Removes the private message from the library. The key won't be used
1472 * after this to protect the private messages with the remote `client_entry'
1473 * client. Returns FALSE on error, TRUE otherwise.
1476 SilcBool silc_client_del_private_message_key(SilcClient client,
1477 SilcClientConnection conn,
1478 SilcClientEntry client_entry);
1480 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1484 * SilcPrivateMessageKeys
1485 * silc_client_list_private_message_keys(SilcClient client,
1486 * SilcClientConnection conn,
1487 * SilcUInt32 *key_count);
1491 * Returns array of set private message keys associated to the connection
1492 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1493 * count to the `key_count' argument. The array must be freed by the caller
1494 * by calling the silc_client_free_private_message_keys function. Note:
1495 * the keys returned in the array is in raw format. It might not be desired
1496 * to show the keys as is. The application might choose not to show the keys
1497 * at all or to show the fingerprints of the keys.
1500 SilcPrivateMessageKeys
1501 silc_client_list_private_message_keys(SilcClient client,
1502 SilcClientConnection conn,
1503 SilcUInt32 *key_count);
1505 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1509 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1510 * SilcUInt32 key_count);
1514 * Frees the SilcPrivateMessageKeys array returned by the function
1515 * silc_client_list_private_message_keys.
1518 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1519 SilcUInt32 key_count);
1522 /* Channel private key management (client_channel.c,
1523 SilcChannelPrivateKey is defined in idlist.h) */
1525 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1529 * SilcBool silc_client_add_channel_private_key(SilcClient client,
1530 * SilcClientConnection conn,
1531 * SilcChannelEntry channel,
1535 * unsigned char *key,
1536 * SilcUInt32 key_len,
1537 * SilcChannelPrivateKey *ret_key);
1541 * Adds private key for channel. When channel has private key then the
1542 * messages are encrypted using that key. All clients on the channel
1543 * must also know the key in order to decrypt the messages. However,
1544 * it is possible to have several private keys per one channel. In this
1545 * case only some of the clients on the channel may know the one key
1546 * and only some the other key. The `name' can be application given
1547 * name for the key. This returns the created key to the 'ret_key'
1548 * pointer if it is non-NULL;
1550 * If `cipher' and/or `hmac' is NULL then default values will be used
1551 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1553 * The private key for channel is optional. If it is not set then the
1554 * channel messages are encrypted using the channel key generated by the
1555 * server. However, setting the private key (or keys) for the channel
1556 * significantly adds security. If more than one key is set the library
1557 * will automatically try all keys at the message decryption phase. Note:
1558 * setting many keys slows down the decryption phase as all keys has to
1559 * be tried in order to find the correct decryption key. However, setting
1560 * a few keys does not have big impact to the decryption performace.
1564 * NOTE: This is entirely local setting. The key set using this function
1565 * is not sent to the network at any phase.
1567 * NOTE: If the key material was originated by the SKE protocol (using
1568 * silc_client_send_key_agreement) then the `key' MUST be the
1569 * key->send_enc_key as this is dictated by the SILC protocol. However,
1570 * currently it is not expected that the SKE key material would be used
1571 * as channel private key. However, this API allows it.
1574 SilcBool silc_client_add_channel_private_key(SilcClient client,
1575 SilcClientConnection conn,
1576 SilcChannelEntry channel,
1582 SilcChannelPrivateKey *ret_key);
1584 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1588 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1589 * SilcClientConnection conn,
1590 * SilcChannelEntry channel);
1594 * Removes all private keys from the `channel'. The old channel key is used
1595 * after calling this to protect the channel messages. Returns FALSE on
1596 * on error, TRUE otherwise.
1599 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1600 SilcClientConnection conn,
1601 SilcChannelEntry channel);
1603 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1607 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1608 * SilcClientConnection conn,
1609 * SilcChannelEntry channel,
1610 * SilcChannelPrivateKey key);
1614 * Removes and frees private key `key' from the channel `channel'.
1615 * The `key' is retrieved by calling the function
1616 * silc_client_list_channel_private_keys. The key is not used after
1617 * this. If the key was last private key then the old channel key is
1618 * used hereafter to protect the channel messages. This returns FALSE
1619 * on error, TRUE otherwise.
1622 SilcBool silc_client_del_channel_private_key(SilcClient client,
1623 SilcClientConnection conn,
1624 SilcChannelEntry channel,
1625 SilcChannelPrivateKey key);
1627 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1632 * silc_client_list_channel_private_keys(SilcClient client,
1633 * SilcClientConnection conn,
1634 * SilcChannelEntry channel);
1638 * Returns list of private keys associated to the `channel'. The caller
1639 * must free the returned list. The pointers in the list may be
1640 * used to delete the specific key by giving the pointer as argument to the
1641 * function silc_client_del_channel_private_key. Each entry in the list
1642 * is SilcChannelPrivateKey.
1645 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1646 SilcClientConnection conn,
1647 SilcChannelEntry channel);
1649 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1653 * void silc_client_current_channel_private_key(SilcClient client,
1654 * SilcClientConnection conn,
1655 * SilcChannelEntry channel,
1656 * SilcChannelPrivateKey key);
1660 * Sets the `key' to be used as current channel private key on the
1661 * `channel'. Packet sent after calling this function will be secured
1665 void silc_client_current_channel_private_key(SilcClient client,
1666 SilcClientConnection conn,
1667 SilcChannelEntry channel,
1668 SilcChannelPrivateKey key);
1671 /* Key Agreement routines */
1673 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1677 * void silc_client_send_key_agreement(SilcClient client,
1678 * SilcClientConnection conn,
1679 * SilcClientEntry client_entry,
1680 * SilcClientConnectionParams *params,
1681 * SilcPublicKey public_key,
1682 * SilcPrivateKey private_key,
1683 * SilcKeyAgreementCallback completion,
1688 * Sends key agreement request to the remote client indicated by the
1691 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1692 * the caller will provide the connection endpoint for the key agreement
1693 * connection. The `bind_ip' can be used to bind to that IP instead of
1694 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1695 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1696 * and `timeout_secs' fields in `params'. Other fields are ignored.
1697 * If `params' is NULL, then the `client_entry' is expected to provide
1698 * the connection endpoint for us. It is recommended the `timeout_secs'
1699 * is specified in case the remote client does not reply anything to
1702 * The `public_key' and `private_key' is our identity in the key agreement.
1704 * In case we do not provide the connection endpoint, we will receive
1705 * the `key_agreement' client operation when the remote send its own
1706 * key agreement request packet. We may then there start the key
1707 * agreement with silc_client_perform_key_agreement. If we provided the
1708 * the connection endpoint, the client operation will not be called.
1710 * There can be only one active key agreement for `client_entry'. Old
1711 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1714 void silc_client_send_key_agreement(SilcClient client,
1715 SilcClientConnection conn,
1716 SilcClientEntry client_entry,
1717 SilcClientConnectionParams *params,
1718 SilcPublicKey public_key,
1719 SilcPrivateKey private_key,
1720 SilcKeyAgreementCallback completion,
1723 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1728 * silc_client_perform_key_agreement(SilcClient client,
1729 * SilcClientConnection conn,
1730 * SilcClientEntry client_entry,
1731 * SilcClientConnectionParams *params,
1732 * SilcPublicKey public_key,
1733 * SilcPrivateKey private_key,
1734 * char *hostname, int port,
1735 * SilcKeyAgreementCallback completion,
1740 * Performs the key agreement protocol. Application may use this to
1741 * initiate the key agreement protocol. Usually this is called after
1742 * receiving the `key_agreement' client operation.
1744 * The `hostname' is the remote hostname (or IP address) and the `port'
1745 * is the remote port. The `completion' callback with the `context' will
1746 * be called after the key agreement protocol.
1748 * The `params' is connection parameters and it may be used to define
1749 * the key agreement connection related parameters. It may be NULL.
1752 void silc_client_perform_key_agreement(SilcClient client,
1753 SilcClientConnection conn,
1754 SilcClientEntry client_entry,
1755 SilcClientConnectionParams *params,
1756 SilcPublicKey public_key,
1757 SilcPrivateKey private_key,
1758 char *hostname, int port,
1759 SilcKeyAgreementCallback completion,
1762 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1767 * silc_client_perform_key_agreement_stream(
1768 * SilcClient client,
1769 * SilcClientConnection conn,
1770 * SilcClientEntry client_entry,
1771 * SilcClientConnectionParams *params,
1772 * SilcPublicKey public_key,
1773 * SilcPrivateKey private_key,
1774 * SilcStream stream,
1775 * SilcKeyAgreementCallback completion,
1780 * Same as silc_client_perform_key_agreement but the caller has created
1781 * the connection. The `stream' is the created connection.
1785 silc_client_perform_key_agreement_stream(SilcClient client,
1786 SilcClientConnection conn,
1787 SilcClientEntry client_entry,
1788 SilcClientConnectionParams *params,
1789 SilcPublicKey public_key,
1790 SilcPrivateKey private_key,
1792 SilcKeyAgreementCallback completion,
1795 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1799 * void silc_client_abort_key_agreement(SilcClient client,
1800 * SilcClientConnection conn,
1801 * SilcClientEntry client_entry);
1805 * This function can be called to unbind the hostname and the port for
1806 * the key agreement protocol. However, this function has effect only
1807 * before the key agreement protocol has been performed. After it has
1808 * been performed the library will automatically unbind the port. The
1809 * `client_entry' is the client to which we sent the key agreement
1810 * request. The key agreement completion callback will be called
1811 * with SILC_KEY_AGREEMENT_ABORTED status.
1814 void silc_client_abort_key_agreement(SilcClient client,
1815 SilcClientConnection conn,
1816 SilcClientEntry client_entry);
1819 /* Misc functions */
1821 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1825 * void silc_client_set_away_message(SilcClient client,
1826 * SilcClientConnection conn,
1831 * Sets away `message'. The away message may be set when the client's
1832 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1833 * to anyone who sends private message. The `message' will be sent
1834 * automatically back to the the client who send private message. If
1835 * away message is already set this replaces the old message with the
1836 * new one. If `message' is NULL the old away message is removed.
1837 * The sender may freely free the memory of the `message'.
1840 void silc_client_set_away_message(SilcClient client,
1841 SilcClientConnection conn,
1844 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1848 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1849 * SilcClientConnection conn,
1850 * SilcAuthMethod auth_meth,
1855 * Connection authentication method request callback. This is called
1856 * by the client library after it has received the authentication method
1857 * that the application requested by calling the function
1858 * silc_client_request_authentication_method.
1861 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1862 SilcClientConnection conn,
1863 SilcAuthMethod auth_meth,
1866 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1871 * silc_client_request_authentication_method(SilcClient client,
1872 * SilcClientConnection conn,
1873 * SilcConnectionAuthRequest
1879 * This function can be used to request the current authentication method
1880 * from the server. This may be called when connecting to the server
1881 * and the client library requests the authentication data from the
1882 * application. If the application does not know the current authentication
1883 * method it can request it from the server using this function.
1884 * The `callback' with `context' will be called after the server has
1885 * replied back with the current authentication method.
1889 silc_client_request_authentication_method(SilcClient client,
1890 SilcClientConnection conn,
1891 SilcConnectionAuthRequest callback,
1894 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1898 * typedef enum { ... } SilcClientMonitorStatus;
1902 * File transmission session status types. These will indicate
1903 * the status of the file transmission session.
1908 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1909 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1910 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1911 SILC_CLIENT_FILE_MONITOR_GET,
1912 SILC_CLIENT_FILE_MONITOR_PUT,
1913 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1914 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1915 } SilcClientMonitorStatus;
1918 /****d* silcclient/SilcClientAPI/SilcClientFileError
1922 * typedef enum { ... } SilcClientFileError;
1926 * File transmission error types. These types are returned by
1927 * some of the file transmission functions, and by the monitor
1928 * callback to indicate error.
1933 SILC_CLIENT_FILE_OK,
1934 SILC_CLIENT_FILE_ERROR,
1935 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1936 SILC_CLIENT_FILE_ALREADY_STARTED,
1937 SILC_CLIENT_FILE_NO_SUCH_FILE,
1938 SILC_CLIENT_FILE_PERMISSION_DENIED,
1939 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1940 } SilcClientFileError;
1943 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1947 * typedef void (*SilcClientFileMonitor)(SilcClient client,
1948 * SilcClientConnection conn,
1949 * SilcClientMonitorStatus status,
1950 * SilcClientFileError error,
1951 * SilcUInt64 offset,
1952 * SilcUInt64 filesize,
1953 * SilcClientEntry client_entry,
1954 * SilcUInt32 session_id,
1955 * const char *filepath,
1960 * Monitor callback that is called during the file transmission to
1961 * monitor the transmission process. The `status' indicates the current
1962 * monitoring process. The `error' will indicate the error type
1963 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
1964 * currently transmitted amount of total `filesize'. The `client_entry'
1965 * indicates the remote client, and the transmission session ID is the
1966 * `session_id'. The filename being transmitted is indicated by the
1970 typedef void (*SilcClientFileMonitor)(SilcClient client,
1971 SilcClientConnection conn,
1972 SilcClientMonitorStatus status,
1973 SilcClientFileError error,
1975 SilcUInt64 filesize,
1976 SilcClientEntry client_entry,
1977 SilcUInt32 session_id,
1978 const char *filepath,
1981 /****f* silcclient/SilcClientAPI/SilcClientFileName
1985 * typedef void (*SilcClientFileName)(const char *filepath,
1990 * Completion callback for the SilcClientFileAskName callback function.
1991 * Application calls this to deliver the filepath and filename where
1992 * the downloaded file is to be saved.
1995 typedef void (*SilcClientFileName)(const char *filepath,
1998 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2002 * typedef void (*SilcClientFileAskName)(SilcClient client,
2003 * SilcClientConnection conn,
2004 * SilcUInt32 session_id,
2005 * const char *remote_filename,
2006 * SilcClientFileName completion,
2007 * void *completion_context,
2012 * File name asking callback, that is called if it is given to the
2013 * silc_client_file_receive and the path given to that as argument was
2014 * NULL. The library calls this to ask the filename and filepath to
2015 * where the file is to be saved. The 'remote_filename' is the file
2016 * that is being downloaded. Application must call the 'completion'
2017 * with 'completion_context' to continue with the file downloading.
2018 * It is not mandatory to provide this to the silc_client_file_receive.
2021 typedef void (*SilcClientFileAskName)(SilcClient client,
2022 SilcClientConnection conn,
2023 SilcUInt32 session_id,
2024 const char *remote_filename,
2025 SilcClientFileName completion,
2026 void *completion_context,
2029 /****f* silcclient/SilcClientAPI/silc_client_file_send
2033 * SilcClientFileError
2034 * silc_client_file_send(SilcClient client,
2035 * SilcClientConnection conn,
2036 * SilcClientFileMonitor monitor,
2037 * void *monitor_context,
2038 * const char *local_ip,
2039 * SilcUInt32 local_port,
2040 * SilcBool do_not_bind,
2041 * SilcClientEntry client_entry,
2042 * const char *filepath);
2043 * SilcUInt32 *session_id);
2047 * Sends a file indicated by the `filepath' to the remote client
2048 * indicated by the `client_entry'. This will negotiate a secret key
2049 * with the remote client before actually starting the transmission of
2050 * the file. The `monitor' callback will be called to monitor the
2051 * transmission of the file.
2053 * This returns a file session ID for the file transmission to the
2054 * `session_id' pointer. It can be used to close the session (and
2055 * abort the file transmission) by calling the silc_client_file_close
2056 * function. The session ID is also returned in the `monitor' callback.
2058 * If the `local_ip' is provided then this will try to bind the
2059 * listener for key exchange protocol to that IP. If `local_port' is
2060 * non-zero that port is used. If `local_ip' is NULL then this will
2061 * automatically attempt to bind it to local IP address of the machine.
2062 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2063 * ignored and it is expected that the receiver will provide the
2064 * point of contact. This is usefull if the sender is behind NAT.
2066 * If error will occur during the file transfer process the error
2067 * status will be returned in the monitor callback. In this case
2068 * the application must call silc_client_file_close to close the
2073 silc_client_file_send(SilcClient client,
2074 SilcClientConnection conn,
2075 SilcClientFileMonitor monitor,
2076 void *monitor_context,
2077 const char *local_ip,
2078 SilcUInt32 local_port,
2079 SilcBool do_not_bind,
2080 SilcClientEntry client_entry,
2081 const char *filepath,
2082 SilcUInt32 *session_id);
2084 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2088 * SilcClientFileError
2089 * silc_client_file_receive(SilcClient client,
2090 * SilcClientConnection conn,
2091 * SilcClientFileMonitor monitor,
2092 * void *monitor_context,
2094 * SilcUInt32 session_id,
2095 * SilcClientFileAskName ask_name,
2096 * void *ask_name_context);
2100 * Receives a file from a client indicated by the `client_entry'. The
2101 * `session_id' indicates the file transmission session and it has been
2102 * received in the `ftp' client operation function. This will actually
2103 * perform the key agreement protocol with the remote client before
2104 * actually starting the file transmission. The `monitor' callback
2105 * will be called to monitor the transmission. If `path' is non-NULL
2106 * the file will be saved into that directory. If NULL the file is
2107 * saved in the current working directory, unless the 'ask_name'
2108 * callback is non-NULL. In this case the callback is called to ask
2109 * the path and filename from application.
2111 * If error will occur during the file transfer process the error
2112 * status will be returned in the monitor callback. In this case
2113 * the application must call silc_client_file_close to close the
2118 silc_client_file_receive(SilcClient client,
2119 SilcClientConnection conn,
2120 SilcClientFileMonitor monitor,
2121 void *monitor_context,
2123 SilcUInt32 session_id,
2124 SilcClientFileAskName ask_name,
2125 void *ask_name_context);
2127 /****f* silcclient/SilcClientAPI/silc_client_file_close
2131 * SilcClientFileError silc_client_file_close(SilcClient client,
2132 * SilcClientConnection conn,
2133 * SilcUInt32 session_id);
2137 * Closes file transmission session indicated by the `session_id'.
2138 * If file transmission is being conducted it will be aborted
2139 * automatically. This function is also used to close the session
2140 * after successful file transmission. This function can be used
2141 * also to reject incoming file transmission request. If the
2142 * session was already started and the monitor callback was set
2143 * the monitor callback will be called with the monitor status
2144 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2147 SilcClientFileError silc_client_file_close(SilcClient client,
2148 SilcClientConnection conn,
2149 SilcUInt32 session_id);
2151 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2155 * SilcAttributePayload
2156 * silc_client_attribute_add(SilcClient client,
2157 * SilcClientConnection conn,
2158 * SilcAttribute attribute,
2160 * SilcUInt32 object_size);
2164 * Add new Requsted Attribute for WHOIS command to the client library.
2165 * The `attribute' object indicated by `object' is added and allocated
2166 * SilcAttributePayload is returned. The `object' must be of correct
2167 * type and of correct size. See the SilcAttribute for object types
2168 * for different attributes. You may also get all added attributes
2169 * from the client with silc_client_attributes_get function.
2171 * Requested Attributes are different personal information about the
2172 * user, status information and other information which other users
2173 * may query with WHOIS command. Application may set these so that
2174 * if someone sends WHOIS query these attributes will be replied back
2175 * to the sender. The library always puts the public key to the
2176 * Requested Attributes, but if application wishes to add additional
2177 * public keys (or certificates) it can be done with this interface.
2178 * Library also always computes digital signature of the attributes
2179 * automatically, so application does not need to do that.
2182 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2183 SilcClientConnection conn,
2184 SilcAttribute attribute,
2186 SilcUInt32 object_size);
2188 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2192 * SilcBool silc_client_attribute_del(SilcClient client,
2193 * SilcClientConnection conn,
2194 * SilcAttribute attribute,
2195 * SilcAttributePayload attr);
2199 * Delete a Requested Attribute from the client. If the `attribute'
2200 * is non-zero then all attributes of that type are deleted and the
2201 * `attr' is ignored. If `attr' is non-NULL then that specific
2202 * attribute is deleted and `attribute' is ignored.
2204 * You may get all added attributes with the function
2205 * silc_client_attributes_get and to get the SilcAttributePayload.
2206 * This function Returns TRUE if the attribute was found and deleted.
2209 SilcBool silc_client_attribute_del(SilcClient client,
2210 SilcClientConnection conn,
2211 SilcAttribute attribute,
2212 SilcAttributePayload attr);
2214 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2218 * const SilcHashTable
2219 * silc_client_attributes_get(SilcClient client,
2220 * SilcClientConnection conn);
2224 * Returns pointer to the SilcHashTable which includes all the added
2225 * Requested Attributes. The caller must not free the hash table.
2226 * The caller may use SilcHashTableList and silc_hash_table_list to
2227 * traverse the table. Each entry in the hash table is one added
2228 * SilcAttributePayload. It is possible to delete a attribute
2229 * payload while traversing the table.
2232 SilcHashTable silc_client_attributes_get(SilcClient client,
2233 SilcClientConnection conn);
2235 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2239 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2243 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2244 * then all attributes are requested. Alternatively, `attribute' and
2245 * all variable arguments can each be requested attribute. In this case
2246 * the last must be set to zero (0) to complete the variable list of
2247 * requested attributes. See SilcAttribute for all attributes.
2248 * You can give the returned buffer as argument to for example
2249 * silc_client_get_client_by_id_resolve function.
2253 * Request all attributes
2254 * buffer = silc_client_attributes_request(0);
2256 * Request only the following attributes
2257 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2258 * SILC_ATTRIBUTE_SERVICE,
2259 * SILC_ATTRIBUTE_MOOD, 0);
2262 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2268 #endif /* SILCCLIENT_H */