[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:08:19 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=049f400
The following commit has been merged in the master branch:
commit 049f400e481a0b305ab10f5afc745585479647e1
Author: Marcin Ziemiński <zieminn at gmail.com>
Date: Wed Jul 23 21:38:36 2014 +0200
Implemented Session - fundamental OTR actions added
Signed-off-by: Marcin Ziemiński <zieminn at gmail.com>
---
otr-proxy/CMakeLists.txt | 5 +-
otr-proxy/KTpProxy/CMakeLists.txt | 1 +
otr-proxy/KTpProxy/otr-constants.h | 8 ++
otr-proxy/KTpProxy/otr-handler.h | 2 +-
otr-proxy/KTpProxy/otr-manager.cpp | 66 +++++----
otr-proxy/KTpProxy/otr-manager.h | 7 +-
otr-proxy/KTpProxy/otr-message.cpp | 1 +
otr-proxy/KTpProxy/otr-session.cpp | 173 ++++++++++++++++++++++-
otr-proxy/KTpProxy/otr-session.h | 45 ++++--
otr-proxy/KTpProxy/{otr-config.h => otr-utils.h} | 27 ++--
10 files changed, 274 insertions(+), 61 deletions(-)
diff --git a/otr-proxy/CMakeLists.txt b/otr-proxy/CMakeLists.txt
index b5e0c19..2077832 100644
--- a/otr-proxy/CMakeLists.txt
+++ b/otr-proxy/CMakeLists.txt
@@ -11,11 +11,14 @@ set(CMAKE_MODULE_PATH
find_package (KDE4 ${KDE_MIN_VERSION} REQUIRED)
find_package (TelepathyQt4 0.9.1 REQUIRED)
find_package (TelepathyQt4Service 0.9.2.1 REQUIRED)
-find_package (LibOTR 4.0.0 REQUIRED)
+find_package (Libgcrypt REQUIRED)
+
+FIND_LIBRARY (LIBGCRYPT_LIBS NAMES gcrypt)
include_directories (${KDE4_INCLUDES}
${TELEPATHY_QT4_INCLUDE_DIR}
${LIBOTR_INCLUDE_DIR}
+ ${LIBGCRYPT_INCLUDE_DIR}
)
include (KDE4Defaults)
diff --git a/otr-proxy/KTpProxy/CMakeLists.txt b/otr-proxy/KTpProxy/CMakeLists.txt
index 6b1b684..a3ea9d4 100644
--- a/otr-proxy/KTpProxy/CMakeLists.txt
+++ b/otr-proxy/KTpProxy/CMakeLists.txt
@@ -20,6 +20,7 @@ set(ktp-proxy_LIBS
${TELEPATHY_QT4_LIBRARIES}
${TELEPATHY_QT4_SERVICE_LIBRARIES}
${LIBOTR_LIBRARY}
+ ${LIBGCRYPT_LIBRARIES}
)
kde4_add_executable(ktp-proxy ${ktp-proxy_SRCS})
diff --git a/otr-proxy/KTpProxy/otr-constants.h b/otr-proxy/KTpProxy/otr-constants.h
index 24724f9..0501413 100644
--- a/otr-proxy/KTpProxy/otr-constants.h
+++ b/otr-proxy/KTpProxy/otr-constants.h
@@ -37,6 +37,14 @@ namespace OTR
INTERNAL
};
+ enum class CryptResult : unsigned int
+ {
+ UNCHANGED,
+ CHANGED,
+ INGORE,
+ ERROR
+ };
+
template <typename T> unsigned int toUInt(T &&t)
{
return static_cast<unsigned int>(t);
diff --git a/otr-proxy/KTpProxy/otr-handler.h b/otr-proxy/KTpProxy/otr-handler.h
index 74cb36d..abb8448 100644
--- a/otr-proxy/KTpProxy/otr-handler.h
+++ b/otr-proxy/KTpProxy/otr-handler.h
@@ -48,7 +48,7 @@ namespace OTR
virtual ~Handler();
virtual const SessionContext& context() const = 0;
- virtual void sendMessage(const Message &message) = 0;
+ virtual void handleMessage(const Message &message) = 0;
virtual void handleSmpEvent(OtrlSMPEvent smpEvent) = 0;
/**
* State of the recipient
diff --git a/otr-proxy/KTpProxy/otr-manager.cpp b/otr-proxy/KTpProxy/otr-manager.cpp
index 70242b3..ce04e69 100644
--- a/otr-proxy/KTpProxy/otr-manager.cpp
+++ b/otr-proxy/KTpProxy/otr-manager.cpp
@@ -18,6 +18,7 @@
***************************************************************************/
#include "otr-manager.h"
+#include "otr-utils.h"
namespace OTR
{
@@ -47,8 +48,7 @@ namespace {
break;
}
- session->setTrustLevel(level);
- session->handler()->onTrustLevelChanged(level);
+ session->onTrustLevelChanged(level, context);
}
/** OTR ops functions ------------------------------------------------------------------------- */
@@ -62,7 +62,11 @@ namespace {
void create_privkey(void *opdata, const char *accountname, const char *protocol)
{
+ Q_UNUSED(accountname);
+ Q_UNUSED(protocol);
+ Session *session = reinterpret_cast<Session*>(opdata);
+ session->parent()->createNewPrivateKey(session);
}
int is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient)
@@ -72,7 +76,7 @@ namespace {
Q_UNUSED(recipient);
Session *session = reinterpret_cast<Session*>(opdata);
- return session->handler()->recipientStatus();
+ return session->recipientStatus();
}
void inject_message(void *opdata, const char *accountname,
@@ -88,7 +92,7 @@ namespace {
msg.setDirection(MessageDirection::TO_PEER);
Session *session = reinterpret_cast<Session*>(opdata);
- session->handler()->sendMessage(msg);
+ session->handleMessage(msg);
}
void update_context_list(void *opdata)
@@ -106,11 +110,8 @@ namespace {
Q_UNUSED(protocol);
Q_UNUSED(username);
- char human[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
- otrl_privkey_hash_to_human(human, fingerprint);
-
Session *session = reinterpret_cast<Session*>(opdata);
- session->handler()->onNewFingeprintReceived(QString::fromLocal8Bit(human, OTRL_PRIVKEY_FPRINT_HUMAN_LEN));
+ session->onNewFingerprintReceived(OTR::utils::humanReadable(fingerprint));
}
void write_fingerprints(void *opdata)
@@ -137,7 +138,7 @@ namespace {
Q_UNUSED(is_reply);
Session *session = reinterpret_cast<Session*>(opdata);
- session->handler()->onSessionRefreshed();
+ session->onSessionRefreshed();
}
int max_message_size(void *opdata, ConnContext *context)
@@ -145,7 +146,7 @@ namespace {
Q_UNUSED(context);
Session *session = reinterpret_cast<Session*>(opdata);
- return session->handler()->maxMessageSize();
+ return session->maxMessageSize();
}
const char* otr_error_message(void *opdata, ConnContext *context,
@@ -338,7 +339,7 @@ namespace {
}
Session *session = reinterpret_cast<Session*>(opdata);
- session->handler()->sendMessage(msg);
+ session->handleMessage(msg);
}
void create_instag(void *opdata, const char *accountname,
@@ -357,7 +358,11 @@ namespace {
session->userStateBox()->setInterval(interval);
}
- /** OTR ops struct ---------------------------------------------------------------------------- */
+} /* anonymous namespace */
+
+/** OTR ops struct ---------------------------------------------------------------------------- */
+namespace global
+{
const OtrlMessageAppOps appOps = {
policy,
create_privkey,
@@ -384,9 +389,7 @@ namespace {
NULL, /* convert_data_free */
timer_control
};
-
-} /* anonymous namespace */
-
+} /* global namespace */
/** Manager implementation -------------------------------------------------------------------- */
Manager::Manager(Config *otrConfig)
@@ -394,27 +397,27 @@ Manager::Manager(Config *otrConfig)
{
}
-SessionPtr Manager::createSession(const HandlerPtr &handler)
+UserStateBox* Manager::getUserState(const SessionContext &ctx)
{
- auto usIt = userStates.find(handler->context().accountId);
+ auto usIt = userStates.find(ctx.accountId);
if(usIt == userStates.end()) {
// initiate new userstate
OtrlUserState userstate = otrl_userstate_create();
- QString path = config->saveLocation() + handler->context().accountId + QLatin1String("_privkeys");
+ QString path = config->saveLocation() + ctx.accountId + QLatin1String("_privkeys");
otrl_privkey_read(userstate, path.toLocal8Bit());
- path = config->saveLocation() + handler->context().accountId + QLatin1String("_fingerprints");
+ path = config->saveLocation() + ctx.accountId + QLatin1String("_fingerprints");
otrl_privkey_read_fingerprints(userstate, path.toLocal8Bit(), NULL, NULL);
- path = config->saveLocation() + handler->context().accountId + QLatin1String("_instags");
+ path = config->saveLocation() + ctx.accountId + QLatin1String("_instags");
otrl_instag_read(userstate, path.toLocal8Bit());
UserStateBoxPtr usPtr(new UserStateBox(userstate));
- userStates.insert(handler->context().accountId, usPtr);
- return SessionPtr(new Session(handler, usPtr.data(), this));
+ userStates.insert(ctx.accountId, usPtr);
+ return usPtr.data();
} else {
- return SessionPtr(new Session(handler, usIt->data(), this));
+ return usIt->data();
}
}
@@ -428,19 +431,28 @@ void Manager::setPolicy(OtrlPolicy policy)
config->setPolicy(policy);
}
+void Manager::createNewPrivateKey(Session *session)
+{
+ const QString path = config->saveLocation() + session->context().accountId + QLatin1String("_privkeys");
+ otrl_privkey_generate(session->userStateBox()->userState(),
+ path.toLocal8Bit(),
+ session->context().accountName.toLocal8Bit(),
+ session->context().protocol.toLocal8Bit());
+}
+
void Manager::saveFingerprints(Session *session)
{
- const QString path = config->saveLocation() + session->handler()->context().accountId + QLatin1String("_fingerprints");
+ const QString path = config->saveLocation() + session->context().accountId + QLatin1String("_fingerprints");
otrl_privkey_write_fingerprints(session->userStateBox()->userState(), path.toLocal8Bit());
}
void Manager::createInstag(Session *session)
{
- const QString path = config->saveLocation() + session->handler()->context().accountId + QLatin1String("_instags");
+ const QString path = config->saveLocation() + session->context().accountId + QLatin1String("_instags");
otrl_instag_generate(session->userStateBox()->userState(),
path.toLocal8Bit(),
- session->handler()->context().accountName.toLocal8Bit(),
- session->handler()->context().protocol.toLocal8Bit());
+ session->context().accountName.toLocal8Bit(),
+ session->context().protocol.toLocal8Bit());
}
} /* namespace OTR */
diff --git a/otr-proxy/KTpProxy/otr-manager.h b/otr-proxy/KTpProxy/otr-manager.h
index 7628f44..4e5f384 100644
--- a/otr-proxy/KTpProxy/otr-manager.h
+++ b/otr-proxy/KTpProxy/otr-manager.h
@@ -21,7 +21,6 @@
#define KTP_PROXY_OTR_MANAGER_HEADER
#include "otr-config.h"
-#include "otr-handler.h"
#include "otr-session.h"
extern "C" {
@@ -34,18 +33,22 @@ extern "C" {
namespace OTR
{
+namespace global
+{
extern const OtrlMessageAppOps appOps;
+}
class Manager
{
public:
Manager(Config *otrConfig);
- SessionPtr createSession(const HandlerPtr &handler);
+ UserStateBox* getUserState(const SessionContext &ctx);
OtrlPolicy getPolicy() const;
void setPolicy(OtrlPolicy policy);
+ void createNewPrivateKey(Session *session);
void saveFingerprints(Session *session);
void createInstag(Session *session);
diff --git a/otr-proxy/KTpProxy/otr-message.cpp b/otr-proxy/KTpProxy/otr-message.cpp
index 8e8be17..1df1322 100644
--- a/otr-proxy/KTpProxy/otr-message.cpp
+++ b/otr-proxy/KTpProxy/otr-message.cpp
@@ -57,6 +57,7 @@ namespace OTR
void Message::setText(const QString &text)
{
+ // FIXME - using only text/plan content-type, what about html?
message[1].insert(QLatin1String("content-type"),
QDBusVariant(QLatin1String("text/plain")));
message[1].insert(QLatin1String("content"), QDBusVariant(text));
diff --git a/otr-proxy/KTpProxy/otr-session.cpp b/otr-proxy/KTpProxy/otr-session.cpp
index 827b342..17879f8 100644
--- a/otr-proxy/KTpProxy/otr-session.cpp
+++ b/otr-proxy/KTpProxy/otr-session.cpp
@@ -18,6 +18,8 @@
***************************************************************************/
#include "otr-session.h"
+#include "otr-manager.h"
+#include "otr-utils.h"
extern "C" {
#include <libotr/privkey.h>
@@ -60,16 +62,19 @@ namespace OTR
otrl_message_poll(us, 0, 0);
}
- Session::Session(const HandlerPtr &handler, UserStateBox *userstate, Manager *parent)
- : hd(handler),
- userstate(userstate),
+
+ Session::Session(const SessionContext &ctx, Manager *parent)
+ : instance(OTRL_INSTAG_BEST),
+ ctx(ctx),
+ tlevel(TrustLevel::NOT_PRIVATE),
pr(parent)
{
+ userstate = pr->getUserState(ctx);
}
- const HandlerPtr& Session::handler()
+ TrustLevel Session::trustLevel() const
{
- return hd;
+ return tlevel;
}
UserStateBox* Session::userStateBox()
@@ -82,4 +87,162 @@ namespace OTR
return pr;
}
+ const SessionContext& Session::context() const
+ {
+ return ctx;
+ }
+
+ QString Session::remoteFingerprint() const
+ {
+ ConnContext *context = otrl_context_find(userstate->userState(),
+ ctx.recipientName.toLocal8Bit(),
+ ctx.accountName.toLocal8Bit(),
+ ctx.protocol.toLocal8Bit(),
+ instance, 0, NULL, NULL, NULL);
+
+ if(context && context->active_fingerprint) {
+ return utils::humanReadable(context->active_fingerprint->fingerprint);
+ } else {
+ return QLatin1String("");
+ }
+ }
+
+ Message Session::startSession()
+ {
+ Message msg;
+
+ char *message = otrl_proto_default_query_msg(ctx.accountName.toLocal8Bit(), pr->getPolicy());
+ msg.setText(QLatin1String(message));
+ msg.setType(Tp::ChannelTextMessageTypeNormal);
+ msg.setDirection(MessageDirection::TO_PEER);
+ otrl_message_free(message);
+
+ return msg;
+ }
+
+ Message Session::stopSession()
+ {
+ Message msg;
+
+ otrl_message_disconnect(
+ userstate->userState(),
+ &global::appOps,
+ this,
+ ctx.accountName.toLocal8Bit(),
+ ctx.protocol.toLocal8Bit(),
+ ctx.recipientName.toLocal8Bit(),
+ instance);
+
+ emit sessionStopped();
+ return msg;
+ }
+
+ CryptResult Session::encrypt(Message &message)
+ {
+ return CryptResult::UNCHANGED;
+
+ if(otrl_proto_message_type(message.text().toLocal8Bit()) == OTRL_MSGTYPE_NOTOTR) {
+
+ char *encMessage = 0;
+ ConnContext *context;
+
+ int err = otrl_message_sending(
+ userstate->userState(),
+ &global::appOps,
+ this,
+ ctx.accountName.toLocal8Bit(),
+ ctx.protocol.toLocal8Bit(),
+ ctx.recipientName.toLocal8Bit(),
+ instance,
+ message.text().toLocal8Bit(),
+ NULL,
+ &encMessage,
+ OTRL_FRAGMENT_SEND_ALL_BUT_LAST,
+ &context,
+ NULL,
+ NULL);
+
+ if(err) {
+ return CryptResult::ERROR;
+ } else if(encMessage != NULL) {
+
+ message.setText(QLatin1String(encMessage));
+ message.setType(Tp::ChannelTextMessageTypeNormal);
+ if(context->active_fingerprint != NULL) {
+ const QString hrFingerprint = OTR::utils::humanReadable(context->active_fingerprint->fingerprint);
+ message.setOTRHeader(QLatin1String("otr-remote-fingerprint"), hrFingerprint);
+ }
+ otrl_message_free(encMessage);
+
+ return CryptResult::CHANGED;
+ }
+ }
+
+ return CryptResult::UNCHANGED;
+ }
+
+ CryptResult Session::decrypt(Message &message)
+ {
+ CryptResult result = CryptResult::INGORE;
+ char *decMsg = NULL;
+ OtrlTLV *tlvs = NULL;
+ ConnContext *context = NULL;
+
+ int ignore = otrl_message_receiving(
+ userstate->userState(),
+ &global::appOps,
+ this,
+ ctx.accountName.toLocal8Bit(),
+ ctx.protocol.toLocal8Bit(),
+ ctx.recipientName.toLocal8Bit(),
+ message.text().toLocal8Bit(),
+ &decMsg,
+ &tlvs,
+ &context, NULL, NULL);
+
+ if(otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED) != NULL) {
+ // TODO contact finished the conversation with us
+ }
+ otrl_tlv_free(tlvs);
+
+ if(!ignore && decMsg != NULL) {
+
+ message.setText(QLatin1String(decMsg));
+ if(context->active_fingerprint != NULL) {
+ const QString hrFingerprint = OTR::utils::humanReadable(context->active_fingerprint->fingerprint);
+ message.setOTRHeader(QLatin1String("otr-remote-fingerprint"), hrFingerprint);
+ }
+ result = CryptResult::CHANGED;
+ } else if(decMsg == NULL) {
+
+ result = CryptResult::UNCHANGED;
+ } else {
+
+ result = CryptResult::INGORE;
+ }
+
+ if(decMsg != NULL) {
+ otrl_message_free(decMsg);
+ }
+
+ return result;
+ }
+
+ void Session::onTrustLevelChanged(TrustLevel trustLevel, const ConnContext *context)
+ {
+ instance = context->their_instance;
+ tlevel = trustLevel;
+ emit trustLevelChanged(trustLevel);
+ }
+
+ void Session::onSessionRefreshed()
+ {
+ emit sessionRefreshed();
+ }
+
+ void Session::onNewFingerprintReceived(const QString &fingerprint)
+ {
+ emit newFingeprintReceived(fingerprint);
+ }
+
} /* namespace OTR */
diff --git a/otr-proxy/KTpProxy/otr-session.h b/otr-proxy/KTpProxy/otr-session.h
index 80d7356..b708d63 100644
--- a/otr-proxy/KTpProxy/otr-session.h
+++ b/otr-proxy/KTpProxy/otr-session.h
@@ -22,7 +22,6 @@
#include "otr-message.h"
#include "otr-constants.h"
-#include "otr-handler.h"
#include <QString>
#include <QTimer>
@@ -36,6 +35,14 @@ namespace OTR
{
class Manager;
+ struct SessionContext
+ {
+ const QString accountId;
+ const QString accountName;
+ const QString recipientName;
+ const QString protocol;
+ };
+
class UserStateBox : public QObject
{
Q_OBJECT
@@ -46,7 +53,6 @@ namespace OTR
OtrlUserState userState();
/** if zero timer is stopped */
void setInterval(uint interval);
- QString remoteFingerprint() const;
private Q_SLOTS:
void otrlMessagePoll();
@@ -62,24 +68,43 @@ namespace OTR
Q_OBJECT
public:
- Session(const HandlerPtr &handler, UserStateBox *userstate, Manager *parent);
+ Session(const SessionContext &context, Manager *parent);
- const HandlerPtr& handler();
UserStateBox* userStateBox();
Manager* parent();
TrustLevel trustLevel() const;
- void setTrustLevel(TrustLevel level);
+ const SessionContext& context() const;
+ QString remoteFingerprint() const;
- void startSession();
- void stopSession();
- void encrypt(Message &message);
- void decrypt(Message &message);
+ /** Returns OTR init message */
+ Message startSession();
+ /** Returns OTR disconnect message */
+ Message stopSession();
+ CryptResult encrypt(Message &message);
+ CryptResult decrypt(Message &message);
void verifyFingerprint();
void initSMPQuery();
void initSMPSecret();
+ // functions called by libotr
+ virtual void handleMessage(const Message &message) = 0;
+ virtual void handleSmpEvent(OtrlSMPEvent smpEvent) = 0;
+ virtual int recipientStatus() const = 0;
+ virtual unsigned int maxMessageSize() const = 0;
+ void onTrustLevelChanged(TrustLevel trustLevel, const ConnContext *context);
+ void onSessionRefreshed();
+ void onNewFingerprintReceived(const QString &fingeprint);
+
+ Q_SIGNALS:
+ void trustLevelChanged(TrustLevel trustLevel);
+ void sessionRefreshed();
+ void sessionStopped();
+ void newFingeprintReceived(const QString &fingeprint);
+
private:
- HandlerPtr hd;
+ otrl_instag_t instance;
+ SessionContext ctx;
+ TrustLevel tlevel;
UserStateBox *userstate;
Manager *pr;
};
diff --git a/otr-proxy/KTpProxy/otr-config.h b/otr-proxy/KTpProxy/otr-utils.h
similarity index 78%
copy from otr-proxy/KTpProxy/otr-config.h
copy to otr-proxy/KTpProxy/otr-utils.h
index de110ac..6398116 100644
--- a/otr-proxy/KTpProxy/otr-config.h
+++ b/otr-proxy/KTpProxy/otr-utils.h
@@ -17,29 +17,26 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#ifndef KTP_PROXY_OTR_CONFIG_HEADER
-#define KTP_PROXY_OTR_CONFIG_HEADER
+#ifndef KTP_PROXY_OTR_UTILS_HEADER
+#define KTP_PROXY_OTR_UTILS_HEADER
#include <QString>
extern "C" {
-#include <libotr/proto.h>
+#include <libotr/privkey.h>
}
-namespace OTR
+namespace OTR {
+namespace utils
{
-
- class Config
+ inline QString humanReadable(const unsigned char fingerprint[20])
{
- public:
- virtual ~Config() = 0;
-
- virtual QString saveLocation() = 0;
- virtual OtrlPolicy getPolicy() const = 0;
- virtual void setPolicy(OtrlPolicy policy) = 0;
-
- };
+ char human[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
+ otrl_privkey_hash_to_human(human, fingerprint);
-} /* namespace OTR */
+ return QString::fromLocal8Bit(human, OTRL_PRIVKEY_FPRINT_HUMAN_LEN);
+ }
+}
+}
#endif
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list