Combined chatwin OTR SMP functions

This commit is contained in:
James Booth
2015-10-27 22:25:02 +00:00
parent 40dcd59727
commit ff9abecd50
8 changed files with 93 additions and 126 deletions

View File

@@ -577,13 +577,13 @@ otr_smp_secret(const char *const recipient, const char *secret)
if (g_hash_table_contains(smp_initiators, recipient)) {
otrl_message_respond_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret));
if (chatwin) {
chatwin_otr_smp_authenticating(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_AUTH, NULL);
}
g_hash_table_remove(smp_initiators, context->username);
} else {
otrl_message_initiate_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret));
if (chatwin) {
chatwin_otr_smp_authenticaton_wait(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_AUTH_WAIT, NULL);
}
}
}
@@ -604,7 +604,7 @@ otr_smp_question(const char *const recipient, const char *question, const char *
otrl_message_initiate_smp_q(user_state, &ops, NULL, context, question, (const unsigned char*)answer, strlen(answer));
ProfChatWin *chatwin = wins_get_chat(recipient);
if (chatwin) {
chatwin_otr_smp_authenticaton_wait(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_AUTH_WAIT, NULL);
}
}

View File

@@ -39,7 +39,7 @@
#include <libotr/message.h>
#include "config/accounts.h"
#include "ui/ui.h"
#include "ui/win_types.h"
typedef enum {
PROF_OTRPOLICY_MANUAL,
@@ -47,6 +47,19 @@ typedef enum {
PROF_OTRPOLICY_ALWAYS
} prof_otrpolicy_t;
typedef enum {
PROF_OTR_SMP_INIT,
PROF_OTR_SMP_INIT_Q,
PROF_OTR_SMP_SENDER_FAIL,
PROF_OTR_SMP_RECEIVER_FAIL,
PROF_OTR_SMP_ABORT,
PROF_OTR_SMP_SUCCESS,
PROF_OTR_SMP_SUCCESS_Q,
PROF_OTR_SMP_FAIL_Q,
PROF_OTR_SMP_AUTH,
PROF_OTR_SMP_AUTH_WAIT
} prof_otr_smp_event_t;
OtrlUserState otr_userstate(void);
OtrlMessageAppOps* otr_messageops(void);
GHashTable* otr_smpinitators(void);

View File

@@ -143,7 +143,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
} else {
ProfChatWin *chatwin = wins_get_chat(context->username);
if (chatwin) {
chatwin_otr_smp_init(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT. NULL);
}
g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username));
}
@@ -158,7 +158,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
char *question = (char *)tlv->data;
char *eoq = memchr(question, '\0', tlv->len);
if (eoq) {
chatwin_otr_smp_init_q(chatwin, question);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT_Q, question);
}
}
}
@@ -181,17 +181,17 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
if (chatwin) {
if (context->smstate->received_question == 0) {
if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) {
chatwin_otr_smp_success(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL);
chatwin_otr_trust(chatwin);
} else {
chatwin_otr_smp_sender_failed(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SENDER_FAIL, NULL);
chatwin_otr_untrust(chatwin);
}
} else {
if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) {
chatwin_otr_smp_answer_success(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS_Q, NULL);
} else {
chatwin_otr_smp_answer_failure(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_FAIL_Q, NULL);
}
}
}
@@ -206,10 +206,10 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
ProfChatWin *chatwin = wins_get_chat(context->username);
if (chatwin) {
if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) {
chatwin_otr_smp_success(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL);
chatwin_otr_trust(chatwin);
} else {
chatwin_otr_smp_receiver_failed(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_RECEIVER_FAIL, NULL);
chatwin_otr_untrust(chatwin);
}
}
@@ -220,7 +220,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
context->smstate->nextExpected = OTRL_SMP_EXPECT1;
ProfChatWin *chatwin = wins_get_chat(context->username);
if (chatwin) {
chatwin_otr_smp_aborted(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_ABORT, NULL);
chatwin_otr_untrust(chatwin);
}
otr_untrust(context->username);

View File

@@ -183,24 +183,24 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event,
{
case OTRL_SMPEVENT_ASK_FOR_SECRET:
if (chatwin) {
chatwin_otr_smp_init(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT, NULL);
}
g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username));
break;
case OTRL_SMPEVENT_ASK_FOR_ANSWER:
if (chatwin) {
chatwin_otr_smp_init_q(chatwin, question);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT_Q, question);
}
break;
case OTRL_SMPEVENT_SUCCESS:
if (chatwin) {
if (context->smstate->received_question == 0) {
chatwin_otr_smp_success(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL);
chatwin_otr_trust(chatwin);
} else {
chatwin_otr_smp_answer_success(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS_Q, NULL);
}
}
break;
@@ -209,13 +209,13 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event,
if (chatwin) {
if (context->smstate->received_question == 0) {
if (nextMsg == OTRL_SMP_EXPECT3) {
chatwin_otr_smp_sender_failed(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SENDER_FAIL, NULL);
} else if (nextMsg == OTRL_SMP_EXPECT4) {
chatwin_otr_smp_receiver_failed(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_RECEIVER_FAIL, NULL);
}
chatwin_otr_untrust(chatwin);
} else {
chatwin_otr_smp_answer_failure(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_FAIL_Q, NULL);
}
}
break;
@@ -230,7 +230,7 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event,
case OTRL_SMPEVENT_ABORT:
if (chatwin) {
chatwin_otr_smp_aborted(chatwin);
chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_ABORT, NULL);
chatwin_otr_untrust(chatwin);
}
break;