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 } SilcKeyAgreementStatus;
275 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
279 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
280 * SilcClientConnection conn,
281 * SilcClientEntry client_entry,
282 * SilcKeyAgreementStatus status,
283 * SilcSKEKeyMaterial *key,
288 * Key agreement callback that is called after the key agreement protocol
289 * has been performed. This is called also if error occurred during the
290 * key agreement protocol. The `key' is the allocated key material and
291 * the caller is responsible of freeing it. The `key' is NULL if error
292 * has occurred. The application can freely use the `key' to whatever
293 * purpose it needs. See lib/silcske/silcske.h for the definition of
294 * the SilcSKEKeyMaterial structure.
297 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
298 SilcClientConnection conn,
299 SilcClientEntry client_entry,
300 SilcKeyAgreementStatus status,
301 SilcSKEKeyMaterial *key,
304 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
308 * typedef struct { ... } SilcPrivateMessageKeys;
312 * Structure to hold the list of private message keys. The list of these
313 * structures is returned by the silc_client_list_private_message_keys
319 SilcClientEntry client_entry; /* The remote client entry */
320 char *cipher; /* The cipher name */
321 unsigned char *key; /* The original key, If the appliation
322 provided it. This is NULL if the
323 library generated the key or 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 /* Asks whether the user would like to perform the key agreement protocol.
557 This is called after we have received an key agreement packet or an
558 reply to our key agreement packet. This returns TRUE if the user wants
559 the library to perform the key agreement protocol and FALSE if it is not
560 desired (application may start it later by calling the function
561 silc_client_perform_key_agreement). If TRUE is returned also the
562 `completion' and `context' arguments must be set by the application. */
563 SilcBool (*key_agreement)(SilcClient client, SilcClientConnection conn,
564 SilcClientEntry client_entry,
565 const char *hostname, SilcUInt16 port,
566 SilcKeyAgreementCallback *completion,
569 /* Notifies application that file transfer protocol session is being
570 requested by the remote client indicated by the `client_entry' from
571 the `hostname' and `port'. The `session_id' is the file transfer
572 session and it can be used to either accept or reject the file
573 transfer request, by calling the silc_client_file_receive or
574 silc_client_file_close, respectively. */
575 void (*ftp)(SilcClient client, SilcClientConnection conn,
576 SilcClientEntry client_entry, SilcUInt32 session_id,
577 const char *hostname, SilcUInt16 port);
579 /* Delivers SILC session detachment data indicated by `detach_data' to the
580 application. If application has issued SILC_COMMAND_DETACH command
581 the client session in the SILC network is not quit. The client remains
582 in the network but is detached. The detachment data may be used later
583 to resume the session in the SILC Network. The appliation is
584 responsible of saving the `detach_data', to for example in a file.
586 The detachment data can be given as argument to the functions
587 silc_client_connect_to_server or silc_client_key_exchange when creating
588 connection to remote host, inside SilcClientConnectionParams structure.
589 If it is provided the client library will attempt to resume the session
590 in the network. After the connection is created successfully, the
591 application is responsible of setting the user interface for user into
592 the same state it was before detaching (showing same channels, channel
593 modes, etc). It can do this by fetching the information (like joined
594 channels) from the client library. */
595 void (*detach)(SilcClient client, SilcClientConnection conn,
596 const unsigned char *detach_data,
597 SilcUInt32 detach_data_len);
599 /* Called when the client library is up and running. After this callback
600 is called the application may start using the client library APIs. */
601 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 /* Number of maximum tasks the client library's scheduler can handle.
647 If set to zero default value will be used. For WIN32 systems this
648 should be set to 64 as it is the hard limit dictated by the WIN32. */
651 /* Rekey timeout in seconds. The client will perform rekey in this
652 time interval. If set to zero, the default value will be used. */
653 unsigned int rekey_secs;
655 /* Connection authentication method request timeout. If server does not
656 reply back the current authentication method when we've requested it
657 in this time interval we'll assume the reply will not come at all.
658 If set to zero, the default value (2 seconds) will be used. */
659 unsigned int connauth_request_secs;
661 /* Nickname format string. This can be used to order the client library
662 to save the nicknames in the library in a certain format. Since
663 nicknames are not unique in SILC it is possible to have multiple same
664 nicknames. Using this format string it is possible to order the library
665 to separate the multiple same nicknames from each other. The format
666 types are defined below and they can appear in any order in the format
667 string. If this is NULL then default format is used which is the
668 default nickname without anything else. The string MUST be NULL
671 Following format types are available:
673 %n nickname - the real nickname returned by the server (mandatory)
674 %h hostname - the stripped hostname of the client
675 %H full hostname - the full hostname of the client
676 %s server name - the server name the client is connected
677 %S full server - the full server name the client is connected
678 %a number - ascending number in case there are several
679 same nicknames (fe. nick@host and nick@host2)
681 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
682 "%a!%n@%s" (fe. nick@server, 2!nick@server)
683 "%n@%H" (fe. nick@host.domain.com)
685 By default this format is employed to the nicknames by the libary
686 only when there appears multiple same nicknames. If the library has
687 only one nickname cached the nickname is saved as is and without the
688 defined format. If you want always to save the nickname in the defined
689 format set the boolean field `nickname_force_format' to value TRUE.
691 char nickname_format[32];
693 /* If this is set to TRUE then the `nickname_format' is employed to all
694 saved nicknames even if there are no multiple same nicknames in the
695 cache. By default this is FALSE, which means that the `nickname_format'
696 is employed only if the library will receive a nickname that is
697 already saved in the cache. It is recommended to leave this to FALSE
699 SilcBool nickname_force_format;
701 /* A callback function provided by the application for the library to
702 parse the nickname from the formatted nickname string. Even though
703 the libary formats the nicknames the application knows generally the
704 format better so this function should be provided for the library
705 if the application sets the `nickname_format' field. The library
706 will call this to get the true nickname from the provided formatted
707 nickname string whenever it needs the true nickname. */
708 SilcNicknameFormatParse nickname_parse;
710 /* If this is set to TRUE then the client will ignore all incoming
711 Requested Attributes queries and does not reply anything back. This
712 usually leads into situation where server does not anymore send
713 the queries after seeing that client does not reply anything back.
714 If your application does not support Requested Attributes or you do
715 not want to use them set this to TRUE. See SilcAttribute and
716 silc_client_attribute_add for more information on attributes. */
717 SilcBool ignore_requested_attributes;
719 /* If this is set to TRUE, the silcclient library will not register and
720 deregister the cipher, pkcs, hash and hmac algorithms. The application
721 itself will need to handle that. */
722 SilcBool dont_register_crypto_library;
728 /* Initialization functions (client.c) */
730 /****f* silcclient/SilcClientAPI/silc_client_alloc
734 * SilcClient silc_client_alloc(SilcClientOperations *ops,
735 * SilcClientParams *params,
737 * const char *silc_version);
741 * Allocates new client object. This has to be done before client may
742 * work. After calling this one must call silc_client_init to initialize
743 * the client. The `application' is application specific user data pointer
744 * and caller must free it. The `silc_version' is the application version
745 * that will be used to compare against remote host's (usually a server)
746 * version string. The `application' context is accessible by the
747 * application by client->application, client being SilcClient.
750 SilcClient silc_client_alloc(SilcClientOperations *ops,
751 SilcClientParams *params,
753 const char *version_string);
755 /****f* silcclient/SilcClientAPI/silc_client_free
759 * void silc_client_free(SilcClient client);
763 * Frees client object and its internals. The execution of the client
764 * should be stopped with silc_client_stop function before calling
768 void silc_client_free(SilcClient client);
770 /****f* silcclient/SilcClientAPI/silc_client_init
774 * SilcBool silc_client_init(SilcClient client, const char *username,
775 * const char *hostname, const char *realname);
779 * Initializes the client. This makes all the necessary steps to make
780 * the client ready to be run. One must call silc_client_run to run the
781 * client. Returns FALSE if error occurred, TRUE otherwise.
783 * The `username', `hostname' and `realname' strings must be given and
784 * they must be UTF-8 encoded. The `username' is the client's username
785 * in the operating system, `hostname' is the client's host name and
786 * the `realname' is the user's real name.
789 SilcBool silc_client_init(SilcClient client, const char *username,
790 const char *hostname, const char *realname);
792 /****f* silcclient/SilcClientAPI/silc_client_run
796 * void silc_client_run(SilcClient client);
800 * Runs the client. This starts the scheduler from the utility library.
801 * When this functions returns the execution of the application is over.
802 * The client must be initialized before calling this.
805 void silc_client_run(SilcClient client);
807 /****f* silcclient/SilcClientAPI/silc_client_run_one
811 * void silc_client_run_one(SilcClient client);
815 * Runs the client and returns immeadiately. This function is used when
816 * the SILC Client object indicated by the `client' is run under some
817 * other scheduler, or event loop or main loop. On GUI applications,
818 * for example this may be desired to used to run the client under the
819 * GUI application's main loop. Typically the GUI application would
820 * register an idle task that calls this function multiple times in
821 * a second to quickly process the SILC specific data.
824 void silc_client_run_one(SilcClient client);
826 /****f* silcclient/SilcClientAPI/silc_client_stop
830 * void silc_client_stop(SilcClient client);
834 * Stops the client. This is called to stop the client and thus to stop
835 * the program. The client context must be freed with the silc_client_free
839 void silc_client_stop(SilcClient client);
842 /* Connecting functions */
844 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
848 * typedef struct { ... } SilcClientConnectionParams;
852 * Client connection parameters. This can be filled by the application
853 * and given as argument to silc_client_connect_to_server,
854 * silc_client_connect_to_client or silc_client_key_exchange.
859 /* If this is provided the user's nickname in the network will be the
860 string given here. If it is given, it must be UTF-8 encoded. If this
861 string is not given, the user's username by default is used as nickname.
862 The nickname may later be changed by using NICK command. The maximum
863 length for the nickname string is 128 bytes. */
866 /* If this key repository pointer is non-NULL then public key received in
867 the key exchange protocol will be verified from this repository. If
868 this is not provided then the `verify_public_key' client operation will
869 be called back to application. If the boolean `verify_notfound' is set
870 to TRUE then the `verify_public_key' client operation will be called
871 in case the public key is not found in `repository'. Only public keys
872 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
873 be checked, other keys will be ignored. */
875 SilcBool verify_notfound;
877 /* Authentication data. Application may set here the authentication data
878 and authentication method to be used in connecting. If `auth_set'
879 boolean is TRUE then authentication data is provided by application.
880 If the authentication method is public key authentication then the key
881 pair given as argument when connecting will be used and `auth' field
882 is NULL. If it is passphrase authentication, it can be provided in
883 `auth' and `auth_len' fields. If `auth_set' is FALSE
884 the `get_auth_method' client operation will be called to get the
885 authentication method and data from application. */
887 SilcAuthMethod auth_method;
891 /* If this boolean is set to TRUE then the client's connection to the
892 remote host will use UDP instead of TCP. The `local_ip' specifies
893 the local IP address used with the UDP connection, and it must be
894 non-NULL. If the `local_port' is non-zero it will be used as local
895 port with the UDP connection. The remote host will also send packets
896 to the specified address and port. */
901 /* If this boolean is set to TRUE then the key exchange is done with
902 perfect forward secrecy. */
905 /* If this boolean is set to TRUE then connection authentication protocol
906 is not performed during connecting. Only key exchange protocol is
907 performed. This usually must be set to TRUE when connecting to another
908 client, but must be FALSE with server connections. */
909 SilcBool no_authentication;
911 /* The SILC session detachment data that was returned by `detach' client
912 operation when the application detached from the network. Application
913 is responsible of saving the data and giving it as argument here
914 for resuming the session in the SILC network.
916 If this is provided here the client library will attempt to resume
917 the session in the network. After the connection is created
918 successfully, the application is responsible of setting the user
919 interface for user into the same state it was before detaching (showing
920 same channels, channel modes, etc). It can do this by fetching the
921 information (like joined channels) from the client library. */
922 unsigned char *detach_data;
923 SilcUInt32 detach_data_len;
925 } SilcClientConnectionParams;
928 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
933 * silc_client_connect_to_server(SilcClient client,
934 * SilcClientConnectionParams *params,
935 * SilcPublicKey public_key,
936 * char *remote_host, int port,
937 * SilcClientConnectCallback callback,
942 * Connects to remote server `remote_host' at port `port'. This function
943 * can be used to create connection to remote SILC server and start
944 * SILC session in the SILC network. The `params' may be provided
945 * to provide various connection parameters. The `public_key' and the
946 * `private_key' is your identity used in this connection. When
947 * authentication method is based on digital signatures, this key pair
948 * will be used. The `callback' with `context' will be called after the
949 * connection has been created. It will also be called later when remote
952 * If application wishes to create the network connection itself, use
953 * the silc_client_key_exchange after creating the connection to start
954 * key exchange and authentication with the server.
956 * Returns when connecting is started and FALSE if connection was not
960 SilcBool silc_client_connect_to_server(SilcClient client,
961 SilcClientConnectionParams *params,
962 SilcPublicKey public_key,
963 SilcPrivateKey private_key,
964 char *remote_host, int port,
965 SilcClientConnectCallback callback,
968 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
973 * silc_client_connect_to_client(SilcClient client,
974 * SilcClientConnectionParams *params,
975 * SilcPublicKey public_key,
976 * char *remote_host, int port,
977 * SilcClientConnectCallback callback,
982 * Connects to remote client `remote_host' at port `port'. This function
983 * can be used to create peer-to-peer connection to another SILC client,
984 * for example, for direct conferencing, or file transfer or for other
985 * purposes. The `params' may be provided to provide various connection
986 * parameters. The `public_key' and the `private_key' is your identity
987 * used in this connection. The `callback' with `context' will be called
988 * after the connection has been created. It will also be called later
989 * when remote host disconnects.
991 * If application wishes to create the network connection itself, use
992 * the silc_client_key_exchange after creating the connection to start
993 * key exchange with the client.
995 * Returns when connecting is started and FALSE if connection was not
999 SilcBool silc_client_connect_to_client(SilcClient client,
1000 SilcClientConnectionParams *params,
1001 SilcPublicKey public_key,
1002 SilcPrivateKey private_key,
1003 char *remote_host, int port,
1004 SilcClientConnectCallback callback,
1007 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1012 * silc_client_key_exchange(SilcClient client,
1013 * SilcClientConnectionParams *params,
1014 * SilcPublicKey public_key,
1015 * SilcPrivateKey private_key,
1016 * SilcStream stream,
1017 * SilcConnectionType conn_type,
1018 * SilcClientConnectCallback callback,
1023 * Starts key exchange protocol and authentication protocol in the
1024 * connection indicated by `stream'. This function can be be used to
1025 * start SILC session with remote host (usually server) when the caller
1026 * has itself created the connection, instead of calling the function
1027 * silc_client_connect_to_server or silc_client_connect_to_client. If
1028 * one of those functions was used this function must not be called as
1029 * in that case the key exchange is performed automatically.
1031 * Use this function only if you have created the connection by yourself.
1032 * After creating the connection the socket must be wrapped into a
1033 * socket stream. See silcsocketstream.h for more information. Note that
1034 * the `stream' must have valid remote IP address (and optionally also
1035 * hostname) and port set.
1037 * The `params' may be provided to provide various connection parameters.
1038 * The `public_key' and the `private_key' is your identity used in this
1039 * session. The `callback' with `context' will be called after the session
1040 * has been set up. It will also be called later when remote host
1041 * disconnects. The `conn_type' is the type of session this is going to
1044 * Returns TRUE when key exchange is started and FALSE if it is not started
1051 * // Create remote connection stream. Resolve hostname and IP also.
1052 * sock = create_connection(remote_host, port);
1053 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1054 * stream_create_cb, app);
1056 * // Stream callback delivers our new SilcStream context
1057 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1061 * if (status != SILC_SOCKET_OK)
1064 * // Start key exchange
1065 * silc_client_key_exchange(client, NULL, public_key, private_key,
1066 * stream, SILC_CONN_SERVER, connection_cb, app);
1071 SilcBool silc_client_key_exchange(SilcClient client,
1072 SilcClientConnectionParams *params,
1073 SilcPublicKey public_key,
1074 SilcPrivateKey private_key,
1076 SilcConnectionType conn_type,
1077 SilcClientConnectCallback callback,
1080 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1084 * void silc_client_close_connection(SilcClient client,
1085 * SilcClientConnection conn);
1089 * Closes the remote connection `conn'. The `conn' will become invalid
1090 * after this call. Usually this function is called only when explicitly
1091 * closing connection for example in case of error, or when the remote
1092 * connection was created by the application or when the remote is client
1093 * connection. Server connections are usually closed by sending QUIT
1094 * command to the server. However, this call may also be used.
1097 void silc_client_close_connection(SilcClient client,
1098 SilcClientConnection conn);
1100 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1102 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1106 * SilcBool silc_client_send_channel_message(SilcClient client,
1107 * SilcClientConnection conn,
1108 * SilcChannelEntry channel,
1109 * SilcChannelPrivateKey key,
1110 * SilcMessageFlags flags,
1112 * unsigned char *data,
1113 * SilcUInt32 data_len);
1117 * Sends packet to the `channel'. Packet to channel is always encrypted
1118 * differently from "normal" packets. SILC header of the packet is
1119 * encrypted with the next receiver's key and the rest of the packet is
1120 * encrypted with the channel specific key. Padding and HMAC is computed
1121 * with the next receiver's key. The `data' is the channel message.
1123 * If `key' is provided then that private key is used to encrypt the
1124 * channel message. If it is not provided, private keys has not been
1125 * set at all, the normal channel key is used automatically. If private
1126 * keys are set then the first key (the key that was added first as
1127 * private key) is used.
1129 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1130 * digitally signed with the SILC key pair.
1132 * Returns TRUE if the message was sent, and FALSE if error occurred or
1133 * the sending is not allowed due to channel modes (like sending is
1134 * blocked). This function is thread safe and private messages can be
1135 * sent from multiple threads.
1138 SilcBool silc_client_send_channel_message(SilcClient client,
1139 SilcClientConnection conn,
1140 SilcChannelEntry channel,
1141 SilcChannelPrivateKey key,
1142 SilcMessageFlags flags,
1144 unsigned char *data,
1145 SilcUInt32 data_len);
1147 /* Block process until channel message from `channel' is received */
1149 silc_client_receive_channel_message(SilcClient client,
1150 SilcClientConnection conn,
1151 SilcChannelEntry channel,
1152 SilcClientEntry *return_sender,
1153 SilcMessageFlags *return_flags,
1154 const unsigned char **return_message,
1155 SilcUInt32 *return_message_len);
1157 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1161 * SilcBool silc_client_send_private_message(SilcClient client,
1162 * SilcClientConnection conn,
1163 * SilcClientEntry client_entry,
1164 * SilcMessageFlags flags,
1166 * unsigned char *data,
1167 * SilcUInt32 data_len);
1171 * Sends private message to remote client. If private message key has
1172 * not been set with this client then the message will be encrypted using
1173 * normal session keys. If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
1174 * the message will be digitally signed with the SILC key pair. In this
1175 * case the caller must also provide the `hash' pointer. By default, the
1176 * hash function must be SHA-1.
1178 * Returns TRUE if the message was sent, and FALSE if error occurred.
1179 * This function is thread safe and private messages can be sent from
1183 SilcBool silc_client_send_private_message(SilcClient client,
1184 SilcClientConnection conn,
1185 SilcClientEntry client_entry,
1186 SilcMessageFlags flags,
1188 unsigned char *data,
1189 SilcUInt32 data_len);
1191 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1195 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1196 * SilcClientEntry client_entry);
1200 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1201 * channel indicated by the `channel'. NULL if client is not joined on
1205 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1206 SilcClientEntry client_entry);
1209 /* Command management */
1211 /****f* silcclient/SilcClientAPI/silc_client_command_call
1215 * SilcUInt16 silc_client_command_call(SilcClient client,
1216 * SilcClientConnection conn,
1217 * const char *command_line, ...);
1221 * Calls and executes the command indicated by the `command_name'.
1222 * The `command_line' is a string which includes the command's name and
1223 * its arguments separated with whitespaces (' '). If `command_line'
1224 * is non-NULL then all variable arguments are ignored by default.
1226 * If `command_line' is NULL, then the variable arguments define the
1227 * command's name and its arguments. The first variable argument must
1228 * be the command name. The variable argument list must be terminated
1231 * Returns FALSE if the command is not known and TRUE after command.
1232 * execution. The "command" client operation is called when the
1233 * command is executed to indicate whether the command executed
1234 * successfully or not.
1236 * The "command_reply" client operation will be called when reply is
1237 * received from the server to the command. Application may also use
1238 * the silc_client_command_pending to attach to the command reply.
1239 * The command identifier for silc_client_command_pending function after
1240 * this function call is conn->cmd_ident, which application may use.
1244 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1246 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1250 * This command executes the commands implemented inside the client
1251 * library. These commands are designed for command line applications,
1252 * but GUI application may call them too if needed. Alternatively
1253 * application may override the library and use silc_client_command_send
1257 SilcUInt16 silc_client_command_call(SilcClient client,
1258 SilcClientConnection conn,
1259 const char *command_line, ...);
1261 /* If FALSE is returned the callback will not be called again, even if there
1262 is more data coming in in the command reply. If there are other pending
1263 commands waiting for the reply, they will receive it even if some other
1264 command reply has returned FALSE. */
1265 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1266 SilcClientConnection conn,
1267 SilcCommand command,
1273 /****f* silcclient/SilcClientAPI/silc_client_command_send
1277 * SilcUInt16 silc_client_command_send(SilcClient client,
1278 * SilcClientConnection conn,
1279 * SilcCommand command,
1280 * SilcClientCommandReply reply,
1281 * void *reply_context,
1282 * SilcUInt32 argc, ...);
1286 * Generic function to send any command. The arguments must be given
1287 * already encoded into correct format and in correct order. If application
1288 * wants to perform the commands by itself, it can do so and send the data
1289 * directly to the server using this function. If application is using
1290 * the silc_client_command_call, this function is usually not used.
1291 * Programmer should get familiar with the SILC protocol commands
1292 * specification when using this function, as the arguments needs to
1293 * be encoded as specified in the protocol.
1295 * The variable arguments are a set of { type, data, data_length },
1296 * and the `argc' is the number of these sets.
1298 * The `reply' callback must be provided, and it is called when the
1299 * command reply is received from the server. Note that, when using this
1300 * function the default `command_reply' client operation will not be
1301 * called, when reply is received. Note however that, `reply' is almost
1302 * identical with `command_reply' callback, and application may forward
1303 * the reply from `reply' to `command_reply' callback, if desired.
1305 * Returns command identifier for this sent command. It can be used
1306 * to additionally attach to the command reply using the function
1307 * silc_client_command_pending, if needed. Returns 0 on error,
1311 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1312 * my_whois_command_reply, cmd_ctx,
1313 * 1, 1, nickname, strlen(nickname));
1316 SilcUInt16 silc_client_command_send(SilcClient client,
1317 SilcClientConnection conn,
1318 SilcCommand command,
1319 SilcClientCommandReply reply,
1320 void *reply_context,
1321 SilcUInt32 argc, ...);
1323 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1327 * void silc_client_command_pending(SilcClientConnection conn,
1328 * SilcCommand reply_cmd,
1329 * SilcUInt16 cmd-ident,
1330 * SilcCommandCb callback,
1335 * This function can be used to add pending command callback to be
1336 * called when an command reply is received to an earlier sent command.
1337 * The `reply_cmd' is the command that must be received in order for
1338 * the pending command callback indicated by `callback' to be called.
1339 * The `callback' will deliver the `context' and
1340 * SilcClientCommandReplyContext which includes the internals of the
1343 * The `cmd_ident' is a command identifier which was set for the earlier
1344 * sent command. The command reply will include the same identifier
1345 * and pending command callback will be called when the reply is
1346 * received with the same command identifier. It is possible to
1347 * add multiple pending command callbacks for same command and for
1350 * Application may use this function to add its own command reply
1351 * handlers if it wishes not to use the standard `command_reply'
1352 * client operation. However, note that the pending command callback
1353 * does not deliver parsed command reply, but application must parse
1356 * Note also that the application is notified about the received command
1357 * reply through the `command_reply' client operation before calling
1358 * the `callback` pending command callback. That is the normal
1359 * command reply handling, and is called regardless whether pending
1360 * command callbacks are used or not.
1362 * Commands that application calls with silc_client_command_call
1363 * will use a command identifier from conn->cmd_ident variable. After
1364 * calling the silc_client_command_call, the conn->cmd_ident includes
1365 * the command identifier that was used for the command sending.
1369 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1370 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1371 * my_ping_handler, my_ping_context);
1374 SilcBool silc_client_command_pending(SilcClientConnection conn,
1375 SilcCommand command,
1376 SilcUInt16 cmd_ident,
1377 SilcClientCommandReply reply,
1381 /* Private Message key management (client_prvmsg.c) */
1383 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1388 * silc_client_add_private_message_key(SilcClient client,
1389 * SilcClientConnection conn,
1390 * SilcClientEntry client_entry,
1391 * const char *cipher,
1393 * unsigned char *key,
1394 * SilcUInt32 key_len,
1395 * SilcBool generate_key,
1396 * SilcBool responder);
1400 * Adds private message key to the client library. The key will be used to
1401 * encrypt all private message between the client and the remote client
1402 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1403 * value `generate_key' is TRUE the library will generate random key.
1404 * The `key' maybe for example pre-shared-key, passphrase or similar.
1405 * The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
1406 * that the requirements of the SILC protocol are met. The API, however,
1407 * allows to allocate any cipher and HMAC.
1409 * If `responder' is TRUE then the sending and receiving keys will be
1410 * set according the client being the receiver of the private key. If
1411 * FALSE the client is being the sender (or negotiator) of the private
1414 * It is not necessary to set key for normal private message usage. If the
1415 * key is not set then the private messages are encrypted using normal
1416 * session keys. Setting the private key, however, increases the security.
1418 * Returns FALSE if the key is already set for the `client_entry', TRUE
1422 SilcBool silc_client_add_private_message_key(SilcClient client,
1423 SilcClientConnection conn,
1424 SilcClientEntry client_entry,
1429 SilcBool generate_key,
1430 SilcBool responder);
1432 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1437 * silc_client_add_private_message_key_ske(SilcClient client,
1438 * SilcClientConnection conn,
1439 * SilcClientEntry client_entry,
1440 * const char *cipher,
1442 * SilcSKEKeyMaterial key);
1446 * Same as silc_client_add_private_message_key but takes the key material
1447 * from the SKE key material structure. This structure is received if
1448 * the application uses the silc_client_send_key_agreement to negotiate
1449 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1450 * negotiated also in the SKE protocol.
1453 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1454 SilcClientConnection conn,
1455 SilcClientEntry client_entry,
1458 SilcSKEKeyMaterial key,
1459 SilcBool responder);
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_send_private_message_key_request
1510 * silc_client_send_private_message_key_request(SilcClient client,
1511 * SilcClientConnection conn,
1512 * SilcClientEntry client_entry);
1516 * This function can be used to send an private message key indicator
1517 * request to the remote client indicated by 'client_entry'. This can
1518 * be used when setting a static or pre-shared private message key.
1519 * The sender of this packet is the initiator and must set the 'responder'
1520 * argument in silc_client_add_private_message_key function to FALSE.
1521 * The receiver of this indicator request must set it to TRUE, if the
1522 * receiver decides to set a private message key. By using this
1523 * function applications may automate initiator/responder setting in
1524 * private message key functions, without asking from user which one is
1525 * the initiator and which one is responder.
1529 * The sender of this packet must set the private message key for
1530 * 'client_entry' before calling this function. The 'responder'
1531 * argument MUST be set to FALSE when setting the key.
1535 silc_client_send_private_message_key_request(SilcClient client,
1536 SilcClientConnection conn,
1537 SilcClientEntry client_entry);
1539 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1543 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1544 * SilcUInt32 key_count);
1548 * Frees the SilcPrivateMessageKeys array returned by the function
1549 * silc_client_list_private_message_keys.
1552 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1553 SilcUInt32 key_count);
1556 /* Channel private key management (client_channel.c,
1557 SilcChannelPrivateKey is defined in idlist.h) */
1559 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1563 * SilcBool silc_client_add_channel_private_key(SilcClient client,
1564 * SilcClientConnection conn,
1565 * SilcChannelEntry channel,
1569 * unsigned char *key,
1570 * SilcUInt32 key_len,
1571 * SilcChannelPrivateKey *ret_key);
1575 * Adds private key for channel. When channel has private key then the
1576 * messages are encrypted using that key. All clients on the channel
1577 * must also know the key in order to decrypt the messages. However,
1578 * it is possible to have several private keys per one channel. In this
1579 * case only some of the clients on the channel may know the one key
1580 * and only some the other key. The `name' can be application given
1581 * name for the key. This returns the created key to the 'ret_key'
1582 * pointer if it is non-NULL;
1584 * If `cipher' and/or `hmac' is NULL then default values will be used
1585 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1587 * The private key for channel is optional. If it is not set then the
1588 * channel messages are encrypted using the channel key generated by the
1589 * server. However, setting the private key (or keys) for the channel
1590 * significantly adds security. If more than one key is set the library
1591 * will automatically try all keys at the message decryption phase. Note:
1592 * setting many keys slows down the decryption phase as all keys has to
1593 * be tried in order to find the correct decryption key. However, setting
1594 * a few keys does not have big impact to the decryption performace.
1598 * NOTE: This is entirely local setting. The key set using this function
1599 * is not sent to the network at any phase.
1601 * NOTE: If the key material was originated by the SKE protocol (using
1602 * silc_client_send_key_agreement) then the `key' MUST be the
1603 * key->send_enc_key as this is dictated by the SILC protocol. However,
1604 * currently it is not expected that the SKE key material would be used
1605 * as channel private key. However, this API allows it.
1608 SilcBool silc_client_add_channel_private_key(SilcClient client,
1609 SilcClientConnection conn,
1610 SilcChannelEntry channel,
1616 SilcChannelPrivateKey *ret_key);
1618 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1622 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1623 * SilcClientConnection conn,
1624 * SilcChannelEntry channel);
1628 * Removes all private keys from the `channel'. The old channel key is used
1629 * after calling this to protect the channel messages. Returns FALSE on
1630 * on error, TRUE otherwise.
1633 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1634 SilcClientConnection conn,
1635 SilcChannelEntry channel);
1637 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1641 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1642 * SilcClientConnection conn,
1643 * SilcChannelEntry channel,
1644 * SilcChannelPrivateKey key);
1648 * Removes and frees private key `key' from the channel `channel'.
1649 * The `key' is retrieved by calling the function
1650 * silc_client_list_channel_private_keys. The key is not used after
1651 * this. If the key was last private key then the old channel key is
1652 * used hereafter to protect the channel messages. This returns FALSE
1653 * on error, TRUE otherwise.
1656 SilcBool silc_client_del_channel_private_key(SilcClient client,
1657 SilcClientConnection conn,
1658 SilcChannelEntry channel,
1659 SilcChannelPrivateKey key);
1661 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1666 * silc_client_list_channel_private_keys(SilcClient client,
1667 * SilcClientConnection conn,
1668 * SilcChannelEntry channel);
1672 * Returns list of private keys associated to the `channel'. The caller
1673 * must free the returned list. The pointers in the list may be
1674 * used to delete the specific key by giving the pointer as argument to the
1675 * function silc_client_del_channel_private_key. Each entry in the list
1676 * is SilcChannelPrivateKey.
1679 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1680 SilcClientConnection conn,
1681 SilcChannelEntry channel);
1683 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1687 * void silc_client_current_channel_private_key(SilcClient client,
1688 * SilcClientConnection conn,
1689 * SilcChannelEntry channel,
1690 * SilcChannelPrivateKey key);
1694 * Sets the `key' to be used as current channel private key on the
1695 * `channel'. Packet sent after calling this function will be secured
1699 void silc_client_current_channel_private_key(SilcClient client,
1700 SilcClientConnection conn,
1701 SilcChannelEntry channel,
1702 SilcChannelPrivateKey key);
1705 /* Key Agreement routines (client_keyagr.c) */
1707 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1711 * void silc_client_send_key_agreement(SilcClient client,
1712 * SilcClientConnection conn,
1713 * SilcClientEntry client_entry,
1716 * SilcUInt32 timeout_secs,
1717 * SilcKeyAgreementCallback completion,
1722 * Sends key agreement request to the remote client indicated by the
1723 * `client_entry'. If the caller provides the `hostname' and the `port'
1724 * arguments then the library will bind the client to that hostname and
1725 * that port for the key agreement protocol. It also sends the `hostname'
1726 * and the `port' in the key agreement packet to the remote client. This
1727 * would indicate that the remote client may initiate the key agreement
1728 * protocol to the `hostname' on the `port'. If port is zero then the
1729 * bound port is undefined (the operating system defines it).
1731 * If the `hostname' and `port' is not provided then empty key agreement
1732 * packet is sent to the remote client. The remote client may reply with
1733 * the same packet including its hostname and port. If the library receives
1734 * the reply from the remote client the `key_agreement' client operation
1735 * callback will be called to verify whether the user wants to perform the
1736 * key agreement or not.
1740 * NOTE: If the application provided the `hostname' and the `port' and the
1741 * remote side initiates the key agreement protocol it is not verified
1742 * from the user anymore whether the protocol should be executed or not.
1743 * By setting the `hostname' and `port' the user gives permission to
1744 * perform the protocol (we are responder in this case).
1746 * NOTE: If the remote side decides not to initiate the key agreement
1747 * or decides not to reply with the key agreement packet then we cannot
1748 * perform the key agreement at all. If the key agreement protocol is
1749 * performed the `completion' callback with the `context' will be called.
1750 * If remote side decides to ignore the request the `completion' will be
1751 * called after the specified timeout, `timeout_secs'.
1753 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1754 * will not be called at all since this does nothing more than sending
1755 * a packet to the remote host.
1757 * NOTE: There can be only one active key agreement for one client entry.
1758 * Before setting new one, the old one must be finished (it is finished
1759 * after calling the completion callback) or the function
1760 * silc_client_abort_key_agreement must be called.
1763 void silc_client_send_key_agreement(SilcClient client,
1764 SilcClientConnection conn,
1765 SilcClientEntry client_entry,
1766 const char *hostname,
1767 const char *bindhost,
1769 SilcUInt32 timeout_secs,
1770 SilcKeyAgreementCallback completion,
1773 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1778 * silc_client_perform_key_agreement(SilcClient client,
1779 * SilcClientConnection conn,
1780 * SilcClientEntry client_entry,
1783 * SilcKeyAgreementCallback completion,
1788 * Performs the actual key agreement protocol. Application may use this
1789 * to initiate the key agreement protocol. This can be called for example
1790 * after the application has received the `key_agreement' client operation,
1791 * and did not return TRUE from it.
1793 * The `hostname' is the remote hostname (or IP address) and the `port'
1794 * is the remote port. The `completion' callback with the `context' will
1795 * be called after the key agreement protocol.
1799 * NOTE: If the application returns TRUE in the `key_agreement' client
1800 * operation the library will automatically start the key agreement. In this
1801 * case the application must not call this function. However, application
1802 * may choose to just ignore the `key_agreement' client operation (and
1803 * merely just print information about it on the screen) and call this
1804 * function when the user whishes to do so (by, for example, giving some
1805 * specific command). Thus, the API provides both, automatic and manual
1806 * initiation of the key agreement. Calling this function is the manual
1807 * initiation and returning TRUE in the `key_agreement' client operation
1808 * is the automatic initiation.
1811 void silc_client_perform_key_agreement(SilcClient client,
1812 SilcClientConnection conn,
1813 SilcClientEntry client_entry,
1816 SilcKeyAgreementCallback completion,
1819 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1824 * silc_client_perform_key_agreement_fd(SilcClient client,
1825 * SilcClientConnection conn,
1826 * SilcClientEntry client_entry,
1829 * SilcKeyAgreementCallback completion,
1834 * Same as above but application has created already the connection to
1835 * the remote host. The `sock' is the socket to the remote connection.
1836 * Application can use this function if it does not want the client library
1837 * to create the connection.
1840 void silc_client_perform_key_agreement_fd(SilcClient client,
1841 SilcClientConnection conn,
1842 SilcClientEntry client_entry,
1845 SilcKeyAgreementCallback completion,
1848 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1852 * void silc_client_abort_key_agreement(SilcClient client,
1853 * SilcClientConnection conn,
1854 * SilcClientEntry client_entry);
1858 * This function can be called to unbind the hostname and the port for
1859 * the key agreement protocol. However, this function has effect only
1860 * before the key agreement protocol has been performed. After it has
1861 * been performed the library will automatically unbind the port. The
1862 * `client_entry' is the client to which we sent the key agreement
1863 * request. The key agreement completion callback will be called
1864 * with SILC_KEY_AGREEMENT_ABORTED status.
1867 void silc_client_abort_key_agreement(SilcClient client,
1868 SilcClientConnection conn,
1869 SilcClientEntry client_entry);
1872 /* Misc functions */
1874 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1878 * void silc_client_set_away_message(SilcClient client,
1879 * SilcClientConnection conn,
1884 * Sets away `message'. The away message may be set when the client's
1885 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1886 * to anyone who sends private message. The `message' will be sent
1887 * automatically back to the the client who send private message. If
1888 * away message is already set this replaces the old message with the
1889 * new one. If `message' is NULL the old away message is removed.
1890 * The sender may freely free the memory of the `message'.
1893 void silc_client_set_away_message(SilcClient client,
1894 SilcClientConnection conn,
1897 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1901 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1902 * SilcClientConnection conn,
1903 * SilcAuthMethod auth_meth,
1908 * Connection authentication method request callback. This is called
1909 * by the client library after it has received the authentication method
1910 * that the application requested by calling the function
1911 * silc_client_request_authentication_method.
1914 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1915 SilcClientConnection conn,
1916 SilcAuthMethod auth_meth,
1919 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1924 * silc_client_request_authentication_method(SilcClient client,
1925 * SilcClientConnection conn,
1926 * SilcConnectionAuthRequest
1932 * This function can be used to request the current authentication method
1933 * from the server. This may be called when connecting to the server
1934 * and the client library requests the authentication data from the
1935 * application. If the application does not know the current authentication
1936 * method it can request it from the server using this function.
1937 * The `callback' with `context' will be called after the server has
1938 * replied back with the current authentication method.
1942 silc_client_request_authentication_method(SilcClient client,
1943 SilcClientConnection conn,
1944 SilcConnectionAuthRequest callback,
1947 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1951 * typedef enum { ... } SilcClientMonitorStatus;
1955 * File transmission session status types. These will indicate
1956 * the status of the file transmission session.
1961 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1962 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1963 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1964 SILC_CLIENT_FILE_MONITOR_GET,
1965 SILC_CLIENT_FILE_MONITOR_PUT,
1966 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1967 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1968 } SilcClientMonitorStatus;
1971 /****d* silcclient/SilcClientAPI/SilcClientFileError
1975 * typedef enum { ... } SilcClientFileError;
1979 * File transmission error types. These types are returned by
1980 * some of the file transmission functions, and by the monitor
1981 * callback to indicate error.
1986 SILC_CLIENT_FILE_OK,
1987 SILC_CLIENT_FILE_ERROR,
1988 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1989 SILC_CLIENT_FILE_ALREADY_STARTED,
1990 SILC_CLIENT_FILE_NO_SUCH_FILE,
1991 SILC_CLIENT_FILE_PERMISSION_DENIED,
1992 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1993 } SilcClientFileError;
1996 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2000 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2001 * SilcClientConnection conn,
2002 * SilcClientMonitorStatus status,
2003 * SilcClientFileError error,
2004 * SilcUInt64 offset,
2005 * SilcUInt64 filesize,
2006 * SilcClientEntry client_entry,
2007 * SilcUInt32 session_id,
2008 * const char *filepath,
2013 * Monitor callback that is called during the file transmission to
2014 * monitor the transmission process. The `status' indicates the current
2015 * monitoring process. The `error' will indicate the error type
2016 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2017 * currently transmitted amount of total `filesize'. The `client_entry'
2018 * indicates the remote client, and the transmission session ID is the
2019 * `session_id'. The filename being transmitted is indicated by the
2023 typedef void (*SilcClientFileMonitor)(SilcClient client,
2024 SilcClientConnection conn,
2025 SilcClientMonitorStatus status,
2026 SilcClientFileError error,
2028 SilcUInt64 filesize,
2029 SilcClientEntry client_entry,
2030 SilcUInt32 session_id,
2031 const char *filepath,
2034 /****f* silcclient/SilcClientAPI/SilcClientFileName
2038 * typedef void (*SilcClientFileName)(const char *filepath,
2043 * Completion callback for the SilcClientFileAskName callback function.
2044 * Application calls this to deliver the filepath and filename where
2045 * the downloaded file is to be saved.
2048 typedef void (*SilcClientFileName)(const char *filepath,
2051 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2055 * typedef void (*SilcClientFileAskName)(SilcClient client,
2056 * SilcClientConnection conn,
2057 * SilcUInt32 session_id,
2058 * const char *remote_filename,
2059 * SilcClientFileName completion,
2060 * void *completion_context,
2065 * File name asking callback, that is called if it is given to the
2066 * silc_client_file_receive and the path given to that as argument was
2067 * NULL. The library calls this to ask the filename and filepath to
2068 * where the file is to be saved. The 'remote_filename' is the file
2069 * that is being downloaded. Application must call the 'completion'
2070 * with 'completion_context' to continue with the file downloading.
2071 * It is not mandatory to provide this to the silc_client_file_receive.
2074 typedef void (*SilcClientFileAskName)(SilcClient client,
2075 SilcClientConnection conn,
2076 SilcUInt32 session_id,
2077 const char *remote_filename,
2078 SilcClientFileName completion,
2079 void *completion_context,
2082 /****f* silcclient/SilcClientAPI/silc_client_file_send
2086 * SilcClientFileError
2087 * silc_client_file_send(SilcClient client,
2088 * SilcClientConnection conn,
2089 * SilcClientFileMonitor monitor,
2090 * void *monitor_context,
2091 * const char *local_ip,
2092 * SilcUInt32 local_port,
2093 * SilcBool do_not_bind,
2094 * SilcClientEntry client_entry,
2095 * const char *filepath);
2096 * SilcUInt32 *session_id);
2100 * Sends a file indicated by the `filepath' to the remote client
2101 * indicated by the `client_entry'. This will negotiate a secret key
2102 * with the remote client before actually starting the transmission of
2103 * the file. The `monitor' callback will be called to monitor the
2104 * transmission of the file.
2106 * This returns a file session ID for the file transmission to the
2107 * `session_id' pointer. It can be used to close the session (and
2108 * abort the file transmission) by calling the silc_client_file_close
2109 * function. The session ID is also returned in the `monitor' callback.
2111 * If the `local_ip' is provided then this will try to bind the
2112 * listener for key exchange protocol to that IP. If `local_port' is
2113 * non-zero that port is used. If `local_ip' is NULL then this will
2114 * automatically attempt to bind it to local IP address of the machine.
2115 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2116 * ignored and it is expected that the receiver will provide the
2117 * point of contact. This is usefull if the sender is behind NAT.
2119 * If error will occur during the file transfer process the error
2120 * status will be returned in the monitor callback. In this case
2121 * the application must call silc_client_file_close to close the
2126 silc_client_file_send(SilcClient client,
2127 SilcClientConnection conn,
2128 SilcClientFileMonitor monitor,
2129 void *monitor_context,
2130 const char *local_ip,
2131 SilcUInt32 local_port,
2132 SilcBool do_not_bind,
2133 SilcClientEntry client_entry,
2134 const char *filepath,
2135 SilcUInt32 *session_id);
2137 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2141 * SilcClientFileError
2142 * silc_client_file_receive(SilcClient client,
2143 * SilcClientConnection conn,
2144 * SilcClientFileMonitor monitor,
2145 * void *monitor_context,
2147 * SilcUInt32 session_id,
2148 * SilcClientFileAskName ask_name,
2149 * void *ask_name_context);
2153 * Receives a file from a client indicated by the `client_entry'. The
2154 * `session_id' indicates the file transmission session and it has been
2155 * received in the `ftp' client operation function. This will actually
2156 * perform the key agreement protocol with the remote client before
2157 * actually starting the file transmission. The `monitor' callback
2158 * will be called to monitor the transmission. If `path' is non-NULL
2159 * the file will be saved into that directory. If NULL the file is
2160 * saved in the current working directory, unless the 'ask_name'
2161 * callback is non-NULL. In this case the callback is called to ask
2162 * the path and filename from application.
2164 * If error will occur during the file transfer process the error
2165 * status will be returned in the monitor callback. In this case
2166 * the application must call silc_client_file_close to close the
2171 silc_client_file_receive(SilcClient client,
2172 SilcClientConnection conn,
2173 SilcClientFileMonitor monitor,
2174 void *monitor_context,
2176 SilcUInt32 session_id,
2177 SilcClientFileAskName ask_name,
2178 void *ask_name_context);
2180 /****f* silcclient/SilcClientAPI/silc_client_file_close
2184 * SilcClientFileError silc_client_file_close(SilcClient client,
2185 * SilcClientConnection conn,
2186 * SilcUInt32 session_id);
2190 * Closes file transmission session indicated by the `session_id'.
2191 * If file transmission is being conducted it will be aborted
2192 * automatically. This function is also used to close the session
2193 * after successful file transmission. This function can be used
2194 * also to reject incoming file transmission request. If the
2195 * session was already started and the monitor callback was set
2196 * the monitor callback will be called with the monitor status
2197 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2200 SilcClientFileError silc_client_file_close(SilcClient client,
2201 SilcClientConnection conn,
2202 SilcUInt32 session_id);
2204 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2208 * SilcAttributePayload
2209 * silc_client_attribute_add(SilcClient client,
2210 * SilcClientConnection conn,
2211 * SilcAttribute attribute,
2213 * SilcUInt32 object_size);
2217 * Add new Requsted Attribute for WHOIS command to the client library.
2218 * The `attribute' object indicated by `object' is added and allocated
2219 * SilcAttributePayload is returned. The `object' must be of correct
2220 * type and of correct size. See the SilcAttribute for object types
2221 * for different attributes. You may also get all added attributes
2222 * from the client with silc_client_attributes_get function.
2224 * Requested Attributes are different personal information about the
2225 * user, status information and other information which other users
2226 * may query with WHOIS command. Application may set these so that
2227 * if someone sends WHOIS query these attributes will be replied back
2228 * to the sender. The library always puts the public key to the
2229 * Requested Attributes, but if application wishes to add additional
2230 * public keys (or certificates) it can be done with this interface.
2231 * Library also always computes digital signature of the attributes
2232 * automatically, so application does not need to do that.
2235 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2236 SilcClientConnection conn,
2237 SilcAttribute attribute,
2239 SilcUInt32 object_size);
2241 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2245 * SilcBool silc_client_attribute_del(SilcClient client,
2246 * SilcClientConnection conn,
2247 * SilcAttribute attribute,
2248 * SilcAttributePayload attr);
2252 * Delete a Requested Attribute from the client. If the `attribute'
2253 * is non-zero then all attributes of that type are deleted and the
2254 * `attr' is ignored. If `attr' is non-NULL then that specific
2255 * attribute is deleted and `attribute' is ignored.
2257 * You may get all added attributes with the function
2258 * silc_client_attributes_get and to get the SilcAttributePayload.
2259 * This function Returns TRUE if the attribute was found and deleted.
2262 SilcBool silc_client_attribute_del(SilcClient client,
2263 SilcClientConnection conn,
2264 SilcAttribute attribute,
2265 SilcAttributePayload attr);
2267 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2271 * const SilcHashTable
2272 * silc_client_attributes_get(SilcClient client,
2273 * SilcClientConnection conn);
2277 * Returns pointer to the SilcHashTable which includes all the added
2278 * Requested Attributes. The caller must not free the hash table.
2279 * The caller may use SilcHashTableList and silc_hash_table_list to
2280 * traverse the table. Each entry in the hash table is one added
2281 * SilcAttributePayload. It is possible to delete a attribute
2282 * payload while traversing the table.
2285 SilcHashTable silc_client_attributes_get(SilcClient client,
2286 SilcClientConnection conn);
2288 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2292 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2296 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2297 * then all attributes are requested. Alternatively, `attribute' and
2298 * all variable arguments can each be requested attribute. In this case
2299 * the last must be set to zero (0) to complete the variable list of
2300 * requested attributes. See SilcAttribute for all attributes.
2301 * You can give the returned buffer as argument to for example
2302 * silc_client_get_client_by_id_resolve function.
2306 * Request all attributes
2307 * buffer = silc_client_attributes_request(0);
2309 * Request only the following attributes
2310 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2311 * SILC_ATTRIBUTE_SERVICE,
2312 * SILC_ATTRIBUTE_MOOD, 0);
2315 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2321 #endif /* SILCCLIENT_H */