From da4dfe251df441d745078b7c477b15a54cdac3fc Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 27 Apr 2014 18:46:40 +0100 Subject: [PATCH] Added SMP secret libotr 4.0.0 handlers --- src/otr/otr.c | 18 +++++++++++ src/otr/otr.h | 7 ++++ src/otr/otrlibv4.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/src/otr/otr.c b/src/otr/otr.c index cd3388d2..de1d6959 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -43,6 +43,24 @@ static char *jid; static gboolean data_loaded; static GHashTable *smp_initiators; +OtrlUserState +otr_userstate(void) +{ + return user_state; +} + +OtrlMessageAppOps * +otr_messageops(void) +{ + return &ops; +} + +GHashTable * +otr_smpinitators(void) +{ + return smp_initiators; +} + // ops callbacks static OtrlPolicy cb_policy(void *opdata, ConnContext *context) diff --git a/src/otr/otr.h b/src/otr/otr.h index 443ee67c..3fc68db8 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -23,10 +23,17 @@ #ifndef OTR_H #define OTR_H +#include +#include + #include "config/accounts.h" void otr_init_module(void); +OtrlUserState otr_userstate(void); +OtrlMessageAppOps* otr_messageops(void); +GHashTable* otr_smpinitators(void); + void (*otr_init)(void); char* (*otr_libotr_version)(void); char* (*otr_start_query)(void); diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index c55d2972..c74e97d8 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -25,6 +25,8 @@ #include #include "ui/ui.h" +#include "otr/otr.h" +#include "otr/otrlib.h" OtrlPolicy otrlib_policy(void) @@ -77,12 +79,84 @@ cb_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, } } +static void +cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, + ConnContext *context, unsigned short progress_percent, + char *question) +{ + NextExpectedSMP nextMsg = context->smstate->nextExpected; + OtrlUserState user_state = otr_userstate(); + OtrlMessageAppOps *ops = otr_messageops(); + GHashTable *smp_initiators = otr_smpinitators(); + + switch(smp_event) + { + case OTRL_SMPEVENT_ASK_FOR_SECRET: + ui_current_print_line("OTRL_SMPEVENT_ASK_FOR_SECRET"); + ui_smp_recipient_initiated(context->username); + g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); + break; + + case OTRL_SMPEVENT_SUCCESS: + ui_current_print_line("OTRL_SMPEVENT_SUCCESS"); + ui_smp_successful(context->username); + ui_trust(context->username); + otr_trust(context->username); + break; + + case OTRL_SMPEVENT_FAILURE: + if (nextMsg == OTRL_SMP_EXPECT3) { + ui_current_print_line("OTRL_SMPEVENT_FAILURE: OTRL_SMP_EXPECT3"); + ui_smp_unsuccessful_sender(context->username); + ui_untrust(context->username); + otr_untrust(context->username); + } else if (nextMsg == OTRL_SMP_EXPECT4) { + ui_current_print_line("OTRL_SMPEVENT_FAILURE: OTRL_SMP_EXPECT4"); + ui_smp_unsuccessful_receiver(context->username); + ui_untrust(context->username); + otr_untrust(context->username); + } else { + ui_current_print_line("OTRL_SMPEVENT_FAILURE"); + } + break; + + case OTRL_SMPEVENT_ERROR: + ui_current_print_line("OTRL_SMPEVENT_ERROR"); + otrl_message_abort_smp(user_state, ops, NULL, context); + break; + + case OTRL_SMPEVENT_CHEATED: + ui_current_print_line("OTRL_SMPEVENT_CHEATED"); + otrl_message_abort_smp(user_state, ops, NULL, context); + break; + + case OTRL_SMPEVENT_ABORT: + ui_current_print_line("OTRL_SMPEVENT_ABORT"); + ui_smp_aborted(context->username); + ui_untrust(context->username); + otr_untrust(context->username); + break; + + case OTRL_SMPEVENT_ASK_FOR_ANSWER: + ui_current_print_line("OTRL_SMPEVENT_ASK_FOR_ANSWER"); + break; + + case OTRL_SMPEVENT_IN_PROGRESS: + ui_current_print_line("OTRL_SMPEVENT_IN_PROGRESS: %d", progress_percent); + break; + + default: + break; + } +} + void otrlib_init_ops(OtrlMessageAppOps *ops) { ops->otr_error_message = cb_otr_error_message; ops->otr_error_message_free = cb_otr_error_message_free; ops->handle_msg_event = cb_handle_msg_event; + ops->handle_smp_event = cb_handle_smp_event; } ConnContext * @@ -145,3 +219,8 @@ otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j NULL, NULL); } + +void +otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs, GHashTable *smp_initiators) +{ +}