/***************************************************************************
- * 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"
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;
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
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();
}
s.setAccountValue("ShowNoCoreSslWarning", false);
s.setAccountValue("SslCert", QString());
+ s.setAccountValue("SslCertDigestVersion", QVariant(QVariant::Int));
}
if (_legacy)
onConnectionReady();
// That way, a warning will appear in case it becomes invalid at some point
CoreAccountSettings s;
s.setAccountValue("SSLCert", QString());
+ s.setAccountValue("SslCertDigestVersion", QVariant(QVariant::Int));
}
emit encrypted(true);
CoreAccountSettings s;
QByteArray knownDigest = s.accountValue("SslCert").toByteArray();
+ ClientAuthHandler::DigestVersion knownDigestVersion = static_cast<ClientAuthHandler::DigestVersion>(s.accountValue("SslCertDigestVersion").toInt());
+
+ QByteArray calculatedDigest;
+ switch (knownDigestVersion) {
+ case ClientAuthHandler::DigestVersion::Md5:
+ calculatedDigest = socket->peerCertificate().digest(QCryptographicHash::Md5);
+ break;
+
+ case ClientAuthHandler::DigestVersion::Sha2_512:
+ calculatedDigest = socket->peerCertificate().digest(QCryptographicHash::Sha512);
+ break;
+
+ default:
+ qWarning() << "Certificate digest version" << QString(knownDigestVersion) << "is not supported";
+ }
- if (knownDigest != socket->peerCertificate().digest()) {
+ if (knownDigest != calculatedDigest) {
bool accepted = false;
bool permanently = false;
emit handleSslErrors(socket, &accepted, &permanently);
return;
}
- if (permanently)
- s.setAccountValue("SslCert", socket->peerCertificate().digest());
- else
+ if (permanently) {
+ s.setAccountValue("SslCert", socket->peerCertificate().digest(QCryptographicHash::Sha512));
+ s.setAccountValue("SslCertDigestVersion", ClientAuthHandler::DigestVersion::Latest);
+ }
+ else {
s.setAccountValue("SslCert", QString());
+ s.setAccountValue("SslCertDigestVersion", QVariant(QVariant::Int));
+ }
+ }
+ else if (knownDigestVersion != ClientAuthHandler::DigestVersion::Latest) {
+ s.setAccountValue("SslCert", socket->peerCertificate().digest(QCryptographicHash::Sha512));
+ s.setAccountValue("SslCertDigestVersion", ClientAuthHandler::DigestVersion::Latest);
}
socket->ignoreSslErrors();