1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Attempt at shared secret authentication for libotr 4.0.0

Bug exists where second attempt always gets stuck
This commit is contained in:
James Booth 2014-04-28 22:23:39 +01:00
parent da4dfe251d
commit 1155ceabbc
6 changed files with 130 additions and 24 deletions

View File

@ -155,11 +155,19 @@ _otr_init(void)
otrlib_init_ops(&ops);
otrlib_init_timer();
smp_initiators = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
data_loaded = FALSE;
}
void
_otr_poll(void)
{
otrlib_poll();
}
static void
_otr_on_connect(ProfAccount *account)
{
@ -359,9 +367,14 @@ _otr_is_trusted(const char * const recipient)
return TRUE;
}
if (context->active_fingerprint &&
g_strcmp0(context->active_fingerprint->trust, "trusted") == 0) {
return TRUE;
if (context->active_fingerprint) {
if (context->active_fingerprint->trust == NULL) {
return FALSE;
} else if (context->active_fingerprint->trust[0] == '\0') {
return FALSE;
} else {
return TRUE;
}
}
return FALSE;
@ -381,6 +394,9 @@ _otr_trust(const char * const recipient)
}
if (context->active_fingerprint) {
if (context->active_fingerprint->trust != NULL) {
free(context->active_fingerprint->trust);
}
context->active_fingerprint->trust = strdup("trusted");
cb_write_fingerprints(NULL);
}
@ -402,6 +418,9 @@ _otr_untrust(const char * const recipient)
}
if (context->active_fingerprint) {
if (context->active_fingerprint->trust != NULL) {
free(context->active_fingerprint->trust);
}
context->active_fingerprint->trust = NULL;
cb_write_fingerprints(NULL);
}
@ -530,6 +549,7 @@ otr_init_module(void)
otr_init = _otr_init;
otr_libotr_version = _otr_libotr_version;
otr_start_query = _otr_start_query;
otr_poll = _otr_poll;
otr_on_connect = _otr_on_connect;
otr_keygen = _otr_keygen;
otr_key_loaded = _otr_key_loaded;

View File

@ -37,6 +37,7 @@ GHashTable* otr_smpinitators(void);
void (*otr_init)(void);
char* (*otr_libotr_version)(void);
char* (*otr_start_query)(void);
void (*otr_poll)(void);
void (*otr_on_connect)(ProfAccount *account);
void (*otr_keygen)(ProfAccount *account);

View File

@ -29,6 +29,9 @@ char* otrlib_start_query(void);
void otrlib_init_ops(OtrlMessageAppOps *ops);
void otrlib_init_timer(void);
void otrlib_poll(void);
ConnContext * otrlib_context_find(OtrlUserState user_state, const char * const recipient, char *jid);
void otrlib_end_session(OtrlUserState user_state, const char * const recipient, char *jid, OtrlMessageAppOps *ops);

View File

@ -33,6 +33,16 @@ otrlib_policy(void)
return OTRL_POLICY_ALLOW_V1 | OTRL_POLICY_ALLOW_V2 ;
}
void
otrlib_init_timer(void)
{
}
void
otrlib_poll(void)
{
}
char *
otrlib_start_query(void)
{
@ -171,4 +181,4 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
ui_untrust(context->username);
otr_untrust(context->username);
}
}
}

View File

@ -28,12 +28,36 @@
#include "otr/otr.h"
#include "otr/otrlib.h"
static GTimer *timer;
static unsigned int current_interval;
OtrlPolicy
otrlib_policy(void)
{
return OTRL_POLICY_ALLOW_V1 | OTRL_POLICY_ALLOW_V2;
}
void
otrlib_init_timer(void)
{
OtrlUserState user_state = otr_userstate();
timer = g_timer_new();
current_interval = otrl_message_poll_get_default_interval(user_state);
}
void
otrlib_poll(void)
{
gdouble elapsed = g_timer_elapsed(timer, NULL);
if (current_interval != 0 && elapsed > current_interval) {
OtrlUserState user_state = otr_userstate();
OtrlMessageAppOps *ops = otr_messageops();
otrl_message_poll(user_state, ops, NULL);
g_timer_start(timer);
}
}
char *
otrlib_start_query(void)
{
@ -65,17 +89,70 @@ cb_otr_error_message_free(void *opdata, const char *err_msg)
free((char *)err_msg);
}
static void
cb_timer_control(void *opdata, unsigned int interval)
{
current_interval = interval;
}
static void
cb_handle_msg_event(void *opdata, OtrlMessageEvent msg_event,
ConnContext *context, const char *message,
gcry_error_t err)
{
if (err != 0) {
if (message != NULL) {
cons_show_error("%s", message);
} else {
cons_show_error("OTR error event with no message.");
}
switch(msg_event)
{
case OTRL_MSGEVENT_ENCRYPTION_REQUIRED:
cons_show_error("Our policy requires encryption but we are trying to send an unencrypted message out.");
break;
case OTRL_MSGEVENT_ENCRYPTION_ERROR:
cons_show_error("An error occured while encrypting a message and the message was not sent.");
break;
case OTRL_MSGEVENT_CONNECTION_ENDED:
cons_show_error("Message has not been sent because our buddy has ended the private conversation. We should either close the connection, or refresh it.");
break;
case OTRL_MSGEVENT_SETUP_ERROR:
cons_show_error("A private conversation could not be set up. A gcry_error_t will be passed.");
break;
case OTRL_MSGEVENT_MSG_REFLECTED:
cons_show_error("Received our own OTR messages.");
break;
case OTRL_MSGEVENT_MSG_RESENT:
cons_show_error("The previous message was resent.");
break;
case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE:
cons_show_error("Received an encrypted message but cannot read it because no private connection is established yet.");
break;
case OTRL_MSGEVENT_RCVDMSG_UNREADABLE:
cons_show_error("Cannot read the received message.");
break;
case OTRL_MSGEVENT_RCVDMSG_MALFORMED:
cons_show_error("The message received contains malformed data.");
break;
case OTRL_MSGEVENT_LOG_HEARTBEAT_RCVD:
cons_show_error("Received a heartbeat.");
break;
case OTRL_MSGEVENT_LOG_HEARTBEAT_SENT:
cons_show_error("Sent a heartbeat.");
break;
case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR:
cons_show_error("Received a general OTR error. The argument 'message' will also be passed and it will contain the OTR error message.");
break;
case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED:
cons_show_error("Received an unencrypted message. The argument 'smessage' will also be passed and it will contain the plaintext message.");
break;
case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED:
cons_show_error("Cannot recognize the type of OTR message received.");
break;
case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE:
cons_show_error("Received and discarded a message intended for another instance.");
break;
default:
break;
}
if (message != NULL) {
cons_show_error("Message: %s", message);
}
}
@ -85,6 +162,7 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event,
char *question)
{
NextExpectedSMP nextMsg = context->smstate->nextExpected;
context->smstate->sm_prog_state = OTRL_SMP_PROG_OK;
OtrlUserState user_state = otr_userstate();
OtrlMessageAppOps *ops = otr_messageops();
GHashTable *smp_initiators = otr_smpinitators();
@ -92,53 +170,43 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event,
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);
// 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);
// 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");
// otr_untrust(context->username);
}
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);
// 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:
@ -157,6 +225,7 @@ otrlib_init_ops(OtrlMessageAppOps *ops)
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;
ops->timer_control = cb_timer_control;
}
ConnContext *

View File

@ -102,6 +102,9 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
ui_handle_special_keys(&ch, inp, size);
ui_update_screen();
#ifdef HAVE_LIBOTR
otr_poll();
#endif
jabber_process_events();
ch = ui_get_char(inp, &size);