1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Handle SMP secret response

This commit is contained in:
James Booth 2014-04-26 22:52:25 +01:00
parent 06d81ed9ce
commit aff9eee433
5 changed files with 30 additions and 10 deletions

View File

@ -2800,8 +2800,8 @@ cmd_otr(gchar **args, struct cmd_help_t help)
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);
} else { } else {
char *recipient = ui_current_recipient(); char *recipient = ui_current_recipient();
otr_smp_init_secret(recipient, secret); otr_smp_secret(recipient, secret);
ui_current_print_formatted_line('!', 0, "OTR secret entered", secret); ui_current_print_formatted_line('!', 0, "OTR secret entered");
} }
} }
return TRUE; return TRUE;

View File

@ -41,6 +41,7 @@ static OtrlUserState user_state;
static OtrlMessageAppOps ops; static OtrlMessageAppOps ops;
static char *jid; static char *jid;
static gboolean data_loaded; static gboolean data_loaded;
static GHashTable *smp_initiators;
// ops callbacks // ops callbacks
static OtrlPolicy static OtrlPolicy
@ -136,6 +137,8 @@ _otr_init(void)
otrlib_init_ops(&ops); otrlib_init_ops(&ops);
smp_initiators = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
data_loaded = FALSE; data_loaded = FALSE;
} }
@ -389,7 +392,7 @@ _otr_untrust(const char * const recipient)
} }
static void static void
_otr_smp_init_secret(const char * const recipient, const char *secret) _otr_smp_secret(const char * const recipient, const char *secret)
{ {
ConnContext *context = otrlib_context_find(user_state, recipient, jid); ConnContext *context = otrlib_context_find(user_state, recipient, jid);
@ -401,7 +404,12 @@ _otr_smp_init_secret(const char * const recipient, const char *secret)
return; return;
} }
// if recipient initiated SMP, send response, else initialise
if (g_hash_table_contains(smp_initiators, recipient)) {
otrl_message_respond_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret));
} else {
otrl_message_initiate_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret)); otrl_message_initiate_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret));
}
} }
static void static void
@ -471,7 +479,7 @@ _otr_decrypt_message(const char * const from, const char * const message, gboole
} }
// library version specific tlv handling // library version specific tlv handling
otrlib_handle_tlvs(user_state, &ops, context, tlvs); otrlib_handle_tlvs(user_state, &ops, context, tlvs, smp_initiators);
return NULL; return NULL;
@ -512,5 +520,5 @@ otr_init_module(void)
otr_encrypt_message = _otr_encrypt_message; otr_encrypt_message = _otr_encrypt_message;
otr_decrypt_message = _otr_decrypt_message; otr_decrypt_message = _otr_decrypt_message;
otr_free_message = _otr_free_message; otr_free_message = _otr_free_message;
otr_smp_init_secret = _otr_smp_init_secret; otr_smp_secret = _otr_smp_secret;
} }

View File

@ -40,7 +40,7 @@ gboolean (*otr_is_trusted)(const char * const recipient);
void (*otr_trust)(const char * const recipient); void (*otr_trust)(const char * const recipient);
void (*otr_untrust)(const char * const recipient); void (*otr_untrust)(const char * const recipient);
void (*otr_smp_init_secret)(const char * const recipient, const char *secret); void (*otr_smp_secret)(const char * const recipient, const char *secret);
void (*otr_end_session)(const char * const recipient); void (*otr_end_session)(const char * const recipient);

View File

@ -39,6 +39,6 @@ gcry_error_t otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps
int otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char * const from, int otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char * const from,
const char * const message, char **decrypted, OtrlTLV **tlvs); const char * const message, char **decrypted, OtrlTLV **tlvs);
void otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs); void otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs, GHashTable *smp_initiators);
#endif #endif

View File

@ -108,7 +108,7 @@ otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j
} }
void void
otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs) otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs, GHashTable *smp_initiators)
{ {
NextExpectedSMP nextMsg = context->smstate->nextExpected; NextExpectedSMP nextMsg = context->smstate->nextExpected;
OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1); OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
@ -116,8 +116,9 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
if (nextMsg != OTRL_SMP_EXPECT1) { if (nextMsg != OTRL_SMP_EXPECT1) {
otrl_message_abort_smp(user_state, ops, NULL, context); otrl_message_abort_smp(user_state, ops, NULL, context);
} else { } else {
cons_debug("%s initiated SMP", context->username);
// [get secret from user and continue SMP]; // [get secret from user and continue SMP];
cons_debug("%s initiated SMP with secret", context->username);
g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username));
} }
} }
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2); tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
@ -138,6 +139,11 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
// We will not expect more messages, so prepare for next SMP // We will not expect more messages, so prepare for next SMP
context->smstate->nextExpected = OTRL_SMP_EXPECT1; context->smstate->nextExpected = OTRL_SMP_EXPECT1;
// Report result to user // Report result to user
if ((context->active_fingerprint->trust != NULL) && (context->active_fingerprint->trust[0] != '\0')) {
cons_debug("SMP SUCCESSFUL");
} else {
cons_debug("SMP UNSUCCESSFUL");
}
} }
} }
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4); tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
@ -148,6 +154,11 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
// We will not expect more messages, so prepare for next SMP // We will not expect more messages, so prepare for next SMP
context->smstate->nextExpected = OTRL_SMP_EXPECT1; context->smstate->nextExpected = OTRL_SMP_EXPECT1;
// Report result to user // Report result to user
if ((context->active_fingerprint->trust != NULL) && (context->active_fingerprint->trust[0] != '\0')) {
cons_debug("SMP SUCCESSFUL");
} else {
cons_debug("SMP UNSUCCESSFUL");
}
} }
} }
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT); tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);
@ -155,5 +166,6 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
// The message we are waiting for will not arrive, so reset // The message we are waiting for will not arrive, so reset
// and prepare for the next SMP // and prepare for the next SMP
context->smstate->nextExpected = OTRL_SMP_EXPECT1; context->smstate->nextExpected = OTRL_SMP_EXPECT1;
cons_debug("SMP ABORTED");
} }
} }