Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disconnect the OTR session #23

Closed
gemamegantara opened this issue Apr 26, 2012 · 4 comments
Closed

How to disconnect the OTR session #23

gemamegantara opened this issue Apr 26, 2012 · 4 comments

Comments

@gemamegantara
Copy link

Hi chris, i've been looking to your code for a while, and i wondering how can i disconnect the OTR session with my friend ?
If I read from the source here http://www.cypherpunks.ca/otr/Protocol-v2-3.1.0.html , it's said we have to use TLV type 1 if we want to disconnect. And how i can do that with your code ? please I already spent two days thinking about it. :)

@chrisballinger
Copy link
Member

OTRCodec.m is where all of the real communication with the OTR library happens. I actually don't know how to explicitly request a disconnect at the moment, but I'm sure if you looked at the Adium OTR plugin source or pidgin-otr plugin you'd be able to figure out what is going on.

@gemamegantara
Copy link
Author

in libotr/message.c, I see this function

/* Put a connection into the PLAINTEXT state, first sending the
  other side a notice that we're doing so if we're currently ENCRYPTED,
  and we think he's logged in. */

void otrl_message_disconnect(OtrlUserState us, const OtrlMessageAppOps *ops, void *opdata, const char *accountname, const char *protocol, const char *username)
{
    ConnContext *context = otrl_context_find(us, username, accountname,
        protocol, 0, NULL, NULL, NULL);

    if (!context) return;

    if (context->msgstate == OTRL_MSGSTATE_ENCRYPTED &&
        context->their_keyid > 0 &&
        ops->is_logged_in &&
        ops->is_logged_in(opdata, accountname, protocol, username) == 1) {
    if (ops->inject_message) {
        char *encmsg = NULL;
        gcry_error_t err;
        OtrlTLV *tlv = otrl_tlv_new(OTRL_TLV_DISCONNECTED, 0, NULL);

        err = otrl_proto_create_data(&encmsg, context, "", tlv,
            OTRL_MSGFLAGS_IGNORE_UNREADABLE);
        if (!err) {
        ops->inject_message(opdata, accountname, protocol,
            username, encmsg);
        }
        free(encmsg);
    }
    }

    otrl_context_force_plaintext(context);
    if (ops->update_context_list) {
    ops->update_context_list(opdata);
    }
}

and I see in Adium OTR plugin source, it also called that function to disconnect.
So I try to add this code below in your OTR iOS :

+(void) disconnectSession:(NSString*)sender recipient:(NSString*)recipient protocol:(NSString*)protocol
{
    
    OTRProtocolManager *protocolManager = [OTRProtocolManager sharedInstance];
    
    OtrlUserState userstate = protocolManager.encryptionManager.userState;
    
    if(!userstate)
        NSLog(@"userstate is nil!");

    otrl_message_disconnect(userstate, &ui_ops,
                                 NULL, [sender UTF8String], [protocol UTF8String],
                                 [recipient UTF8String]);
  
}

but it does nothing. It suppose to call the inject_message function. Can you help me here Chris ?

@chrisballinger
Copy link
Member

Hmm if it isn't forcing plaintext by injecting a message then perhaps err != nil?

@chrisballinger
Copy link
Member

Were you able to figure out the problem? I'm going to close this issue for now, feel free to reopen it if you have any other questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants