[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:20 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=5c4c476

The following commit has been merged in the master branch:
commit 5c4c4768a1d031ab3f3cb2b10dffa87c7026db5e
Author: Marcin Ziemiński <zieminn at gmail.com>
Date:   Sat Jul 26 23:23:46 2014 +0200

    Add trustFingerprint method for the OTR::Session along with some testing.
    
    Signed-off-by: Marcin Ziemiński <zieminn at gmail.com>
---
 otr-proxy/KTpProxy/otr-constants.h |  7 +++++
 otr-proxy/KTpProxy/otr-manager.cpp | 30 ++++++++++++++++++++
 otr-proxy/KTpProxy/otr-manager.h   |  5 +++-
 otr-proxy/KTpProxy/otr-session.cpp | 58 +++++++++++++++++++++++++++++---------
 otr-proxy/KTpProxy/otr-session.h   |  5 +++-
 otr-proxy/test/otr-test.cpp        | 48 +++++++++++++++++++++++++++++--
 6 files changed, 134 insertions(+), 19 deletions(-)

diff --git a/otr-proxy/KTpProxy/otr-constants.h b/otr-proxy/KTpProxy/otr-constants.h
index 16a442a..08f1a14 100644
--- a/otr-proxy/KTpProxy/otr-constants.h
+++ b/otr-proxy/KTpProxy/otr-constants.h
@@ -45,6 +45,13 @@ namespace OTR
         ERROR      // error during encryption or decryption operation
     };
 
+    enum class TrustFpResult : unsigned int
+    {
+        OK,
+        INVALID_FINGERPRINT, // when given fingerprint was in invalid format
+        NO_SUCH_FINGERPRINT  // when could not find such fingerprint
+    };
+
     template <typename T> unsigned int toUInt(T &&t)
     {
         return static_cast<unsigned int>(t);
diff --git a/otr-proxy/KTpProxy/otr-manager.cpp b/otr-proxy/KTpProxy/otr-manager.cpp
index f4230fc..d370d02 100644
--- a/otr-proxy/KTpProxy/otr-manager.cpp
+++ b/otr-proxy/KTpProxy/otr-manager.cpp
@@ -455,4 +455,34 @@ void Manager::createInstag(Session *session)
             session->context().protocol.toLocal8Bit());
 }
 
+TrustFpResult Manager::trustFingerprint(const SessionContext &ctx, const QString &fingerprint, bool trust)
+{
+    Q_UNUSED(ctx);
+    Q_UNUSED(fingerprint);
+    Q_UNUSED(trust);
+    // TODO
+    //UserStateBox *usBox = getUserState(ctx);
+    //OtrlUserState usersate = usBox->userState();
+    return TrustFpResult::OK;
+}
+
+TrustFpResult Manager::trustFingerprint(const SessionContext &ctx, Fingerprint *fingerprint, bool trust)
+{
+    if(fingerprint == nullptr) {
+        return TrustFpResult::NO_SUCH_FINGERPRINT;
+    }
+
+    UserStateBox* usBox = getUserState(ctx);
+    if(trust) {
+        otrl_context_set_trust(fingerprint, "VERIFIED");
+    } else {
+        otrl_context_set_trust(fingerprint, NULL);
+    }
+
+    const QString path = config->saveLocation() + ctx.accountId + QLatin1String("_fingerprints");
+	otrl_privkey_write_fingerprints(usBox->userState(), path.toLocal8Bit());
+
+    return TrustFpResult::OK;
+}
+
 } /* namespace OTR */
diff --git a/otr-proxy/KTpProxy/otr-manager.h b/otr-proxy/KTpProxy/otr-manager.h
index 81261d9..4f6bf20 100644
--- a/otr-proxy/KTpProxy/otr-manager.h
+++ b/otr-proxy/KTpProxy/otr-manager.h
@@ -48,8 +48,11 @@ namespace global
             OtrlPolicy getPolicy() const;
             void setPolicy(OtrlPolicy policy);
 
-            void createNewPrivateKey(Session *session);
             void saveFingerprints(Session *session);
+            TrustFpResult trustFingerprint(const SessionContext &ctx, const QString &fingerprint, bool trust);
+            TrustFpResult trustFingerprint(const SessionContext &ctx, Fingerprint *fingerprint, bool trust);
+
+            void createNewPrivateKey(Session *session);
             void createInstag(Session *session);
 
         private:
diff --git a/otr-proxy/KTpProxy/otr-session.cpp b/otr-proxy/KTpProxy/otr-session.cpp
index fa97a62..d729c2f 100644
--- a/otr-proxy/KTpProxy/otr-session.cpp
+++ b/otr-proxy/KTpProxy/otr-session.cpp
@@ -92,7 +92,7 @@ namespace OTR
         return ctx;
     }
 
-    QString Session::remoteFingerprint() const
+    Fingerprint* Session::getFingerprint() const
     {
         ConnContext *context = otrl_context_find(userstate->userState(),
                 ctx.recipientName.toLocal8Bit(),
@@ -101,7 +101,17 @@ namespace OTR
                 instance, 0, NULL, NULL, NULL);
 
         if(context && context->active_fingerprint) {
-            return utils::humanReadable(context->active_fingerprint->fingerprint);
+            return context->active_fingerprint;
+        } else {
+            return nullptr;
+        }
+    }
+
+    QString Session::remoteFingerprint() const
+    {
+        Fingerprint *fp = getFingerprint();
+        if(fp) {
+            return utils::humanReadable(fp->fingerprint);
         } else {
             return QLatin1String("");
         }
@@ -131,7 +141,7 @@ namespace OTR
                 ctx.recipientName.toLocal8Bit(),
                 instance);
 
-        onTrustLevelChanged(TrustLevel::NOT_PRIVATE, NULL);
+        onTrustLevelChanged(TrustLevel::NOT_PRIVATE, nullptr);
     }
 
     CryptResult Session::encrypt(Message &message)
@@ -159,11 +169,11 @@ namespace OTR
 
             if(err) {
                 return CryptResult::ERROR;
-            } else if(encMessage != NULL) {
+            } else if(encMessage != nullptr) {
 
                 message.setText(QLatin1String(encMessage));
                 message.setType(Tp::ChannelTextMessageTypeNormal);
-                if(context->active_fingerprint != NULL) {
+                if(context->active_fingerprint != nullptr) {
                     const QString hrFingerprint = OTR::utils::humanReadable(context->active_fingerprint->fingerprint);
                     message.setOTRheader(QLatin1String("otr-remote-fingerprint"), hrFingerprint);
                 }
@@ -179,9 +189,9 @@ namespace OTR
     CryptResult Session::decrypt(Message &message)
     {
         CryptResult result = CryptResult::OTR;
-        char *decMsg = NULL;
-        OtrlTLV *tlvs = NULL;
-        ConnContext *context = NULL;
+        char *decMsg = nullptr;
+        OtrlTLV *tlvs = nullptr;
+        ConnContext *context = nullptr;
 
         bool isFinished = false;
 
@@ -197,15 +207,15 @@ namespace OTR
                 &tlvs,
                 &context, NULL, NULL);
 
-		if(otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED) != NULL) {
+		if(otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED) != nullptr) {
             isFinished = true;
         }
         otrl_tlv_free(tlvs);
 
         if(!ignore) {
-            if(decMsg != NULL) {
+            if(decMsg != nullptr) {
                 message.setText(QLatin1String(decMsg));
-                if(context->active_fingerprint != NULL) {
+                if(context->active_fingerprint != nullptr) {
                     const QString hrFingerprint = OTR::utils::humanReadable(context->active_fingerprint->fingerprint);
                     message.setOTRheader(QLatin1String("otr-remote-fingerprint"), hrFingerprint);
                 }
@@ -217,20 +227,40 @@ namespace OTR
             result = CryptResult::OTR;
         }
 
-        if(decMsg != NULL) {
+        if(decMsg != nullptr) {
             otrl_message_free(decMsg);
         }
 
         if(isFinished) {
-            onTrustLevelChanged(TrustLevel::FINISHED, NULL);
+            onTrustLevelChanged(TrustLevel::FINISHED, nullptr);
         }
 
         return result;
     }
 
+    TrustFpResult Session::trustFingerprint(bool trust)
+    {
+        Fingerprint* fp = getFingerprint();
+        if(fp != nullptr) {
+
+            TrustFpResult res = pr->trustFingerprint(ctx, fp, trust);
+            if(res == TrustFpResult::OK && trustLevel() != TrustLevel::FINISHED) {
+                if(trust) {
+                    onTrustLevelChanged(TrustLevel::VERIFIED, nullptr);
+                } else {
+                    onTrustLevelChanged(TrustLevel::UNVERIFIED, nullptr);
+                }
+            }
+            return res;
+        } else {
+
+            return TrustFpResult::NO_SUCH_FINGERPRINT;
+        }
+    }
+
     void Session::onTrustLevelChanged(TrustLevel trustLevel, const ConnContext *context)
     {
-        if(context != NULL) {
+        if(context != nullptr) {
             instance = context->their_instance;
         }
         tlevel = trustLevel;
diff --git a/otr-proxy/KTpProxy/otr-session.h b/otr-proxy/KTpProxy/otr-session.h
index d37c21e..51c1358 100644
--- a/otr-proxy/KTpProxy/otr-session.h
+++ b/otr-proxy/KTpProxy/otr-session.h
@@ -82,9 +82,9 @@ namespace OTR
             void stopSession();
             CryptResult encrypt(Message &message);
             CryptResult decrypt(Message &message);
-            void verifyFingerprint();
             void initSMPQuery();
             void initSMPSecret();
+            TrustFpResult trustFingerprint(bool trust);
 
             // functions called by libotr
             virtual void handleMessage(const Message &message) = 0;
@@ -95,6 +95,9 @@ namespace OTR
             void onSessionRefreshed();
             void onNewFingerprintReceived(const QString &fingeprint);
 
+        private:
+            Fingerprint* getFingerprint() const;
+
         Q_SIGNALS:
             void trustLevelChanged(TrustLevel trustLevel);
             void sessionRefreshed();
diff --git a/otr-proxy/test/otr-test.cpp b/otr-proxy/test/otr-test.cpp
index 9d4c138..7fd70e2 100644
--- a/otr-proxy/test/otr-test.cpp
+++ b/otr-proxy/test/otr-test.cpp
@@ -133,6 +133,7 @@ class OTRTest : public QObject
         void testSessionPolicyAlways();
         void testEncUnencryptedErrors();
         void testDoubleConversation();
+        void testTrustDistrustFingerprint();
 
         void cleanup();
 
@@ -377,9 +378,6 @@ void OTRTest::startSession(TestSession& alice, TestSession &bob)
     QVERIFY(alice.eventQueue.empty());
     QVERIFY(bob.mesQueue.empty());
     QVERIFY(bob.eventQueue.empty());
-
-    QCOMPARE(bob.trustLevel(), TrustLevel::UNVERIFIED);
-    QCOMPARE(alice.trustLevel(), TrustLevel::UNVERIFIED);
 }
 
 void OTRTest::testEncUnencryptedErrors()
@@ -466,6 +464,50 @@ void OTRTest::testDoubleConversation()
     QCOMPARE(alice.trustLevel(), TrustLevel::FINISHED);
 }
 
+void OTRTest::testTrustDistrustFingerprint()
+{
+    TestSession &alice = aliceEnv->ses;
+    TestSession &bob = bobEnv->ses;
+
+    QCOMPARE(TrustFpResult::NO_SUCH_FINGERPRINT, alice.trustFingerprint(true));
+
+    startSession(alice, bob);
+    QCOMPARE(alice.trustLevel(), TrustLevel::UNVERIFIED);
+    QCOMPARE(bob.trustLevel(), TrustLevel::UNVERIFIED);
+
+    QCOMPARE(TrustFpResult::OK, alice.trustFingerprint(true));
+    QCOMPARE(alice.trustLevel(), TrustLevel::VERIFIED);
+
+    delete aliceEnv;
+    delete bobEnv;
+    delete bobMan;
+    delete aliceMan;
+
+    init();
+
+    TestSession &alice2 = aliceEnv->ses;
+    TestSession &bob2 = bobEnv->ses;
+    startSession(alice2, bob2);
+    QCOMPARE(alice2.trustLevel(), TrustLevel::VERIFIED);
+    QCOMPARE(bob2.trustLevel(), TrustLevel::UNVERIFIED);
+
+    QCOMPARE(TrustFpResult::OK, alice2.trustFingerprint(false));
+    QCOMPARE(alice2.trustLevel(), TrustLevel::UNVERIFIED);
+    QCOMPARE(bob2.trustLevel(), TrustLevel::UNVERIFIED);
+
+    delete aliceEnv;
+    delete bobEnv;
+    delete bobMan;
+    delete aliceMan;
+    init();
+
+    TestSession &alice3 = aliceEnv->ses;
+    TestSession &bob3 = bobEnv->ses;
+    startSession(alice3, bob3);
+    QCOMPARE(alice3.trustLevel(), TrustLevel::UNVERIFIED);
+    QCOMPARE(bob3.trustLevel(), TrustLevel::UNVERIFIED);
+}
+
 void OTRTest::cleanup()
 {
     delete aliceEnv;

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list