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 /src/otr/otrlibv4.c | |
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
Diffstat (limited to 'src/otr/otrlibv4.c')
-rw-r--r-- | src/otr/otrlibv4.c | 109 |
1 files changed, 89 insertions, 20 deletions
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 * |