diff options
author | James Booth <boothj5@gmail.com> | 2014-04-28 22:23:39 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-04-28 22:23:39 +0100 |
commit | 1155ceabbc4424db8de19b8f540e514a90696bab (patch) | |
tree | def9646f6204ebcab8eb965696816da42c92f999 | |
parent | da4dfe251df441d745078b7c477b15a54cdac3fc (diff) | |
download | profani-tty-1155ceabbc4424db8de19b8f540e514a90696bab.tar.gz |
Attempt at shared secret authentication for libotr 4.0.0
Bug exists where second attempt always gets stuck
-rw-r--r-- | src/otr/otr.c | 26 | ||||
-rw-r--r-- | src/otr/otr.h | 1 | ||||
-rw-r--r-- | src/otr/otrlib.h | 3 | ||||
-rw-r--r-- | src/otr/otrlibv3.c | 12 | ||||
-rw-r--r-- | src/otr/otrlibv4.c | 109 | ||||
-rw-r--r-- | src/profanity.c | 3 |
6 files changed, 130 insertions, 24 deletions
diff --git a/src/otr/otr.c b/src/otr/otr.c index de1d6959..72dded2a 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -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; diff --git a/src/otr/otr.h b/src/otr/otr.h index 3fc68db8..f2f20d17 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -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); diff --git a/src/otr/otrlib.h b/src/otr/otrlib.h index 263e44df..c0ca518f 100644 --- a/src/otr/otrlib.h +++ b/src/otr/otrlib.h @@ -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); diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index bfd25a5f..7ec8a492 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -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); } -} \ No newline at end of file +} diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index c74e97d8..bd007dbd 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -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) { @@ -66,16 +90,69 @@ cb_otr_error_message_free(void *opdata, const 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 * diff --git a/src/profanity.c b/src/profanity.c index 95355670..209289e2 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -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); |