adium/adium

Parents 604bcdb5ff17
Children 463075e8de4d
More verbosity about the SMP process. Additionally, verify the OTR session still exists before sending the question.
--- a/Source/AdiumOTREncryption.m Mon May 05 18:45:49 2014 +0200
+++ b/Source/AdiumOTREncryption.m Mon May 05 19:32:17 2014 +0200
@@ -753,40 +753,68 @@
otrl_instag_generate(otrg_plugin_userstate, INSTAG_PATH, accountname, protocol);
}
-/* Something related to Socialis Millionaire Protocol happened. Handle it. */
+/* Something related to Socialist Millionaire Protocol happened. Handle it. */
static void
handle_smp_event_cb(void *opdata, OtrlSMPEvent smp_event, ConnContext *context, unsigned short progress_percent, char *question)
{
AIListContact *listContact = contactForContext(context);
+ AIChat *chat = chatForContext(context);
+ if (!chat) chat = [adium.chatController chatWithContact:listContact];
+
switch (smp_event) {
case OTRL_SMPEVENT_ASK_FOR_ANSWER: {
AIOTRSMPSecretAnswerWindowController *questionController = [[AIOTRSMPSecretAnswerWindowController alloc]
initWithQuestion:[NSString stringWithUTF8String:question]
from:listContact
completionHandler:^(NSData *answer,NSString *_question){
- if(!answer) {
- otrl_message_abort_smp(otrg_get_userstate(), &ui_ops, opdata, context);
- } else
- otrl_message_respond_smp(otrg_get_userstate(), &ui_ops, opdata, context, [answer bytes], [answer length]);
- }
+
+ if (context != contextForChat(chat)) {
+ AILogWithSignature(@"Something's wrong: %p != %p. Did the conversation close before you sent the secret question?", context, contextForChat(chat));
+ return;
+ }
+
+ if(!answer) {
+ otrl_message_abort_smp(otrg_get_userstate(), &ui_ops, opdata, context);
+ } else
+ otrl_message_respond_smp(otrg_get_userstate(), &ui_ops, opdata, context, [answer bytes], [answer length]);
+ }
isInitiator:NO];
[questionController showWindow:nil];
[questionController.window orderFront:nil];
+ [adium.contentController displayEvent:[NSString stringWithFormat:AILocalizedStringFromTableInBundle(@"%@ has sent you a secret question and is awaiting your answer to verify your identity.", nil,
+ [NSBundle bundleForClass:[AdiumOTREncryption class]], nil),
+ listContact.displayName]
+ ofType:@"encryption"
+ inChat:chat];
+
break;
}
case OTRL_SMPEVENT_ASK_FOR_SECRET: {
AIOTRSMPSharedSecretWindowController *questionController = [[AIOTRSMPSharedSecretWindowController alloc]
initFrom:listContact
completionHandler:^(NSData *answer){
- otrl_message_respond_smp(otrg_get_userstate(), &ui_ops, opdata, context, [answer bytes], [answer length]);
- }
+
+ if (context != contextForChat(chat)) {
+ AILogWithSignature(@"Something's wrong: %p != %p. Did the conversation close before you sent the secret question?", context, contextForChat(chat));
+ return;
+ }
+
+ otrl_message_respond_smp(otrg_get_userstate(), &ui_ops, opdata, context, [answer bytes], [answer length]);
+ }
isInitiator:NO];
[questionController showWindow:nil];
[questionController.window orderFront:nil];
+
+ [adium.contentController displayEvent:[NSString stringWithFormat:AILocalizedStringFromTableInBundle(@"%@ has requested to compare your shared secret to verify your identity.", nil,
+ [NSBundle bundleForClass:[AdiumOTREncryption class]], nil),
+ listContact.displayName]
+ ofType:@"encryption"
+ inChat:chat];
+
break;
}
case OTRL_SMPEVENT_CHEATED:
@@ -797,9 +825,6 @@
nil,
[NSBundle bundleForClass:[AdiumOTREncryption class]], nil);
- AIChat *chat = chatForContext(context);
- if (!chat) chat = [adium.chatController chatWithContact:listContact];
-
[adium.contentController displayEvent:localizedMessage
ofType:@"encryption"
inChat:chat];
@@ -810,9 +835,6 @@
nil,
[NSBundle bundleForClass:[AdiumOTREncryption class]], nil);
- AIChat *chat = chatForContext(context);
- if (!chat) chat = [adium.chatController chatWithContact:listContact];
-
[adium.contentController displayEvent:localizedMessage
ofType:@"encryption"
inChat:chat];
@@ -960,6 +982,11 @@
from:inChat.listObject
completionHandler:^(NSData *answer, NSString *question) {
+ if (context != contextForChat(inChat)) {
+ AILogWithSignature(@"Something's wrong: %p != %p. Did the conversation close before you sent the secret question?", context, contextForChat(inChat));
+ return;
+ }
+
otrl_message_initiate_smp_q(otrg_get_userstate(),
&ui_ops, NULL, context,
(const char *)[question UTF8String],
@@ -986,6 +1013,11 @@
initFrom:inChat.listObject
completionHandler:^(NSData *answer) {
+ if (context != contextForChat(inChat)) {
+ AILogWithSignature(@"Something's wrong: %p != %p. Did the conversation close before you sent the secret question?", context, contextForChat(inChat));
+ return;
+ }
+
otrl_message_initiate_smp(otrg_get_userstate(),
&ui_ops, NULL,
context,