void OtrInternal::startSMP(const QString& account, const QString& contact,
                           const QString& question, const QString& secret)
{
    ConnContext* context = otrl_context_find(m_userstate,
                                             contact.toUtf8().constData(),
                                             account.toUtf8().constData(),
                                             OTR_PROTOCOL_STRING,
#if (OTRL_VERSION_MAJOR >= 4)
                                             OTRL_INSTAG_BEST,
#endif
                                             false, NULL, NULL, NULL);
    if (context)
    {
        QByteArray  secretArray   = secret.toUtf8();
        const char* secretPointer = secretArray.constData();
        size_t      secretLength  = qstrlen(secretPointer);

        if (question.isEmpty())
        {
            otrl_message_initiate_smp(m_userstate, &m_uiOps, this, context,
                                      reinterpret_cast<const unsigned char*>(const_cast<char*>(secretPointer)),
                                      secretLength);
        }
        else
        {
            otrl_message_initiate_smp_q(m_userstate, &m_uiOps, this, context,
                                        question.toUtf8().constData(),
                                        reinterpret_cast<const unsigned char*>(const_cast<char*>(secretPointer)),
                                        secretLength);
        }
    }
}
Beispiel #2
0
void OtrInternal::requestAuth(TreeModelItem &item, bool agree, QString answer, QString question)
{
    qutimotr::Fingerprint fingerprint;
    bool found = false;
    foreach(fingerprint, getFingerprints())
    {
        if (fingerprint.username == item.m_item_name
            && fingerprint.account == item.m_account_name )
        {
            found = true;
            break;
        }
    }
    if(!found)
        return;
    ConnContext *context = otrl_context_find(m_userstate,item.m_item_name.toAscii().data(),item.m_account_name.toAscii().data(),item.m_protocol_name.toAscii().data(),0,NULL,NULL,NULL);
    if(!context)
        return;
    if(!question.isNull())
    {
        otrl_message_initiate_smp_q( m_userstate,&m_uiOps,this,context,question.toAscii(),(unsigned char *)answer.toAscii().data(),answer.toAscii().count());
    } else
        if(!answer.isNull())
        {
        otrl_message_initiate_smp(m_userstate,&m_uiOps,this,context,(unsigned char *)answer.toAscii().data(),answer.toAscii().count());
    } else    
//        if(agree)
        {
        verifyFingerprint(fingerprint, agree);
    }
}
Beispiel #3
0
static void
_otr_smp_question(const char * const recipient, const char *question, const char *answer)
{
    ConnContext *context = otrlib_context_find(user_state, recipient, jid);

    if (context == NULL) {
        return;
    }

    if (context->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
        return;
    }

    otrl_message_initiate_smp_q(user_state, &ops, NULL, context, question, (const unsigned char*)answer, strlen(answer));
    ui_otr_authetication_waiting(recipient);
}
Beispiel #4
0
void
otr_smp_question(const char *const recipient, const char *question, const char *answer)
{
    ConnContext *context = otrlib_context_find(user_state, recipient, jid);

    if (context == NULL) {
        return;
    }

    if (context->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
        return;
    }

    otrl_message_initiate_smp_q(user_state, &ops, NULL, context, question, (const unsigned char*)answer, strlen(answer));
    ProfChatWin *chatwin = wins_get_chat(recipient);
    if (chatwin) {
        chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_AUTH_WAIT, NULL);
    }
}
Beispiel #5
0
/*
 * Initiate or respond to SMP authentication.
 */
void otr_auth(SERVER_REC *irssi, const char *nick, const char *question,
		const char *secret)
{
	int ret;
	size_t secret_len = 0;
	ConnContext *ctx;
	struct otr_peer_context *opc;

	assert(irssi);
	assert(nick);

	ctx = otr_find_context(irssi, nick, 0);
	if (!ctx) {
		IRSSI_NOTICE(irssi, nick, "Context for %9%s%9 not found.", nick);
		goto end;
	}

	opc = ctx->app_data;
	/* Again, code flow error. */
	assert(opc);

	if (ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
		IRSSI_INFO(irssi, nick,
				"You need to establish an OTR session before you "
				"can authenticate.");
		goto end;
	}

	/* Aborting an ongoing auth */
	if (ctx->smstate->nextExpected != OTRL_SMP_EXPECT1) {
		otr_auth_abort(irssi, nick);
	}

	/* reset trust level */
	if (ctx->active_fingerprint) {
		ret = otrl_context_is_fingerprint_trusted(ctx->active_fingerprint);
		if (!ret) {
			otrl_context_set_trust(ctx->active_fingerprint, "");
			key_write_fingerprints(user_state_global);
		}
	}

	/* Libotr allows empty secret. */
	if (secret) {
		secret_len = strlen(secret);
	}

	if (opc->ask_secret) {
		otrl_message_respond_smp(user_state_global->otr_state, &otr_ops,
				irssi, ctx, (unsigned char *) secret, secret_len);
		otr_status_change(irssi, nick, OTR_STATUS_SMP_RESPONDED);
		IRSSI_NOTICE(irssi, nick, "%yResponding to authentication...%n");
	} else {
		if (question) {
			otrl_message_initiate_smp_q(user_state_global->otr_state,
				&otr_ops, irssi, ctx, question, (unsigned char *) secret,
				secret_len);
		} else {
			otrl_message_initiate_smp(user_state_global->otr_state,
				&otr_ops, irssi, ctx, (unsigned char *) secret, secret_len);
		}
		otr_status_change(irssi, nick, OTR_STATUS_SMP_STARTED);
		IRSSI_NOTICE(irssi, nick, "%yInitiated authentication...%n");
	}

	opc->ask_secret = 0;

end:
	return;
}