Esempio n. 1
0
static char *
_otr_decrypt_message(const char * const from, const char * const message, gboolean *was_decrypted)
{
    char *decrypted = NULL;
    OtrlTLV *tlvs = NULL;
    OtrlTLV *tlv = NULL;

    int result = otrlib_decrypt_message(user_state, &ops, jid, from, message, &decrypted, &tlvs);

    // internal libotr message
    if (result == 1) {
        tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
        if (tlv) {
            ConnContext *context = otrlib_context_find(user_state, from, jid);

            if (context != NULL) {
                otrl_context_force_plaintext(context);
                ui_gone_insecure(from);
            }
        }
        return NULL;

    // message was decrypted, return to user
    } else if (decrypted != NULL) {
        *was_decrypted = TRUE;
        return decrypted;

    // normal non OTR message
    } else {
        *was_decrypted = FALSE;
        return strdup(message);
    }
}
Esempio n. 2
0
File: tests.c Progetto: Ri0n/libotr
void test_crash1(void)
{
    ConnContext *alicecontext, *bobcontext;

    printf("\n\n*** Testing old double gcry_cipher_release case ***\n\n");

    otrl_context_forget_all(us);
    ALICEPOLICY = OTRL_POLICY_DEFAULT;
    sending(ALICE, BOB, "?OTR?");
    dispatch();

    alicecontext = otrl_context_find(us, BOB, ALICE, PROTO, 0, 0, NULL, NULL, NULL);
    bobcontext = otrl_context_find(us, ALICE, BOB, PROTO, 0, 0, NULL, NULL, NULL);

    sending(ALICE, BOB, "Hi!"); dispatch();
    sending(BOB, ALICE, "There!"); dispatch();
    sending(ALICE, BOB, "You!"); dispatch();
    otrl_context_force_plaintext(bobcontext);
    sending(BOB, ALICE, "?OTR?"); dispatch();
    sending(ALICE, BOB, "now."); dispatch();
    printf("%d %p %p\n", alicecontext->our_keyid, alicecontext->their_y, alicecontext->their_old_y);
    printf("%p %p %p %p\n",
    alicecontext->sesskeys[0][0].sendenc,
    alicecontext->sesskeys[0][1].sendenc,
    alicecontext->sesskeys[1][0].sendenc,
    alicecontext->sesskeys[1][1].sendenc);
    sending(BOB, ALICE, "then."); dispatch();
}
Esempio n. 3
0
/* Forget all the contexts in a given OtrlUserState. */
void otrl_context_forget_all(OtrlUserState us)
{
    while (us->context_root) {
	otrl_context_force_plaintext(us->context_root);
	otrl_context_forget(us->context_root);
    }
}
Esempio n. 4
0
/* Forget a whole context, so long as it's PLAINTEXT. If a context has child
 * instances, don't remove this instance unless children are also all in
 * PLAINTEXT state. In this case, the children will also be removed.
 * Returns 0 on success, 1 on failure. */
int otrl_context_forget(ConnContext *context)
{
    if (context->msgstate != OTRL_MSGSTATE_PLAINTEXT) return 1;

    if (context->their_instance == OTRL_INSTAG_MASTER) {
	ConnContext *c_iter;

	for (c_iter = context; c_iter &&
		c_iter->m_context == context->m_context;
		c_iter = c_iter->next) {
	    if (c_iter->msgstate != OTRL_MSGSTATE_PLAINTEXT) return 1;
	}

	c_iter = context->next;
	while (c_iter && c_iter->m_context == context->m_context) {
	    if (!otrl_context_forget(c_iter)) {
		c_iter = context->next;
	    } else {
		return 1;
	    }
	}

    }

    /* Just to be safe, force to plaintext.  This also frees any
     * extraneous data lying around. */
    otrl_context_force_plaintext(context);

    /* First free all the Fingerprints */
    while(context->fingerprint_root.next) {
	otrl_context_forget_fingerprint(context->fingerprint_root.next, 0);
    }
    /* Now free all the dynamic info here */
    free(context->username);
    free(context->accountname);
    free(context->protocol);
    free(context->smstate);
    context->username = NULL;
    context->accountname = NULL;
    context->protocol = NULL;
    context->smstate = NULL;

    /* Free the application data, if it exists */
    if (context->app_data && context->app_data_free) {
	(context->app_data_free)(context->app_data);
	context->app_data = NULL;
    }

    /* Fix the list linkages */
    *(context->tous) = context->next;
    if (context->next) {
	context->next->tous = context->tous;
    }

    free(context);
    return 0;
}
Esempio n. 5
0
/* Forget all the contexts in a given OtrlUserState. */
void otrl_context_forget_all(OtrlUserState us)
{
    ConnContext *c_iter;

    for (c_iter = us->context_root; c_iter; c_iter = c_iter->next) {
	otrl_context_force_plaintext(c_iter);
    }

    while (us->context_root) {
	otrl_context_forget(us->context_root);
    }
}
Esempio n. 6
0
File: tests.c Progetto: Ri0n/libotr
void test_unreadable(void)
{
    ConnContext *bobcontext;

    printf("\n\n*** Testing Bob receiving unreadable messages from "
	    "Alice ***\n\n");

    bobcontext = otrl_context_find(us, ALICE, BOB, PROTO, 0, 0, NULL, NULL, NULL);
    otrl_context_force_plaintext(bobcontext);
    sending(ALICE, BOB, "unreadable text");
    dispatch();

}
Esempio n. 7
0
char*
otr_decrypt_message(const char *const from, const char *const message, gboolean *decrypted)
{
    char *newmessage = NULL;
    OtrlTLV *tlvs = NULL;

    int result = otrlib_decrypt_message(user_state, &ops, jid, from, message, &newmessage, &tlvs);

    // internal libotr message
    if (result == 1) {
        ConnContext *context = otrlib_context_find(user_state, from, jid);

        // common tlv handling
        OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
        if (tlv) {
            if (context) {
                otrl_context_force_plaintext(context);
                ProfChatWin *chatwin = wins_get_chat(from);
                if (chatwin) {
                    chatwin_otr_unsecured(chatwin);
                }
            }
        }

        // library version specific tlv handling
        otrlib_handle_tlvs(user_state, &ops, context, tlvs, smp_initiators);
        _otr_tlv_free(tlvs);

        return NULL;

    // message was processed, return to user
    } else if (newmessage) {
        _otr_tlv_free(tlvs);
        if (g_str_has_prefix(message, "?OTR:")) {
            *decrypted = TRUE;
        }
        return newmessage;

    // normal non OTR message
    } else {
        _otr_tlv_free(tlvs);
        *decrypted = FALSE;
        return strdup(message);
    }
}
Esempio n. 8
0
char *
otr_decrypt_message(const char * const from, const char * const message, gboolean *was_decrypted)
{
    char *decrypted = NULL;
    OtrlTLV *tlvs = NULL;

    int result = otrlib_decrypt_message(user_state, &ops, jid, from, message, &decrypted, &tlvs);

    // internal libotr message
    if (result == 1) {
        ConnContext *context = otrlib_context_find(user_state, from, jid);

        // common tlv handling
        OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
        if (tlv) {

            if (context) {
                otrl_context_force_plaintext(context);
                ui_gone_insecure(from);
            }
        }

        // library version specific tlv handling
        otrlib_handle_tlvs(user_state, &ops, context, tlvs, smp_initiators);

        return NULL;

    // message was decrypted, return to user
    } else if (decrypted) {
        *was_decrypted = TRUE;
        return decrypted;

    // normal non OTR message
    } else {
        *was_decrypted = FALSE;
        return strdup(message);
    }
}
Esempio n. 9
0
/* Forget a whole context, so long as it's PLAINTEXT. */
void otrl_context_forget(ConnContext *context)
{
    if (context->msgstate != OTRL_MSGSTATE_PLAINTEXT) return;

    /* Just to be safe, force to plaintext.  This also frees any
     * extraneous data lying around. */
    otrl_context_force_plaintext(context);

    /* First free all the Fingerprints */
    while(context->fingerprint_root.next) {
	otrl_context_forget_fingerprint(context->fingerprint_root.next, 0);
    }
    /* Now free all the dynamic info here */
    free(context->username);
    free(context->accountname);
    free(context->protocol);
    free(context->smstate);
    context->username = NULL;
    context->accountname = NULL;
    context->protocol = NULL;
    context->smstate = NULL;

    /* Free the application data, if it exists */
    if (context->app_data && context->app_data_free) {
	(context->app_data_free)(context->app_data);
	context->app_data = NULL;
    }

    /* Fix the list linkages */
    *(context->tous) = context->next;
    if (context->next) {
	context->next->tous = context->tous;
    }

    free(context);
}