File: otr-session.h

package info (click to toggle)
ktp-common-internals 17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,192 kB
  • sloc: cpp: 18,785; xml: 719; makefile: 7; sh: 6
file content (151 lines) | stat: -rw-r--r-- 5,332 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/***************************************************************************
 *   Copyright (C) 2014 by Marcin ZiemiƄski <zieminn@gmail.com>            *
 *                                                                         *
 * This library is free software; you can redistribute it and/or           *
 * modify it under the terms of the GNU Lesser General Public		   *
 * License as published by the Free Software Foundation; either		   *
 * version 2.1 of the License, or (at your option) any later version.	   *
 * 									   *
 * This library is distributed in the hope that it will be useful,	   *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of	   *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU	   *
 * Lesser General Public License for more details.			   *
 * 									   *
 * You should have received a copy of the GNU Lesser General Public	   *
 * License along with this library; if not, write to the Free Software	   *
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*
 ***************************************************************************/

#ifndef KTP_PROXY_OTR_SESSION_HEADER
#define KTP_PROXY_OTR_SESSION_HEADER

#include "otr-message.h"
#include "otr-constants.h"
#include "otr-proxy-channel.h"
#include "otr-utils.h"

#include <QString>
#include <QTimer>

extern "C" {
#include <gcrypt.h>
#include <libotr/userstate.h>
}

namespace OTR
{
    class Manager;

    class UserStateBox : public QObject
    {
        Q_OBJECT
        public:
            UserStateBox(OtrlUserState userState);
            ~UserStateBox();

            OtrlUserState userState();
            /** if zero timer is stopped */
            void setInterval(uint interval);

        private Q_SLOTS:
            void otrlMessagePoll();

        private:
            OtrlUserState us;
            QTimer periodicTimer;
    };
    typedef QSharedPointer<UserStateBox> UserStateBoxPtr;

    class Session : public QObject
    {
        Q_OBJECT

        public:
            Session(const SessionContext &context, Manager *parent);
            virtual ~Session() = default;

            UserStateBox* userStateBox() const;
            Manager* parent() const;
            TrustLevel trustLevel() const;
            const SessionContext& context() const;
            QString remoteFingerprint() const;
            QString localFingerprint() const;
            /** forces OTR session into plain text state */
            void forceUnencrypted();

            /** Returns OTR init message */
            Message startSession();
            void stopSession();
            CryptResult encrypt(Message &message);
            CryptResult decrypt(Message &message);

            void initSMPQuery(const QString &question, const QString &secret);
            void initSMPSecret(const QString &secret);
            void abortSMPAuthentiaction(ConnContext *context = NULL);
            void respondSMPAuthentication(const QString &answer);

            TrustFpResult trustFingerprint(bool trust);

            // functions called by libotr ---------------------------------------
            virtual void handleMessage(const Message &message) = 0;

            /** Report whether you think the given user is online.  Return 1 if
              you think he is, 0 if you think he isn't, -1 if you're not sure. */
            virtual int recipientStatus() const = 0;
            virtual unsigned int maxMessageSize() const = 0;

            void onTrustLevelChanged(const ConnContext *context = nullptr);
            void onSessionRefreshed();
            void onNewFingerprintReceived(const QString &fingeprint);

            void onSMPFinished(bool success);
            void onSMPInProgress();
            void onSMPError();
            void onSMPAborted();
            void onSMPCheated();
            void onSMPQuery(const QString &question);

        private:
            Fingerprint* getFingerprint() const;
            ConnContext* findContext() const;

        private Q_SLOTS:
            void onFingerprintTrusted(const QString &accountId, const QString &fingerprint, bool trusted);

        Q_SIGNALS:
            void trustLevelChanged(TrustLevel trustLevel);
            void sessionRefreshed();
            void newFingerprintReceived(const QString &fingeprint);

            void authenticationConcluded(bool success);
            void authenticationError();
            void authenticationAborted();
            void authenticationCheated();
            /** empty string if secret */
            void authenticationRequested(const QString &question);
            void authenticationInProgress();

        private:
            otrl_instag_t instance;
            SessionContext ctx;
            UserStateBox *userstate;
            Manager *pr;
    };
    typedef QSharedPointer<Session> SessionPtr;

    class ProxySession : public Session
    {
        public:
            ProxySession(OtrProxyChannel::Adaptee *pca, const SessionContext &ctx, Manager *parent);

            virtual void handleMessage(const Message &message) override;
            virtual int recipientStatus() const override;
            virtual unsigned int maxMessageSize() const override;

        private:
            OtrProxyChannel::Adaptee *pca;
    };

} /* namespace OTR */

#endif