20
20
#ifndef __CONTEXT_H__
21
21
#define __CONTEXT_H__
29
OTRL_MSGSTATE_PLAINTEXT, /* Not yet started an encrypted
31
OTRL_MSGSTATE_ENCRYPTED, /* Currently in an encrypted
33
OTRL_MSGSTATE_FINISHED /* The remote side has sent us a
34
notification that he has ended
35
his end of the encrypted
36
conversation; prevent any
37
further messages from being
32
41
typedef struct fingerprint {
42
struct fingerprint *next; /* The next fingerprint in the list */
43
struct fingerprint **tous; /* A pointer to the pointer to us */
33
44
unsigned char *fingerprint; /* The fingerprint, or NULL */
34
45
struct context *context; /* The context to which we belong */
35
struct fingerprint *next; /* The next fingerprint in the list */
36
struct fingerprint **tous; /* A pointer to the pointer to us */
46
char *trust; /* The trust level of the fingerprint */
39
49
typedef struct context {
50
struct context * next; /* Linked list pointer */
51
struct context ** tous; /* A pointer to the pointer to us */
40
53
char * username; /* The user this context is for */
41
54
char * accountname; /* The username is relative to
43
56
char * protocol; /* ... and this protocol */
44
ConnectionState state; /* The state of our connection to this
58
char *fragment; /* The part of the fragmented message
60
size_t fragment_len; /* The length of fragment */
61
unsigned short fragment_n; /* The total number of fragments
63
unsigned short fragment_k; /* The highest fragment number
64
we've seen so far for this
67
OtrlMessageState msgstate; /* The state of message disposition
69
OtrlAuthInfo auth; /* The state of ongoing
70
authentication with this user */
46
72
Fingerprint fingerprint_root; /* The root of a linked list of
47
73
Fingerprints entries */
48
74
Fingerprint *active_fingerprint; /* Which fingerprint is in use now?
62
88
derived from DH key[our_keyid-i]
63
89
and mpi Y[their_keyid-j] */
91
unsigned char sessionid[20]; /* The sessionid and bold half */
92
size_t sessionid_len; /* determined when this private */
93
OtrlSessionIdHalf sessionid_half; /* connection was established. */
95
unsigned int protocol_version; /* The version of OTR in use */
97
unsigned char *preshared_secret; /* A secret you share with this
100
size_t preshared_secret_len; /* The length of the above secret. */
65
102
/* saved mac keys to be revealed later */
66
103
unsigned int numsavedkeys;
67
104
unsigned char *saved_mac_keys;
88
125
/* A function to free the above data when we forget this context */
89
126
void (*app_data_free)(void *);
91
struct context * next; /* Linked list pointer */
92
struct context ** tous; /* A pointer to the pointer to us */
95
129
#include "userstate.h"
97
/* Strings describing the connection states */
98
extern const char *otrl_context_statestr[];
100
131
/* Look up a connection context by name/account/protocol from the given
101
132
* OtrlUserState. If add_if_missing is true, allocate and return a new
102
133
* context if one does not currently exist. In that event, call
112
143
Fingerprint *otrl_context_find_fingerprint(ConnContext *context,
113
144
unsigned char fingerprint[20], int add_if_missing, int *addedp);
115
/* Force a context into the CONN_SETUP state (so that it only has local
117
void otrl_context_force_setup(ConnContext *context);
119
/* Force a context into the CONN_UNCONNECTED state. */
120
void otrl_context_force_disconnect(ConnContext *context);
146
/* Set the trust level for a given fingerprint */
147
void otrl_context_set_trust(Fingerprint *fprint, const char *trust);
149
/* Set the preshared secret for a given fingerprint. Note that this
150
* currently only stores the secret in the ConnContext structure, but
151
* doesn't yet do anything with it. */
152
void otrl_context_set_preshared_secret(ConnContext *context,
153
const unsigned char *secret, size_t secret_len);
155
/* Force a context into the OTRL_MSGSTATE_FINISHED state. */
156
void otrl_context_force_finished(ConnContext *context);
158
/* Force a context into the OTRL_MSGSTATE_PLAINTEXT state. */
159
void otrl_context_force_plaintext(ConnContext *context);
122
161
/* Forget a fingerprint (so long as it's not the active one. If it's a
123
162
* fingerprint_root, forget the whole context (as long as
124
* and_maybe_context is set, and it's UNCONNECTED). Also, if it's not
163
* and_maybe_context is set, and it's PLAINTEXT). Also, if it's not
125
164
* the fingerprint_root, but it's the only fingerprint, and we're
126
* UNCONNECTED, forget the whole context if and_maybe_context is set. */
165
* PLAINTEXT, forget the whole context if and_maybe_context is set. */
127
166
void otrl_context_forget_fingerprint(Fingerprint *fprint,
128
167
int and_maybe_context);
130
/* Forget a whole context, so long as it's UNCONNECTED. */
169
/* Forget a whole context, so long as it's PLAINTEXT. */
131
170
void otrl_context_forget(ConnContext *context);
133
/* Forget all the contexts in a given OtrlUserState, forcing them to
172
/* Forget all the contexts in a given OtrlUserState. */
135
173
void otrl_context_forget_all(OtrlUserState us);