X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientauthhandler.cpp;h=260128b7b7ef16c5eeb0a70665a63ebf36048bd4;hp=5048554756bf676544492d1f128664461d60ce09;hb=efe4239f96f0cf10b1c94e87f8fdd21f3bdbe10e;hpb=8c6448c2e0048389fbac9e2e9daf22b5b050d5b6 diff --git a/src/client/clientauthhandler.cpp b/src/client/clientauthhandler.cpp index 50485547..260128b7 100644 --- a/src/client/clientauthhandler.cpp +++ b/src/client/clientauthhandler.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,20 +21,13 @@ #include "clientauthhandler.h" #include - -#ifdef HAVE_SSL -# include -#else -# include -#endif +#include #include "client.h" #include "clientsettings.h" #include "peerfactory.h" #include "util.h" -using namespace Protocol; - ClientAuthHandler::ClientAuthHandler(CoreAccount account, QObject* parent) : AuthHandler(parent) , _peer(nullptr) @@ -53,24 +46,9 @@ void ClientAuthHandler::connectToCore() { CoreAccountSettings s; -#ifdef HAVE_SSL auto* socket = new QSslSocket(this); // make sure the warning is shown if we happen to connect without SSL support later s.setAccountValue("ShowNoClientSslWarning", true); -#else - if (_account.useSsl()) { - if (s.accountValue("ShowNoClientSslWarning", true).toBool()) { - bool accepted = false; - emit handleNoSslInClient(&accepted); - if (!accepted) { - emit errorMessage(tr("Unencrypted connection canceled")); - return; - } - s.setAccountValue("ShowNoClientSslWarning", false); - } - } - QTcpSocket* socket = new QTcpSocket(this); -#endif #ifndef QT_NO_NETWORKPROXY QNetworkProxy proxy; @@ -181,10 +159,7 @@ void ClientAuthHandler::onSocketConnected() stream.setVersion(QDataStream::Qt_4_2); quint32 magic = Protocol::magic; -#ifdef HAVE_SSL - if (_account.useSsl()) - magic |= Protocol::Encryption; -#endif + magic |= Protocol::Encryption; magic |= Protocol::Compression; stream << magic; @@ -277,7 +252,7 @@ void ClientAuthHandler::setPeer(RemotePeer* peer) connect(_peer, &RemotePeer::transferProgress, this, &ClientAuthHandler::transferProgress); // The legacy protocol enables SSL later, after registration - if (!_account.useSsl() || _legacy) + if (_legacy) startRegistration(); // otherwise, do it now else @@ -288,22 +263,16 @@ void ClientAuthHandler::startRegistration() { emit statusMessage(tr("Synchronizing to core...")); - // useSsl will be ignored by non-legacy peers - bool useSsl = false; -#ifdef HAVE_SSL - useSsl = _account.useSsl(); -#endif - - _peer->dispatch(RegisterClient(Quassel::Features{}, Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().commitDate, useSsl)); + _peer->dispatch(Protocol::RegisterClient(Quassel::Features{}, Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().commitDate)); } -void ClientAuthHandler::handle(const ClientDenied& msg) +void ClientAuthHandler::handle(const Protocol::ClientDenied& msg) { emit errorPopup(msg.errorString); requestDisconnect(tr("The core refused connection from this client")); } -void ClientAuthHandler::handle(const ClientRegistered& msg) +void ClientAuthHandler::handle(const Protocol::ClientRegistered& msg) { _coreConfigured = msg.coreConfigured; _backendInfo = msg.backendInfo; @@ -312,7 +281,7 @@ void ClientAuthHandler::handle(const ClientRegistered& msg) _peer->setFeatures(std::move(msg.features)); // The legacy protocol enables SSL at this point - if (_legacy && _account.useSsl()) + if (_legacy) checkAndEnableSsl(msg.sslSupported); else onConnectionReady(); @@ -340,17 +309,17 @@ void ClientAuthHandler::onConnectionReady() login(); } -void ClientAuthHandler::setupCore(const SetupData& setupData) +void ClientAuthHandler::setupCore(const Protocol::SetupData& setupData) { _peer->dispatch(setupData); } -void ClientAuthHandler::handle(const SetupFailed& msg) +void ClientAuthHandler::handle(const Protocol::SetupFailed& msg) { emit coreSetupFailed(msg.errorString); } -void ClientAuthHandler::handle(const SetupDone& msg) +void ClientAuthHandler::handle(const Protocol::SetupDone& msg) { Q_UNUSED(msg) @@ -377,22 +346,22 @@ void ClientAuthHandler::login(const QString& previousError) } } - _peer->dispatch(Login(_account.user(), _account.password())); + _peer->dispatch(Protocol::Login(_account.user(), _account.password())); } -void ClientAuthHandler::handle(const LoginFailed& msg) +void ClientAuthHandler::handle(const Protocol::LoginFailed& msg) { login(msg.errorString); } -void ClientAuthHandler::handle(const LoginSuccess& msg) +void ClientAuthHandler::handle(const Protocol::LoginSuccess& msg) { Q_UNUSED(msg) emit loginSuccessful(_account); } -void ClientAuthHandler::handle(const SessionState& msg) +void ClientAuthHandler::handle(const Protocol::SessionState& msg) { disconnect(socket(), nullptr, this, nullptr); // this is the last message we shall ever get @@ -405,21 +374,16 @@ void ClientAuthHandler::handle(const SessionState& msg) void ClientAuthHandler::checkAndEnableSsl(bool coreSupportsSsl) { -#ifndef HAVE_SSL - Q_UNUSED(coreSupportsSsl); -#else CoreAccountSettings s; - if (coreSupportsSsl && _account.useSsl()) { + if (coreSupportsSsl) { // Make sure the warning is shown next time we don't have SSL in the core s.setAccountValue("ShowNoCoreSslWarning", true); - auto* sslSocket = qobject_cast(socket()); - Q_ASSERT(sslSocket); - connect(sslSocket, &QSslSocket::encrypted, this, &ClientAuthHandler::onSslSocketEncrypted); - connect(sslSocket, selectOverload&>(&QSslSocket::sslErrors), this, &ClientAuthHandler::onSslErrors); + connect(socket(), &QSslSocket::encrypted, this, &ClientAuthHandler::onSslSocketEncrypted); + connect(socket(), selectOverload&>(&QSslSocket::sslErrors), this, &ClientAuthHandler::onSslErrors); qDebug() << "Starting encryption..."; - sslSocket->flush(); - sslSocket->startClientEncryption(); + socket()->flush(); + socket()->startClientEncryption(); } else { if (s.accountValue("ShowNoCoreSslWarning", true).toBool()) { @@ -438,10 +402,8 @@ void ClientAuthHandler::checkAndEnableSsl(bool coreSupportsSsl) else startRegistration(); } -#endif } -#ifdef HAVE_SSL void ClientAuthHandler::onSslSocketEncrypted() { @@ -466,9 +428,6 @@ void ClientAuthHandler::onSslSocketEncrypted() void ClientAuthHandler::onSslErrors() { - auto* socket = qobject_cast(sender()); - Q_ASSERT(socket); - CoreAccountSettings s; QByteArray knownDigest = s.accountValue("SslCert").toByteArray(); ClientAuthHandler::DigestVersion knownDigestVersion = static_cast( @@ -477,11 +436,11 @@ void ClientAuthHandler::onSslErrors() QByteArray calculatedDigest; switch (knownDigestVersion) { case ClientAuthHandler::DigestVersion::Md5: - calculatedDigest = socket->peerCertificate().digest(QCryptographicHash::Md5); + calculatedDigest = socket()->peerCertificate().digest(QCryptographicHash::Md5); break; case ClientAuthHandler::DigestVersion::Sha2_512: - calculatedDigest = socket->peerCertificate().digest(QCryptographicHash::Sha512); + calculatedDigest = socket()->peerCertificate().digest(QCryptographicHash::Sha512); break; default: @@ -491,7 +450,7 @@ void ClientAuthHandler::onSslErrors() if (knownDigest != calculatedDigest) { bool accepted = false; bool permanently = false; - emit handleSslErrors(socket, &accepted, &permanently); + emit handleSslErrors(socket(), &accepted, &permanently); if (!accepted) { requestDisconnect(tr("Unencrypted connection canceled")); @@ -499,7 +458,7 @@ void ClientAuthHandler::onSslErrors() } if (permanently) { - s.setAccountValue("SslCert", socket->peerCertificate().digest(QCryptographicHash::Sha512)); + s.setAccountValue("SslCert", socket()->peerCertificate().digest(QCryptographicHash::Sha512)); s.setAccountValue("SslCertDigestVersion", ClientAuthHandler::DigestVersion::Latest); } else { @@ -508,11 +467,9 @@ void ClientAuthHandler::onSslErrors() } } else if (knownDigestVersion != ClientAuthHandler::DigestVersion::Latest) { - s.setAccountValue("SslCert", socket->peerCertificate().digest(QCryptographicHash::Sha512)); + s.setAccountValue("SslCert", socket()->peerCertificate().digest(QCryptographicHash::Sha512)); s.setAccountValue("SslCertDigestVersion", ClientAuthHandler::DigestVersion::Latest); } - socket->ignoreSslErrors(); + socket()->ignoreSslErrors(); } - -#endif /* HAVE_SSL */