X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientauthhandler.cpp;h=469299fd457db8eb7d85962bd5077a525ab03578;hp=52bd1e4a827fee8cf52676844f05a8379ce2a0db;hb=c0d6dc0dec628f2e143e37ecc95cec45e636f8a5;hpb=af29862368978b94f00f13b957f685d78c7e8104 diff --git a/src/client/clientauthhandler.cpp b/src/client/clientauthhandler.cpp index 52bd1e4a..469299fd 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,12 +21,7 @@ #include "clientauthhandler.h" #include - -#ifdef HAVE_SSL -# include -#else -# include -#endif +#include #include "client.h" #include "clientsettings.h" @@ -51,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; @@ -179,10 +159,8 @@ 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::Compression; stream << magic; @@ -288,9 +266,7 @@ void ClientAuthHandler::startRegistration() // useSsl will be ignored by non-legacy peers bool useSsl = false; -#ifdef HAVE_SSL useSsl = _account.useSsl(); -#endif _peer->dispatch(Protocol::RegisterClient(Quassel::Features{}, Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().commitDate, useSsl)); } @@ -403,21 +379,16 @@ void ClientAuthHandler::handle(const Protocol::SessionState& msg) void ClientAuthHandler::checkAndEnableSsl(bool coreSupportsSsl) { -#ifndef HAVE_SSL - Q_UNUSED(coreSupportsSsl); -#else CoreAccountSettings s; if (coreSupportsSsl && _account.useSsl()) { // 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()) { @@ -436,10 +407,8 @@ void ClientAuthHandler::checkAndEnableSsl(bool coreSupportsSsl) else startRegistration(); } -#endif } -#ifdef HAVE_SSL void ClientAuthHandler::onSslSocketEncrypted() { @@ -464,9 +433,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( @@ -475,11 +441,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: @@ -489,7 +455,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")); @@ -497,7 +463,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 { @@ -506,11 +472,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 */