silcclient: auto-negotiation of private message key using SKE over SILCnet
[silc.git] / lib / silcclient / client.h
1 /*
2
3   client.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2014 Pekka Riikonen
8
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.
12
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.
17
18 */
19
20 #ifndef CLIENT_H
21 #define CLIENT_H
22
23 #ifndef SILCCLIENT_H
24 #error "Do not include this header directly"
25 #endif
26
27 /* Forward declarations */
28 typedef struct SilcClientStruct *SilcClient;
29 typedef struct SilcClientConnectionStruct *SilcClientConnection;
30 typedef struct SilcClientEntryStruct *SilcClientEntry;
31 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
32 typedef struct SilcServerEntryStruct *SilcServerEntry;
33
34 typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
35 typedef struct SilcClientAutonegMessageKeyStruct *SilcClientAutonegMessageKey;
36 typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
37 typedef struct SilcClientCommandReplyContextStruct
38                                            *SilcClientCommandReplyContext;
39 typedef struct SilcChannelUserStruct *SilcChannelUser;
40 typedef struct SilcClientInternalStruct *SilcClientInternal;
41 typedef struct SilcClientConnectionInternalStruct
42      *SilcClientConnectionInternal;
43 typedef struct SilcChannelPrivateKeyStruct *SilcChannelPrivateKey;
44
45 /* Internal client entry context */
46 typedef struct SilcClientEntryInternalStruct {
47   void *prv_waiter;             /* Private message packet waiter */
48   SilcRwLock lock;              /* Read/write lock */
49   SilcCipher send_key;          /* Private message key for sending */
50   SilcCipher receive_key;       /* Private message key for receiving */
51   SilcHmac hmac_send;           /* Private mesage key HMAC for sending */
52   SilcHmac hmac_receive;        /* Private mesage key HMAC for receiving */
53   unsigned char *key;           /* Valid if application provided the key */
54   SilcUInt32 key_len;           /* Key data length */
55   SilcClientKeyAgreement ke;    /* Current key agreement context or NULL */
56   SilcAsyncOperation op;        /* Asynchronous operation with this client */
57
58   SilcClientAutonegMessageKey ake; /* Current auto-negotiation context */
59   SilcInt64 ake_rekey;          /* Next private message key auto-negotation */
60   SilcUInt32 ake_generation;    /* current AKE rekey generation */
61
62   SilcAtomic32 refcnt;          /* Reference counter */
63   SilcAtomic32 deleted;         /* Flag indicating whether the client object is
64                                    already scheduled for deletion */
65   SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
66
67   /* Flags */
68   unsigned int valid       : 1; /* FALSE if this entry is not valid.  Entry
69                                    without nickname is not valid. */
70   unsigned int generated   : 1; /* TRUE if library generated `key' */
71   unsigned int prv_resp    : 1; /* TRUE if we are responder when using
72                                    private message keys. */
73   unsigned int no_ake      : 1; /* TRUE if client doesn't support
74                                    auto-negotiation of private message key,
75                                    or it doesn't work. */
76 } SilcClientEntryInternal;
77
78 /* Internal channel entry context */
79 typedef struct SilcChannelEntryInternalStruct {
80   SilcRwLock lock;                           /* Read/write lock */
81
82   /* SilcChannelEntry status information */
83   SilcDList old_channel_keys;
84   SilcDList old_hmacs;
85
86   /* Channel private keys */
87   SilcDList private_keys;                    /* List of private keys or NULL */
88   SilcChannelPrivateKey curr_key;            /* Current private key */
89
90   /* Channel keys */
91   SilcCipher send_key;                       /* The channel key */
92   SilcCipher receive_key;                    /* The channel key */
93   SilcHmac hmac;                             /* Current HMAC */
94   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
95
96   SilcAtomic32 refcnt;                       /* Reference counter */
97   SilcAtomic32 deleted;                      /* Flag indicating whether the
98                                                 channel object is already
99                                                 scheduled for deletion */
100   SilcUInt16 resolve_cmd_ident;              /* Channel information resolving
101                                                 identifier. This is used when
102                                                 resolving users, and other
103                                                 stuff that relates to the
104                                                 channel. Not used for the
105                                                 channel resolving itself. */
106 } SilcChannelEntryInternal;
107
108 /* Internal server entry context */
109 typedef struct SilcServerEntryInternalStruct {
110   SilcRwLock lock;                           /* Read/write lock */
111   SilcUInt16 resolve_cmd_ident;              /* Resolving identifier */
112   SilcAtomic32 refcnt;                       /* Reference counter */
113   SilcAtomic32 deleted;                      /* Flag indicating whether the
114                                                 server object is already
115                                                 scheduled for deletion. */
116 } SilcServerEntryInternal;
117
118 #endif /* CLIENT_H */