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:
parent
06d81ed9ce
commit
aff9eee433
@ -2800,8 +2800,8 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
||||
cons_show("Usage: %s", help.usage);
|
||||
} else {
|
||||
char *recipient = ui_current_recipient();
|
||||
otr_smp_init_secret(recipient, secret);
|
||||
ui_current_print_formatted_line('!', 0, "OTR secret entered", secret);
|
||||
otr_smp_secret(recipient, secret);
|
||||
ui_current_print_formatted_line('!', 0, "OTR secret entered");
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -41,6 +41,7 @@ static OtrlUserState user_state;
|
||||
static OtrlMessageAppOps ops;
|
||||
static char *jid;
|
||||
static gboolean data_loaded;
|
||||
static GHashTable *smp_initiators;
|
||||
|
||||
// ops callbacks
|
||||
static OtrlPolicy
|
||||
@ -136,6 +137,8 @@ _otr_init(void)
|
||||
|
||||
otrlib_init_ops(&ops);
|
||||
|
||||
smp_initiators = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
|
||||
data_loaded = FALSE;
|
||||
}
|
||||
|
||||
@ -389,7 +392,7 @@ _otr_untrust(const char * const recipient)
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -401,8 +404,13 @@ _otr_smp_init_secret(const char * const recipient, const char *secret)
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_otr_end_session(const char * const recipient)
|
||||
@ -471,7 +479,7 @@ _otr_decrypt_message(const char * const from, const char * const message, gboole
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
@ -512,5 +520,5 @@ otr_init_module(void)
|
||||
otr_encrypt_message = _otr_encrypt_message;
|
||||
otr_decrypt_message = _otr_decrypt_message;
|
||||
otr_free_message = _otr_free_message;
|
||||
otr_smp_init_secret = _otr_smp_init_secret;
|
||||
otr_smp_secret = _otr_smp_secret;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ gboolean (*otr_is_trusted)(const char * const recipient);
|
||||
void (*otr_trust)(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);
|
||||
|
||||
|
@ -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,
|
||||
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
|
||||
|
@ -108,7 +108,7 @@ otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j
|
||||
}
|
||||
|
||||
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;
|
||||
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) {
|
||||
otrl_message_abort_smp(user_state, ops, NULL, context);
|
||||
} else {
|
||||
cons_debug("%s initiated SMP", context->username);
|
||||
// [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);
|
||||
@ -138,6 +139,11 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
|
||||
// We will not expect more messages, so prepare for next SMP
|
||||
context->smstate->nextExpected = OTRL_SMP_EXPECT1;
|
||||
// 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);
|
||||
@ -148,6 +154,11 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
|
||||
// We will not expect more messages, so prepare for next SMP
|
||||
context->smstate->nextExpected = OTRL_SMP_EXPECT1;
|
||||
// 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);
|
||||
@ -155,5 +166,6 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
|
||||
// The message we are waiting for will not arrive, so reset
|
||||
// and prepare for the next SMP
|
||||
context->smstate->nextExpected = OTRL_SMP_EXPECT1;
|
||||
cons_debug("SMP ABORTED");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user