/***************************************************************************
- * Copyright (C) 2005-2014 by the Quassel Project *
+ * Copyright (C) 2005-2016 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
#include "clientsettings.h"
#include "peerfactory.h"
+#if QT_VERSION < 0x050000
+# include "../../3rdparty/sha512/sha512.h"
+#endif
+
using namespace Protocol;
ClientAuthHandler::ClientAuthHandler(CoreAccount account, QObject *parent)
_probing = true;
QDataStream stream(socket()); // stream handles the endianness for us
+ stream.setVersion(QDataStream::Qt_4_2);
quint32 magic = Protocol::magic;
#ifdef HAVE_SSL
useSsl = _account.useSsl();
#endif
- _peer->dispatch(RegisterClient(Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().buildDate, useSsl));
+ _peer->dispatch(RegisterClient(Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().commitDate, useSsl));
}
{
_coreConfigured = msg.coreConfigured;
_backendInfo = msg.backendInfo;
+ _authenticatorInfo = msg.authenticatorInfo;
Client::setCoreFeatures(static_cast<Quassel::Features>(msg.coreFeatures));
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:
+#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 != 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) {
+#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 {
s.setAccountValue("SslCert", QString());
+ s.setAccountValue("SslCertDigestVersion", QVariant(QVariant::Int));
+ }
+ }
+ 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 */