diff options
author | Timothy Pearson <[email protected]> | 2014-09-22 17:22:32 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2014-09-22 17:22:32 -0500 |
commit | 1b9b8e3c30b106485611a77130ddaa203111d77b (patch) | |
tree | 6fe3d7cd99246e5ef52dd73226610858be9f2baa /src | |
parent | c8e8b9c67e66818b15e29929f8a0ca36a1e94d45 (diff) | |
download | kopete-otr-1b9b8e3c30b106485611a77130ddaa203111d77b.tar.gz kopete-otr-1b9b8e3c30b106485611a77130ddaa203111d77b.zip |
Add preliminary untested support for libotr 4.x
This relates to Bug 1987
Diffstat (limited to 'src')
-rw-r--r-- | src/otrlchatinterface.cpp | 406 | ||||
-rw-r--r-- | src/otrlchatinterface.h | 9 | ||||
-rw-r--r-- | src/smppopup.cpp | 18 | ||||
-rw-r--r-- | src/smppopup.h | 3 |
4 files changed, 419 insertions, 17 deletions
diff --git a/src/otrlchatinterface.cpp b/src/otrlchatinterface.cpp index 7f2a946..49895e4 100644 --- a/src/otrlchatinterface.cpp +++ b/src/otrlchatinterface.cpp @@ -1,6 +1,7 @@ /*************************************************************************** - * Copyright (C) 2007 by Michael Zanetti - * + * Copyright (C) 2007 by Michael Zanetti * + * Copyright (C) 2014 by Timothy Pearson <[email protected]> * + * * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -15,7 +16,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ @@ -59,6 +60,8 @@ #include "privkeypopup.h" #include "smppopup.h" +#include "config.h" + OtrlChatInterface *OtrlChatInterface::mSelf = 0; static OtrlUserState userstate; static OtrlPolicy confPolicy; @@ -140,10 +143,13 @@ static void inject_message( void *opdata, const char *accountname, const char *p } } +#ifndef HAVE_LIBOTR_0400 static void notify(void *opdata, OtrlNotifyLevel level, const char *accountname, const char *protocol, const char *username, const char *title, const char *primary, const char *secondary){ KMessageBox::information(NULL, TQString( primary ) + TQString( secondary ), TQString( title ) ); } +#endif // HAVE_LIBOTR_0400 +#ifndef HAVE_LIBOTR_0400 static int display_otr_message( void *opdata, const char *accountname, const char *protocol, const char *username, const char *message ){ Kopete::ChatSession *session= ((Kopete::ChatSession*)opdata); Kopete::ContactPtrList list = session->members(); @@ -157,20 +163,25 @@ static int display_otr_message( void *opdata, const char *accountname, const cha } return 1; } +#endif // HAVE_LIBOTR_0400 static void update_context_list(void *opdata){ //Not used... } +#ifndef HAVE_LIBOTR_0400 static const char *protocol_name(void *opdata, const char *protocol){ //Never seen... kdDebug() << "protocol_name called" << endl; } +#endif // HAVE_LIBOTR_0400 +#ifndef HAVE_LIBOTR_0400 static void protocol_name_free(void *opdata, const char *protocol_name){ //Never seen... kdDebug() << "protocol_name_free called" << endl; } +#endif // HAVE_LIBOTR_0400 static void new_fingerprint(void *opdata, OtrlUserState us, const char *accountname, const char *protocol, const char *username, unsigned char fingerprint[20]){ kdDebug() << "Received a new Fingerprint" << endl; @@ -197,6 +208,8 @@ static void gone_secure(void *opdata, ConnContext *context){ session->appendMessage( msg ); OTRPlugin::plugin()->emitGoneSecure( ((Kopete::ChatSession*)opdata), 1 ); } + + session->setProperty("otr-instag", QString::number(context->their_instance)); } /* Actually I've never seen this event but its implemented in case someone should receive it @@ -223,10 +236,313 @@ static void still_secure(void *opdata, ConnContext *context, int is_reply){ } } +#ifndef HAVE_LIBOTR_0400 static void log_message(void *opdata, const char *message){ kdDebug() << "libotr: "<< message << endl; } +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +static void received_symkey(void *opdata, ConnContext *context, unsigned int use, const unsigned char *usedata, size_t usedatalen, const unsigned char *symkey){ + // Not used +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +static const char *otr_error_message(void *opdata, ConnContext *context, OtrlErrorCode err_code){ + Q_UNUSED(opdata) + + char *err_msg = 0; + switch (err_code) + { + case OTRL_ERRCODE_NONE : + break; + case OTRL_ERRCODE_ENCRYPTION_ERROR : { + TQString message = i18n("Error occurred encrypting message."); + err_msg = (char*)malloc(message.length() + 1); + memset(err_msg, 0, message.length() + 1); + memcpy(err_msg, message.utf8().data(), message.length()); + break; + } + case OTRL_ERRCODE_MSG_NOT_IN_PRIVATE : + if (context) { + TQString message = i18n("You sent encrypted data to %s, who wasn't expecting it.").arg(context->accountname); + err_msg = (char*)malloc(message.length() + 1); + memset(err_msg, 0, message.length() + 1); + memcpy(err_msg, message.utf8().data(), message.length()); + } + break; + case OTRL_ERRCODE_MSG_UNREADABLE : { + TQString message = i18n("You transmitted an unreadable encrypted message."); + err_msg = (char*)malloc(message.length() + 1); + memset(err_msg, 0, message.length() + 1); + memcpy(err_msg, message.utf8().data(), message.length()); + break; + } + case OTRL_ERRCODE_MSG_MALFORMED : { + TQString message = i18n("You transmitted a malformed data message."); + err_msg = (char*)malloc(message.length() + 1); + memset(err_msg, 0, message.length() + 1); + memcpy(err_msg, message.utf8().data(), message.length()); + break; + } + } + return err_msg; +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +void otr_error_message_free(void *opdata, const char *err_msg){ + Q_UNUSED(opdata) + + if (err_msg) { + free((char*)err_msg); + } +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +const char *resent_msg_prefix(void *opdata, ConnContext *context){ + Q_UNUSED(opdata) + Q_UNUSED(context) + + TQString message = i18n("[resent]"); + char *msg_prefix = (char*)malloc(message.length() + 1); + memset(msg_prefix, 0, message.length() + 1); + memcpy(msg_prefix, message.utf8().data(), message.length()); + return msg_prefix; +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +void resent_msg_prefix_free(void *opdata, const char *prefix){ + Q_UNUSED(opdata) + + if (prefix) { + free((char*)prefix); + } +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +void handle_smp_event(void *opdata, OtrlSMPEvent smp_event, ConnContext *context, unsigned short progress_percent, char *question){ + Q_UNUSED(progress_percent) + + Kopete::ChatSession *chatSession = (Kopete::ChatSession*)opdata; + + if (!context) { + return; + } + + switch (smp_event) { + case OTRL_SMPEVENT_NONE: + break; + case OTRL_SMPEVENT_ASK_FOR_SECRET: { + SMPPopup *popup = new SMPPopup( chatSession->view()->mainWidget(), i18n("Enter authentication secret"), TQString::null, TQt::WStyle_Dialog | TQt::WStyle_StaysOnTop, context, chatSession, false ); + popup->show(); + break; + } + case OTRL_SMPEVENT_ASK_FOR_ANSWER: { + SMPPopup *popup = new SMPPopup( chatSession->view()->mainWidget(), question, question, TQt::WStyle_Dialog | TQt::WStyle_StaysOnTop, context, chatSession, false ); + popup->show(); + break; + } + case OTRL_SMPEVENT_IN_PROGRESS: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("<b>Authenticating contact...</b>"), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_SMPEVENT_SUCCESS: { + if (context->active_fingerprint->trust && context->active_fingerprint->trust[0]) { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("<b>Authentication successful. The conversation is now secure!</b>"), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + OTRPlugin::plugin()->emitGoneSecure( chatSession, 2 ); + } + else { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("<b>Authentication failed. The conversation is now insecure!</b>"), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + OTRPlugin::plugin()->emitGoneSecure( chatSession, 1 ); + } + break; + } + case OTRL_SMPEVENT_FAILURE: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("<b>Authentication failed. The conversation is now insecure!</b>"), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + OTRPlugin::plugin()->emitGoneSecure( chatSession, 1 ); + break; + } + case OTRL_SMPEVENT_ABORT: + case OTRL_SMPEVENT_CHEATED: + case OTRL_SMPEVENT_ERROR: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("<b>Authentication error!</b>"), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + OtrlChatInterface::self()->abortSMP( context, chatSession ); + break; + } + } +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +void handle_msg_event(void *opdata, OtrlMessageEvent msg_event, ConnContext *context, const char *message, gcry_error_t err){ + Kopete::ChatSession *chatSession= ((Kopete::ChatSession*)opdata); + Kopete::ContactPtrList list = chatSession->members(); + + switch (msg_event) + { + case OTRL_MSGEVENT_NONE: + break; + case OTRL_MSGEVENT_ENCRYPTION_REQUIRED: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("You attempted to send an unencrypted message to <b>%1</b>").arg(context->username) , Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_ENCRYPTION_ERROR: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("An error occurred when encrypting your message. The message was not sent."), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_CONNECTION_ENDED: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("<b>%1</b> has ended the OTR session. You should do the same.").arg(context->username) , Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_SETUP_ERROR: { + if (!err) { + err = GPG_ERR_INV_VALUE; + } + switch(gcry_err_code(err)) { + case GPG_ERR_INV_VALUE: + kdDebug() << "Error setting up private conversation: Malformed message received"; + default: + kdDebug() << "Error setting up private conversation:" << err; + } + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("OTR error"), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_MSG_REFLECTED: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("We are receiving our own OTR messages. You are either trying to talk to yourself, or someone is reflecting your messages back at you."), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_MSG_RESENT: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("The last message to <b>%1</b> was resent.").arg(context->username) , Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("The encrypted message received from <b>%1</b> is unreadable, as you are not currently communicating privately.").arg(context->username) , Kopete::Message::Inbound, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + //OtrlChatInterface::self()->m_blacklistIds.append(msg.id()); + break; + } + case OTRL_MSGEVENT_RCVDMSG_UNREADABLE: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("We received an unreadable encrypted message from <b>%1</b>."), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_RCVDMSG_MALFORMED: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("We received a malformed data message from <b>%1</b>."), Kopete::Message::Internal, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_LOG_HEARTBEAT_RCVD: { + kdDebug() << "Heartbeat received from" << context->username; + return; + } + case OTRL_MSGEVENT_LOG_HEARTBEAT_SENT: { + kdDebug() << "Heartbeat sent to" << context->username; + break; + } + case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), message, Kopete::Message::Inbound, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + break; + } + case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("<b>The following message received from <b>%1</b> was <i>not</i> encrypted: [</b>%2<b>]</b>").arg(context->username).arg(message), Kopete::Message::Inbound, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + //OtrlChatInterface::self()->m_blacklistIds.append(msg.id()); + break; + } + case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED: { + kdDebug() << "Unrecognized OTR message received from" << context->username; + break; + } + case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE: { + Kopete::Message msg( chatSession->members().getFirst(), chatSession->account()->myself(), i18n("<b>%1</b> has sent an encrypted message intended for a different session. If you are logged in multiple times, another session may have received the message.").arg(context->username), Kopete::Message::Inbound, Kopete::Message::RichText ); + chatSession->appendMessage( msg ); + //OtrlChatInterface::self()->m_blacklistIds.append(msg.id()); + break; + } + } +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +void create_instag(void *opdata, const char *accountname, const char *protocol){ + Q_UNUSED(opdata) + + otrl_instag_generate(OtrlChatInterface::self()->getUserstate(), TQString(TDEGlobal::dirs()->saveLocation("data", "kopete_otr/", true )) + "instags", accountname, protocol); +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +void convert_msg(void *opdata, ConnContext *context, OtrlConvertType convert_type, char ** dest, const char *src){ + // Not used +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +void convert_free(void *opdata, ConnContext *context, char *dest){ + // Not used +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +void timer_control(void *opdata, unsigned int interval){ + kdDebug() << "timer_control called" << endl; + + Q_UNUSED(opdata) + if (interval > 0) { + OtrlChatInterface::self()->forwardSecrecyTimerStart(interval); + } + else { + OtrlChatInterface::self()->forwardSecrecyTimerStop(); + } +} +#endif // HAVE_LIBOTR_0400 + +#ifdef HAVE_LIBOTR_0400 +static OtrlMessageAppOps ui_ops = { + policy, + create_privkey, + is_logged_in, + inject_message, + update_context_list, + new_fingerprint, + write_fingerprints, + gone_secure, + gone_insecure, + still_secure, + NULL, // max_message_size, + NULL, // account_name, + NULL, // account_name_free, + received_symkey, + otr_error_message, + otr_error_message_free, + resent_msg_prefix, + resent_msg_prefix_free, + handle_smp_event, + handle_msg_event, + create_instag, + NULL, // convert_msg, + NULL, // convert_free, + timer_control +}; +#else // HAVE_LIBOTR_0400 static OtrlMessageAppOps ui_ops = { policy, create_privkey, @@ -244,6 +560,7 @@ static OtrlMessageAppOps ui_ops = { still_secure, log_message }; +#endif // HAVE_LIBOTR_0400 /*********************** Gui_UI_Ops finished *************************/ @@ -258,11 +575,15 @@ OtrlChatInterface::OtrlChatInterface(){ userstate = otrl_userstate_create(); otrl_privkey_read( userstate, TQString(TDEGlobal::dirs()->saveLocation("data", "kopete_otr/", true )) + "privkeys" ); - - otrl_privkey_read_fingerprints(userstate, TQString(TDEGlobal::dirs()->saveLocation("data", "kopete_otr/", true )) + "fingerprints", NULL, NULL); + otrl_instag_read(userstate, TQString(TDEGlobal::dirs()->saveLocation("data", "kopete_otr/", true )) + "instags"); + + unsigned int interval = otrl_message_poll_get_default_interval(userstate); + forwardSecrecyTimerStart(interval); + connect(&m_forwardSecrecyTimer, SIGNAL(timeout()), this, SLOT(otrlMessagePoll())); + } OtrlChatInterface::~ OtrlChatInterface(){ @@ -277,6 +598,18 @@ OtrlChatInterface *OtrlChatInterface::self(){ return mSelf; } +void OtrlChatInterface::forwardSecrecyTimerStart(int interval){ + m_forwardSecrecyTimer.start(interval * 1000); +} + +void OtrlChatInterface::forwardSecrecyTimerStop(){ + m_forwardSecrecyTimer.stop(); +} + +void OtrlChatInterface::otrlMessagePoll(){ + otrl_message_poll(userstate, 0, 0); +} + /********************* Chat section ***************************/ OtrlUserState OtrlChatInterface::getUserstate(){ @@ -294,8 +627,11 @@ int OtrlChatInterface::decryptMessage( TQString *msg, TQString accountId, ConnContext *context; NextExpectedSMP nextMsg; - +#ifdef HAVE_LIBOTR_0400 + ignoremessage = otrl_message_receiving( userstate, &ui_ops, chatSession, accountId.latin1(), protocol.latin1(), contactId.latin1(), msg->latin1(), &newMessage, &tlvs, NULL, NULL, NULL ); +#else // HAVE_LIBOTR_0400 ignoremessage = otrl_message_receiving( userstate, &ui_ops, chatSession, accountId.latin1(), protocol.latin1(), contactId.latin1(), msg->latin1(), &newMessage, &tlvs, NULL, NULL ); +#endif // HAVE_LIBOTR_0400 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); @@ -306,7 +642,11 @@ int OtrlChatInterface::decryptMessage( TQString *msg, TQString accountId, OTRPlugin::plugin()->emitGoneSecure( chatSession, 3 ); } +#ifdef HAVE_LIBOTR_0400 + context = otrl_context_find( userstate, contactId.latin1(), accountId.latin1(), protocol.latin1(), 0, 0, NULL, NULL, NULL); +#else // HAVE_LIBOTR_0400 context = otrl_context_find( userstate, contactId.latin1(), accountId.latin1(), protocol.latin1(), 0, NULL, NULL, NULL); +#endif // HAVE_LIBOTR_0400 if (context) { nextMsg = context->smstate->nextExpected; @@ -315,7 +655,7 @@ int OtrlChatInterface::decryptMessage( TQString *msg, TQString accountId, if (nextMsg != OTRL_SMP_EXPECT1){ abortSMP( context, chatSession ); } else { - SMPPopup *popup = new SMPPopup( chatSession->view()->mainWidget(), i18n("Enter authentication secret"), TQt::WStyle_Dialog | TQt::WStyle_StaysOnTop, context, chatSession, false ); + SMPPopup *popup = new SMPPopup( chatSession->view()->mainWidget(), i18n("Enter authentication secret"), TQString::null, TQt::WStyle_Dialog | TQt::WStyle_StaysOnTop, context, chatSession, false ); popup->show(); } } @@ -392,7 +732,12 @@ TQString OtrlChatInterface::encryptMessage( TQString msg, TQString accountId, char * newMessage; if( otrl_proto_message_type( msg ) == OTRL_MSGTYPE_NOTOTR ){ msg.replace( TQString("<"), TQString("<"), false ); +#ifdef HAVE_LIBOTR_0400 + otrl_instag_t instance = chatSession->property("otr-instag").toUInt(); + err = otrl_message_sending( userstate, &ui_ops, chatSession, accountId.latin1(), protocol.latin1(), contactId.latin1(), instance, msg.utf8(), NULL, &newMessage, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, NULL, NULL ); +#else // HAVE_LIBOTR_0400 err = otrl_message_sending( userstate, &ui_ops, chatSession, accountId.latin1(), protocol.latin1(), contactId.latin1(), msg.utf8(), NULL, &newMessage, NULL, NULL ); +#endif // HAVE_LIBOTR_0400 if( err != 0 ){ msg = i18n("Encryption error"); @@ -419,7 +764,12 @@ TQString OtrlChatInterface::getDefaultQuery( TQString accountId ){ } void OtrlChatInterface::disconnectSession( Kopete::ChatSession *chatSession ){ +#ifdef HAVE_LIBOTR_0400 + otrl_instag_t instance = chatSession->property("otr-instag").toUInt(); + otrl_message_disconnect( userstate, &ui_ops, chatSession, chatSession->account()->accountId().latin1(), chatSession->account()->protocol()->displayName().latin1(), chatSession->members().getFirst()->contactId(), instance ); +#else // HAVE_LIBOTR_0400 otrl_message_disconnect( userstate, &ui_ops, chatSession, chatSession->account()->accountId().latin1(), chatSession->account()->protocol()->displayName().latin1(), chatSession->members().getFirst()->contactId() ); +#endif // HAVE_LIBOTR_0400 OTRPlugin::plugin()->emitGoneSecure( chatSession, false ); Kopete::Message msg( chatSession->account()->myself(), chatSession->members().getFirst(), i18n("Terminating OTR session."), Kopete::Message::Internal ); @@ -451,8 +801,13 @@ void OtrlChatInterface::setPolicy( OtrlPolicy policy ){ int OtrlChatInterface::privState( Kopete::ChatSession *session ){ ConnContext *context; - + +#ifdef HAVE_LIBOTR_0400 + otrl_instag_t instance = session->property("otr-instag").toUInt(); + context = otrl_context_find(userstate, session->members().getFirst()->contactId(), session->account()->accountId(), session->account()->protocol()->displayName(), instance, 0, NULL, NULL, NULL); +#else // HAVE_LIBOTR_0400 context = otrl_context_find(userstate, session->members().getFirst()->contactId(), session->account()->accountId(), session->account()->protocol()->displayName(), 0, NULL, NULL, NULL); +#endif // HAVE_LIBOTR_0400 if( context ){ switch( context->msgstate ){ @@ -485,12 +840,15 @@ TQString OtrlChatInterface::formatContact(TQString contactId){ void OtrlChatInterface::verifyFingerprint( Kopete::ChatSession *session ){ ConnContext *context; +#ifdef HAVE_LIBOTR_0400 + otrl_instag_t instance = session->property("otr-instag").toUInt(); + context = otrl_context_find( userstate, session->members().getFirst()->contactId().latin1(), session->account()->accountId().latin1(), session->protocol()->displayName().latin1(), instance, 0, NULL, NULL, NULL); +#else // HAVE_LIBOTR_0400 context = otrl_context_find( userstate, session->members().getFirst()->contactId().latin1(), session->account()->accountId().latin1(), session->protocol()->displayName().latin1(), 0, NULL, NULL, NULL); +#endif // HAVE_LIBOTR_0400 - SMPPopup *popup = new SMPPopup( session->view()->mainWidget(), i18n("Enter authentication secret"), TQt::WStyle_Dialog | TQt::WStyle_StaysOnTop, context, session, true ); + SMPPopup *popup = new SMPPopup( session->view()->mainWidget(), i18n("Enter authentication secret"), TQString::null, TQt::WStyle_Dialog | TQt::WStyle_StaysOnTop, context, session, true ); popup->show(); - - } void OtrlChatInterface::setTrust( Kopete::ChatSession *session, bool trust ){ @@ -656,11 +1014,33 @@ void OtrlChatInterface::abortSMP( ConnContext *context, Kopete::ChatSession *ses void OtrlChatInterface::respondSMP( ConnContext *context, Kopete::ChatSession *session, TQString secret, bool initiate ){ if( initiate ){ +#ifdef HAVE_LIBOTR_0400 + otrl_instag_t instance = session->property("otr-instag").toUInt(); + context = otrl_context_find( userstate, session->members().getFirst()->contactId().latin1(), session->account()->accountId().latin1(), session->protocol()->displayName().latin1(), instance, 0, NULL, NULL, NULL); +#else // HAVE_LIBOTR_0400 context = otrl_context_find( userstate, session->members().getFirst()->contactId().latin1(), session->account()->accountId().latin1(), session->protocol()->displayName().latin1(), 0, NULL, NULL, NULL); +#endif // HAVE_LIBOTR_0400 otrl_message_initiate_smp( userstate, &ui_ops, session, context, (unsigned char*)secret.latin1(), secret.length() ); + } + else { + otrl_message_respond_smp( userstate, &ui_ops, session, context, (unsigned char*)secret.latin1(), secret.length()); + } - - } else { + Kopete::Message msg( session->members().getFirst(), session->account()->myself(), i18n("<b>Authenticating contact...</b>"), Kopete::Message::Internal, Kopete::Message::RichText ); + session->appendMessage( msg ); +} + +void OtrlChatInterface::respondSMPQ( ConnContext *context, Kopete::ChatSession *session, TQString question, TQString secret, bool initiate ){ + if( initiate ){ +#ifdef HAVE_LIBOTR_0400 + otrl_instag_t instance = session->property("otr-instag").toUInt(); + context = otrl_context_find( userstate, session->members().getFirst()->contactId().latin1(), session->account()->accountId().latin1(), session->protocol()->displayName().latin1(), instance, 0, NULL, NULL, NULL); +#else // HAVE_LIBOTR_0400 + context = otrl_context_find( userstate, session->members().getFirst()->contactId().latin1(), session->account()->accountId().latin1(), session->protocol()->displayName().latin1(), 0, NULL, NULL, NULL); +#endif // HAVE_LIBOTR_0400 + otrl_message_initiate_smp_q( userstate, &ui_ops, session, context, (const char*)question.latin1(), (unsigned char*)secret.latin1(), secret.length() ); + } + else { otrl_message_respond_smp( userstate, &ui_ops, session, context, (unsigned char*)secret.latin1(), secret.length()); } diff --git a/src/otrlchatinterface.h b/src/otrlchatinterface.h index 1fa499b..1f2fd3e 100644 --- a/src/otrlchatinterface.h +++ b/src/otrlchatinterface.h @@ -30,6 +30,7 @@ #include <tqvaluelist.h> #include <tqthread.h> #include <tqmutex.h> +#include <tqtimer.h> #include <kopetechatsession.h> @@ -42,6 +43,7 @@ extern "C" { class OtrlChatInterface: public TQObject { + Q_OBJECT public: ~OtrlChatInterface(); @@ -65,12 +67,19 @@ public: void verifyFingerprint( Kopete::ChatSession *session ); void abortSMP( ConnContext *context, Kopete::ChatSession *session ); void respondSMP( ConnContext *context, Kopete::ChatSession *session, TQString secret, bool initiate ); + void respondSMPQ( ConnContext *context, Kopete::ChatSession *session, TQString question, TQString secret, bool initiate ); void setTrust( Kopete::ChatSession *session, bool trust ); + void forwardSecrecyTimerStart(int interval); + void forwardSecrecyTimerStop(); + +private slots: + void otrlMessagePoll(); private: OtrlChatInterface(); static OtrlChatInterface *mSelf; Fingerprint *findFingerprint( TQString username ); + TQTimer m_forwardSecrecyTimer; }; class KeyGenThread : public TQThread { diff --git a/src/smppopup.cpp b/src/smppopup.cpp index 59fa9f2..66f28c1 100644 --- a/src/smppopup.cpp +++ b/src/smppopup.cpp @@ -29,13 +29,20 @@ #include "smppopup.h" #include "verifypopup.h" -SMPPopup::SMPPopup(TQWidget* parent, const char* name, WFlags fl, ConnContext *context, Kopete::ChatSession *session, bool initiate ) +SMPPopup::SMPPopup(TQWidget* parent, const char* name, TQString title, WFlags fl, ConnContext *context, Kopete::ChatSession *session, bool initiate ) : SMPPopupUI(parent,name,fl) { this->context = context; this->session = session; this->initiate = initiate; - tlText->setText( i18n("Please enter the secret passphrase to authenticate %1:").arg(OtrlChatInterface::self()->formatContact(session->members().getFirst()->contactId()))); + if (title.isNull()) { + question = false; + tlText->setText( i18n("Please enter the secret passphrase to authenticate %1:").arg(OtrlChatInterface::self()->formatContact(session->members().getFirst()->contactId()))); + } + else { + question = true; + tlText->setText( title ); + } } SMPPopup::~SMPPopup() @@ -51,7 +58,12 @@ void SMPPopup::cancelSMP() void SMPPopup::respondSMP() { - OtrlChatInterface::self()->respondSMP( context, session, leSecret->text(), initiate ); + if (question) { + OtrlChatInterface::self()->respondSMPQ( context, session, tlText->text(), leSecret->text(), initiate ); + } + else { + OtrlChatInterface::self()->respondSMP( context, session, leSecret->text(), initiate ); + } this->close(); } diff --git a/src/smppopup.h b/src/smppopup.h index edbdf64..69c9513 100644 --- a/src/smppopup.h +++ b/src/smppopup.h @@ -36,7 +36,7 @@ class SMPPopup : public SMPPopupUI public: - SMPPopup(TQWidget* parent = 0, const char* name = 0, WFlags fl = 0, ConnContext *context = 0, Kopete::ChatSession *session = 0, bool initiate = true ); + SMPPopup(TQWidget* parent = 0, const char* name = 0, TQString title = TQString::null, WFlags fl = 0, ConnContext *context = 0, Kopete::ChatSession *session = 0, bool initiate = true ); ~SMPPopup(); /*$PUBLIC_FUNCTIONS$*/ @@ -53,6 +53,7 @@ protected: ConnContext *context; Kopete::ChatSession *session; bool initiate; + bool question; protected slots: /*$PROTECTED_SLOTS$*/ |