5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2007 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/SilcClientRunning
90 * typedef void (*SilcClientRunning)(SilcClient client, void *context);
94 * The callback given as argument to silc_client_init function. Once
95 * this is called the client library is running and application may
96 * start using the Client library API.
99 typedef void (*SilcClientRunning)(SilcClient client, void *context);
101 /****f* silcclient/SilcClientAPI/SilcClientStopped
105 * typedef void (*SilcClientStopped)(SilcClient client, void *context);
109 * The callback given as argument to silc_client_stop. Once this is
110 * called the client library has stopped and can be freed by calling
111 * silc_client_free. Note that this won't be called if there are
112 * active connections in the client. Connections must first be closed
113 * by calling silc_client_close_connection or by sending QUIT command to
114 * the server connection.
117 typedef void (*SilcClientStopped)(SilcClient client, void *context);
119 /****f* silcclient/SilcClientAPI/SilcClientConnectCallback
123 * void (*SilcClientConnectCallback)(SilcClient client,
124 * SilcClientConnection conn,
125 * SilcClientConnectionStatus status,
127 * const char *message,
132 * Connect callbak given as argument to silc_client_connect_to_server,
133 * silc_client_connect_to_client and silc_client_key_exchange functions.
134 * It is called to indicate the status of the connection, indicated
135 * by the `status'. It is called after the connection has been
136 * established to the remote host and when connection is disconnected
137 * by the remote host. The `context' is the context given as argument
138 * to the connecting function.
140 * When the `status' is SILC_CLIENT_CONN_DISCONNECTED the `error' will
141 * indicate the reason for disconnection. If the `message' is non-NULL
142 * it delivers error or disconnection message.
145 typedef void (*SilcClientConnectCallback)(SilcClient client,
146 SilcClientConnection conn,
147 SilcClientConnectionStatus status,
152 /****s* silcclient/SilcClientAPI/SilcClient
156 * typedef struct SilcClientStruct { ... } *SilcClient
160 * This is the actual SILC Client structure which represents one
161 * SILC Client. It is allocated with the silc_client_alloc function
162 * and given as argument to all SILC Client Library functions. It
163 * is initialized with silc_client_init function, and freed with
164 * silc_client_free function.
166 * This context represents the client. Each connection to remote server
167 * is represented by SilcClientConnection context.
171 struct SilcClientStruct {
172 char *username; /* Username */
173 char *hostname; /* hostname */
174 char *realname; /* Real name */
175 SilcSchedule schedule; /* Client scheduler */
176 SilcRng rng; /* Random number generator */
177 void *application; /* Application specific context, set with
178 silc_client_alloc. */
180 /* Internal data for client library. Application cannot access this. */
181 SilcClientInternal internal;
185 /****s* silcclient/SilcClientAPI/SilcClientConnection
189 * typedef struct SilcClientConnectionStruct { ... }
190 * *SilcClientConnection
194 * This structure represents a connection. It is allocated and freed by
195 * the library. It is returned to application in SilcClientConnectCallback.
196 * It includes all the important data for the session such as local
197 * client entry (which includes current nickname), local and remote IDs,
198 * and other information. All strings in the structure are UTF-8 encoded.
202 struct SilcClientConnectionStruct {
203 SilcClientEntry local_entry; /* Our own Client Entry */
204 SilcClientID *local_id; /* Our current Client ID */
206 char *remote_host; /* Remote host name */
207 int remote_port; /* Remote port */
208 SilcID remote_id; /* Remote ID */
210 SilcChannelEntry current_channel; /* Current joined channel */
211 SilcPublicKey public_key; /* Public key used in this connection */
212 SilcPrivateKey private_key; /* Private key */
213 SilcPacketStream stream; /* Connection to remote host */
214 SilcConnectionType type; /* Connection type */
215 SilcClientConnectCallback callback; /* Connection callback */
216 void *callback_context; /* Connection context */
217 SilcClient client; /* Pointer back to SilcClient */
219 /* Application specific data. Application may set here whatever it wants. */
222 /* Internal data for client library. Application cannot access this. */
223 SilcClientConnectionInternal internal;
227 /****s* silcclient/SilcClientAPI/SilcChannelUser
231 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
235 * This structure represents a client that has joined to a channel.
236 * It shows the client and the channel and the client's mode (channel
237 * user mode) on the channel.
241 struct SilcChannelUserStruct {
242 SilcClientEntry client; /* Client joined on channel */
243 SilcUInt32 mode; /* mode, ChannelUserModes */
244 SilcChannelEntry channel; /* The channel user has joined */
246 /* Application specific data. Application may set here whatever it wants. */
251 /****s* silcclient/SilcClientAPI/SilcClientStats
255 * typedef struct { ... } SilcClientStats;
259 * This structure holds SILC network statistics returned by the
260 * SILC_COMMAND_STATS command reply to the application.
265 SilcUInt32 starttime; /* SILC server start time */
266 SilcUInt32 uptime; /* SILC server uptime*/
267 SilcUInt32 my_clients; /* Number of clients in the server */
268 SilcUInt32 my_channels; /* Number of channel in the server */
269 SilcUInt32 my_server_ops; /* Number of server operators in the server */
270 SilcUInt32 my_router_ops; /* Number of router operators in the router */
271 SilcUInt32 cell_clients; /* Number of clients in the cell */
272 SilcUInt32 cell_channels; /* Number of channels in the cell */
273 SilcUInt32 cell_servers; /* Number of server in the cell */
274 SilcUInt32 clients; /* All clients in SILC network */
275 SilcUInt32 channels; /* All channels in SILC network */
276 SilcUInt32 servers; /* All servers in SILC network */
277 SilcUInt32 routers; /* All routers in SILC network */
278 SilcUInt32 server_ops; /* All server operators in SILC network */
279 SilcUInt32 router_ops; /* All router operators in SILC network */
283 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
287 * typedef enum { ... } SilcKeyAgreementStatus;
291 * Key agreement status types indicating the status of the key
292 * agreement protocol. These types are returned to the application
293 * in the SilcKeyAgreementCallback callback function.
298 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
299 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
300 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
301 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
302 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
303 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
304 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
305 SILC_KEY_AGREEMENT_NO_MEMORY, /* System out of memory */
306 } SilcKeyAgreementStatus;
309 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
313 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
314 * SilcClientConnection conn,
315 * SilcClientEntry client_entry,
316 * SilcKeyAgreementStatus status,
317 * SilcSKEKeyMaterial *key,
322 * Key agreement callback that is called after the key agreement protocol
323 * has been performed. This is called also if error occurred during the
324 * key agreement protocol. The `key' is the allocated key material and
325 * the caller is responsible of freeing it. The `key' is NULL if error
326 * has occurred. The application can freely use the `key' to whatever
327 * purpose it needs. See lib/silcske/silcske.h for the definition of
328 * the SilcSKEKeyMaterial structure.
331 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
332 SilcClientConnection conn,
333 SilcClientEntry client_entry,
334 SilcKeyAgreementStatus status,
335 SilcSKEKeyMaterial key,
338 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
342 * typedef struct { ... } SilcPrivateMessageKeys;
346 * Structure to hold the list of private message keys. The list of these
347 * structures is returned by the silc_client_list_private_message_keys
353 SilcClientEntry client_entry; /* The remote client entry */
354 char *cipher; /* The cipher name */
355 unsigned char *key; /* The original key, If the appliation
356 provided it. This is NULL if
357 the SKE key material was used. */
358 SilcUInt32 key_len; /* The key length */
359 } *SilcPrivateMessageKeys;
362 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
366 * typedef struct SilcChannelPrivateKeyStruct { ... }
367 * *SilcChannelPrivateKey;
371 * Structure to hold one channel private key. The array of this structure
372 * is returned by silc_client_list_channel_private_keys function.
376 struct SilcChannelPrivateKeyStruct {
377 char *name; /* Application given name */
378 SilcCipher cipher; /* The cipher and key */
379 SilcHmac hmac; /* The HMAC and hmac key */
383 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
387 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
388 * SilcUInt32 passphrase_len,
393 * Ask passphrase callback. This is called by the application when the
394 * library calls `ask_passphrase' client operation. The callback delivers
395 * the passphrase to the library. The passphrases in SILC protocol
396 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
397 * encoded, and if it is not then library will attempt to encode it.
400 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
401 SilcUInt32 passphrase_len,
404 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
408 * typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
412 * Public key (or certificate) verification callback. This is called
413 * by the application to indicate that the public key verification was
414 * either success or failure.
417 typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
419 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
423 * typedef void (*SilcGetAuthMeth)(SilcBool success,
424 * SilcAuthMethod auth_meth,
425 * void *auth, SilcUInt32 auth_len,
430 * Authentication data resolving callback. This is called by the
431 * application to return the resolved authentication data. The client
432 * library has called the get_auth_method client operation and given
433 * this function pointer as argument. The `auth_meth' is the selected
434 * authentication method. The `auth_data' and the `auth_data_len'
435 * are the resolved authentication data. The `context' is the libary's
436 * context sent to the get_auth_method client operation.
438 * If the `auth_method' is SILC_AUTH_PASSWORD then `auth' and `auth_len'
439 * is the passphrase and its length. If it is SILC_AUTH_PUBLIC_KEY the
440 * `auth' must be NULL. The library will use the private key given as
441 * argument to silc_client_connect_to_server, silc_client_connect_to_client
442 * or silc_client_key_exchange. If it is SILC_AUTH_NONE, both `auth' and
443 * `auth_len' are ignored.
446 typedef void (*SilcGetAuthMeth)(SilcAuthMethod auth_meth,
447 void *auth, SilcUInt32 auth_len,
450 /****d* silcclient/SilcClientAPI/SilcClientMessageType
454 * typedef enum { ... } SilcClientMessageType;
458 * Different message types for `say' client operation. The application
459 * may filter the message sent by the library according this type.
464 SILC_CLIENT_MESSAGE_INFO, /* Informational */
465 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
466 SILC_CLIENT_MESSAGE_ERROR, /* Error */
467 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
468 } SilcClientMessageType;
471 /****s* silcclient/SilcClientAPI/SilcClientOperations
475 * typedef struct { ... } SilcClientOperations;
479 * SILC Client Operations. These must be implemented by the application.
480 * The Client library may call any of these routines at any time. The
481 * routines are used to deliver certain information to the application
482 * or from the application to the client library.
487 /* Message sent to the application by library. `conn' associates the
488 message to a specific connection. `conn', however, may be NULL.
489 The `type' indicates the type of the message sent by the library.
490 The application can for example filter the message according the
491 type. The variable argument list is arguments to the formatted
492 message that `msg' may be. */
493 void (*say)(SilcClient client, SilcClientConnection conn,
494 SilcClientMessageType type, char *msg, ...);
496 /* Message for a channel. The `sender' is the sender of the message
497 The `channel' is the channel. The `message' is the message. Note
498 that `message' maybe NULL. The `flags' indicates message flags
499 and it is used to determine how the message can be interpreted
500 (like it may tell the message is multimedia message). */
501 void (*channel_message)(SilcClient client, SilcClientConnection conn,
502 SilcClientEntry sender, SilcChannelEntry channel,
503 SilcMessagePayload payload,
504 SilcChannelPrivateKey key, SilcMessageFlags flags,
505 const unsigned char *message,
506 SilcUInt32 message_len);
508 /* Private message to the client. The `sender' is the sender of the
509 message. The message is `message'and maybe NULL. The `flags'
510 indicates message flags and it is used to determine how the message
511 can be interpreted (like it may tell the message is multimedia
513 void (*private_message)(SilcClient client, SilcClientConnection conn,
514 SilcClientEntry sender, SilcMessagePayload payload,
515 SilcMessageFlags flags, const unsigned char *message,
516 SilcUInt32 message_len);
518 /* Notify message to the client. The notify arguments are sent in the
519 same order as servers sends them. The arguments are same as received
520 from the server except for ID's. If ID is received application receives
521 the corresponding entry to the ID. For example, if Client ID is received
522 application receives SilcClientEntry. Also, if the notify type is
523 for channel the channel entry is sent to application (even if server
524 does not send it because client library gets the channel entry from
525 the Channel ID in the packet's header). */
526 void (*notify)(SilcClient client, SilcClientConnection conn,
527 SilcNotifyType type, ...);
529 /* Command handler. This function is called always after application has
530 called a command. It will be called to indicate that the command
531 was processed. It will also be called if error occurs while processing
532 the command. The `success' indicates whether the command was sent
533 or if error occurred. The `status' indicates the actual error.
534 The `argc' and `argv' are the command line arguments sent to the
535 command by application. Note that, this is not reply to the command
536 from server, this is merely and indication to application that the
537 command was processed. */
538 void (*command)(SilcClient client, SilcClientConnection conn,
539 SilcBool success, SilcCommand command, SilcStatus status,
540 SilcUInt32 argc, unsigned char **argv);
542 /* Command reply handler. This function is called always in the command reply
543 function. If error occurs it will be called as well. Normal scenario
544 is that it will be called after the received command data has been parsed
545 and processed. The function is used to pass the received command data to
548 `conn' is the associated client connection. `cmd_payload' is the command
549 payload data received from server and it can be ignored. It is provided
550 if the application would like to re-parse the received command data,
551 however, it must be noted that the data is parsed already by the library
552 thus the payload can be ignored. `success' is FALSE if error occurred.
553 In this case arguments are not sent to the application. The `status' is
554 the command reply status server returned. The `command' is the command
555 reply being processed. The function has variable argument list and each
556 command defines the number and type of arguments it passes to the
557 application (on error they are not sent).
559 The arguments are sent in the same order as servers sends them. The
560 arguments are same as received from the server except for ID's. If
561 ID is received application receives the corresponding entry to the
562 ID. For example, if Client ID is receives application receives
564 void (*command_reply)(SilcClient client, SilcClientConnection conn,
565 SilcCommand command, SilcStatus status,
566 SilcStatus error, va_list ap);
568 /* Find authentication method and authentication data by hostname and
569 port. The hostname may be IP address as well. The `auth_method' is
570 the authentication method the remote connection requires. It is
571 however possible that remote accepts also some other authentication
572 method. Application should use the method that may have been
573 configured for this connection. If none has been configured it should
574 use the required `auth_method'. If the `auth_method' is
575 SILC_AUTH_NONE, server does not require any authentication or the
576 required authentication method is not known. The `completion'
577 callback must be called to deliver the chosen authentication method
578 and data. The `conn' may be NULL. */
579 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
580 char *hostname, SilcUInt16 port,
581 SilcAuthMethod auth_method,
582 SilcGetAuthMeth completion, void *context);
584 /* Verifies received public key. The `conn_type' indicates which entity
585 (server or client) has sent the public key. If user decides to trust
586 the key the application may save the key as trusted public key for
587 later use. The `completion' must be called after the public key has
589 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
590 SilcConnectionType conn_type,
591 SilcPublicKey public_key,
592 SilcVerifyPublicKey completion, void *context);
594 /* Ask (interact, that is) a passphrase from user. The passphrase is
595 returned to the library by calling the `completion' callback with
596 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
597 if not then the library will attempt to encode. */
598 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
599 SilcAskPassphrase completion, void *context);
601 /* Called to indicate that incoming key agreement request has been
602 received. If the application wants to perform key agreement it may
603 call silc_client_perform_key_agreement to initiate key agreementn or
604 silc_client_send_key_agreement to provide connection point to the
605 remote client in case the `hostname' is NULL. If key agreement is
606 not desired this request can be ignored. The `protocol' is either
607 value 0 for TCP or value 1 for UDP. */
608 void (*key_agreement)(SilcClient client, SilcClientConnection conn,
609 SilcClientEntry client_entry,
610 const char *hostname, SilcUInt16 protocol,
613 /* Notifies application that file transfer protocol session is being
614 requested by the remote client indicated by the `client_entry' from
615 the `hostname' and `port'. The `session_id' is the file transfer
616 session and it can be used to either accept or reject the file
617 transfer request, by calling the silc_client_file_receive or
618 silc_client_file_close, respectively. */
619 void (*ftp)(SilcClient client, SilcClientConnection conn,
620 SilcClientEntry client_entry, SilcUInt32 session_id,
621 const char *hostname, SilcUInt16 port);
622 } SilcClientOperations;
625 /****s* silcclient/SilcClientAPI/SilcClientParams
629 * typedef struct { ... } SilcClientParams;
633 * Client parameters. This can be filled with proper values and
634 * given as argument to the silc_client_alloc function. The structure
635 * hold various parameters which affects the function of the client.
640 /* If this boolean is set to TRUE then the client library will use
641 threads. Any of the callback functions in the SilcClientOperations
642 and other callbacks may be called at any time in a thread. The
643 application may need to employ appropriate concurrency control
644 in the callbacks to protect application specific data. */
647 /* Nickname format string. This can be used to order the client library
648 to save the nicknames in the library in a certain format. Since
649 nicknames are not unique in SILC it is possible to have multiple same
650 nicknames. Using this format string it is possible to order the library
651 to separate the multiple same nicknames from each other. If this is
652 empty then default format is used which is the default nickname
653 without anything else. The string MUST be NULL terminated.
655 Following format types are available:
657 %n nickname - the real nickname returned by the server (mandatory)
658 %h hostname - the stripped hostname of the client
659 %H full hostname - the full hostname of the client
660 %s server name - the server name the client is connected
661 %S full server - the full server name the client is connected
662 %a number - ascending number in case there are several
663 same nicknames (fe. nick@host and nick@host2)
665 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
666 "%a!%n@%s" (fe. nick@server, 2!nick@server)
667 "%n@%H" (fe. nick@host.domain.com)
669 Note that there must always be some separator characters around '%n'
670 format. It is not possible to put format characters before or after
671 '%n' without separators (such ash '@'). Also note that the separator
672 character should be a character that cannot be part of normal nickname.
674 char nickname_format[32];
676 /* If this is set to TRUE then the `nickname_format' is employed to all
677 saved nicknames even if there are no multiple same nicknames in the
678 cache. By default this is FALSE, which means that the `nickname_format'
679 is employed only if the library will receive a nickname that is
680 already saved in the cache. It is recommended to leave this to FALSE
682 SilcBool nickname_force_format;
684 /* If this is set to TRUE, the silcclient library will not register and
685 deregister the cipher, pkcs, hash and hmac algorithms. The application
686 itself will need to handle that. */
687 SilcBool dont_register_crypto_library;
693 /* Initialization functions (client.c) */
695 /****f* silcclient/SilcClientAPI/silc_client_alloc
699 * SilcClient silc_client_alloc(SilcClientOperations *ops,
700 * SilcClientParams *params,
702 * const char *silc_version);
706 * Allocates new client object. This has to be done before client may
707 * work. After calling this one must call silc_client_init to initialize
708 * the client. The `application' is application specific user data pointer
709 * and caller must free it. The `silc_version' is the application version
710 * that will be used to compare against remote host's (usually a server)
711 * version string. The `application' context is accessible by the
712 * application by client->application, client being SilcClient.
715 SilcClient silc_client_alloc(SilcClientOperations *ops,
716 SilcClientParams *params,
718 const char *version_string);
720 /****f* silcclient/SilcClientAPI/silc_client_free
724 * void silc_client_free(SilcClient client);
728 * Frees client object and its internals. The execution of the client
729 * should be stopped with silc_client_stop function before calling
733 void silc_client_free(SilcClient client);
735 /****f* silcclient/SilcClientAPI/silc_client_init
739 * SilcBool silc_client_init(SilcClient client, const char *username,
740 * const char *hostname, const char *realname,
741 * SilcClientRunning running, void *context);
745 * Initializes the client. This makes all the necessary steps to make
746 * the client ready to be run. One must call silc_client_run to run the
747 * client. Returns FALSE if error occurred, TRUE otherwise.
749 * The `username' and `hostname' strings must be given and they must be
750 * UTF-8 encoded. The `username' is the client's username in the
751 * operating system, `hostname' is the client's host name and the
752 * `realname' is the user's real name.
754 * The `running' callback is called after the client is running after
755 * silc_client_run or silc_client_run_one has been called. Application
756 * may start using the Client library API after that. Setting the
757 * callback is optional, but recommended.
760 SilcBool silc_client_init(SilcClient client, const char *username,
761 const char *hostname, const char *realname,
762 SilcClientRunning running, void *context);
764 /****f* silcclient/SilcClientAPI/silc_client_run
768 * void silc_client_run(SilcClient client);
772 * Runs the client. This starts the scheduler from the utility library.
773 * When this functions returns the execution of the application is over.
774 * The client must be initialized before calling this.
777 void silc_client_run(SilcClient client);
779 /****f* silcclient/SilcClientAPI/silc_client_run_one
783 * void silc_client_run_one(SilcClient client);
787 * Runs the client and returns immeadiately. This function is used when
788 * the SILC Client object indicated by the `client' is run under some
789 * other scheduler, or event loop or main loop. On GUI applications,
790 * for example this may be desired to used to run the client under the
791 * GUI application's main loop. Typically the GUI application would
792 * register an idle task that calls this function multiple times in
793 * a second to quickly process the SILC specific data.
796 void silc_client_run_one(SilcClient client);
799 /****f* silcclient/SilcClientAPI/silc_client_stop
803 * void silc_client_stop(SilcClient client, SilcClientStopped stopped,
808 * Stops the client. This is called to stop the client and thus to stop
809 * the program. The client context must be freed with the silc_client_free
810 * function. All connections that exist in this client must be closed
811 * before calling this function. Connections can be closed by calling
812 * silc_client_close_connection.
814 * The `stopped' will be called once the client and all connections have
815 * finished. The client may be freed after that. Note that the `stopped'
816 * won't be called before all connections have finished. Setting the
817 * callback is optional.
820 void silc_client_stop(SilcClient client, SilcClientStopped stopped,
823 /* Connecting functions */
825 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
829 * typedef struct { ... } SilcClientConnectionParams;
833 * Client connection parameters. This can be filled by the application
834 * and given as argument to silc_client_connect_to_server,
835 * silc_client_connect_to_client, silc_client_key_exchange or
836 * silc_client_send_key_agreement.
841 /* If this is provided the user's nickname in the network will be the
842 string given here. If it is given, it must be UTF-8 encoded. If this
843 string is not given, the user's username by default is used as nickname.
844 The nickname may later be changed by using NICK command. The maximum
845 length for the nickname string is 128 bytes. */
848 /* If this key repository pointer is non-NULL then public key received in
849 the key exchange protocol will be verified from this repository. If
850 this is not provided then the `verify_public_key' client operation will
851 be called back to application. If the boolean `verify_notfound' is set
852 to TRUE then the `verify_public_key' client operation will be called
853 in case the public key is not found in `repository'. Only public keys
854 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
855 be checked, other keys will be ignored. */
857 SilcBool verify_notfound;
859 /* Authentication data. Application may set here the authentication data
860 and authentication method to be used in connecting. If `auth_set'
861 boolean is TRUE then authentication data is provided by application.
862 If the authentication method is public key authentication then the key
863 pair given as argument when connecting will be used and `auth' field
864 is NULL. If it is passphrase authentication, it can be provided in
865 `auth' and `auth_len' fields. If `auth_set' is FALSE
866 the `get_auth_method' client operation will be called to get the
867 authentication method and data from application. */
869 SilcAuthMethod auth_method;
873 /* If this boolean is set to TRUE then the connection will use UDP instead
874 of TCP. If UDP is set then also the next `local_ip' and `local_port'
878 /* The `local_ip' specifies the local IP address used with the connection.
879 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
880 non-zero it will be used as local port with UDP connection. The remote
881 host will also send packets to the specified address and port. If the
882 `bind_ip' is non-NULL a listener is bound to that address instead of
888 /* If this boolean is set to TRUE then the key exchange is done with
889 perfect forward secrecy. */
892 /* If this boolean is set to TRUE then connection authentication protocol
893 is not performed during connecting. Only key exchange protocol is
894 performed. This usually must be set to TRUE when connecting to another
895 client, but must be FALSE with server connections. */
896 SilcBool no_authentication;
898 /* The SILC session detachment data that was returned in the `command_reply'
899 client operation for SILC_COMMAND_DETACH command. If this is provided
900 here the client library will attempt to resume the session in the network.
901 After the connection is created and the session has been resumed the
902 client will receive SILC_COMMAND_NICK command_reply for the client's
903 nickname in the network and SILC_COMMAND_JOIN command reply for all the
904 channels that the client has joined in the network. It may also receive
905 SILC_COMMAND_UMODE command reply to set user's mode on the network. */
906 unsigned char *detach_data;
907 SilcUInt32 detach_data_len;
909 /* Connection timeout. If non-zero, the connection will timeout unless
910 the SILC connection is completed in the specified amount of time. */
911 SilcUInt32 timeout_secs;
913 /* Rekey timeout in seconds. The client will perform rekey in this
914 time interval. If set to zero, the default value will be used
915 (3600 seconds, 1 hour). */
916 unsigned int rekey_secs;
918 /* If this is set to TRUE then the client will ignore all incoming
919 Requested Attributes queries and does not reply anything back. This
920 usually leads into situation where server does not anymore send
921 the queries after seeing that client does not reply anything back.
922 If your application does not support Requested Attributes or you do
923 not want to use them set this to TRUE. See SilcAttribute and
924 silc_client_attribute_add for more information on attributes. */
925 SilcBool ignore_requested_attributes;
927 } SilcClientConnectionParams;
930 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
935 * silc_client_connect_to_server(SilcClient client,
936 * SilcClientConnectionParams *params,
937 * SilcPublicKey public_key,
938 * SilcPrivateKey private_key,
939 * char *remote_host, int port,
940 * SilcClientConnectCallback callback,
945 * Connects to remote server `remote_host' at port `port'. This function
946 * can be used to create connection to remote SILC server and start
947 * SILC session in the SILC network. The `params' may be provided
948 * to provide various connection parameters. The `public_key' and the
949 * `private_key' is your identity used in this connection. When
950 * authentication method is based on digital signatures, this key pair
951 * will be used. The `callback' with `context' will be called after the
952 * connection has been created. It will also be called later when remote
955 * If application wishes to create the network connection itself, use
956 * the silc_client_key_exchange after creating the connection to start
957 * key exchange and authentication with the server.
959 * Returns SilcAsyncOperation which can be used to cancel the connecting,
960 * or NULL on error. Note that the returned pointer becomes invalid
961 * after the `callback' is called.
965 silc_client_connect_to_server(SilcClient client,
966 SilcClientConnectionParams *params,
967 SilcPublicKey public_key,
968 SilcPrivateKey private_key,
969 char *remote_host, int port,
970 SilcClientConnectCallback callback,
973 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
978 * silc_client_connect_to_client(SilcClient client,
979 * SilcClientConnectionParams *params,
980 * SilcPublicKey public_key,
981 * SilcPrivateKey private_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 SilcAsyncOperation which can be used to cancel the connecting,
1002 * or NULL on error. Note that the returned pointer becomes invalid
1003 * after the `callback' is called.
1007 silc_client_connect_to_client(SilcClient client,
1008 SilcClientConnectionParams *params,
1009 SilcPublicKey public_key,
1010 SilcPrivateKey private_key,
1011 char *remote_host, int port,
1012 SilcClientConnectCallback callback,
1015 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1019 * SilcAsyncOperation
1020 * silc_client_key_exchange(SilcClient client,
1021 * SilcClientConnectionParams *params,
1022 * SilcPublicKey public_key,
1023 * SilcPrivateKey private_key,
1024 * SilcStream stream,
1025 * SilcConnectionType conn_type,
1026 * SilcClientConnectCallback callback,
1031 * Starts key exchange protocol and authentication protocol in the
1032 * connection indicated by `stream'. This function can be be used to
1033 * start SILC session with remote host (usually server) when the caller
1034 * has itself created the connection, instead of calling the function
1035 * silc_client_connect_to_server or silc_client_connect_to_client. If
1036 * one of those functions was used this function must not be called as
1037 * in that case the key exchange is performed automatically.
1039 * Use this function only if you have created the connection by yourself.
1040 * After creating the connection the socket must be wrapped into a
1041 * socket stream. See silcsocketstream.h for more information. Note that
1042 * the `stream' must have valid remote IP address (and optionally also
1043 * hostname) and port set.
1045 * The `params' may be provided to provide various connection parameters.
1046 * The `public_key' and the `private_key' is your identity used in this
1047 * session. The `callback' with `context' will be called after the session
1048 * has been set up. It will also be called later when remote host
1049 * disconnects. The `conn_type' is the type of session this is going to
1052 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1053 * or NULL on error. Note that the returned pointer becomes invalid
1054 * after the `callback' is called.
1060 * // Create remote connection stream. Resolve hostname and IP also.
1061 * sock = create_connection(remote_host, port);
1062 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1063 * stream_create_cb, app);
1065 * // Stream callback delivers our new SilcStream context
1066 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1070 * if (status != SILC_SOCKET_OK)
1073 * // Start key exchange
1074 * silc_client_key_exchange(client, NULL, public_key, private_key,
1075 * stream, SILC_CONN_SERVER, connection_cb, app);
1081 silc_client_key_exchange(SilcClient client,
1082 SilcClientConnectionParams *params,
1083 SilcPublicKey public_key,
1084 SilcPrivateKey private_key,
1086 SilcConnectionType conn_type,
1087 SilcClientConnectCallback callback,
1090 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1094 * void silc_client_close_connection(SilcClient client,
1095 * SilcClientConnection conn);
1099 * Closes the remote connection `conn'. The `conn' will become invalid
1100 * after this call. Usually this function is called only when explicitly
1101 * closing connection for example in case of error, or when the remote
1102 * connection was created by the application or when the remote is client
1103 * connection. Server connections are usually closed by sending QUIT
1104 * command to the server. However, this call may also be used.
1107 void silc_client_close_connection(SilcClient client,
1108 SilcClientConnection conn);
1110 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1112 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1116 * SilcBool silc_client_send_channel_message(SilcClient client,
1117 * SilcClientConnection conn,
1118 * SilcChannelEntry channel,
1119 * SilcChannelPrivateKey key,
1120 * SilcMessageFlags flags,
1122 * unsigned char *data,
1123 * SilcUInt32 data_len);
1127 * Sends packet to the `channel'. Packet to channel is always encrypted
1128 * differently from "normal" packets. SILC header of the packet is
1129 * encrypted with the next receiver's key and the rest of the packet is
1130 * encrypted with the channel specific key. Padding and HMAC is computed
1131 * with the next receiver's key. The `data' is the channel message.
1133 * If `key' is provided then that private key is used to encrypt the
1134 * channel message. If it is not provided, private keys has not been
1135 * set at all, the normal channel key is used automatically. If private
1136 * keys are set then the first key (the key that was added first as
1137 * private key) is used.
1139 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1140 * digitally signed with the SILC key pair.
1142 * Returns TRUE if the message was sent, and FALSE if error occurred or
1143 * the sending is not allowed due to channel modes (like sending is
1144 * blocked). This function is thread safe and private messages can be
1145 * sent from multiple threads.
1148 SilcBool silc_client_send_channel_message(SilcClient client,
1149 SilcClientConnection conn,
1150 SilcChannelEntry channel,
1151 SilcChannelPrivateKey key,
1152 SilcMessageFlags flags,
1154 unsigned char *data,
1155 SilcUInt32 data_len);
1157 /* Block process until channel message from `channel' is received */
1159 silc_client_receive_channel_message(SilcClient client,
1160 SilcClientConnection conn,
1161 SilcChannelEntry channel,
1162 SilcClientEntry *return_sender,
1163 SilcMessageFlags *return_flags,
1164 const unsigned char **return_message,
1165 SilcUInt32 *return_message_len);
1167 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1171 * SilcBool silc_client_send_private_message(SilcClient client,
1172 * SilcClientConnection conn,
1173 * SilcClientEntry client_entry,
1174 * SilcMessageFlags flags,
1176 * unsigned char *data,
1177 * SilcUInt32 data_len);
1181 * Sends private message to remote client. If private message key has
1182 * not been set with this client then the message will be encrypted using
1183 * normal session keys. If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
1184 * the message will be digitally signed with the SILC key pair. In this
1185 * case the caller must also provide the `hash' pointer. By default, the
1186 * hash function must be SHA-1.
1188 * Returns TRUE if the message was sent, and FALSE if error occurred.
1189 * This function is thread safe and private messages can be sent from
1193 SilcBool silc_client_send_private_message(SilcClient client,
1194 SilcClientConnection conn,
1195 SilcClientEntry client_entry,
1196 SilcMessageFlags flags,
1198 unsigned char *data,
1199 SilcUInt32 data_len);
1201 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1205 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1206 * SilcClientEntry client_entry);
1210 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1211 * channel indicated by the `channel'. NULL if client is not joined on
1215 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1216 SilcClientEntry client_entry);
1219 /* Command management */
1221 /****f* silcclient/SilcClientAPI/silc_client_command_call
1225 * SilcUInt16 silc_client_command_call(SilcClient client,
1226 * SilcClientConnection conn,
1227 * const char *command_line, ...);
1231 * Calls and executes the command indicated by the `command_name'.
1232 * The `command_line' is a string which includes the command's name and
1233 * its arguments separated with whitespaces (' '). If `command_line'
1234 * is non-NULL then all variable arguments are ignored by default.
1236 * If `command_line' is NULL, then the variable arguments define the
1237 * command's name and its arguments. The first variable argument must
1238 * be the command name. The variable argument list must be terminated
1241 * Returns FALSE if the command is not known and TRUE after command.
1242 * execution. The "command" client operation is called when the
1243 * command is executed to indicate whether the command executed
1244 * successfully or not.
1246 * The "command_reply" client operation will be called when reply is
1247 * received from the server to the command. Application may also use
1248 * the silc_client_command_pending to attach to the command reply.
1249 * The command identifier for silc_client_command_pending function after
1250 * this function call is conn->cmd_ident, which application may use.
1254 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1256 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1260 * This command executes the commands implemented inside the client
1261 * library. These commands are designed for command line applications,
1262 * but GUI application may call them too if needed. Alternatively
1263 * application may override the library and use silc_client_command_send
1267 SilcUInt16 silc_client_command_call(SilcClient client,
1268 SilcClientConnection conn,
1269 const char *command_line, ...);
1271 /* If FALSE is returned the callback will not be called again, even if there
1272 is more data coming in in the command reply. If there are other pending
1273 commands waiting for the reply, they will receive it even if some other
1274 command reply has returned FALSE. */
1275 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1276 SilcClientConnection conn,
1277 SilcCommand command,
1283 /****f* silcclient/SilcClientAPI/silc_client_command_send
1287 * SilcUInt16 silc_client_command_send(SilcClient client,
1288 * SilcClientConnection conn,
1289 * SilcCommand command,
1290 * SilcClientCommandReply reply,
1291 * void *reply_context,
1292 * SilcUInt32 argc, ...);
1296 * Generic function to send any command. The arguments must be given
1297 * already encoded into correct format and in correct order. If application
1298 * wants to perform the commands by itself, it can do so and send the data
1299 * directly to the server using this function. If application is using
1300 * the silc_client_command_call, this function is usually not used.
1301 * Programmer should get familiar with the SILC protocol commands
1302 * specification when using this function, as the arguments needs to
1303 * be encoded as specified in the protocol.
1305 * The variable arguments are a set of { type, data, data_length },
1306 * and the `argc' is the number of these sets.
1308 * The `reply' callback must be provided, and it is called when the
1309 * command reply is received from the server. Note that, when using this
1310 * function the default `command_reply' client operation will not be
1311 * called, when reply is received. Note however that, `reply' is almost
1312 * identical with `command_reply' callback, and application may forward
1313 * the reply from `reply' to `command_reply' callback, if desired.
1315 * Returns command identifier for this sent command. It can be used
1316 * to additionally attach to the command reply using the function
1317 * silc_client_command_pending, if needed. Returns 0 on error,
1321 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1322 * my_whois_command_reply, cmd_ctx,
1323 * 1, 1, nickname, strlen(nickname));
1326 SilcUInt16 silc_client_command_send(SilcClient client,
1327 SilcClientConnection conn,
1328 SilcCommand command,
1329 SilcClientCommandReply reply,
1330 void *reply_context,
1331 SilcUInt32 argc, ...);
1333 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1337 * void silc_client_command_pending(SilcClientConnection conn,
1338 * SilcCommand reply_cmd,
1339 * SilcUInt16 cmd-ident,
1340 * SilcCommandCb callback,
1345 * This function can be used to add pending command callback to be
1346 * called when an command reply is received to an earlier sent command.
1347 * The `reply_cmd' is the command that must be received in order for
1348 * the pending command callback indicated by `callback' to be called.
1349 * The `callback' will deliver the `context' and
1350 * SilcClientCommandReplyContext which includes the internals of the
1353 * The `cmd_ident' is a command identifier which was set for the earlier
1354 * sent command. The command reply will include the same identifier
1355 * and pending command callback will be called when the reply is
1356 * received with the same command identifier. It is possible to
1357 * add multiple pending command callbacks for same command and for
1360 * Application may use this function to add its own command reply
1361 * handlers if it wishes not to use the standard `command_reply'
1362 * client operation. However, note that the pending command callback
1363 * does not deliver parsed command reply, but application must parse
1366 * Note also that the application is notified about the received command
1367 * reply through the `command_reply' client operation before calling
1368 * the `callback` pending command callback. That is the normal
1369 * command reply handling, and is called regardless whether pending
1370 * command callbacks are used or not.
1372 * Commands that application calls with silc_client_command_call
1373 * will use a command identifier from conn->cmd_ident variable. After
1374 * calling the silc_client_command_call, the conn->cmd_ident includes
1375 * the command identifier that was used for the command sending.
1379 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1380 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1381 * my_ping_handler, my_ping_context);
1384 SilcBool silc_client_command_pending(SilcClientConnection conn,
1385 SilcCommand command,
1386 SilcUInt16 cmd_ident,
1387 SilcClientCommandReply reply,
1391 /* Private Message key management (client_prvmsg.c) */
1393 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1398 * silc_client_add_private_message_key(SilcClient client,
1399 * SilcClientConnection conn,
1400 * SilcClientEntry client_entry,
1401 * const char *cipher,
1403 * unsigned char *key,
1404 * SilcUInt32 key_len);
1408 * Adds a static private message key to the client library. The key
1409 * will be used to encrypt all private message between the client and
1410 * the remote client indicated by the `client_entry'. The `key' can
1411 * be for example a pre-shared-key, passphrase or similar shared secret
1412 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1413 * to assure that the requirements of the SILC protocol are met. The
1414 * API, however, allows to allocate any cipher and HMAC.
1416 * If the private message key is added to client without first receiving
1417 * a request for it from the remote `client_entry' this function will
1418 * send the request to `client_entry'. Note that, the actual key is
1419 * not sent to the network.
1421 * It is not necessary to set key for normal private message usage. If the
1422 * key is not set then the private messages are encrypted using normal
1423 * session keys. Setting the private key, however, increases the security.
1425 * Returns FALSE if the key is already set for the `client_entry', TRUE
1429 SilcBool silc_client_add_private_message_key(SilcClient client,
1430 SilcClientConnection conn,
1431 SilcClientEntry client_entry,
1435 SilcUInt32 key_len);
1437 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1442 * silc_client_add_private_message_key_ske(SilcClient client,
1443 * SilcClientConnection conn,
1444 * SilcClientEntry client_entry,
1445 * const char *cipher,
1447 * SilcSKEKeyMaterial key);
1451 * Same as silc_client_add_private_message_key but takes the key material
1452 * from the SKE key material structure. This structure is received if
1453 * the application uses the silc_client_send_key_agreement to negotiate
1454 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1455 * negotiated also in the SKE protocol.
1458 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1459 SilcClientConnection conn,
1460 SilcClientEntry client_entry,
1463 SilcSKEKeyMaterial key);
1465 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1469 * SilcBool silc_client_del_private_message_key(SilcClient client,
1470 * SilcClientConnection conn,
1471 * SilcClientEntry client_entry);
1475 * Removes the private message from the library. The key won't be used
1476 * after this to protect the private messages with the remote `client_entry'
1477 * client. Returns FALSE on error, TRUE otherwise.
1480 SilcBool silc_client_del_private_message_key(SilcClient client,
1481 SilcClientConnection conn,
1482 SilcClientEntry client_entry);
1484 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1488 * SilcPrivateMessageKeys
1489 * silc_client_list_private_message_keys(SilcClient client,
1490 * SilcClientConnection conn,
1491 * SilcUInt32 *key_count);
1495 * Returns array of set private message keys associated to the connection
1496 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1497 * count to the `key_count' argument. The array must be freed by the caller
1498 * by calling the silc_client_free_private_message_keys function. Note:
1499 * the keys returned in the array is in raw format. It might not be desired
1500 * to show the keys as is. The application might choose not to show the keys
1501 * at all or to show the fingerprints of the keys.
1504 SilcPrivateMessageKeys
1505 silc_client_list_private_message_keys(SilcClient client,
1506 SilcClientConnection conn,
1507 SilcUInt32 *key_count);
1509 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1513 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1514 * SilcUInt32 key_count);
1518 * Frees the SilcPrivateMessageKeys array returned by the function
1519 * silc_client_list_private_message_keys.
1522 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1523 SilcUInt32 key_count);
1526 /* Channel private key management (client_channel.c,
1527 SilcChannelPrivateKey is defined in idlist.h) */
1529 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1533 * SilcBool silc_client_add_channel_private_key(SilcClient client,
1534 * SilcClientConnection conn,
1535 * SilcChannelEntry channel,
1539 * unsigned char *key,
1540 * SilcUInt32 key_len,
1541 * SilcChannelPrivateKey *ret_key);
1545 * Adds private key for channel. When channel has private key then the
1546 * messages are encrypted using that key. All clients on the channel
1547 * must also know the key in order to decrypt the messages. However,
1548 * it is possible to have several private keys per one channel. In this
1549 * case only some of the clients on the channel may know the one key
1550 * and only some the other key. The `name' can be application given
1551 * name for the key. This returns the created key to the 'ret_key'
1552 * pointer if it is non-NULL;
1554 * If `cipher' and/or `hmac' is NULL then default values will be used
1555 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1557 * The private key for channel is optional. If it is not set then the
1558 * channel messages are encrypted using the channel key generated by the
1559 * server. However, setting the private key (or keys) for the channel
1560 * significantly adds security. If more than one key is set the library
1561 * will automatically try all keys at the message decryption phase. Note:
1562 * setting many keys slows down the decryption phase as all keys has to
1563 * be tried in order to find the correct decryption key. However, setting
1564 * a few keys does not have big impact to the decryption performace.
1568 * NOTE: This is entirely local setting. The key set using this function
1569 * is not sent to the network at any phase.
1571 * NOTE: If the key material was originated by the SKE protocol (using
1572 * silc_client_send_key_agreement) then the `key' MUST be the
1573 * key->send_enc_key as this is dictated by the SILC protocol. However,
1574 * currently it is not expected that the SKE key material would be used
1575 * as channel private key. However, this API allows it.
1578 SilcBool silc_client_add_channel_private_key(SilcClient client,
1579 SilcClientConnection conn,
1580 SilcChannelEntry channel,
1586 SilcChannelPrivateKey *ret_key);
1588 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1592 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1593 * SilcClientConnection conn,
1594 * SilcChannelEntry channel);
1598 * Removes all private keys from the `channel'. The old channel key is used
1599 * after calling this to protect the channel messages. Returns FALSE on
1600 * on error, TRUE otherwise.
1603 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1604 SilcClientConnection conn,
1605 SilcChannelEntry channel);
1607 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1611 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1612 * SilcClientConnection conn,
1613 * SilcChannelEntry channel,
1614 * SilcChannelPrivateKey key);
1618 * Removes and frees private key `key' from the channel `channel'.
1619 * The `key' is retrieved by calling the function
1620 * silc_client_list_channel_private_keys. The key is not used after
1621 * this. If the key was last private key then the old channel key is
1622 * used hereafter to protect the channel messages. This returns FALSE
1623 * on error, TRUE otherwise.
1626 SilcBool silc_client_del_channel_private_key(SilcClient client,
1627 SilcClientConnection conn,
1628 SilcChannelEntry channel,
1629 SilcChannelPrivateKey key);
1631 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1636 * silc_client_list_channel_private_keys(SilcClient client,
1637 * SilcClientConnection conn,
1638 * SilcChannelEntry channel);
1642 * Returns list of private keys associated to the `channel'. The caller
1643 * must free the returned list with silc_dlist_uninit. The pointers in
1644 * the list may be used to delete the specific key by giving the pointer
1645 * as argument to the function silc_client_del_channel_private_key. Each
1646 * entry in the list is SilcChannelPrivateKey.
1649 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1650 SilcClientConnection conn,
1651 SilcChannelEntry channel);
1653 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1657 * void silc_client_current_channel_private_key(SilcClient client,
1658 * SilcClientConnection conn,
1659 * SilcChannelEntry channel,
1660 * SilcChannelPrivateKey key);
1664 * Sets the `key' to be used as current channel private key on the
1665 * `channel'. Packet sent after calling this function will be secured
1669 void silc_client_current_channel_private_key(SilcClient client,
1670 SilcClientConnection conn,
1671 SilcChannelEntry channel,
1672 SilcChannelPrivateKey key);
1675 /* Key Agreement routines */
1677 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1681 * void silc_client_send_key_agreement(SilcClient client,
1682 * SilcClientConnection conn,
1683 * SilcClientEntry client_entry,
1684 * SilcClientConnectionParams *params,
1685 * SilcPublicKey public_key,
1686 * SilcPrivateKey private_key,
1687 * SilcKeyAgreementCallback completion,
1692 * Sends key agreement request to the remote client indicated by the
1695 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1696 * the caller will provide the connection endpoint for the key agreement
1697 * connection. The `bind_ip' can be used to bind to that IP instead of
1698 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1699 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1700 * and `timeout_secs' fields in `params'. Other fields are ignored.
1701 * If `params' is NULL, then the `client_entry' is expected to provide
1702 * the connection endpoint for us. It is recommended the `timeout_secs'
1703 * is specified in case the remote client does not reply anything to
1706 * The `public_key' and `private_key' is our identity in the key agreement.
1708 * In case we do not provide the connection endpoint, we will receive
1709 * the `key_agreement' client operation when the remote send its own
1710 * key agreement request packet. We may then there start the key
1711 * agreement with silc_client_perform_key_agreement. If we provided the
1712 * the connection endpoint, the client operation will not be called.
1714 * There can be only one active key agreement for `client_entry'. Old
1715 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1719 * // Send key agreement request (we don't provide connection endpoint)
1720 * silc_client_send_key_agreement(client, conn, remote_client,
1721 * NULL, public_key, private_key,
1722 * my_keyagr_completion, my_context);
1724 * // Another example where we provide connection endpoint (TCP).
1725 * SilcClientConnectionParams params;
1726 * memset(¶ms, 0, sizeof(params));
1727 * params.local_ip = local_ip;
1728 * params.local_port = local_port;
1729 * params.timeout_secs = 60;
1730 * silc_client_send_key_agreement(client, conn, remote_client,
1731 * ¶ms, public_key, private_key,
1732 * my_keyagr_completion, my_context);
1735 void silc_client_send_key_agreement(SilcClient client,
1736 SilcClientConnection conn,
1737 SilcClientEntry client_entry,
1738 SilcClientConnectionParams *params,
1739 SilcPublicKey public_key,
1740 SilcPrivateKey private_key,
1741 SilcKeyAgreementCallback completion,
1744 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1749 * silc_client_perform_key_agreement(SilcClient client,
1750 * SilcClientConnection conn,
1751 * SilcClientEntry client_entry,
1752 * SilcClientConnectionParams *params,
1753 * SilcPublicKey public_key,
1754 * SilcPrivateKey private_key,
1755 * char *hostname, int port,
1756 * SilcKeyAgreementCallback completion,
1761 * Performs the key agreement protocol. Application may use this to
1762 * initiate the key agreement protocol. Usually this is called after
1763 * receiving the `key_agreement' client operation.
1765 * The `hostname' is the remote hostname (or IP address) and the `port'
1766 * is the remote port. The `completion' callback with the `context' will
1767 * be called after the key agreement protocol.
1769 * The `params' is connection parameters and it may be used to define
1770 * the key agreement connection related parameters. It may be NULL.
1773 void silc_client_perform_key_agreement(SilcClient client,
1774 SilcClientConnection conn,
1775 SilcClientEntry client_entry,
1776 SilcClientConnectionParams *params,
1777 SilcPublicKey public_key,
1778 SilcPrivateKey private_key,
1779 char *hostname, int port,
1780 SilcKeyAgreementCallback completion,
1783 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1788 * silc_client_perform_key_agreement_stream(
1789 * SilcClient client,
1790 * SilcClientConnection conn,
1791 * SilcClientEntry client_entry,
1792 * SilcClientConnectionParams *params,
1793 * SilcPublicKey public_key,
1794 * SilcPrivateKey private_key,
1795 * SilcStream stream,
1796 * SilcKeyAgreementCallback completion,
1801 * Same as silc_client_perform_key_agreement but the caller has created
1802 * the connection. The `stream' is the created connection.
1806 silc_client_perform_key_agreement_stream(SilcClient client,
1807 SilcClientConnection conn,
1808 SilcClientEntry client_entry,
1809 SilcClientConnectionParams *params,
1810 SilcPublicKey public_key,
1811 SilcPrivateKey private_key,
1813 SilcKeyAgreementCallback completion,
1816 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1820 * void silc_client_abort_key_agreement(SilcClient client,
1821 * SilcClientConnection conn,
1822 * SilcClientEntry client_entry);
1826 * This function can be called to unbind the hostname and the port for
1827 * the key agreement protocol. However, this function has effect only
1828 * before the key agreement protocol has been performed. After it has
1829 * been performed the library will automatically unbind the port. The
1830 * `client_entry' is the client to which we sent the key agreement
1831 * request. The key agreement completion callback will be called
1832 * with SILC_KEY_AGREEMENT_ABORTED status.
1835 void silc_client_abort_key_agreement(SilcClient client,
1836 SilcClientConnection conn,
1837 SilcClientEntry client_entry);
1840 /* Misc functions */
1842 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1846 * void silc_client_set_away_message(SilcClient client,
1847 * SilcClientConnection conn,
1852 * Sets away `message'. The away message may be set when the client's
1853 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1854 * to anyone who sends private message. The `message' will be sent
1855 * automatically back to the the client who send private message. If
1856 * away message is already set this replaces the old message with the
1857 * new one. If `message' is NULL the old away message is removed.
1858 * The sender may freely free the memory of the `message'.
1861 void silc_client_set_away_message(SilcClient client,
1862 SilcClientConnection conn,
1865 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1869 * typedef enum { ... } SilcClientMonitorStatus;
1873 * File transmission session status types. These will indicate
1874 * the status of the file transmission session.
1879 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1880 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1881 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1882 SILC_CLIENT_FILE_MONITOR_GET,
1883 SILC_CLIENT_FILE_MONITOR_PUT,
1884 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1885 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1886 } SilcClientMonitorStatus;
1889 /****d* silcclient/SilcClientAPI/SilcClientFileError
1893 * typedef enum { ... } SilcClientFileError;
1897 * File transmission error types. These types are returned by
1898 * some of the file transmission functions, and by the monitor
1899 * callback to indicate error.
1904 SILC_CLIENT_FILE_OK,
1905 SILC_CLIENT_FILE_ERROR,
1906 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1907 SILC_CLIENT_FILE_ALREADY_STARTED,
1908 SILC_CLIENT_FILE_NO_SUCH_FILE,
1909 SILC_CLIENT_FILE_PERMISSION_DENIED,
1910 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1911 } SilcClientFileError;
1914 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1918 * typedef void (*SilcClientFileMonitor)(SilcClient client,
1919 * SilcClientConnection conn,
1920 * SilcClientMonitorStatus status,
1921 * SilcClientFileError error,
1922 * SilcUInt64 offset,
1923 * SilcUInt64 filesize,
1924 * SilcClientEntry client_entry,
1925 * SilcUInt32 session_id,
1926 * const char *filepath,
1931 * Monitor callback that is called during the file transmission to
1932 * monitor the transmission process. The `status' indicates the current
1933 * monitoring process. The `error' will indicate the error type
1934 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
1935 * currently transmitted amount of total `filesize'. The `client_entry'
1936 * indicates the remote client, and the transmission session ID is the
1937 * `session_id'. The filename being transmitted is indicated by the
1941 typedef void (*SilcClientFileMonitor)(SilcClient client,
1942 SilcClientConnection conn,
1943 SilcClientMonitorStatus status,
1944 SilcClientFileError error,
1946 SilcUInt64 filesize,
1947 SilcClientEntry client_entry,
1948 SilcUInt32 session_id,
1949 const char *filepath,
1952 /****f* silcclient/SilcClientAPI/SilcClientFileName
1956 * typedef void (*SilcClientFileName)(const char *filepath,
1961 * Completion callback for the SilcClientFileAskName callback function.
1962 * Application calls this to deliver the filepath and filename where
1963 * the downloaded file is to be saved.
1966 typedef void (*SilcClientFileName)(const char *filepath,
1969 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
1973 * typedef void (*SilcClientFileAskName)(SilcClient client,
1974 * SilcClientConnection conn,
1975 * SilcUInt32 session_id,
1976 * const char *remote_filename,
1977 * SilcClientFileName completion,
1978 * void *completion_context,
1983 * File name asking callback, that is called if it is given to the
1984 * silc_client_file_receive and the path given to that as argument was
1985 * NULL. The library calls this to ask the filename and filepath to
1986 * where the file is to be saved. The 'remote_filename' is the file
1987 * that is being downloaded. Application must call the 'completion'
1988 * with 'completion_context' to continue with the file downloading.
1989 * It is not mandatory to provide this to the silc_client_file_receive.
1992 typedef void (*SilcClientFileAskName)(SilcClient client,
1993 SilcClientConnection conn,
1994 SilcUInt32 session_id,
1995 const char *remote_filename,
1996 SilcClientFileName completion,
1997 void *completion_context,
2000 /****f* silcclient/SilcClientAPI/silc_client_file_send
2004 * SilcClientFileError
2005 * silc_client_file_send(SilcClient client,
2006 * SilcClientConnection conn,
2007 * SilcClientFileMonitor monitor,
2008 * void *monitor_context,
2009 * const char *local_ip,
2010 * SilcUInt32 local_port,
2011 * SilcBool do_not_bind,
2012 * SilcClientEntry client_entry,
2013 * const char *filepath);
2014 * SilcUInt32 *session_id);
2018 * Sends a file indicated by the `filepath' to the remote client
2019 * indicated by the `client_entry'. This will negotiate a secret key
2020 * with the remote client before actually starting the transmission of
2021 * the file. The `monitor' callback will be called to monitor the
2022 * transmission of the file.
2024 * This returns a file session ID for the file transmission to the
2025 * `session_id' pointer. It can be used to close the session (and
2026 * abort the file transmission) by calling the silc_client_file_close
2027 * function. The session ID is also returned in the `monitor' callback.
2029 * If the `local_ip' is provided then this will try to bind the
2030 * listener for key exchange protocol to that IP. If `local_port' is
2031 * non-zero that port is used. If `local_ip' is NULL then this will
2032 * automatically attempt to bind it to local IP address of the machine.
2033 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2034 * ignored and it is expected that the receiver will provide the
2035 * point of contact. This is usefull if the sender is behind NAT.
2037 * If error will occur during the file transfer process the error
2038 * status will be returned in the monitor callback. In this case
2039 * the application must call silc_client_file_close to close the
2044 silc_client_file_send(SilcClient client,
2045 SilcClientConnection conn,
2046 SilcClientFileMonitor monitor,
2047 void *monitor_context,
2048 const char *local_ip,
2049 SilcUInt32 local_port,
2050 SilcBool do_not_bind,
2051 SilcClientEntry client_entry,
2052 const char *filepath,
2053 SilcUInt32 *session_id);
2055 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2059 * SilcClientFileError
2060 * silc_client_file_receive(SilcClient client,
2061 * SilcClientConnection conn,
2062 * SilcClientFileMonitor monitor,
2063 * void *monitor_context,
2065 * SilcUInt32 session_id,
2066 * SilcClientFileAskName ask_name,
2067 * void *ask_name_context);
2071 * Receives a file from a client indicated by the `client_entry'. The
2072 * `session_id' indicates the file transmission session and it has been
2073 * received in the `ftp' client operation function. This will actually
2074 * perform the key agreement protocol with the remote client before
2075 * actually starting the file transmission. The `monitor' callback
2076 * will be called to monitor the transmission. If `path' is non-NULL
2077 * the file will be saved into that directory. If NULL the file is
2078 * saved in the current working directory, unless the 'ask_name'
2079 * callback is non-NULL. In this case the callback is called to ask
2080 * the path and filename from application.
2082 * If error will occur during the file transfer process the error
2083 * status will be returned in the monitor callback. In this case
2084 * the application must call silc_client_file_close to close the
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);
2098 /****f* silcclient/SilcClientAPI/silc_client_file_close
2102 * SilcClientFileError silc_client_file_close(SilcClient client,
2103 * SilcClientConnection conn,
2104 * SilcUInt32 session_id);
2108 * Closes file transmission session indicated by the `session_id'.
2109 * If file transmission is being conducted it will be aborted
2110 * automatically. This function is also used to close the session
2111 * after successful file transmission. This function can be used
2112 * also to reject incoming file transmission request. If the
2113 * session was already started and the monitor callback was set
2114 * the monitor callback will be called with the monitor status
2115 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2118 SilcClientFileError silc_client_file_close(SilcClient client,
2119 SilcClientConnection conn,
2120 SilcUInt32 session_id);
2122 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2126 * SilcAttributePayload
2127 * silc_client_attribute_add(SilcClient client,
2128 * SilcClientConnection conn,
2129 * SilcAttribute attribute,
2131 * SilcUInt32 object_size);
2135 * Add new Requsted Attribute for WHOIS command to the client library.
2136 * The `attribute' object indicated by `object' is added and allocated
2137 * SilcAttributePayload is returned. The `object' must be of correct
2138 * type and of correct size. See the SilcAttribute for object types
2139 * for different attributes. You may also get all added attributes
2140 * from the client with silc_client_attributes_get function.
2142 * Requested Attributes are different personal information about the
2143 * user, status information and other information which other users
2144 * may query with WHOIS command. Application may set these so that
2145 * if someone sends WHOIS query these attributes will be replied back
2146 * to the sender. The library always puts the public key to the
2147 * Requested Attributes, but if application wishes to add additional
2148 * public keys (or certificates) it can be done with this interface.
2149 * Library also always computes digital signature of the attributes
2150 * automatically, so application does not need to do that.
2153 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2154 SilcClientConnection conn,
2155 SilcAttribute attribute,
2157 SilcUInt32 object_size);
2159 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2163 * SilcBool silc_client_attribute_del(SilcClient client,
2164 * SilcClientConnection conn,
2165 * SilcAttribute attribute,
2166 * SilcAttributePayload attr);
2170 * Delete a Requested Attribute from the client. If the `attribute'
2171 * is non-zero then all attributes of that type are deleted and the
2172 * `attr' is ignored. If `attr' is non-NULL then that specific
2173 * attribute is deleted and `attribute' is ignored.
2175 * You may get all added attributes with the function
2176 * silc_client_attributes_get and to get the SilcAttributePayload.
2177 * This function Returns TRUE if the attribute was found and deleted.
2180 SilcBool silc_client_attribute_del(SilcClient client,
2181 SilcClientConnection conn,
2182 SilcAttribute attribute,
2183 SilcAttributePayload attr);
2185 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2189 * const SilcHashTable
2190 * silc_client_attributes_get(SilcClient client,
2191 * SilcClientConnection conn);
2195 * Returns pointer to the SilcHashTable which includes all the added
2196 * Requested Attributes. The caller must not free the hash table.
2197 * The caller may use SilcHashTableList and silc_hash_table_list to
2198 * traverse the table. Each entry in the hash table is one added
2199 * SilcAttributePayload. It is possible to delete a attribute
2200 * payload while traversing the table.
2203 SilcHashTable silc_client_attributes_get(SilcClient client,
2204 SilcClientConnection conn);
2206 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2210 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2214 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2215 * then all attributes are requested. Alternatively, `attribute' and
2216 * all variable arguments can each be requested attribute. In this case
2217 * the last must be set to zero (0) to complete the variable list of
2218 * requested attributes. See SilcAttribute for all attributes.
2219 * You can give the returned buffer as argument to for example
2220 * silc_client_get_client_by_id_resolve function.
2224 * Request all attributes
2225 * buffer = silc_client_attributes_request(0);
2227 * Request only the following attributes
2228 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2229 * SILC_ATTRIBUTE_SERVICE,
2230 * SILC_ATTRIBUTE_MOOD, 0);
2233 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2235 /****f* silcclient/SilcClientAPI/silc_client_nickname_format
2240 * silc_client_nickname_format(SilcClient client,
2241 * SilcClientConnection conn,
2242 * SilcClientEntry client_entry,
2243 * SilcBool priority);
2247 * Formats the nickname of `client_entry' according to the nickname
2248 * formatting rules set in SilcClientParams. If the `priority' is TRUE
2249 * then the `client_entry' will always get the unformatted nickname.
2250 * If FALSE and there are more than one same nicknames in the client
2251 * the nickname will be formatted.
2253 * This returns NULL on error. Otherwise, the client entry that was
2254 * formatted is returned. If `priority' is FALSE this always returns
2255 * the `client_entry'. If it is TRUE, this may return the client entry
2256 * that was formatted after giving the `client_entry' the unformatted
2259 * Usually application does not need to call this function, as the library
2260 * automatically formats nicknames. However, if application wants to
2261 * for example force the `client_entry' to always have the unformatted
2262 * nickname it may call this function to do so.
2265 SilcClientEntry silc_client_nickname_format(SilcClient client,
2266 SilcClientConnection conn,
2267 SilcClientEntry client_entry,
2274 #endif /* SILCCLIENT_H */