/*
- client.h
+ client.h
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2002 Pekka Riikonen
+ Copyright (C) 1997 - 2007 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#ifndef CLIENT_H
#define CLIENT_H
+#ifndef SILCCLIENT_H
+#error "Do not include this header directly"
+#endif
+
/* Forward declarations */
+typedef struct SilcClientStruct *SilcClient;
+typedef struct SilcClientConnectionStruct *SilcClientConnection;
+typedef struct SilcClientEntryStruct *SilcClientEntry;
+typedef struct SilcChannelEntryStruct *SilcChannelEntry;
+typedef struct SilcServerEntryStruct *SilcServerEntry;
+
+typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
+typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
+typedef struct SilcClientCommandReplyContextStruct
+ *SilcClientCommandReplyContext;
+typedef struct SilcChannelUserStruct *SilcChannelUser;
typedef struct SilcClientInternalStruct *SilcClientInternal;
-
-/* Generic rekey context for connections */
-typedef struct {
- /* Current sending encryption key, provided for re-key. The `pfs'
- is TRUE if the Perfect Forward Secrecy is performed in re-key. */
- unsigned char *send_enc_key;
- SilcUInt32 enc_key_len;
- int ske_group;
- bool pfs;
- SilcUInt32 timeout;
- void *context;
-} *SilcClientRekey;
-
-/* Context to hold the connection authentication request callbacks that
- will be called when the server has replied back to our request about
- current authentication method in the session. */
-typedef struct {
- SilcConnectionAuthRequest callback;
- void *context;
- SilcTask timeout;
-} *SilcClientConnAuthRequest;
-
-/* Connection structure used in client to associate all the important
- connection specific data to this structure. */
-struct SilcClientConnectionStruct {
- /*
- * Local data
- */
- char *nickname;
-
- /* Local client ID for this connection */
- SilcClientID *local_id;
-
- /* Decoded local ID so that the above defined ID would not have
- to be decoded for every packet. */
- unsigned char *local_id_data;
- SilcUInt32 local_id_data_len;
-
- /* Own client entry. */
- SilcClientEntry local_entry;
-
- /*
- * Remote data
- */
- char *remote_host;
- int remote_port;
- int remote_type;
- char *remote_info;
-
- /* Remote server ID for this connection */
- SilcServerID *remote_id;
-
- /* Decoded remote ID so that the above defined ID would not have
- to be decoded for every packet. */
- unsigned char *remote_id_data;
- SilcUInt32 remote_id_data_len;
-
- /*
- * Common data
- */
- /* Keys and stuff negotiated in the SKE protocol */
- SilcCipher send_key;
- SilcCipher receive_key;
- SilcHmac hmac_send;
- SilcHmac hmac_receive;
- SilcHash hash;
- SilcUInt32 psn_send;
- SilcUInt32 psn_receive;
-
- /* Client ID and Channel ID cache. Messages transmitted in SILC network
- are done using different unique ID's. These are the cache for
- thoses ID's used in the communication. */
- SilcIDCache client_cache;
- SilcIDCache channel_cache;
- SilcIDCache server_cache;
-
- /* Current channel on window. All channels are saved (allocated) into
- the cache entries. */
- SilcChannelEntry current_channel;
-
- /* Socket connection object for this connection (window). This
- object will have a back-pointer to this window object for fast
- referencing (sock->user_data). */
- SilcSocketConnection sock;
-
- /* Pending command queue for this connection */
- SilcDList pending_commands;
-
- /* Current command identifier, 0 not used */
- SilcUInt16 cmd_ident;
-
- /* Requested pings. */
- SilcClientPing *ping;
- SilcUInt32 ping_count;
-
- /* Set away message */
- SilcClientAway *away;
-
- /* Re-key context */
- SilcClientRekey rekey;
-
- /* Authentication request context. */
- SilcClientConnAuthRequest connauth;
-
- /* File transmission sessions */
- SilcDList ftp_sessions;
- SilcUInt32 next_session_id;
- SilcClientFtpSession active_session;
-
- /* Requested Attributes */
- SilcHashTable attrs;
-
- /* Pointer back to the SilcClient. This object is passed to the application
- and the actual client object is accesible through this pointer. */
- SilcClient client;
-
- /* Connection parameters */
- SilcClientConnectionParams params;
-
- /* User data context. Library does not touch this. */
- void *context;
-};
-
-/* Main client structure. */
-struct SilcClientStruct {
- char *username; /* Username, must be set by application */
- char *nickname; /* Nickname, may be set by application */
- char *hostname; /* hostname, must be set by application */
- char *realname; /* Real name, must be set be application */
-
- SilcPublicKey public_key; /* Public key of user, set by application */
- SilcPrivateKey private_key; /* Private key of user, set by application */
- SilcPKCS pkcs; /* PKCS allocated by application */
-
- SilcSchedule schedule; /* Scheduler, automatically allocated by
- the client library. */
-
- /* Random Number Generator. Application should use this as its primary
- random number generator. */
- SilcRng rng;
-
- /* Application specific user data pointer. Client library does not
- touch this. This the context sent as argument to silc_client_alloc. */
- void *application;
-
- /* Generic hash context for application usage */
- SilcHash md5hash;
- SilcHash sha1hash;
-
- /* Internal data for client library. Application cannot access this
- data at all. */
- SilcClientInternal internal;
-};
-
-#endif
+typedef struct SilcClientConnectionInternalStruct
+ *SilcClientConnectionInternal;
+typedef struct SilcChannelPrivateKeyStruct *SilcChannelPrivateKey;
+
+/* Internal client entry context */
+typedef struct SilcClientEntryInternalStruct {
+ void *prv_waiter; /* Private message packet waiter */
+ SilcRwLock lock; /* Read/write lock */
+ SilcCipher send_key; /* Private message key for sending */
+ SilcCipher receive_key; /* Private message key for receiving */
+ SilcHmac hmac_send; /* Private mesage key HMAC for sending */
+ SilcHmac hmac_receive; /* Private mesage key HMAC for receiving */
+ unsigned char *key; /* Valid if application provided the key */
+ SilcUInt32 key_len; /* Key data length */
+ SilcClientKeyAgreement ke; /* Current key agreement context or NULL */
+
+ /* Flags */
+ unsigned int valid : 1; /* FALSE if this entry is not valid. Entry
+ without nickname is not valid. */
+ unsigned int generated : 1; /* TRUE if library generated `key' */
+ unsigned int prv_resp : 1; /* TRUE if we are responder when using
+ private message keys. */
+ SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
+ SilcAtomic16 refcnt; /* Reference counter */
+} SilcClientEntryInternal;
+
+/* Internal channel entry context */
+typedef struct SilcChannelEntryInternalStruct {
+ SilcRwLock lock; /* Read/write lock */
+
+ /* SilcChannelEntry status information */
+ SilcDList old_channel_keys;
+ SilcDList old_hmacs;
+
+ /* Channel private keys */
+ SilcDList private_keys; /* List of private keys or NULL */
+ SilcChannelPrivateKey curr_key; /* Current private key */
+
+ /* Channel keys */
+ SilcCipher send_key; /* The channel key */
+ SilcCipher receive_key; /* The channel key */
+ SilcHmac hmac; /* Current HMAC */
+ unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
+
+ SilcUInt16 resolve_cmd_ident; /* Channel information resolving
+ identifier. This is used when
+ resolving users, and other
+ stuff that relates to the
+ channel. Not used for the
+ channel resolving itself. */
+ SilcAtomic16 refcnt; /* Reference counter */
+} SilcChannelEntryInternal;
+
+/* Internal server entry context */
+typedef struct SilcServerEntryInternalStruct {
+ SilcRwLock lock; /* Read/write lock */
+ SilcUInt16 resolve_cmd_ident; /* Resolving identifier */
+ SilcAtomic8 refcnt; /* Reference counter */
+} SilcServerEntryInternal;
+
+#endif /* CLIENT_H */