#include "clientauthhandler.h"
-// TODO: support system application proxy (new in Qt 4.6)
-
#include <QtEndian>
#ifdef HAVE_SSL
#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)
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
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;
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()));
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:
}
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 */