Implement support for the HAProxy proxy protocol
[quassel.git] / src / core / coreauthhandler.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 #ifndef COREAUTHHANDLER_H
22 #define COREAUTHHANDLER_H
23
24 #include "authhandler.h"
25 #include "metricsserver.h"
26 #include "peerfactory.h"
27 #include "proxyline.h"
28 #include "remotepeer.h"
29 #include "types.h"
30
31 class CoreAuthHandler : public AuthHandler
32 {
33     Q_OBJECT
34
35 public:
36     CoreAuthHandler(QTcpSocket* socket, QObject* parent = nullptr);
37
38     QHostAddress hostAddress() const;
39     bool isLocal() const override;
40
41 signals:
42     void handshakeComplete(RemotePeer* peer, UserId uid);
43
44 private:
45     using AuthHandler::handle;
46
47     void handle(const Protocol::RegisterClient& msg) override;
48     void handle(const Protocol::SetupData& msg) override;
49     void handle(const Protocol::Login& msg) override;
50
51     void setPeer(RemotePeer* peer);
52     void startSsl();
53
54     bool checkClientRegistered();
55
56 private slots:
57     void onReadyRead();
58
59 #ifdef HAVE_SSL
60     void onSslErrors();
61 #endif
62
63     // only in legacy mode
64     void onProtocolVersionMismatch(int actual, int expected);
65
66 private:
67     RemotePeer* _peer;
68     MetricsServer* _metricsServer;
69
70     bool _proxyReceived;
71     ProxyLine _proxyLine;
72     bool _useProxyLine;
73     bool _magicReceived;
74     bool _legacy;
75     bool _clientRegistered;
76     quint8 _connectionFeatures;
77     QVector<PeerFactory::ProtoDescriptor> _supportedProtos;
78 };
79
80 #endif