/***************************************************************************
- * Copyright (C) 2005-2015 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 *
#include "clientauthhandler.h"
-// TODO: support system application proxy (new in Qt 4.6)
-
#include <QtEndian>
#ifdef HAVE_SSL
#include "client.h"
#include "clientsettings.h"
+#include "logmessage.h"
#include "peerfactory.h"
-
-#if QT_VERSION < 0x050000
-# include "../../3rdparty/sha512/sha512.h"
-#endif
+#include "util.h"
using namespace Protocol;
ClientAuthHandler::ClientAuthHandler(CoreAccount account, QObject *parent)
: AuthHandler(parent),
- _peer(0),
+ _peer(nullptr),
_account(account),
_probing(false),
_legacy(false),
}
+Peer *ClientAuthHandler::peer() const
+{
+ return _peer;
+}
+
+
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
QTcpSocket *socket = new QTcpSocket(this);
#endif
-// TODO: Handle system proxy
#ifndef QT_NO_NETWORKPROXY
- if (_account.useProxy()) {
- QNetworkProxy proxy(_account.proxyType(), _account.proxyHostName(), _account.proxyPort(), _account.proxyUser(), _account.proxyPassword());
+ QNetworkProxy proxy;
+ proxy.setType(_account.proxyType());
+ if (_account.proxyType() == QNetworkProxy::Socks5Proxy ||
+ _account.proxyType() == QNetworkProxy::HttpProxy) {
+ proxy.setHostName(_account.proxyHostName());
+ proxy.setPort(_account.proxyPort());
+ proxy.setUser(_account.proxyUser());
+ proxy.setPassword(_account.proxyPassword());
+ }
+
+ if (_account.proxyType() == QNetworkProxy::DefaultProxy) {
+ QNetworkProxyFactory::setUseSystemConfiguration(true);
+ } else {
+ QNetworkProxyFactory::setUseSystemConfiguration(false);
socket->setProxy(proxy);
}
#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());
// The baseclass implementation will make sure to only send the signal once.
// However, we do want to prefer a potential socket error signal that may be on route already, so
// give this a chance to overtake us by spinning the loop...
- QTimer::singleShot(0, this, SLOT(onSocketDisconnected()));
+ QTimer::singleShot(0, this, &ClientAuthHandler::onSocketDisconnected);
}
break;
default:
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;
qDebug() << "Legacy core detected, switching to compatibility mode";
- RemotePeer *peer = PeerFactory::createPeer(PeerFactory::ProtoDescriptor(Protocol::LegacyProtocol, 0), this, socket(), Compressor::NoCompression, this);
+ auto *peer = PeerFactory::createPeer(PeerFactory::ProtoDescriptor(Protocol::LegacyProtocol, 0), this, socket(), Compressor::NoCompression, this);
// Only needed for the legacy peer, as all others check the protocol version before instantiation
- connect(peer, SIGNAL(protocolVersionMismatch(int,int)), SLOT(onProtocolVersionMismatch(int,int)));
+ connect(peer, &RemotePeer::protocolVersionMismatch, this, &ClientAuthHandler::onProtocolVersionMismatch);
setPeer(peer);
}
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<quint32>(reply);
- Protocol::Type type = static_cast<Protocol::Type>(reply & 0xff);
- quint16 protoFeatures = static_cast<quint16>(reply>>8 & 0xffff);
+ auto type = static_cast<Protocol::Type>(reply & 0xff);
+ auto protoFeatures = static_cast<quint16>(reply>>8 & 0xffff);
_connectionFeatures = static_cast<quint8>(reply>>24);
Compressor::CompressionLevel level;
}
if (peer->protocol() == Protocol::LegacyProtocol) {
- connect(peer, SIGNAL(protocolVersionMismatch(int,int)), SLOT(onProtocolVersionMismatch(int,int)));
+ connect(peer, &RemotePeer::protocolVersionMismatch, this, &ClientAuthHandler::onProtocolVersionMismatch);
_legacy = true;
}
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)
useSsl = _account.useSsl();
#endif
- _peer->dispatch(RegisterClient(Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().buildDate, useSsl));
+ _peer->dispatch(RegisterClient(Quassel::Features{}, Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().commitDate, useSsl));
}
{
_coreConfigured = msg.coreConfigured;
_backendInfo = msg.backendInfo;
+ _authenticatorInfo = msg.authenticatorInfo;
- Client::setCoreFeatures(static_cast<Quassel::Features>(msg.coreFeatures));
+ _peer->setFeatures(std::move(msg.features));
// The legacy protocol enables SSL at this point
if(_legacy && _account.useSsl())
void ClientAuthHandler::onConnectionReady()
{
+ const auto &coreFeatures = _peer->features();
+ auto unsupported = coreFeatures.toStringList(false);
+ if (!unsupported.isEmpty()) {
+ quInfo() << qPrintable(tr("Core does not support the following features: %1").arg(unsupported.join(", ")));
+ }
+ if (!coreFeatures.unknownFeatures().isEmpty()) {
+ quInfo() << qPrintable(tr("Core supports unknown features: %1").arg(coreFeatures.unknownFeatures().join(", ")));
+ }
+
emit connectionReady();
emit statusMessage(tr("Connected to %1").arg(_account.accountName()));
if (!_coreConfigured) {
// start wizard
- emit startCoreSetup(_backendInfo);
+ emit startCoreSetup(_backendInfo, _authenticatorInfo);
}
else // TODO: check if we need LoginEnabled
login();
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);
}
// Make sure the warning is shown next time we don't have SSL in the core
s.setAccountValue("ShowNoCoreSslWarning", true);
- QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket());
+ auto *sslSocket = qobject_cast<QSslSocket *>(socket());
Q_ASSERT(sslSocket);
- connect(sslSocket, SIGNAL(encrypted()), SLOT(onSslSocketEncrypted()));
- connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)), SLOT(onSslErrors()));
+ connect(sslSocket, &QSslSocket::encrypted, this, &ClientAuthHandler::onSslSocketEncrypted);
+ connect(sslSocket, selectOverload<const QList<QSslError>&>(&QSslSocket::sslErrors), this, &ClientAuthHandler::onSslErrors);
qDebug() << "Starting encryption...";
sslSocket->flush();
sslSocket->startClientEncryption();
void ClientAuthHandler::onSslSocketEncrypted()
{
- QSslSocket *socket = qobject_cast<QSslSocket *>(sender());
+ auto *socket = qobject_cast<QSslSocket *>(sender());
Q_ASSERT(socket);
if (!socket->sslErrors().count()) {
void ClientAuthHandler::onSslErrors()
{
- QSslSocket *socket = qobject_cast<QSslSocket *>(sender());
+ auto *socket = qobject_cast<QSslSocket *>(sender());
Q_ASSERT(socket);
CoreAccountSettings s;
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:
qWarning() << "Certificate digest version" << QString(knownDigestVersion) << "is not supported";
}
-
+
if (knownDigest != calculatedDigest) {
bool accepted = false;
bool permanently = false;
}
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 {
}
}
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 */