X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientauthhandler.cpp;h=68f545ee06c2b3b8b9266a2933731aa057c71ec5;hp=54afcd3f0ae23087d3efb51ba34de241bf8034ad;hb=fcacaaf16551524c7ebb6114254d005274cc3d63;hpb=9f91e0dd3c4eb5c2e2dedfc8d36a068d433d51b1 diff --git a/src/client/clientauthhandler.cpp b/src/client/clientauthhandler.cpp index 54afcd3f..68f545ee 100644 --- a/src/client/clientauthhandler.cpp +++ b/src/client/clientauthhandler.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,8 +20,6 @@ #include "clientauthhandler.h" -// TODO: support system application proxy (new in Qt 4.6) - #include #ifdef HAVE_SSL @@ -32,13 +30,9 @@ #include "client.h" #include "clientsettings.h" -#include "logger.h" +#include "logmessage.h" #include "peerfactory.h" -#if QT_VERSION < 0x050000 -# include "../../3rdparty/sha512/sha512.h" -#endif - using namespace Protocol; ClientAuthHandler::ClientAuthHandler(CoreAccount account, QObject *parent) @@ -64,7 +58,7 @@ void ClientAuthHandler::connectToCore() CoreAccountSettings s; #ifdef HAVE_SSL - QSslSocket *socket = new QSslSocket(this); + 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 @@ -102,9 +96,9 @@ void ClientAuthHandler::connectToCore() #endif setSocket(socket); - connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(onSocketStateChanged(QAbstractSocket::SocketState))); - connect(socket, SIGNAL(readyRead()), SLOT(onReadyRead())); - connect(socket, SIGNAL(connected()), SLOT(onSocketConnected())); + connect(socket, &QAbstractSocket::stateChanged, this, &ClientAuthHandler::onSocketStateChanged); + connect(socket, &QIODevice::readyRead, this, &ClientAuthHandler::onReadyRead); + connect(socket, &QAbstractSocket::connected, this, &ClientAuthHandler::onSocketConnected); emit statusMessage(tr("Connecting to %1...").arg(_account.accountName())); socket->connectToHost(_account.hostName(), _account.port()); @@ -167,7 +161,7 @@ void ClientAuthHandler::onSocketDisconnected() if (_probing && _legacy) { // Remote host has closed the connection while probing _probing = false; - disconnect(socket(), SIGNAL(readyRead()), this, SLOT(onReadyRead())); + disconnect(socket(), &QIODevice::readyRead, this, &ClientAuthHandler::onReadyRead); emit statusMessage(tr("Reconnecting in compatibility mode...")); socket()->connectToHost(_account.hostName(), _account.port()); return; @@ -237,14 +231,14 @@ void ClientAuthHandler::onReadyRead() return; // make sure to not read more data than needed _probing = false; - disconnect(socket(), SIGNAL(readyRead()), this, SLOT(onReadyRead())); + disconnect(socket(), &QIODevice::readyRead, this, &ClientAuthHandler::onReadyRead); quint32 reply; socket()->read((char *)&reply, 4); reply = qFromBigEndian(reply); - Protocol::Type type = static_cast(reply & 0xff); - quint16 protoFeatures = static_cast(reply>>8 & 0xffff); + auto type = static_cast(reply & 0xff); + auto protoFeatures = static_cast(reply>>8 & 0xffff); _connectionFeatures = static_cast(reply>>24); Compressor::CompressionLevel level; @@ -285,7 +279,7 @@ void ClientAuthHandler::setPeer(RemotePeer *peer) qDebug().nospace() << "Using " << qPrintable(peer->protocolName()) << "..."; _peer = peer; - connect(_peer, SIGNAL(transferProgress(int,int)), SIGNAL(transferProgress(int,int))); + connect(_peer, &RemotePeer::transferProgress, this, &ClientAuthHandler::transferProgress); // The legacy protocol enables SSL later, after registration if (!_account.useSsl() || _legacy) @@ -417,10 +411,10 @@ void ClientAuthHandler::handle(const LoginSuccess &msg) void ClientAuthHandler::handle(const SessionState &msg) { - disconnect(socket(), 0, this, 0); // this is the last message we shall ever get + disconnect(socket(), nullptr, this, nullptr); // this is the last message we shall ever get // give up ownership of the peer; CoreSession takes responsibility now - _peer->setParent(0); + _peer->setParent(nullptr); emit handshakeComplete(_peer, msg); } @@ -437,9 +431,9 @@ void ClientAuthHandler::checkAndEnableSsl(bool coreSupportsSsl) // Make sure the warning is shown next time we don't have SSL in the core s.setAccountValue("ShowNoCoreSslWarning", true); - QSslSocket *sslSocket = qobject_cast(socket()); + auto *sslSocket = qobject_cast(socket()); Q_ASSERT(sslSocket); - connect(sslSocket, SIGNAL(encrypted()), SLOT(onSslSocketEncrypted())); + connect(sslSocket, &QSslSocket::encrypted, this, &ClientAuthHandler::onSslSocketEncrypted); connect(sslSocket, SIGNAL(sslErrors(QList)), SLOT(onSslErrors())); qDebug() << "Starting encryption..."; sslSocket->flush(); @@ -469,7 +463,7 @@ void ClientAuthHandler::checkAndEnableSsl(bool coreSupportsSsl) void ClientAuthHandler::onSslSocketEncrypted() { - QSslSocket *socket = qobject_cast(sender()); + auto *socket = qobject_cast(sender()); Q_ASSERT(socket); if (!socket->sslErrors().count()) { @@ -491,7 +485,7 @@ void ClientAuthHandler::onSslSocketEncrypted() void ClientAuthHandler::onSslErrors() { - QSslSocket *socket = qobject_cast(sender()); + auto *socket = qobject_cast(sender()); Q_ASSERT(socket); CoreAccountSettings s; @@ -505,11 +499,7 @@ void ClientAuthHandler::onSslErrors() break; case ClientAuthHandler::DigestVersion::Sha2_512: -#if QT_VERSION >= 0x050000 calculatedDigest = socket->peerCertificate().digest(QCryptographicHash::Sha512); -#else - calculatedDigest = sha2_512(socket->peerCertificate().toDer()); -#endif break; default: @@ -527,11 +517,7 @@ void ClientAuthHandler::onSslErrors() } if (permanently) { -#if QT_VERSION >= 0x050000 s.setAccountValue("SslCert", socket->peerCertificate().digest(QCryptographicHash::Sha512)); -#else - s.setAccountValue("SslCert", sha2_512(socket->peerCertificate().toDer())); -#endif s.setAccountValue("SslCertDigestVersion", ClientAuthHandler::DigestVersion::Latest); } else { @@ -540,28 +526,11 @@ void ClientAuthHandler::onSslErrors() } } else if (knownDigestVersion != ClientAuthHandler::DigestVersion::Latest) { -#if QT_VERSION >= 0x050000 s.setAccountValue("SslCert", socket->peerCertificate().digest(QCryptographicHash::Sha512)); -#else - s.setAccountValue("SslCert", sha2_512(socket->peerCertificate().toDer())); -#endif s.setAccountValue("SslCertDigestVersion", ClientAuthHandler::DigestVersion::Latest); } socket->ignoreSslErrors(); } -#if QT_VERSION < 0x050000 -QByteArray ClientAuthHandler::sha2_512(const QByteArray &input) { - unsigned char output[64]; - sha512((unsigned char*) input.constData(), input.size(), output, false); - // QByteArray::fromRawData() cannot be used here because that constructor - // does not copy "output" and the data is clobbered when the variable goes - // out of scope. - QByteArray result; - result.append((char*) output, 64); - return result; -} -#endif - #endif /* HAVE_SSL */