Commit 5900b2a6 authored by jvoisin's avatar jvoisin
Browse files

Remove tests macros and related things

parent c9710e9b
......@@ -33,39 +33,6 @@
#include "context.h"
#include "mem.h"
#if OTRL_DEBUGGING
#include <stdio.h>
/* Dump the contents of an OtrlAuthInfo to the FILE *f. */
void otrl_auth_dump(FILE *f, const OtrlAuthInfo *auth)
{
int i;
fprintf(f, " Auth info %p:\n", auth);
fprintf(f, " State: %d (%s)\n", auth->authstate,
auth->authstate == OTRL_AUTHSTATE_NONE ? "NONE" :
auth->authstate == OTRL_AUTHSTATE_AWAITING_DHKEY ? "AWAITING_DHKEY" :
auth->authstate == OTRL_AUTHSTATE_AWAITING_REVEALSIG ?
"AWAITING_REVEALSIG" :
auth->authstate == OTRL_AUTHSTATE_AWAITING_SIG ? "AWAITING_SIG" :
auth->authstate == OTRL_AUTHSTATE_V1_SETUP ? "V1_SETUP" :
"INVALID");
fprintf(f, " Context: %p\n", auth->context);
fprintf(f, " Our keyid: %u\n", auth->our_keyid);
fprintf(f, " Their keyid: %u\n", auth->their_keyid);
fprintf(f, " Their fingerprint: ");
for (i=0;i<20;++i) {
fprintf(f, "%02x", auth->their_fingerprint[i]);
}
fprintf(f, "\n Initiated = %d\n", auth->initiated);
fprintf(f, "\n Proto version = %d\n", auth->protocol_version);
fprintf(f, "\n Lastauthmsg = %s\n",
auth->lastauthmsg ? auth->lastauthmsg : "(nil)");
fprintf(f, "\n Commit sent time = %ld\n",
(long) auth->commit_sent_time);
}
#endif
/*
* Initialize the fields of an OtrlAuthInfo (already allocated).
......@@ -1468,106 +1435,3 @@ void otrl_auth_copy_on_key(OtrlAuthInfo *m_auth, OtrlAuthInfo *auth)
break;
}
}
#ifdef OTRL_TESTING_AUTH
#include "mem.h"
#include "privkey.h"
#define CHECK_ERR if (err) { printf("Error: %s\n", gcry_strerror(err)); \
return 1; }
static gcry_error_t starting(const OtrlAuthInfo *auth, void *asdata)
{
char *name = asdata;
fprintf(stderr, "\nStarting ENCRYPTED mode for %s (v%d).\n",
name, auth->protocol_version);
fprintf(stderr, "\nour_dh (%d):", auth->our_keyid);
gcry_mpi_dump(auth->our_dh.pub);
fprintf(stderr, "\ntheir_pub (%d):", auth->their_keyid);
gcry_mpi_dump(auth->their_pub);
debug_data("\nTheir fingerprint", auth->their_fingerprint, 20);
debug_data("\nSecure session id", auth->secure_session_id,
auth->secure_session_id_len);
fprintf(stderr, "Sessionid half: %d\n\n", auth->session_id_half);
return gpg_error(GPG_ERR_NO_ERROR);
}
int main(int argc, char **argv)
{
OtrlAuthInfo alice, bob;
gcry_error_t err;
int havemsg;
OtrlUserState us;
OtrlPrivKey *alicepriv, *bobpriv;
otrl_mem_init();
otrl_dh_init();
otrl_auth_new(&alice);
otrl_auth_new(&bob);
us = otrl_userstate_create();
otrl_privkey_read(us, "/home/iang/.gaim/otr.private_key");
alicepriv = otrl_privkey_find(us, "oneeyedian", "prpl-oscar");
bobpriv = otrl_privkey_find(us, "otr4ian", "prpl-oscar");
printf("\n\n ***** V2 *****\n\n");
err = otrl_auth_start_v23(&bob, NULL, 0);
CHECK_ERR
printf("\nBob: %d\n%s\n\n", strlen(bob.lastauthmsg), bob.lastauthmsg);
err = otrl_auth_handle_commit(&alice, bob.lastauthmsg, NULL, 0);
CHECK_ERR
printf("\nAlice: %d\n%s\n\n", strlen(alice.lastauthmsg), alice.lastauthmsg);
err = otrl_auth_handle_key(&bob, alice.lastauthmsg, &havemsg, bobpriv);
CHECK_ERR
if (havemsg) {
printf("\nBob: %d\n%s\n\n", strlen(bob.lastauthmsg), bob.lastauthmsg);
} else {
printf("\nIGNORE\n\n");
}
err = otrl_auth_handle_revealsig(&alice, bob.lastauthmsg, &havemsg,
alicepriv, starting, "Alice");
CHECK_ERR
if (havemsg) {
printf("\nAlice: %d\n%s\n\n", strlen(alice.lastauthmsg),
alice.lastauthmsg);
} else {
printf("\nIGNORE\n\n");
}
err = otrl_auth_handle_signature(&bob, alice.lastauthmsg, &havemsg,
starting, "Bob");
CHECK_ERR
printf("\n\n ***** V1 *****\n\n");
err = otrl_auth_start_v1(&bob, NULL, 0, bobpriv);
CHECK_ERR
printf("\nBob: %d\n%s\n\n", strlen(bob.lastauthmsg), bob.lastauthmsg);
err = otrl_auth_handle_v1_key_exchange(&alice, bob.lastauthmsg,
&havemsg, alicepriv, NULL, 0, starting, "Alice");
CHECK_ERR
if (havemsg) {
printf("\nAlice: %d\n%s\n\n", strlen(alice.lastauthmsg),
alice.lastauthmsg);
} else {
printf("\nIGNORE\n\n");
}
err = otrl_auth_handle_v1_key_exchange(&bob, alice.lastauthmsg,
&havemsg, bobpriv, NULL, 0, starting, "Bob");
CHECK_ERR
if (havemsg) {
printf("\nBob: %d\n%s\n\n", strlen(bob.lastauthmsg), bob.lastauthmsg);
} else {
printf("\nIGNORE\n\n");
}
otrl_userstate_free(us);
otrl_auth_clear(&alice);
otrl_auth_clear(&bob);
return 0;
}
#endif
......@@ -30,95 +30,6 @@
#include "context.h"
#include "instag.h"
#if OTRL_DEBUGGING
#include <stdio.h>
void otrl_auth_dump(FILE *f, const OtrlAuthInfo *auth);
void otrl_sm_dump(FILE *f, const OtrlSMState *sm);
/* Dump the contents of a context to the FILE *f. */
void otrl_context_dump(FILE *f, const ConnContext *context)
{
const Fingerprint *fing;
fprintf(f, "Context %p:\n\n", context);
fprintf(f, " Username: %s\n", context->username);
fprintf(f, " Accountname: %s\n", context->accountname);
fprintf(f, " Protocol: %s\n\n", context->protocol);
fprintf(f, " Master context: %p%s\n", context->m_context,
context->m_context == context ? " IS MASTER" : "");
fprintf(f, " Recent recv child: %p\n", context->recent_rcvd_child);
fprintf(f, " Recent sent child: %p\n", context->recent_sent_child);
fprintf(f, " Recent child: %p\n\n", context->recent_child);
fprintf(f, " Our instance: %08x\n", context->our_instance);
fprintf(f, " Their instance: %08x\n\n", context->their_instance);
fprintf(f, " Msgstate: %d (%s)\n\n", context->msgstate,
context->msgstate == OTRL_MSGSTATE_PLAINTEXT ? "PLAINTEXT" :
context->msgstate == OTRL_MSGSTATE_ENCRYPTED ? "ENCRYPTED" :
context->msgstate == OTRL_MSGSTATE_FINISHED ? "FINISHED" :
"INVALID");
otrl_auth_dump(f, &context->auth);
fprintf(f, "\n Fingerprints:\n");
for (fing = context->fingerprint_root.next; fing; fing = fing->next) {
fprintf(f, " %p ", fing);
if (fing->fingerprint == NULL) {
fprintf(f, "(null)");
} else {
int i;
for (i=0;i<20;++i) {
fprintf(f, "%02x", fing->fingerprint[i]);
}
}
fprintf(f, " %p", fing->context);
if (fing->trust && fing->trust[0]) {
fprintf(f, " %s", fing->trust);
}
fprintf(f, "\n");
}
fprintf(f, "\n Active fingerprint: %p\n\n", context->active_fingerprint);
fprintf(f, " Protocol version: %d\n", context->protocol_version);
fprintf(f, " OTR offer: %d (%s)\n\n", context->otr_offer,
context->otr_offer == OFFER_NOT ? "NOT" :
context->otr_offer == OFFER_SENT ? "SENT" :
context->otr_offer == OFFER_REJECTED ? "REJECTED" :
context->otr_offer == OFFER_ACCEPTED ? "ACCEPTED" :
"INVALID");
fprintf(f, " Application data: %p\n", context->app_data);
if (context->smstate == NULL) {
fprintf(f, " SM state: NULL\n");
} else {
otrl_sm_dump(f, context->smstate);
}
fprintf(f, "\n");
}
/* Dump the master context of this context, and all of its children. */
void otrl_context_siblings_dump(FILE *f, const ConnContext *context)
{
const ConnContext *citer;
for (citer = context->m_context;
citer && citer->m_context == context->m_context;
citer = citer->next) {
if (citer == context) {
fprintf(f, "*** ");
}
otrl_context_dump(f, citer);
}
}
/* Dump all contexts. */
void otrl_context_all_dump(FILE *f, OtrlUserState us)
{
const ConnContext *citer;
unsigned int ctxnum = 1;
for (citer = us->context_root; citer; citer = citer->next, ++ctxnum) {
fprintf(f, "%u. ", ctxnum);
otrl_context_dump(f, citer);
}
}
#endif
/* Create a new connection context. */
static ConnContext * new_context(const char * user, const char * accountname,
......
......@@ -36,16 +36,6 @@
#include "sm.h"
#include "instag.h"
#if OTRL_DEBUGGING
#include <stdio.h>
/* If OTRL_DEBUGGING is on, and the user types this string, the current
* context and its siblings will be dumped to stderr. */
const char *OTRL_DEBUGGING_DEBUGSTR = "?OTR!";
void otrl_context_all_dump(FILE *f, OtrlUserState us);
void otrl_context_siblings_dump(FILE *f, const ConnContext *context);
#endif
/* The API version */
extern unsigned int otrl_api_version;
......@@ -261,30 +251,6 @@ gcry_error_t otrl_message_sending(OtrlUserState us,
goto fragment;
}
#if OTRL_DEBUGGING
/* If the user typed the magic debug string, dump this context and
* its siblings. */
{
const char *debugtag = strstr(original_msg, OTRL_DEBUGGING_DEBUGSTR);
if (debugtag) {
const char *debugargs =
debugtag + strlen(OTRL_DEBUGGING_DEBUGSTR);
if (debugargs[0] == '!') { /* typed ?OTR!! */
otrl_context_all_dump(stderr, us);
} else { /* typed ?OTR! without extra command chars */
otrl_context_siblings_dump(stderr, context);
}
/* Don't actually send the message */
*messagep = strdup("");
if (!(*messagep)) {
err = gcry_error(GPG_ERR_ENOMEM);
}
goto fragment;
}
}
#endif
/* If this is an OTR Query message, don't encrypt it. */
if (otrl_proto_message_type(original_msg) == OTRL_MSGTYPE_QUERY) {
......
......@@ -39,9 +39,6 @@
#include "tlv.h"
#include "serial.h"
#if OTRL_DEBUGGING
extern const char *OTRL_DEBUGGING_DEBUGSTR;
#endif
/* For now, we need to know the API version the client is using so that
* we don't use any UI callbacks it hasn't set. */
......@@ -80,12 +77,6 @@ gcry_error_t otrl_init(unsigned int ver_major, unsigned int ver_minor,
/* Initialize the SM module */
otrl_sm_init();
#if OTRL_DEBUGGING
/* Inform the user that debugging is available */
fprintf(stderr, "\nlibotr debugging is available. Type %s in a message\n"
" to see debug info.\n\n", OTRL_DEBUGGING_DEBUGSTR);
#endif
return gcry_error(GPG_ERR_NO_ERROR);
}
......
......@@ -31,30 +31,6 @@
#include "sm.h"
#include "serial.h"
#if OTRL_DEBUGGING
/* Dump the contents of an SMState to the FILE *f. */
void otrl_sm_dump(FILE *f, const OtrlSMState *sm)
{
fprintf(f, " SM state:\n");
fprintf(f, " Next expected: %d (%s)\n", sm->nextExpected,
sm->nextExpected == OTRL_SMP_EXPECT1 ? "EXPECT1" :
sm->nextExpected == OTRL_SMP_EXPECT2 ? "EXPECT2" :
sm->nextExpected == OTRL_SMP_EXPECT3 ? "EXPECT3" :
sm->nextExpected == OTRL_SMP_EXPECT4 ? "EXPECT4" :
sm->nextExpected == OTRL_SMP_EXPECT5 ? "EXPECT5" :
"INVALID");
fprintf(f, " Received_Q: %d\n", sm->received_question);
fprintf(f, " Progress state: %d (%s)\n", sm->sm_prog_state,
sm->sm_prog_state == OTRL_SMP_PROG_OK ? "OK" :
sm->sm_prog_state == OTRL_SMP_PROG_CHEATED ? "CHEATED" :
sm->sm_prog_state == OTRL_SMP_PROG_FAILED ? "FAILED" :
sm->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED ? "SUCCEEDED" :
"INVALID");
}
#endif
static const int SM_MSG1_LEN = 6;
static const int SM_MSG2_LEN = 11;
static const int SM_MSG3_LEN = 8;
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "proto.h"
#include "privkey.h"
#include "message.h"
#include "instag.h"
#define ALICE "alice"
#define BOB "bob"
#define PROTO "prpl-oscar"
static OtrlPolicy ALICEPOLICY = OTRL_POLICY_DEFAULT &~ OTRL_POLICY_ALLOW_V1;
static OtrlPolicy BOBPOLICY = OTRL_POLICY_DEFAULT;
void receiving(const char *from, const char *to, const char *msg);
typedef struct s_node {
struct s_node *next;
char *from, *to, *msg;
} MsgNode;
static MsgNode *noderoot = NULL;
static MsgNode **nodeend = &noderoot;
void otrl_sm_init(void) {}
void otrl_sm_state_new(OtrlSMState *smst) {}
void otrl_sm_state_init(OtrlSMState *smst) {}
void otrl_sm_state_free(OtrlSMState *smst) {}
gcry_error_t otrl_sm_step1(OtrlSMAliceState *astate, const unsigned char* secret, int secretlen, unsigned char** output, int* outputlen) {return gcry_error(GPG_ERR_NO_ERROR);}
gcry_error_t otrl_sm_step2a(OtrlSMBobState *bstate, const unsigned char* input, const int inputlen, int received_question) {return gcry_error(GPG_ERR_NO_ERROR);}
gcry_error_t otrl_sm_step2b(OtrlSMBobState *bstate, const unsigned char* secret, int secretlen, unsigned char **output, int* outputlen) {return gcry_error(GPG_ERR_NO_ERROR);}
gcry_error_t otrl_sm_step3(OtrlSMAliceState *astate, const unsigned char* input, const int inputlen, unsigned char **output, int* outputlen) {return gcry_error(GPG_ERR_NO_ERROR);}
gcry_error_t otrl_sm_step4(OtrlSMBobState *bstate, const unsigned char* input, const int inputlen, unsigned char **output, int* outputlen) {return gcry_error(GPG_ERR_NO_ERROR);}
gcry_error_t otrl_sm_step5(OtrlSMAliceState *astate, const unsigned char* input, const int inputlen) {return gcry_error(GPG_ERR_NO_ERROR);}
static void dispatch(void)
{
while(noderoot) {
MsgNode *node = noderoot;
receiving(node->from, node->to, node->msg);
free(node->from);
free(node->to);
free(node->msg);
noderoot = node->next;
free(node);
if (noderoot == NULL) nodeend = &noderoot;
}
}
static void inject(const char *from, const char *to, const char *msg)
{
MsgNode *node = malloc(sizeof(*node));
node->from = strdup(from);
node->to = strdup(to);
node->msg = strdup(msg);
node->next = NULL;
*nodeend = node;
nodeend = &(node->next);
printf("[%s->%s: %s]\n\n", from, to, msg);
}
static OtrlPolicy op_policy(void *opdata, ConnContext *context)
{
if (!strcmp(context->accountname, ALICE)) return ALICEPOLICY;
if (!strcmp(context->accountname, BOB)) return BOBPOLICY;
return OTRL_POLICY_DEFAULT;
}
static void op_inject(void *opdata, const char *accountname,
const char *protocol, const char *recipient, const char *message)
{
inject(accountname, recipient, message);
}
static void op_notify(void *opdata, OtrlNotifyLevel level,
const char *accountname, const char *protocol,
const char *username, const char *title,
const char *primary, const char *secondary)
{
}
static int op_display_otr_message(void *opdata, const char *accountname,
const char *protocol, const char *username, const char *msg)
{
return -1;
}
static void op_gone_secure(void *opdata, ConnContext *context)
{
printf("SECURE (%d): %s / %s\n\n", context->protocol_version,
context->accountname, context->username);
}
static void op_gone_insecure(void *opdata, ConnContext *context)
{
printf("INSECURE: %s / %s\n\n", context->accountname, context->username);
}
static void op_still_secure(void *opdata, ConnContext *context, int is_reply)
{
printf("REFRESH (%d/%d): %s / %s\n\n", is_reply, context->protocol_version,
context->accountname, context->username);
}
static OtrlMessageAppOps ops = {
op_policy,
NULL,
NULL,
op_inject,
op_notify,
op_display_otr_message,
NULL,
NULL,
NULL,
NULL,
NULL,
op_gone_secure,
op_gone_insecure,
op_still_secure,
NULL
};
static OtrlUserState us;
void receiving(const char *from, const char *to, const char *msg)
{
int ignore;
char *newmsg;
OtrlTLV *tlvs;
ignore = otrl_message_receiving(us, &ops, NULL, to, PROTO, from, msg,
&newmsg, &tlvs, NULL, NULL);
if (!ignore) {
printf("%s> %s\n\n", from, newmsg ? newmsg : msg);
}
otrl_message_free(newmsg);
otrl_tlv_free(tlvs);
}
static void sending(const char *from, const char *to, const char *msg)
{
gcry_error_t err;
OtrlTLV *tlvs = NULL;
char *newmsg;
err = otrl_message_sending(us, &ops, NULL, from, PROTO, to, msg,
tlvs, &newmsg, NULL, NULL, NULL);
if (!err) {
inject(from, to, newmsg ? newmsg : msg);
}
otrl_message_free(newmsg);
otrl_tlv_free(tlvs);
}
static void test(int vers, int both)
{
printf("\n\n*** Testing version %d, %s ***\n\n", vers,
both ? "simultaneous start" : "Alice start");
otrl_context_forget_all(us);
if (vers == 1)
ALICEPOLICY = OTRL_POLICY_ALLOW_V1;
else if (vers == 2)
ALICEPOLICY = OTRL_POLICY_ALLOW_V2;
else
ALICEPOLICY = OTRL_POLICY_DEFAULT;
sending(ALICE, BOB, "?OTR?");
if (both) {
sending(BOB, ALICE, "?OTR?");
}
dispatch();
sending(ALICE, BOB, "Hi there");
dispatch();
}
void test_unreadable(void)
{
ConnContext *bobcontext;
printf("\n\n*** Testing Bob receiving unreadable messages from "
"Alice ***\n\n");
bobcontext = otrl_context_find(us, ALICE, BOB, PROTO, 0, 0, NULL, NULL, NULL);
otrl_context_force_plaintext(bobcontext);
sending(ALICE, BOB, "unreadable text");
dispatch();
}
void test_crash1(void)
{
ConnContext *alicecontext, *bobcontext;
printf("\n\n*** Testing old double gcry_cipher_release case ***\n\n");
otrl_context_forget_all(us);
ALICEPOLICY = OTRL_POLICY_DEFAULT;
sending(ALICE, BOB, "?OTR?");
dispatch();
alicecontext = otrl_context_find(us, BOB, ALICE, PROTO, 0, 0, NULL, NULL, NULL);
bobcontext = otrl_context_find(us, ALICE, BOB, PROTO, 0, 0, NULL, NULL, NULL);
sending(ALICE, BOB, "Hi!"); dispatch();
sending(BOB, ALICE, "There!"); dispatch();
sending(ALICE, BOB, "You!"); dispatch();
otrl_context_force_plaintext(bobcontext);
sending(BOB, ALICE, "?OTR?"); dispatch();
sending(ALICE, BOB, "now."); dispatch();
printf("%d %p %p\n", alicecontext->our_keyid, alicecontext->their_y, alicecontext->their_old_y);
printf("%p %p %p %p\n",
alicecontext->sesskeys[0][0].sendenc,
alicecontext->sesskeys[0][1].sendenc,
alicecontext->sesskeys[1][0].sendenc,
alicecontext->sesskeys[1][1].sendenc);
sending(BOB, ALICE, "then."); dispatch();
}
void test_refresh(int vers)
{
ConnContext *alicecontext, *bobcontext;
printf("\n\n*** Testing refresh ***\n\n");
otrl_context_forget_all(us);
if (vers == 1)
ALICEPOLICY = OTRL_POLICY_ALLOW_V1;
else if (vers == 2)
ALICEPOLICY = OTRL_POLICY_ALLOW_V2;
else
ALICEPOLICY = OTRL_POLICY_DEFAULT;
sending(ALICE, BOB, "?OTR?"); dispatch();
alicecontext = otrl_context_find(us, BOB, ALICE, PROTO, 0, 0, NULL, NULL, NULL);
bobcontext = otrl_context_find(us, ALICE, BOB, PROTO, 0, 0, NULL, NULL, NULL);
printf("%p %p\n", alicecontext, bobcontext);
sending(ALICE, BOB, "Hi!"); dispatch();
sending(BOB, ALICE, "There!"); dispatch();
sending(ALICE, BOB, "You!"); dispatch();
sending(ALICE, BOB, "Guys!"); dispatch();
sending(BOB, ALICE, "?OTR?"); dispatch();
sending(ALICE, BOB, "Refreshed!"); dispatch();
sending(BOB, ALICE, "Also refreshed!"); dispatch();
}
int main(int argc, char **argv)
{
OTRL_INIT;
us = otrl_userstate_create();
otrl_privkey_read(us, "/home/iang/.gaim/otr.private_key");
otrl_instag_read(us, "inst.txt");
test(1,0);
test(2,0);
test(3,0);
test(1,1);
test(2,1);
test_unreadable();
test_crash1();
test_refresh(3);
test_refresh(2);
test_refresh(1);
otrl_userstate_free(us);
return 0;