Commit c87b3fe6 authored by Rob Smits's avatar Rob Smits

2012-04-30:

	* AUTHORS:
	* README:
	* test_suite/
	* toolkit/otr_parse.c:
	* toolkit/otr_remac.c:
	* toolkit/parse.c:
	* toolkit/parse.h:
	* src/auth.c:
	* src/auth.h:
	* src/context.c:
	* src/context.h:
	* src/message.c:
	* src/message.h:
	* src/privkey.c:
	* src/privkey.h:
	* src/proto.c:
	* src/proto.h:
	* src/serial.h:
	* src/tests.c:
	* src/userstate.c:
	* src/userstate.h: More changes for instance tags (Rob Smits).

2009-06-11:

	* src/auth.c:
	* src/auth.h:
	* src/context.c:
	* src/context.h:
	* src/context_priv.h:
	* src/message.c:
	* src/message.h:
	* src/privkey.c:
	* src/privkey.h:
	* src/proto.c:
	* src/proto.h:
	* src/serial.h:
	* src/tests.c:
	* src/userstate.c:
	* src/userstate.h: Core instance tag functionality (Lisa Du).
parent 31efa5e6
......@@ -2,7 +2,7 @@ Off-the-Record Messaging Library and Toolkit
Authors:
Ian Goldberg, Chris Alexander, Willy Lew, Nikita Borisov
Ian Goldberg, Rob Smits, Chris Alexander, Willy Lew, Lisa Du, Nikita Borisov
<otr@cypherpunks.ca>
See the README file for mailing list information
2012-04-30:
* AUTHORS:
* README:
* toolkit/otr_parse.c:
* toolkit/otr_remac.c:
* toolkit/parse.c:
* toolkit/parse.h:
* src/auth.c:
* src/auth.h:
* src/context.c:
* src/context.h:
* src/message.c:
* src/message.h:
* src/privkey.c:
* src/privkey.h:
* src/proto.c:
* src/proto.h:
* src/serial.h:
* src/tests.c:
* src/userstate.c:
* src/userstate.h: More changes for instance tags (Rob Smits).
2009-06-11:
* src/auth.c:
* src/auth.h:
* src/context.c:
* src/context.h:
* src/context_priv.h:
* src/message.c:
* src/message.h:
* src/privkey.c:
* src/privkey.h:
* src/proto.c:
* src/proto.h:
* src/serial.h:
* src/tests.c:
* src/userstate.c:
* src/userstate.h: Core instance tag functionality (Lisa Du).
2009-09-30:
* Protocol-v2.html: Edits from Göran Weinholt
......
Off-the-Record Messaging Library and Toolkit
v3.2.0, 15 Jun 2008
v4.0.0, 2012
This is a library and toolkit which implements Off-the-Record (OTR) Messaging.
......@@ -49,6 +49,10 @@ To read stored private keys:
otrl_privkey_read(userstate, privkeyfilename);
To read stored instance tags:
otrl_instag_read(userstate, instagfilename);
To read stored fingerprints:
otrl_privkey_read_fingerprints(userstate, fingerprintfilename,
......@@ -80,8 +84,14 @@ of the UI functions in message.h.
3. Sending messages
When you have a message you're about to send, you'll need to know four
things: you account name, the protocol id, the name of the recipient, and
the message.
things: you account name, the protocol id, the name of the recipient,
their instance tag, and the message.
OTR protocol version 3 introduces the notion of "instance tags." A
client may be logged into the same account multiple times from different
locations. An instance tag is intended to differentiate these clients.
When sending a message, you may also specify a particular instance tag,
or use meta instance tags like OTRL_INSTAG_MOST_SECURE.
The protocol id is just a unique string that is used to distinguish
the user foo on AIM from the user foo on MSN, etc. It can be anything
......@@ -108,8 +118,9 @@ next function), simply do this:
char *newmessage = NULL;
err = otrl_message_sending(userstate, &ui_ops, opdata, accountname,
protocolid, recipient_name, message, tlvs, &newmessage,
add_app_info, add_app_info_data);
protocolid, recipient_name, instag, message, tlvs,
&newmessage, fragPolicy, contextp, add_app_info,
add_app_info_data);
add_app_info and add_app_info_data are as above, and may be NULL.
......@@ -117,6 +128,9 @@ tlvs should usually be NULL. If it's not, then it points to a chain of
OtrlTLVs which represent machine-readable data to send along with this
message.
If contextp is not NULL, it will be set to the context that was used
for sending the message.
If err is non-zero, then the library tried to encrypt the message,
but for some reason failed. DO NOT send the message in the clear in
that case.
......@@ -160,10 +174,13 @@ and the message.
ignore_message = otrl_message_receiving(userstate, &ui_ops, opdata,
accountname, protocolid, sender_name, message, &newmessage,
&tlvs, add_app_info, add_app_info_data);
&tlvs, contextp, add_app_info, add_app_info_data);
add_app_info and add_app_info_data are as above, and may be NULL.
If contextp is not NULL, it will be set to the context that was used
for receiving the message.
If otrl_message_receiving returns 1, then the message you received was
an internal protocol message, and no message should be delivered to the
user.
......@@ -235,7 +252,8 @@ Here are the six programs in the toolkit:
you can still forge messages of your choice using the otr_readforge
command, above.
- otr_remac mackey flags keyid keyid pubkey counter encdata revealed_mackeys
- otr_remac mackey sender_instance receiver_instance flags keyid keyid
pubkey counter encdata revealed_mackeys
- Make a new OTR Data Message, with the given pieces (note that the
data part is already encrypted). MAC it with the given mackey.
......@@ -244,6 +262,30 @@ NOTES
Please send your bug reports, comments, suggestions, patches, etc. to us
at the contact address below.
In otrl_message_sending, specifying an instance tag allows you to send a
message to a particular session of a buddy who is logged in multiple times
with an otr-enabled client. The OTRL_INSTAG_RECENT_RECEIVED meta-instance
relies on the time that libotr processed the most recent message. Meta-
instance tags resolve to actual instance tags before a message is sent. An
instant messaging network may not agree on which session of the remote party is
the most recent, e.g., due to underlying network race conditions. If the
behaviour of an instant messaging network is to only deliver to the most recent,
and libotr and the network disagree on which session is the most recent, the
other party will not process the given message. That is, the instant messaging
network will deliver the message to the session whose actual instance tag does
not match the addressed instance tag. Also note that OTRL_INSTAG_BEST also
prefers more recent instance tags in the case of multiple instances with the
same "best" status (most secure). In this case, the most recent has a
resolution of one second.
If otrl_message_sending is called with an original_msg that contains the text
"?OTR?", this is a signal to initiate or refresh an OTR session. There is
currently no way to indicate if this text was actually typed in by a user and
part of a conversation (e.g., someone communicating instructions on how to
refresh OTR). In the future, we may allow a policy to specify whether "?OTR?"
is a signal to start OTR, or just an ordinary message for encrypted and
unencrypted conversations.
MAILING LISTS
There are three mailing lists pertaining to Off-the-Record Messaging:
......@@ -267,8 +309,8 @@ The Off-the-Record Messaging library (in the src directory) is
covered by the following (LGPL) license:
Off-the-Record Messaging library
Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
Nikita Borisov
Copyright (C) 2004-2012 Ian Goldberg, Rob Smits, Chris Alexander,
Willy Lew, Lisa Du, Nikita Borisov
<otr@cypherpunks.ca>
This library is free software; you can redistribute it and/or
......@@ -289,7 +331,8 @@ The Off-the-Record Messaging Toolkit (in the toolkit directory) is covered
by the following (GPL) license:
Off-the-Record Messaging Toolkit
Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov
Copyright (C) 2004-2012 Ian Goldberg, Rob Smits, Chris Alexander,
Nikita Borisov
<otr@cypherpunks.ca>
This program is free software; you can redistribute it and/or modify
......@@ -311,7 +354,8 @@ CONTACT
To report problems, comments, suggestions, patches, etc., you can email
the authors:
Ian Goldberg, Chris Alexander, and Nikita Borisov <otr@cypherpunks.ca>
Ian Goldberg, Rob Smits, Chris Alexander, Lisa Du, Nikita Borisov
<otr@cypherpunks.ca>
For more information on Off-the-Record Messaging, visit
http://otr.cypherpunks.ca/
......@@ -5,7 +5,7 @@ includedir=@includedir@
Name: libotr
Description: Off-the-Record Messaging Library
Version: 3.1.0
Version: @VERSION@
URL: http://otr.cypherpunks.ca/
Libs: -L${libdir} -lotr
Cflags: -I${includedir}
......@@ -3,7 +3,7 @@ INCLUDES = @LIBGCRYPT_CFLAGS@
lib_LTLIBRARIES = libotr.la
libotr_la_SOURCES = privkey.c context.c proto.c b64.c dh.c mem.c message.c \
userstate.c tlv.c auth.c sm.c context_priv.c
userstate.c tlv.c auth.c sm.c context_priv.c instag.c
libotr_la_LDFLAGS = -version-info @LIBOTR_LIBTOOL_VERSION@ @LIBS@ @LIBGCRYPT_LIBS@
......@@ -11,4 +11,4 @@ otrincdir = $(includedir)/libotr
otrinc_HEADERS = b64.h context.h dh.h mem.h message.h privkey.h proto.h \
version.h userstate.h tlv.h serial.h auth.h sm.h privkey-t.h \
context_priv.h
context_priv.h instag.h
This diff is collapsed.
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
* Nikita Borisov
* Copyright (C) 2004-2012 Ian Goldberg, Rob Smits, Chris Alexander,
* Willy Lew, Lisa Du, Nikita Borisov
* <otr@cypherpunks.ca>
*
* This library is free software; you can redistribute it and/or
......@@ -24,6 +24,7 @@
#include <gcrypt.h>
#include "dh.h"
typedef enum {
OTRL_AUTHSTATE_NONE,
OTRL_AUTHSTATE_AWAITING_DHKEY,
......@@ -35,6 +36,8 @@ typedef enum {
typedef struct {
OtrlAuthState authstate; /* Our state */
struct context *context; /* The context which points to us */
DH_keypair our_dh; /* Our D-H key */
unsigned int our_keyid; /* ...and its keyid */
......@@ -47,6 +50,7 @@ typedef struct {
gcry_mpi_t their_pub; /* Their D-H public key */
unsigned int their_keyid; /* ...and its keyid */
gcry_cipher_hd_t enc_c, enc_cp; /* c and c' encryption keys */
gcry_md_hd_t mac_m1, mac_m1p; /* m1 and m1' MAC keys */
gcry_md_hd_t mac_m2, mac_m2p; /* m2 and m2' MAC keys */
......@@ -78,7 +82,7 @@ typedef struct {
/*
* Initialize the fields of an OtrlAuthInfo (already allocated).
*/
void otrl_auth_new(OtrlAuthInfo *auth);
void otrl_auth_new(struct context *context);
/*
* Clear the fields of an OtrlAuthInfo (but leave it allocated).
......@@ -86,11 +90,11 @@ void otrl_auth_new(OtrlAuthInfo *auth);
void otrl_auth_clear(OtrlAuthInfo *auth);
/*
* Start a fresh AKE (version 2) using the given OtrlAuthInfo. Generate
* Start a fresh AKE (version 2 or 3) using the given OtrlAuthInfo. Generate
* a fresh DH keypair to use. If no error is returned, the message to
* transmit will be contained in auth->lastauthmsg.
*/
gcry_error_t otrl_auth_start_v2(OtrlAuthInfo *auth);
gcry_error_t otrl_auth_start_v23(OtrlAuthInfo *auth, int version);
/*
* Handle an incoming D-H Commit Message. If no error is returned, the
......@@ -98,7 +102,7 @@ gcry_error_t otrl_auth_start_v2(OtrlAuthInfo *auth);
* keypair to use.
*/
gcry_error_t otrl_auth_handle_commit(OtrlAuthInfo *auth,
const char *commitmsg);
const char *commitmsg, int version);
/*
* Handle an incoming D-H Key Message. If no error is returned, and
......@@ -155,4 +159,22 @@ gcry_error_t otrl_auth_handle_v1_key_exchange(OtrlAuthInfo *auth,
gcry_error_t (*auth_succeeded)(const OtrlAuthInfo *auth, void *asdata),
void *asdata);
/*
* Copy relevant information from the master OtrlAuthInfo to an
* instance OtrlAuthInfo in response to a D-H Commit with a new
* instance. The fields copied will depend on the state of the
* master auth.
*/
gcry_error_t otrl_auth_copy_on_commit(OtrlAuthInfo *m_auth,
OtrlAuthInfo *auth);
/*
* Copy relevant information from the master OtrlAuthInfo to an
* instance OtrlAuthInfo in response to a D-H Key with a new
* instance. The fields copied will depend on the state of the
* master auth.
*/
gcry_error_t otrl_auth_copy_on_key(OtrlAuthInfo *m_auth,
OtrlAuthInfo *auth);
#endif
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
* Copyright (C) 2004-2012 Ian Goldberg, Chris Alexander, Willy Lew,
* Nikita Borisov
* <otr@cypherpunks.ca>
*
......@@ -28,30 +28,30 @@ AUTHOR: Bob Trower 08/04/01
LICENCE: Copyright (c) 2001 Bob Trower, Trantor Standard Systems Inc.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
VERSION HISTORY:
Bob Trower 08/04/01 -- Create Version 0.00.00B
Bob Trower 08/04/01 -- Create Version 0.00.00B
\******************************************************************* */
......@@ -88,9 +88,9 @@ static void encodeblock( char *out, const unsigned char *in, size_t len )
out[0] = cb64[ in0 >> 2 ];
out[1] = cb64[ ((in0 & 0x03) << 4) | ((in1 & 0xf0) >> 4) ];
out[2] = len > 1 ? cb64[ ((in1 & 0x0f) << 2) | ((in2 & 0xc0) >> 6) ]
: '=';
: '=';
out[3] = len > 2 ? cb64[ in2 & 0x3f ]
: '=';
: '=';
}
/*
......@@ -120,7 +120,7 @@ size_t otrl_base64_encode(char *base64data, const unsigned char *data,
}
static size_t decode(unsigned char *out, const char *in, size_t b64len)
{
{
size_t written = 0;
unsigned char c = 0;
......@@ -228,9 +228,10 @@ int otrl_base64_otr_decode(const char *msg, unsigned char **bufp,
if (!otrtag) {
return -2;
}
endtag = strchr(otrtag, '.');
if (endtag) {
msglen = endtag-otrtag;
msglen = endtag-otrtag;
} else {
return -2;
}
......@@ -241,6 +242,7 @@ int otrl_base64_otr_decode(const char *msg, unsigned char **bufp,
if (!rawmsg && rawlen > 0) {
return -1;
}
rawlen = otrl_base64_decode(rawmsg, otrtag+5, msglen-5); /* actual size */
*bufp = rawmsg;
......
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
* Copyright (C) 2004-2012 Ian Goldberg, Chris Alexander, Willy Lew,
* Nikita Borisov
* <otr@cypherpunks.ca>
*
......
This diff is collapsed.
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
* Nikita Borisov
* Copyright (C) 2004-2012 Ian Goldberg, Rob Smits, Chris Alexander,
* Willy Lew, Lisa Du, Nikita Borisov
* <otr@cypherpunks.ca>
*
* This library is free software; you can redistribute it and/or
......@@ -29,6 +29,10 @@
#include "auth.h"
#include "sm.h"
typedef struct context ConnContext; /* Forward declare */
#include "instag.h"
typedef enum {
OTRL_MSGSTATE_PLAINTEXT, /* Not yet started an encrypted
conversation */
......@@ -50,7 +54,7 @@ typedef struct s_fingerprint {
char *trust; /* The trust level of the fingerprint */
} Fingerprint;
typedef struct context {
struct context {
struct context * next; /* Linked list pointer */
struct context ** tous; /* A pointer to the pointer to us */
......@@ -65,15 +69,39 @@ typedef struct context {
this account... */
char * protocol; /* ... and this protocol */
struct context *m_context; /* If this is a child context, this
field will point to the master
context. Otherwise it will point to
itself. */
struct context *recent_rcvd_child; /* If this is a master context, this
points to the child context that
has received a message most recently.
By default, it will point to the
master context. In child contexts
this field is NULL. */
struct context *recent_sent_child; /* Similar to above, but it points to
the child who has sent most
recently. */
struct context *recent_child; /* Similar to above, but will point to
the most recent of recent_rcvd_child
and recent_sent_child */
otrl_instag_t our_instance; /* Our instance tag for this computer*/
otrl_instag_t their_instance; /* The user's instance tag */
OtrlMessageState msgstate; /* The state of message disposition
with this user */
OtrlAuthInfo auth; /* The state of ongoing
authentication with this user */
Fingerprint fingerprint_root; /* The root of a linked list of
Fingerprints entries */
Fingerprints entries. This list will
only be populated in master contexts.
For child contexts,
fingerprint_root.next will always
point to NULL. */
Fingerprint *active_fingerprint; /* Which fingerprint is in use now?
A pointer into the above list */
A pointer into the above list */
unsigned char sessionid[20]; /* The sessionid and bold half */
size_t sessionid_len; /* determined when this private */
......@@ -95,21 +123,29 @@ typedef struct context {
void (*app_data_free)(void *);
OtrlSMState *smstate; /* The state of the current
socialist millionaires exchange */
} ConnContext;
socialist millionaires exchange */
};
#include "userstate.h"
/* Look up a connection context by name/account/protocol from the given
* OtrlUserState. If add_if_missing is true, allocate and return a new
* context if one does not currently exist. In that event, call
/* Look up a connection context by name/account/protocol/instance from the
* given OtrlUserState. If add_if_missing is true, allocate and return a
* new context if one does not currently exist. In that event, call
* add_app_data(data, context) so that app_data and app_data_free can be
* filled in by the application, and set *addedp to 1. */
* filled in by the application, and set *addedp to 1.
* In the 'their_instance' field note that you can also specify a 'meta-
* instance' value such as OTRL_INSTAG_MASTER, OTRL_INSTAL_RECENT,
* OTRL_INSTAG_RECENT_RECEIVED and OTRL_INSTAG_RECENT_SENT. */
ConnContext * otrl_context_find(OtrlUserState us, const char *user,
const char *accountname, const char *protocol, int add_if_missing,
int *addedp,
const char *accountname, const char *protocol,
otrl_instag_t their_instance, int add_if_missing, int *addedp,
void (*add_app_data)(void *data, ConnContext *context), void *data);
/* This method gets called after sending or receiving a message, to update the
* master context's "recent context" pointers. */
void otrl_context_update_recent_child(ConnContext *context,
unsigned int sent_msg);
/* Find a fingerprint in a given context, perhaps adding it if not
* present. */
Fingerprint *otrl_context_find_fingerprint(ConnContext *context,
......@@ -132,8 +168,11 @@ void otrl_context_force_plaintext(ConnContext *context);
void otrl_context_forget_fingerprint(Fingerprint *fprint,
int and_maybe_context);
/* Forget a whole context, so long as it's PLAINTEXT. */
void otrl_context_forget(ConnContext *context);
/* Forget a whole context, so long as it's PLAINTEXT. If a context has child
* instances, don't remove this instance unless children are also all in
* PLAINTEXT state. In this case, the children will also be removed.
* Returns 0 on success, 1 on failure. */
int otrl_context_forget(ConnContext *context);
/* Forget all the contexts in a given OtrlUserState. */
void otrl_context_forget_all(OtrlUserState us);
......
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
* Copyright (C) 2004-2012 Ian Goldberg, Chris Alexander, Willy Lew,
* Nikita Borisov
* <otr@cypherpunks.ca>
*
......@@ -44,6 +44,7 @@ ConnContextPriv *context_priv_new()
context_priv->generation = 0;
context_priv->lastsent = 0;
context_priv->lastmessage = NULL;
context_priv->lastrecv = 0;
context_priv->may_retransmit = 0;
context_priv->their_keyid = 0;
context_priv->their_y = NULL;
......
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
* Nikita Borisov
* Copyright (C) 2004-2012 Ian Goldberg, Chris Alexander, Willy Lew,
* Lisa Du, Nikita Borisov
* <otr@cypherpunks.ca>
*
* This library is free software; you can redistribute it and/or
......@@ -74,6 +74,9 @@ typedef struct context_priv {
/* 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;
......
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
* Copyright (C) 2004-2012 Ian Goldberg, Chris Alexander, Willy Lew,
* Nikita Borisov
* <otr@cypherpunks.ca>
*
......@@ -27,6 +27,7 @@
/* libotr headers */
#include "dh.h"
static const char* DH1536_MODULUS_S = "0x"
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
......@@ -91,7 +92,7 @@ void otrl_dh_keypair_free(DH_keypair *kp)
/*
* Generate a DH keypair for a specified group.
*/
*/
gcry_error_t otrl_dh_gen_keypair(unsigned int groupid, DH_keypair *kp)
{
unsigned char *secbuf = NULL;
......
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew,
* Copyright (C) 2004-2012 Ian Goldberg, Chris Alexander, Willy Lew,
* Nikita Borisov
* <otr@cypherpunks.ca>
*
......@@ -74,7 +74,7 @@ void otrl_dh_keypair_free(DH_keypair *kp);
/*
* Generate a DH keypair for a specified group.
*/
*/
gcry_error_t otrl_dh_gen_keypair(unsigned int groupid, DH_keypair *kp);
/*
......
/*
* Off-the-Record Messaging library
* Copyright (C) 2004-2012 Ian Goldberg, Rob Smits, Chris Alexander,
* Willy Lew, Lisa Du, Nikita Borisov
* <otr@cypherpunks.ca>
*
* 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
*/
/* system headers */
#include <stdio.h>
#include <stdlib.h>
/* libgcrypt headers */
#include <gcrypt.h>
/* libotr headers */
#include "instag.h"
#include "userstate.h"
/* Forget the given instag. */
void otrl_instag_forget(OtrlInsTag* instag) {
if (!instag) return;
if (instag->accountname) free(instag->accountname);
if (instag->protocol) free(instag->protocol);
/* Re-link the list */
*(instag->tous) = instag->next;
if (instag->next) {
instag->next->tous = instag->tous;
}
free(instag);
}
/* Forget all instags in a given OtrlUserState. */
void otrl_instag_forget_all(OtrlUserState us) {
while(us->instag_root) {
otrl_instag_forget(us->instag_root);
}
}
/* Fetch the instance tag from the given OtrlUserState associated with
* the given account */
OtrlInsTag * otrl_instag_find(OtrlUserState us, const char *accountname,
const char *protocol)
{
OtrlInsTag *p;
for(p=us->instag_root; p; p=p->next) {
if (!strcmp(p->accountname, accountname) &&
!strcmp(p->protocol, protocol)) {
return p;
}
}
return NULL;
}
/* Read our instance tag from a file on disk into the given
* OtrlUserState. */
gcry_error_t otrl_instag_read(OtrlUserState us, const char *filename)
{
gcry_error_t err;
FILE *instf;
/* Open the instance tag file. */
instf = fopen(filename, "rb");
if (!instf) {
return gcry_error_from_errno(errno);
}
err = otrl_instag_read_FILEp(us, instf);
fclose(instf);
return err;
}
/* Read our instance tag from a file on disk into the given
* OtrlUserState. The FILE* must be open for reading. */
gcry_error_t otrl_instag_read_FILEp(OtrlUserState us, FILE *instf)
{
if (!instf) return gcry_error(GPG_ERR_NO_ERROR);
OtrlInsTag *p;
char storeline[1000];
size_t maxsize = sizeof(storeline);
while(fgets(storeline, maxsize, instf)) {
char *prevpos;
char *pos;
unsigned int instag = 0;
int i;
p = malloc(sizeof(*p));
if (!p) {
return gcry_error(GPG_ERR_ENOMEM);
}
/* Parse the line, which should be of the form:
* accountname\tprotocol\t40_hex_nybbles\n */
prevpos = storeline;
pos = strchr(prevpos, '\t');
if (!pos) {
free(p);
continue;
}
*pos = '\0';
pos++;
p->accountname = malloc(pos - prevpos);
memmove(p->accountname, prevpos, pos - prevpos);
prevpos = pos;
pos = strchr(prevpos, '\t');
if (!pos) {
free(p);
continue;
}
*pos = '\0';
pos++;
p->protocol = malloc(pos - prevpos);
memmove(p->protocol, prevpos, pos - prevpos);
prevpos = pos;
pos = strchr(prevpos, '\r');
if (!pos) pos = strchr(prevpos, '\n');
if (!pos) {
free(p);
continue;
}
*pos = '\0';
pos++;
/* hex str of length 8 */
if (strlen(prevpos) != 8) {