/**
 * Returns a list of all known fingerprints.
 *
 */
QList< Fprint > OtrConnection::getFingerprints() {
	QList< Fprint > fpList;
	ConnContext* context;
	Fingerprint* fingerprint;
	char hash[45];
	for (context = userstate->context_root; context != NULL; context = context->next) {
		fingerprint = context->fingerprint_root.next;
		while(fingerprint) {
			Fprint fpData;
			// my account
			fpData.setAccount(context->accountname); 
			// buddy username
			fpData.setUsername(context->username);
			// fingerprint
	    		fpData.setFingerprint(fingerprint->fingerprint);
			otrl_privkey_hash_to_human(hash, fingerprint->fingerprint);
		    	fpData.setFingerprintHuman(hash);
			// trust level 
			fpData.setTrust(fingerprint->trust);
			// message state
			fpData.setMessageState(getMessageStateString(
				context->accountname,
				context->username));
			fpList.append(fpData);	
			fingerprint = fingerprint->next;
		}
	}
	return fpList;
}
/**
 * Decrypt a received message.
 */
const char* OtrConnection::decryptMessage(const char* from, const char* to, const char* cryptedMessage) {
	int ignore_message = 0;
	char *newMessage = NULL;

    	ignore_message = otrl_message_receiving(
    		userstate, 
	    	&ui_ops,
    		this,
       		to,
  		"prpl-jabber",
        	from,
        	cryptedMessage,
        	&newMessage,
        	NULL,
        	NULL,
        	NULL);
	if (ignore_message == 1) {
		// internal protocol message. show user what kind of message was received.
		QString msg;
		OtrlMessageType type = otrl_proto_message_type(cryptedMessage);
		if (type == OTRL_MSGTYPE_NOTOTR) msg = "no OTR Message";
		else if (type == OTRL_MSGTYPE_TAGGEDPLAINTEXT) msg= "OTR TaggedPlaintexMessage";
		else if (type == OTRL_MSGTYPE_QUERY) msg= "OTR QueryMessage";
		else if (type == OTRL_MSGTYPE_DH_COMMIT) msg= "OTR DH-Commit Message";
		else if (type == OTRL_MSGTYPE_DH_KEY) msg= "OTR DH-Key Message";
		else if (type == OTRL_MSGTYPE_REVEALSIG) msg= "OTR Reveal Signature Message";
		else if (type == OTRL_MSGTYPE_SIGNATURE) msg= "OTR Signature Message";
		else if (type == OTRL_MSGTYPE_V1_KEYEXCH) msg= "OTR Version 1 Key Exchange Message";
		else if (type == OTRL_MSGTYPE_DATA) msg ="OTR Data Message";
		else if (type == OTRL_MSGTYPE_ERROR) msg ="OTR Error Message";
		else if (type == OTRL_MSGTYPE_UNKNOWN) msg= "OTR Unknown Message";
		else msg= "Unknown Message Type";
		
		msg.insert(0, "Received ");
		QString state = "[" + getMessageStateString(to, from) + "]";
		msg.append(" " + state);	
		OtrlMessageState* stateId;
		stateId = getMessageState(to, from);
		if (stateId != NULL && *stateId == OTRL_MSGSTATE_ENCRYPTED) {
			msg.append("\nsessionId: " + getSessionId(to, from));
		}
		char* retMsg = (char*) malloc( msg.length() + 1 );
		strcpy(retMsg, msg.toStdString().c_str());
		return retMsg;
	}
	else if (ignore_message == 0) {
		if (newMessage != NULL) {
			// replace message
			return newMessage;
		}
		else {
			// no otr message
			char* retMsg = (char*) malloc(strlen(cryptedMessage)+1);
			strcpy(retMsg, cryptedMessage);
			return retMsg;
		}
	}
	return NULL;	
}
Ejemplo n.º 3
0
QList<qutimotr::Fingerprint> OtrInternal::getFingerprints()
{
    QList<qutimotr::Fingerprint> fpList;
    ConnContext* context;
    ::Fingerprint* fingerprint;

    for (context = m_userstate->context_root; context != NULL;
         context = context->next)
    {
        fingerprint = context->fingerprint_root.next;
        while(fingerprint)
        {
            qutimotr::Fingerprint fp;

            fp.account = QString(context->accountname);

            fp.username = QString(context->username);

            fp.fingerprint = fingerprint->fingerprint;
            char fpHash[45];
            otrl_privkey_hash_to_human(fpHash, fingerprint->fingerprint);
            fp.fingerprintHuman = QString(fpHash);

            fp.trust = QString(fingerprint->trust);

            if (fingerprint == context->active_fingerprint)
            {
                TreeModelItem item;
                item.m_account_name = context->accountname;
                item.m_item_type = 0;
                item.m_protocol_name = context->protocol;
                fp.messageState = QString(
                    getMessageStateString(context->accountname,
                                          context->username,
                                          item));
            }
            else
            {
                fp.messageState.clear();
            }

            fpList.append(fp);
            fingerprint = fingerprint->next;
        }
    }
    return fpList;
}
Ejemplo n.º 4
0
QString OtrInternal::decryptMessage(const QString& from, const QString& to,
                                    const QString& cryptedMessage, TreeModelItem &item)
{
    QString protocol = item.m_protocol_name;
    int ignoreMessage = 0;
    char *newMessage = NULL;
    OtrlTLV *tlvs = NULL;
    OtrlTLV *tlv = NULL;
    ConnContext *context = 0;
    NextExpectedSMP nextMsg;

    ignoreMessage = otrl_message_receiving(m_userstate, &m_uiOps, this,
                                           to.toStdString().c_str(),
                                           protocol.toStdString().c_str(),
                                           from.toStdString().c_str(),
                                           cryptedMessage.toUtf8().data(),
                                           &newMessage,
                                           &tlvs, NULL, NULL);

    context = otrl_context_find( m_userstate, from.toStdString().c_str(), to.toStdString().c_str(), protocol.toStdString().c_str(), 0, NULL, NULL, NULL);

//    qDebug() << "[OTR] context fragment: " << QString(context->lastmessage);

    tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
    if( tlv ){
            sendCustomNessage(item,tr("%1 has ended the OTR session. You should do the same.").arg(item.m_item_name));
            gone_insecure(context);
    }

    while (context) {
        OtrlSMState *state = context->smstate;
        if(!state)
            break;
        nextMsg = state->nextExpected;
        tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1Q);
        if (tlv) {
//            qDebug() << "[OTR] SMP detected. Found SMP1Q";
            //a-la pidgin
            if (nextMsg != OTRL_SMP_EXPECT1)
                abortSMP(context,item);
            else {
                char *question = (char *)tlv->data;
                char *eoq = (char*)memchr(question, '\0', tlv->len);
                if (eoq)
                {
                    QString ans = QInputDialog::getText(NULL,tr("Auth"),tr("Please, answer the question to be authorised by %1.<br>Question: <b>%2</b>").arg(from).arg(QString(question)));
                    if(!ans.isEmpty())
                        respondSMP(context,item,ans,false);
                    else
                        abortSMP(context,item);
                }
            }
        }

        tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
        if (tlv) {
//            qDebug() << "[OTR] SMP detected. Found SMP1";
            if (nextMsg != OTRL_SMP_EXPECT1 ){
                abortSMP( context, item );
            } else {
                QString s = QInputDialog::getText ( NULL, tr("Authorysing"), tr("Please, enter passphrase to authorise %1").arg(context->username), QLineEdit::Normal);
                if(!s.isEmpty())
                    respondSMP(context,item,s,false);
                else
                    abortSMP(context,item);
            }
        }
        tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
        if (tlv) {
//            qDebug() << "[OTR] SMP detected. Found SMP2";
            if (nextMsg != OTRL_SMP_EXPECT2){
                abortSMP( context, item );
            } else {
                context->smstate->nextExpected = OTRL_SMP_EXPECT4;
            }
        }
        tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
        if (tlv) {
//            qDebug() << "[OTR] SMP detected. Found SMP3";
            if (nextMsg != OTRL_SMP_EXPECT3){
                abortSMP( context, item );
            } else {
                if (context->active_fingerprint->trust && context->active_fingerprint->trust[0]) {
                    sendCustomNessage(item, tr("Your buddy has successfully authenticated you. The conversation is now secure!"));
                    gone_secure(context);
                } else {
//                    sendCustomNessage(item, tr("Authentication failed. The conversation is now insecure!"));
                    sendCustomNessage(item,tr("Your buddy has successfully authenticated you. You may want to authenticate your buddy as well by asking your own question."));
                    gone_secure(context);
                }

                context->smstate->nextExpected = OTRL_SMP_EXPECT1;
            }
        }
        tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
        if (tlv) {
//            qDebug() << "[OTR] SMP detected. Found SMP4";
            if (nextMsg != OTRL_SMP_EXPECT4) {
                abortSMP( context, item );
            } else {
                if (context->active_fingerprint->trust && context->active_fingerprint->trust[0]) {
                    sendCustomNessage(item, tr("Authentication successful. The conversation is now secure!"));
                    gone_secure(context);
                } else {
                    sendCustomNessage(item, tr("Authentication failed. The conversation is now insecure!"));
                    gone_secure(context);
                }
                context->smstate->nextExpected = OTRL_SMP_EXPECT1;
            }
        }
        tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);
        if (tlv) {
//            qDebug() << "[OTR] SMP detected. Found SMP_ABORT";
            sendCustomNessage(item,tr("Authentication error!").toLocal8Bit() );
            context->smstate->nextExpected = OTRL_SMP_EXPECT1;
        }

        otrl_tlv_free(tlvs);
        break;
    }

    if (ignoreMessage == 1) // internal protocol message
    {
        OtrlMessageType type = otrl_proto_message_type(
                cryptedMessage.toStdString().c_str());


        QString retMessage("<Internal OTR message>\n"+tr("received %1 \nOTR state now is [%2]").arg(otrlMessageTypeToString(type)).arg(getMessageStateString(to, from, item))) ;

        if (getMessageState(to, from, item) == qutimotr::OTR_MESSAGESTATE_ENCRYPTED)
        {
            retMessage.append(tr("\nsessionId: ") + getSessionId(to, from, item));
        }

//        TODO: если бы эти сообщения можна было заблокировать...
//        но recivelevel1/2 не дает такой возможности... почему то
//        хотя в вики написано обратное
//        sendCustomNessage(item,retMessage);

        return retMessage;
    }
    else if (ignoreMessage == 0)
    {
        if (newMessage != NULL) // message has been decrypted. replace it
        {
            QString retMessage = QString::fromUtf8(newMessage);
            otrl_message_free(newMessage);

            return retMessage;
        }
        else // received message was not an otr message
        {
            return cryptedMessage;
        }
    }

    assert(false);
    return QString();
}