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

« back to all changes in this revision

Viewing changes to src/proto.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:
26
26
 
27
27
/* If we ever see this sequence in a plaintext message, we'll assume the
28
28
 * other side speaks OTR, and try to establish a connection. */
29
 
#define OTR_MESSAGE_TAG " \t  \t\t\t\t \t \t \t   \t \t  \t "
30
 
    /* This is the bit sequence of the string "OTR", encoded in tabs and
31
 
     * spaces. */
32
 
 
33
 
typedef enum {
34
 
    OTR_NOTOTR,
35
 
    OTR_TAGGEDPLAINTEXT,
36
 
    OTR_QUERY,
37
 
    OTR_KEYEXCH,
38
 
    OTR_DATA,
39
 
    OTR_ERROR,
40
 
    OTR_UNKNOWN
41
 
} OTRMessageType;
42
 
 
43
 
typedef struct s_OTRKeyExchangeMsg {
44
 
    gcry_sexp_t digest_sexp;              /* SHA-1 hash of the raw message,
45
 
                                             except for the DSA sig; used
46
 
                                             for checking the sig */
47
 
    unsigned char is_reply;               /* Was this a reply to a Key
48
 
                                             Exchange Message we sent
49
 
                                             them? */
50
 
    unsigned char key_fingerprint[20];    /* The key fingerprint */
51
 
    gcry_sexp_t dsa_pubkey;               /* DSA public key */
52
 
    unsigned int keyid;                   /* DH key id */
53
 
    gcry_mpi_t dh_pubkey;                 /* DH public key */
54
 
    gcry_sexp_t dsa_sig;                  /* Signature on packet */
55
 
} * OTRKeyExchangeMsg;
 
29
#define OTRL_MESSAGE_TAG_BASE " \t  \t\t\t\t \t \t \t  "
 
30
/* The following must each be of length 8 */
 
31
#define OTRL_MESSAGE_TAG_V1 " \t \t  \t "
 
32
#define OTRL_MESSAGE_TAG_V2 "  \t\t  \t "
 
33
 
 
34
/* The possible flags contained in a Data Message */
 
35
#define OTRL_MSGFLAGS_IGNORE_UNREADABLE         0x01
 
36
 
 
37
typedef unsigned int OtrlPolicy;
 
38
 
 
39
#define OTRL_POLICY_ALLOW_V1                    0x01
 
40
#define OTRL_POLICY_ALLOW_V2                    0x02
 
41
#define OTRL_POLICY_REQUIRE_ENCRYPTION          0x04
 
42
#define OTRL_POLICY_SEND_WHITESPACE_TAG         0x08
 
43
#define OTRL_POLICY_WHITESPACE_START_AKE        0x08
 
44
#define OTRL_POLICY_ERROR_START_AKE             0x10
 
45
 
 
46
#define OTRL_POLICY_VERSION_MASK (OTRL_POLICY_ALLOW_V1 | OTRL_POLICY_ALLOW_V2)
 
47
 
 
48
/* For v1 compatibility */
 
49
#define OTRL_POLICY_NEVER                       0x00
 
50
#define OTRL_POLICY_OPPORTUNISTIC \
 
51
            ( OTRL_POLICY_ALLOW_V1 | \
 
52
            OTRL_POLICY_ALLOW_V2 | \
 
53
            OTRL_POLICY_SEND_WHITESPACE_TAG | \
 
54
            OTRL_POLICY_WHITESPACE_START_AKE | \
 
55
            OTRL_POLICY_ERROR_START_AKE )
 
56
#define OTRL_POLICY_MANUAL \
 
57
            ( OTRL_POLICY_ALLOW_V1 | \
 
58
            OTRL_POLICY_ALLOW_V2 )
 
59
#define OTRL_POLICY_ALWAYS \
 
60
            ( OTRL_POLICY_ALLOW_V1 | \
 
61
            OTRL_POLICY_ALLOW_V2 | \
 
62
            OTRL_POLICY_REQUIRE_ENCRYPTION | \
 
63
            OTRL_POLICY_WHITESPACE_START_AKE | \
 
64
            OTRL_POLICY_ERROR_START_AKE )
 
65
#define OTRL_POLICY_DEFAULT OTRL_POLICY_OPPORTUNISTIC
 
66
 
 
67
typedef enum {
 
68
    OTRL_MSGTYPE_NOTOTR,
 
69
    OTRL_MSGTYPE_TAGGEDPLAINTEXT,
 
70
    OTRL_MSGTYPE_QUERY,
 
71
    OTRL_MSGTYPE_DH_COMMIT,
 
72
    OTRL_MSGTYPE_DH_KEY,
 
73
    OTRL_MSGTYPE_REVEALSIG,
 
74
    OTRL_MSGTYPE_SIGNATURE,
 
75
    OTRL_MSGTYPE_V1_KEYEXCH,
 
76
    OTRL_MSGTYPE_DATA,
 
77
    OTRL_MSGTYPE_ERROR,
 
78
    OTRL_MSGTYPE_UNKNOWN
 
79
} OtrlMessageType;
 
80
 
 
81
typedef enum {
 
82
    OTRL_FRAGMENT_UNFRAGMENTED,
 
83
    OTRL_FRAGMENT_INCOMPLETE,
 
84
    OTRL_FRAGMENT_COMPLETE
 
85
} OtrlFragmentResult;
56
86
 
57
87
/* Initialize the OTR library.  Pass the version of the API you are
58
88
 * using. */
68
98
 * the OTR library. */
69
99
const char *otrl_version(void);
70
100
 
71
 
/* Create a public key block from a private key */
72
 
gcry_error_t otrl_proto_make_pubkey(unsigned char **pubbufp, size_t *publenp,
73
 
        gcry_sexp_t privkey);
74
 
 
75
101
/* Return a pointer to a newly-allocated OTR query message, customized
76
102
 * with our name.  The caller should free() the result when he's done
77
103
 * with it. */
78
 
char *otrl_proto_default_query_msg(const char *ourname);
 
104
char *otrl_proto_default_query_msg(const char *ourname, OtrlPolicy policy);
 
105
 
 
106
/* Return the best version of OTR support by both sides, given an OTR
 
107
 * Query Message and the local policy. */
 
108
unsigned int otrl_proto_query_bestversion(const char *querymsg,
 
109
        OtrlPolicy policy);
 
110
 
 
111
/* Locate any whitespace tag in this message, and return the best
 
112
 * version of OTR support on both sides.  Set *starttagp and *endtagp to
 
113
 * the start and end of the located tag, so that it can be snipped out. */
 
114
unsigned int otrl_proto_whitespace_bestversion(const char *msg,
 
115
        const char **starttagp, const char **endtagp, OtrlPolicy policy);
79
116
 
80
117
/* Return the Message type of the given message. */
81
 
OTRMessageType otrl_proto_message_type(const char *message);
82
 
 
83
 
/* Create a Key Exchange message for our correspondent.  If we need a
84
 
 * private key and don't have one, create_privkey will be called.  Use
85
 
 * the privkeys from the given OtrlUserState. */
86
 
gcry_error_t otrl_proto_create_key_exchange(OtrlUserState us,
87
 
        char **messagep, ConnContext *context, unsigned char is_reply,
88
 
        void (*create_privkey)(void *create_privkey_data,
89
 
            const char *accountname, const char *protocol),
90
 
        void *create_privkey_data);
91
 
 
92
 
/* Deallocate an OTRKeyExchangeMsg returned from proto_parse_key_exchange */
93
 
void otrl_proto_free_key_exchange(OTRKeyExchangeMsg kem);
94
 
 
95
 
/* Parse a purported Key Exchange message.  Possible error code portions
96
 
 * of the return value:
97
 
 *   GPG_ERR_NO_ERROR:      Success
98
 
 *   GPG_ERR_ENOMEM:        Out of memory condition
99
 
 *   GPG_ERR_INV_VALUE:     The message was not a well-formed Key Exchange
100
 
 *                          message
101
 
 *   GPG_ERR_BAD_SIGNATURE: The signature on the message didn't verify
102
 
 */
103
 
gcry_error_t otrl_proto_parse_key_exchange(OTRKeyExchangeMsg *kemp,
104
 
        const char *msg);
105
 
 
106
 
/* Deal with a Key Exchange Message once it's been received and passed
107
 
 * all the validity and UI ("accept this fingerprint?") tests.
108
 
 * context/fprint is the ConnContext and Fingerprint to which it
109
 
 * belongs.  Use the given OtrlUserState to look up any necessary
110
 
 * private keys.  It is the caller's responsibility to
111
 
 * otrl_proto_free_key_exchange(kem) when we're done.  If *messagep gets
112
 
 * set to non-NULL by this function, then it's a message that needs to
113
 
 * get sent to the correspondent.  If we need a private key and don't
114
 
 * have one, create_privkey will be called. */
115
 
gcry_error_t otrl_proto_accept_key_exchange(OtrlUserState us,
116
 
        ConnContext *context, Fingerprint *fprint, OTRKeyExchangeMsg kem,
117
 
        char **messagep,
118
 
        void (*create_privkey)(void *create_privkey_data,
119
 
            const char *accountname, const char *protocol),
120
 
        void *create_privkey_data);
 
118
OtrlMessageType otrl_proto_message_type(const char *message);
121
119
 
122
120
/* Create an OTR Data message.  Pass the plaintext as msg, and an
123
121
 * optional chain of TLVs.  A newly-allocated string will be returned in
124
122
 * *encmessagep. */
125
123
gcry_error_t otrl_proto_create_data(char **encmessagep, ConnContext *context,
126
 
        const char *msg, OtrlTLV *tlvs);
 
124
        const char *msg, const OtrlTLV *tlvs, unsigned char flags);
 
125
 
 
126
/* Extract the flags from an otherwise unreadable Data Message. */
 
127
gcry_error_t otrl_proto_data_read_flags(const char *datamsg,
 
128
        unsigned char *flagsp);
127
129
 
128
130
/* Accept an OTR Data Message in datamsg.  Decrypt it and put the
129
 
 * plaintext into *plaintextp, and any TLVs into tlvsp. */
 
131
 * plaintext into *plaintextp, and any TLVs into tlvsp.  Put any
 
132
 * received flags into *flagsp (if non-NULL). */
130
133
gcry_error_t otrl_proto_accept_data(char **plaintextp, OtrlTLV **tlvsp,
131
 
        ConnContext *context, const char *datamsg);
 
134
        ConnContext *context, const char *datamsg, unsigned char *flagsp);
 
135
 
 
136
/* Accumulate a potential fragment into the current context. */
 
137
OtrlFragmentResult otrl_proto_fragment_accumulate(char **unfragmessagep,
 
138
        ConnContext *context, const char *msg);
132
139
 
133
140
#endif