~ubuntu-branches/ubuntu/oneiric/libotr/oneiric-security

« back to all changes in this revision

Viewing changes to src/context.h

  • Committer: Bazaar Package Importer
  • Author(s): Thibaut VARENE
  • Date: 2006-01-02 19:52:18 UTC
  • mfrom: (2.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060102195218-wb8803196y9mycx6
Tags: 3.0.0-2
Fix typo: "malformed messahes" (Closes: #345400)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef __CONTEXT_H__
21
21
#define __CONTEXT_H__
22
22
 
23
 
#include "gcrypt.h"
 
23
#include <gcrypt.h>
 
24
 
24
25
#include "dh.h"
 
26
#include "auth.h"
25
27
 
26
28
typedef enum {
27
 
    CONN_UNCONNECTED,
28
 
    CONN_SETUP,
29
 
    CONN_CONNECTED
30
 
} ConnectionState;
 
29
    OTRL_MSGSTATE_PLAINTEXT,           /* Not yet started an encrypted
 
30
                                          conversation */
 
31
    OTRL_MSGSTATE_ENCRYPTED,           /* Currently in an encrypted
 
32
                                          conversation */
 
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
 
38
                                          sent to him. */
 
39
} OtrlMessageState;
31
40
 
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 */
37
47
} Fingerprint;
38
48
 
39
49
typedef struct context {
 
50
    struct context * next;             /* Linked list pointer */
 
51
    struct context ** tous;            /* A pointer to the pointer to us */
 
52
 
40
53
    char * username;                   /* The user this context is for */
41
54
    char * accountname;                /* The username is relative to
42
55
                                          this account... */
43
56
    char * protocol;                   /* ... and this protocol */
44
 
    ConnectionState state;             /* The state of our connection to this
45
 
                                          user */
 
57
 
 
58
    char *fragment;                    /* The part of the fragmented message
 
59
                                          we've seen so far */
 
60
    size_t fragment_len;               /* The length of fragment */
 
61
    unsigned short fragment_n;         /* The total number of fragments
 
62
                                          in this message */
 
63
    unsigned short fragment_k;         /* The highest fragment number
 
64
                                          we've seen so far for this
 
65
                                          message */
 
66
 
 
67
    OtrlMessageState msgstate;         /* The state of message disposition
 
68
                                          with this user */
 
69
    OtrlAuthInfo auth;                 /* The state of ongoing
 
70
                                          authentication with this user */
 
71
 
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] */
64
90
 
 
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. */
 
94
 
 
95
    unsigned int protocol_version;     /* The version of OTR in use */
 
96
 
 
97
    unsigned char *preshared_secret;   /* A secret you share with this
 
98
                                          user, in order to do
 
99
                                          authentication. */
 
100
    size_t preshared_secret_len;       /* The length of the above secret. */
 
101
 
65
102
    /* saved mac keys to be revealed later */
66
103
    unsigned int numsavedkeys;
67
104
    unsigned char *saved_mac_keys;
87
124
    void *app_data;
88
125
    /* A function to free the above data when we forget this context */
89
126
    void (*app_data_free)(void *);
90
 
 
91
 
    struct context * next;             /* Linked list pointer */
92
 
    struct context ** tous;            /* A pointer to the pointer to us */
93
127
} ConnContext;
94
128
 
95
129
#include "userstate.h"
96
130
 
97
 
/* Strings describing the connection states */
98
 
extern const char *otrl_context_statestr[];
99
 
 
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);
114
145
 
115
 
/* Force a context into the CONN_SETUP state (so that it only has local
116
 
 * DH keys). */
117
 
void otrl_context_force_setup(ConnContext *context);
118
 
 
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);
 
148
 
 
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);
 
154
 
 
155
/* Force a context into the OTRL_MSGSTATE_FINISHED state. */
 
156
void otrl_context_force_finished(ConnContext *context);
 
157
 
 
158
/* Force a context into the OTRL_MSGSTATE_PLAINTEXT state. */
 
159
void otrl_context_force_plaintext(ConnContext *context);
121
160
 
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);
129
168
 
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);
132
171
 
133
 
/* Forget all the contexts in a given OtrlUserState, forcing them to
134
 
 * UNCONNECTED. */
 
172
/* Forget all the contexts in a given OtrlUserState. */
135
173
void otrl_context_forget_all(OtrlUserState us);
136
174
 
137
175
#endif