ssl: Remove fallback code for missing SSL support
[quassel.git] / src / client / clientauthhandler.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2020 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "authhandler.h"
24 #include "compressor.h"
25 #include "coreaccount.h"
26
27 class QSslSocket;
28
29 class RemotePeer;
30
31 class ClientAuthHandler : public AuthHandler
32 {
33     Q_OBJECT
34
35 public:
36     enum DigestVersion
37     {
38         Md5,
39         Sha2_512,
40         Latest = Sha2_512
41     };
42
43     ClientAuthHandler(CoreAccount account, QObject* parent = nullptr);
44
45     Peer* peer() const;
46
47 public slots:
48     void connectToCore();
49
50     void login(const QString& previousError = QString());
51     void login(const QString& user, const QString& password, bool remember);
52     void setupCore(const Protocol::SetupData& setupData);
53
54 signals:
55     void statusMessage(const QString& message);
56     void errorMessage(const QString& message);
57     void errorPopup(const QString& message);
58     void transferProgress(int current, int max);
59
60     void requestDisconnect(const QString& errorString = QString(), bool wantReconnect = false);
61
62     void connectionReady();
63     void loginSuccessful(const CoreAccount& account);
64     void handshakeComplete(RemotePeer* peer, const Protocol::SessionState& sessionState);
65
66     // These signals MUST be handled synchronously!
67     void userAuthenticationRequired(CoreAccount* account, bool* valid, const QString& errorMessage = QString());
68     void handleNoSslInClient(bool* accepted);
69     void handleNoSslInCore(bool* accepted);
70     void handleSslErrors(const QSslSocket* socket, bool* accepted, bool* permanently);
71
72     void encrypted(bool isEncrypted = true);
73     void startCoreSetup(const QVariantList& backendInfo, const QVariantList& authenticatorInfo);
74     void coreSetupSuccessful();
75     void coreSetupFailed(const QString& error);
76
77 private:
78     using AuthHandler::handle;
79
80     void handle(const Protocol::ClientDenied& msg) override;
81     void handle(const Protocol::ClientRegistered& msg) override;
82     void handle(const Protocol::SetupFailed& msg) override;
83     void handle(const Protocol::SetupDone& msg) override;
84     void handle(const Protocol::LoginFailed& msg) override;
85     void handle(const Protocol::LoginSuccess& msg) override;
86     void handle(const Protocol::SessionState& msg) override;
87
88     void setPeer(RemotePeer* peer);
89     void checkAndEnableSsl(bool coreSupportsSsl);
90     void startRegistration();
91
92 private slots:
93     void onSocketConnected();
94     void onSocketStateChanged(QAbstractSocket::SocketState state);
95     void onSocketError(QAbstractSocket::SocketError) override;
96     void onSocketDisconnected() override;
97     void onReadyRead();
98
99     void onSslSocketEncrypted();
100     void onSslErrors();
101
102     void onProtocolVersionMismatch(int actual, int expected);
103
104     void onConnectionReady();
105
106 private:
107     RemotePeer* _peer;
108     bool _coreConfigured;
109     QVariantList _backendInfo;
110     QVariantList _authenticatorInfo;
111     CoreAccount _account;
112     bool _probing;
113     bool _legacy;
114     quint8 _connectionFeatures;
115 };