/* * Off-the-Record Messaging library * Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew, * Nikita Borisov * * * This library is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General * Public License as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __CONTEXT_PRIV_H__ #define __CONTEXT_PRIV_H__ #include #include #include "dh.h" #include "auth.h" #include "sm.h" // maximum number of file transfers #define OTR_MAX_FT 256 // minimum value of allowed file transfer id #define OTR_MIN_FT 1 typedef struct context_priv { /* The part of the fragmented message we've seen so far */ char *fragment; /* The length of fragment */ size_t fragment_len; /* The total number of fragments in this message */ unsigned short fragment_n; /* The highest fragment number we've seen so far for this message */ unsigned short fragment_k; /* current keyid used by other side; this is set to 0 if we get * a OTRL_TLV_DISCONNECTED message from them. */ unsigned int their_keyid; /* Y[their_keyid] (their DH pubkey) */ gcry_mpi_t their_y; /* Y[their_keyid-1] (their prev DH pubkey) */ gcry_mpi_t their_old_y; /* current keyid used by us */ unsigned int our_keyid; /* DH key[our_keyid] */ DH_keypair our_dh_key; /* DH key[our_keyid-1] */ DH_keypair our_old_dh_key; /* sesskeys[i][j] are the session keys derived from DH * key[our_keyid-i] and mpi Y[their_keyid-j] */ DH_sesskeys sesskeys[2][2]; /* saved mac keys to be revealed later */ unsigned int numsavedkeys; unsigned char *saved_mac_keys; /* generation number: increment every time we go private, and never * reset to 0 (unless we remove the context entirely) */ unsigned int generation; /* The last time a Data Message was sent */ time_t lastsent; /* The last time a Data Message was received */ time_t lastrecv; /* The plaintext of the last Data Message sent */ char *lastmessage; /* Is the last message eligible for retransmission? */ int may_retransmit; // list of currently active file transfers int * file_transfers_recv; // list of file descriptors (for writing received data) char ** file_transfers_send; // list of mapped files (for reading send data) size_t * ft_send_len; // size of each mapped region size_t * ft_send_offset; // list of appropriate offset (data already sent) } ConnContextPriv; /* Create a new private connection context. */ ConnContextPriv * context_priv_new(); // check if file transfer with given id is active in this context bool context_priv_ft_recv_id(const ConnContextPriv * context_priv, unsigned char id); bool context_priv_ft_send_id(const ConnContextPriv * context_priv, unsigned char id); // file transfer manipulation routines unsigned char context_priv_ft_add_recv(ConnContextPriv * context_priv, char * filename); unsigned char context_priv_ft_add_send(ConnContextPriv * context_priv, char * filename); int context_priv_ft_del_recv(ConnContextPriv * context_priv, unsigned char id); int context_priv_ft_del_send(ConnContextPriv * context_priv, unsigned char id); // sending data: get next chunk and rewind offset accordingly char * context_priv_ft_chunk(ConnContextPriv * context_priv, unsigned char id, size_t chunk_len); // total number of file transfers in context unsigned int context_priv_ft_get_total_id_recv(ConnContextPriv * context_priv); unsigned int context_priv_ft_get_total_id_send(ConnContextPriv * context_priv); /* Frees up memory that was used in context_priv_new */ void context_priv_force_finished(ConnContextPriv * context_priv); #endif