aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2016-01-14 17:11:03 +0100
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2016-01-18 12:17:15 +0000
commitb72c3cba2451881aca5cfb4989f08114da4f615f (patch)
tree86b4ce6d869cd3aa1319299087c9cab114bfa193
parent54d64971d8047d9fd6655fa53634bc1df9b63466 (diff)
SSH: Use categorized logging.
Change-Id: I9890c7d4a86320c835e70e66c523c5a2f7b41421 Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
-rw-r--r--src/libs/ssh/sftpchannel.cpp29
-rw-r--r--src/libs/ssh/sftpincomingpacket.cpp5
-rw-r--r--src/libs/ssh/sftpoutgoingpacket.cpp6
-rw-r--r--src/libs/ssh/ssh.pro2
-rw-r--r--src/libs/ssh/ssh.qbs1
-rw-r--r--src/libs/ssh/sshchannel.cpp21
-rw-r--r--src/libs/ssh/sshconnection.cpp12
-rw-r--r--src/libs/ssh/sshcryptofacility.cpp18
-rw-r--r--src/libs/ssh/sshdirecttcpiptunnel.cpp11
-rw-r--r--src/libs/ssh/sshhostkeydatabase.cpp4
-rw-r--r--src/libs/ssh/sshincomingpacket.cpp31
-rw-r--r--src/libs/ssh/sshkeyexchange.cpp53
-rw-r--r--src/libs/ssh/sshlogging.cpp37
-rw-r--r--src/libs/ssh/sshlogging_p.h42
-rw-r--r--src/libs/ssh/sshoutgoingpacket.cpp9
-rw-r--r--src/libs/ssh/sshpacket.cpp17
-rw-r--r--src/libs/ssh/sshremoteprocess.cpp19
-rw-r--r--src/libs/ssh/sshsendfacility.cpp5
18 files changed, 166 insertions, 156 deletions
diff --git a/src/libs/ssh/sftpchannel.cpp b/src/libs/ssh/sftpchannel.cpp
index f68e427702..cf5811cf5a 100644
--- a/src/libs/ssh/sftpchannel.cpp
+++ b/src/libs/ssh/sftpchannel.cpp
@@ -33,6 +33,7 @@
#include "sshexception_p.h"
#include "sshincomingpacket_p.h"
+#include "sshlogging_p.h"
#include "sshsendfacility_p.h"
#include <QDir>
@@ -256,9 +257,7 @@ void SftpChannelPrivate::handleChannelSuccess()
{
if (channelState() == CloseRequested)
return;
-#ifdef CREATOR_SSH_DEBUG
- qDebug("sftp subsystem initialized");
-#endif
+ qCDebug(sshLog, "sftp subsystem initialized");
sendData(m_outgoingPacket.generateInit(ProtocolVersion).rawData());
m_sftpState = InitSent;
}
@@ -293,15 +292,13 @@ void SftpChannelPrivate::handleChannelDataInternal(const QByteArray &data)
void SftpChannelPrivate::handleChannelExtendedDataInternal(quint32 type,
const QByteArray &data)
{
- qWarning("Unexpected extended data '%s' of type %d on SFTP channel.",
- data.data(), type);
+ qCWarning(sshLog, "Unexpected extended data '%s' of type %d on SFTP channel.",
+ data.data(), type);
}
void SftpChannelPrivate::handleExitStatus(const SshChannelExitStatus &exitStatus)
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Remote SFTP service exited with exit code %d", exitStatus.exitStatus);
-#endif
+ qCDebug(sshLog, "Remote SFTP service exited with exit code %d", exitStatus.exitStatus);
if (channelState() == CloseRequested || channelState() == Closed)
return;
@@ -322,9 +319,7 @@ void SftpChannelPrivate::handleExitSignal(const SshChannelExitSignal &signal)
void SftpChannelPrivate::handleCurrentPacket()
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Handling SFTP packet of type %d", m_incomingPacket.type());
-#endif
+ qCDebug(sshLog, "Handling SFTP packet of type %d", m_incomingPacket.type());
switch (m_incomingPacket.type()) {
case SSH_FXP_VERSION:
handleServerVersion();
@@ -359,9 +354,7 @@ void SftpChannelPrivate::handleServerVersion()
"Unexpected SSH_FXP_VERSION packet.");
}
-#ifdef CREATOR_SSH_DEBUG
- qDebug("sftp init received");
-#endif
+ qCDebug(sshLog, "sftp init received");
const quint32 serverVersion = m_incomingPacket.extractServerVersion();
if (serverVersion != ProtocolVersion) {
emit channelError(tr("Protocol version mismatch: Expected %1, got %2")
@@ -450,9 +443,7 @@ void SftpChannelPrivate::handlePutHandle(const JobMap::Iterator &it)
void SftpChannelPrivate::handleStatus()
{
const SftpStatusResponse &response = m_incomingPacket.asStatusResponse();
-#ifdef CREATOR_SSH_DEBUG
- qDebug("%s: status = %d", Q_FUNC_INFO, response.status);
-#endif
+ qCDebug(sshLog, "%s: status = %d", Q_FUNC_INFO, response.status);
JobMap::Iterator it = lookupJob(response.requestId);
switch (it.value()->type()) {
case AbstractSftpOperation::ListDir:
@@ -850,9 +841,7 @@ void SftpChannelPrivate::closeHook()
void SftpChannelPrivate::handleOpenSuccessInternal()
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("SFTP session started");
-#endif
+ qCDebug(sshLog, "SFTP session started");
m_sendFacility.sendSftpPacket(remoteChannel());
m_sftpState = SubsystemRequested;
}
diff --git a/src/libs/ssh/sftpincomingpacket.cpp b/src/libs/ssh/sftpincomingpacket.cpp
index 4953d5a7b5..ef46640ce5 100644
--- a/src/libs/ssh/sftpincomingpacket.cpp
+++ b/src/libs/ssh/sftpincomingpacket.cpp
@@ -31,6 +31,7 @@
#include "sftpincomingpacket_p.h"
#include "sshexception_p.h"
+#include "sshlogging_p.h"
#include "sshpacketparser_p.h"
namespace QSsh {
@@ -42,10 +43,8 @@ SftpIncomingPacket::SftpIncomingPacket() : m_length(0)
void SftpIncomingPacket::consumeData(QByteArray &newData)
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("%s: current data size = %d, new data size = %d", Q_FUNC_INFO,
+ qCDebug(sshLog, "%s: current data size = %d, new data size = %d", Q_FUNC_INFO,
m_data.size(), newData.size());
-#endif
if (isComplete() || dataSize() + newData.size() < sizeof m_length)
return;
diff --git a/src/libs/ssh/sftpoutgoingpacket.cpp b/src/libs/ssh/sftpoutgoingpacket.cpp
index 6fe75fc5b2..b112b43f66 100644
--- a/src/libs/ssh/sftpoutgoingpacket.cpp
+++ b/src/libs/ssh/sftpoutgoingpacket.cpp
@@ -30,6 +30,7 @@
#include "sftpoutgoingpacket_p.h"
+#include "sshlogging_p.h"
#include "sshpacket_p.h"
#include <QtEndian>
@@ -183,10 +184,7 @@ SftpOutgoingPacket &SftpOutgoingPacket::init(SftpPacketType type,
m_data[TypeOffset] = type;
if (type != SSH_FXP_INIT) {
appendInt(requestId);
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Generating SFTP packet of type %d with request id %u", type,
- requestId);
-#endif
+ qCDebug(sshLog, "Generating SFTP packet of type %d with request id %u", type, requestId);
}
return *this;
}
diff --git a/src/libs/ssh/ssh.pro b/src/libs/ssh/ssh.pro
index f2b8036e89..8608d619dc 100644
--- a/src/libs/ssh/ssh.pro
+++ b/src/libs/ssh/ssh.pro
@@ -29,6 +29,7 @@ SOURCES = $$PWD/sshsendfacility.cpp \
$$PWD/sshkeycreationdialog.cpp \
$$PWD/sshinit.cpp \
$$PWD/sshdirecttcpiptunnel.cpp \
+ $$PWD/sshlogging.cpp \
$$PWD/sshhostkeydatabase.cpp
HEADERS = $$PWD/sshsendfacility_p.h \
@@ -66,6 +67,7 @@ HEADERS = $$PWD/sshsendfacility_p.h \
$$PWD/sshdirecttcpiptunnel_p.h \
$$PWD/sshinit_p.h \
$$PWD/sshdirecttcpiptunnel.h \
+ $$PWD/sshlogging_p.h \
$$PWD/sshhostkeydatabase.h
FORMS = $$PWD/sshkeycreationdialog.ui
diff --git a/src/libs/ssh/ssh.qbs b/src/libs/ssh/ssh.qbs
index 8062f1a58e..185f397b61 100644
--- a/src/libs/ssh/ssh.qbs
+++ b/src/libs/ssh/ssh.qbs
@@ -36,6 +36,7 @@ QtcLibrary {
"sshkeygenerator.cpp", "sshkeygenerator.h",
"sshkeypasswordretriever.cpp",
"sshkeypasswordretriever_p.h",
+ "sshlogging.cpp", "sshlogging_p.h",
"sshoutgoingpacket.cpp", "sshoutgoingpacket_p.h",
"sshpacket.cpp", "sshpacket_p.h",
"sshpacketparser.cpp", "sshpacketparser_p.h",
diff --git a/src/libs/ssh/sshchannel.cpp b/src/libs/ssh/sshchannel.cpp
index c816a99e6f..b5b2fe3ff4 100644
--- a/src/libs/ssh/sshchannel.cpp
+++ b/src/libs/ssh/sshchannel.cpp
@@ -31,6 +31,7 @@
#include "sshchannel_p.h"
#include "sshincomingpacket_p.h"
+#include "sshlogging_p.h"
#include "sshsendfacility_p.h"
#include <botan/botan.h>
@@ -80,7 +81,7 @@ void AbstractSshChannel::requestSessionStart()
setChannelState(SessionRequested);
m_timeoutTimer.start(ReplyTimeout);
} catch (const Botan::Exception &e) {
- qDebug("Botan error: %s", e.what());
+ qCWarning(sshLog, "Botan error: %s", e.what());
closeChannel();
}
}
@@ -91,7 +92,7 @@ void AbstractSshChannel::sendData(const QByteArray &data)
m_sendBuffer += data;
flushSendBuffer();
} catch (const Botan::Exception &e) {
- qDebug("Botan error: %s", e.what());
+ qCWarning(sshLog, "Botan error: %s", e.what());
closeChannel();
}
}
@@ -154,11 +155,9 @@ void AbstractSshChannel::handleOpenSuccess(quint32 remoteChannelId,
"Maximum packet size too low.");
}
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Channel opened. remote channel id: %u, remote window size: %u, "
+ qCDebug(sshLog, "Channel opened. remote channel id: %u, remote window size: %u, "
"remote max packet size: %u",
remoteChannelId, remoteWindowSize, remoteMaxPacketSize);
-#endif
m_remoteChannel = remoteChannelId;
m_remoteWindowSize = remoteWindowSize;
m_remoteMaxPacketSize = remoteMaxPacketSize;
@@ -183,9 +182,7 @@ void AbstractSshChannel::handleOpenFailure(const QString &reason)
m_timeoutTimer.stop();
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Channel open request failed for channel %u", m_localChannel);
-#endif
+ qCDebug(sshLog, "Channel open request failed for channel %u", m_localChannel);
handleOpenFailureInternal(reason);
}
@@ -201,9 +198,7 @@ void AbstractSshChannel::handleChannelEof()
void AbstractSshChannel::handleChannelClose()
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Receiving CLOSE for channel %u", m_localChannel);
-#endif
+ qCDebug(sshLog, "Receiving CLOSE for channel %u", m_localChannel);
if (channelState() == Inactive || channelState() == Closed) {
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
"Unexpected SSH_MSG_CHANNEL_CLOSE message.");
@@ -235,7 +230,7 @@ void AbstractSshChannel::handleChannelRequest(const SshIncomingPacket &packet)
else if (requestType == SshIncomingPacket::ExitSignalType)
handleExitSignal(packet.extractChannelExitSignal());
else if (requestType != "eow@openssh.com") // Suppress warning for this one, as it's sent all the time.
- qWarning("Ignoring unknown request type '%s'", requestType.data());
+ qCWarning(sshLog, "Ignoring unknown request type '%s'", requestType.data());
}
int AbstractSshChannel::handleChannelOrExtendedChannelData(const QByteArray &data)
@@ -244,7 +239,7 @@ int AbstractSshChannel::handleChannelOrExtendedChannelData(const QByteArray &dat
const int bytesToDeliver = qMin<quint32>(data.size(), maxDataSize());
if (bytesToDeliver != data.size())
- qWarning("Misbehaving server does not respect local window, clipping.");
+ qCWarning(sshLog, "Misbehaving server does not respect local window, clipping.");
m_localWindowSize -= bytesToDeliver;
if (m_localWindowSize < maxPacketSize()) {
diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp
index 9a3cd8eb2f..103026d42e 100644
--- a/src/libs/ssh/sshconnection.cpp
+++ b/src/libs/ssh/sshconnection.cpp
@@ -39,6 +39,7 @@
#include "sshexception_p.h"
#include "sshinit_p.h"
#include "sshkeyexchange_p.h"
+#include "sshlogging_p.h"
#include "sshremoteprocess.h"
#include <botan/botan.h>
@@ -196,7 +197,7 @@ int SshConnection::closeAllChannels()
try {
return d->m_channelManager->closeAllChannels(Internal::SshChannelManager::CloseAllRegular);
} catch (const Botan::Exception &e) {
- qDebug("%s: %s", Q_FUNC_INFO, e.what());
+ qCWarning(Internal::sshLog, "%s: %s", Q_FUNC_INFO, e.what());
return -1;
}
}
@@ -324,10 +325,7 @@ void SshConnectionPrivate::handleIncomingData()
if (!canUseSocket())
return;
m_incomingData += m_socket->readAll();
-#ifdef CREATOR_SSH_DEBUG
- qDebug("state = %d, remote data size = %d", m_state,
- m_incomingData.count());
-#endif
+ qCDebug(sshLog, "state = %d, remote data size = %d", m_state, m_incomingData.count());
if (m_serverId.isEmpty())
handleServerId();
handlePackets();
@@ -346,10 +344,8 @@ void SshConnectionPrivate::handleIncomingData()
// RFC 4253, 4.2.
void SshConnectionPrivate::handleServerId()
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("%s: incoming data size = %d, incoming data = '%s'",
+ qCDebug(sshLog, "%s: incoming data size = %d, incoming data = '%s'",
Q_FUNC_INFO, m_incomingData.count(), m_incomingData.data());
-#endif
const int newLinePos = m_incomingData.indexOf('\n');
if (newLinePos == -1)
return; // Not enough data yet.
diff --git a/src/libs/ssh/sshcryptofacility.cpp b/src/libs/ssh/sshcryptofacility.cpp
index 4dc27929f8..21e9d55ad5 100644
--- a/src/libs/ssh/sshcryptofacility.cpp
+++ b/src/libs/ssh/sshcryptofacility.cpp
@@ -35,6 +35,7 @@
#include "sshexception_p.h"
#include "sshkeyexchange_p.h"
#include "sshkeypasswordretriever_p.h"
+#include "sshlogging_p.h"
#include "sshpacket_p.h"
#include <botan/botan.h>
@@ -213,9 +214,7 @@ void SshEncryptionFacility::createAuthenticationKey(const QByteArray &privKeyFil
return;
m_authKeyAlgoName.clear();
-#ifdef CREATOR_SSH_DEBUG
- qDebug("%s: Key not cached, reading", Q_FUNC_INFO);
-#endif
+ qCDebug(sshLog, "%s: Key not cached, reading", Q_FUNC_INFO);
QList<BigInt> pubKeyParams;
QList<BigInt> allKeyParams;
QString error1;
@@ -223,9 +222,7 @@ void SshEncryptionFacility::createAuthenticationKey(const QByteArray &privKeyFil
if (!createAuthenticationKeyFromPKCS8(privKeyFileContents, pubKeyParams, allKeyParams, error1)
&& !createAuthenticationKeyFromOpenSSL(privKeyFileContents, pubKeyParams, allKeyParams,
error2)) {
-#ifdef CREATOR_SSH_DEBUG
- qDebug("%s: %s\n\t%s\n", Q_FUNC_INFO, qPrintable(error1), qPrintable(error2));
-#endif
+ qCDebug(sshLog, "%s: %s\n\t%s\n", Q_FUNC_INFO, qPrintable(error1), qPrintable(error2));
throw SshClientException(SshKeyFileError, SSH_TR("Decoding of private key file failed: "
"Format not understood."));
}
@@ -274,7 +271,8 @@ bool SshEncryptionFacility::createAuthenticationKeyFromPKCS8(const QByteArray &p
<< ecdsaKey->public_point().get_affine_y();
allKeyParams << pubKeyParams << value;
} else {
- qWarning("%s: Unexpected code flow, expected success or exception.", Q_FUNC_INFO);
+ qCWarning(sshLog, "%s: Unexpected code flow, expected success or exception.",
+ Q_FUNC_INFO);
return false;
}
} catch (const Exception &ex) {
@@ -438,13 +436,11 @@ void SshDecryptionFacility::decrypt(QByteArray &data, quint32 offset,
quint32 dataSize) const
{
convert(data, offset, dataSize);
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Decrypted data:");
+ qCDebug(sshLog, "Decrypted data:");
const char * const start = data.constData() + offset;
const char * const end = start + dataSize;
for (const char *c = start; c < end; ++c)
- qDebug() << "'" << *c << "' (0x" << (static_cast<int>(*c) & 0xff) << ")";
-#endif
+ qCDebug(sshLog, ) << "'" << *c << "' (0x" << (static_cast<int>(*c) & 0xff) << ")";
}
} // namespace Internal
diff --git a/src/libs/ssh/sshdirecttcpiptunnel.cpp b/src/libs/ssh/sshdirecttcpiptunnel.cpp
index 8f7be39847..504b3fd742 100644
--- a/src/libs/ssh/sshdirecttcpiptunnel.cpp
+++ b/src/libs/ssh/sshdirecttcpiptunnel.cpp
@@ -31,6 +31,7 @@
#include "sshdirecttcpiptunnel_p.h"
#include "sshincomingpacket_p.h"
+#include "sshlogging_p.h"
#include "sshsendfacility_p.h"
#include <QTimer>
@@ -82,18 +83,18 @@ void SshDirectTcpIpTunnelPrivate::handleChannelDataInternal(const QByteArray &da
void SshDirectTcpIpTunnelPrivate::handleChannelExtendedDataInternal(quint32 type,
const QByteArray &data)
{
- qDebug("%s: Unexpected extended channel data. Type is %u, content is '%s'.", Q_FUNC_INFO, type,
- data.constData());
+ qCWarning(sshLog, "%s: Unexpected extended channel data. Type is %u, content is '%s'.",
+ Q_FUNC_INFO, type, data.constData());
}
void SshDirectTcpIpTunnelPrivate::handleExitStatus(const SshChannelExitStatus &exitStatus)
{
- qDebug("%s: Unexpected exit status %d.", Q_FUNC_INFO, exitStatus.exitStatus);
+ qCWarning(sshLog, "%s: Unexpected exit status %d.", Q_FUNC_INFO, exitStatus.exitStatus);
}
void SshDirectTcpIpTunnelPrivate::handleExitSignal(const SshChannelExitSignal &signal)
{
- qDebug("%s: Unexpected exit signal %s.", Q_FUNC_INFO, signal.signal.constData());
+ qCWarning(sshLog, "%s: Unexpected exit signal %s.", Q_FUNC_INFO, signal.signal.constData());
}
void SshDirectTcpIpTunnelPrivate::closeHook()
@@ -166,7 +167,7 @@ void SshDirectTcpIpTunnel::initialize()
d->setChannelState(AbstractSshChannel::SessionRequested);
d->m_timeoutTimer.start(d->ReplyTimeout);
} catch (const Botan::Exception &e) { // Won't happen, but let's play it safe.
- qDebug("Botan error: %s", e.what());
+ qCWarning(sshLog, "Botan error: %s", e.what());
d->closeChannel();
}
}
diff --git a/src/libs/ssh/sshhostkeydatabase.cpp b/src/libs/ssh/sshhostkeydatabase.cpp
index efec5f764f..163540c073 100644
--- a/src/libs/ssh/sshhostkeydatabase.cpp
+++ b/src/libs/ssh/sshhostkeydatabase.cpp
@@ -29,6 +29,8 @@
****************************************************************************/
#include "sshhostkeydatabase.h"
+#include "sshlogging_p.h"
+
#include <QByteArray>
#include <QCoreApplication>
#include <QDir>
@@ -72,7 +74,7 @@ bool SshHostKeyDatabase::load(const QString &filePath, QString *error)
foreach (const QByteArray &line, content.split('\n')) {
const QList<QByteArray> &lineData = line.trimmed().split(' ');
if (lineData.count() != 2) {
- qDebug("Unexpected line \"%s\" in file \"%s\".", line.constData(),
+ qCDebug(Internal::sshLog, "Unexpected line \"%s\" in file \"%s\".", line.constData(),
qPrintable(filePath));
continue;
}
diff --git a/src/libs/ssh/sshincomingpacket.cpp b/src/libs/ssh/sshincomingpacket.cpp
index efa8ec319e..3cc76c4630 100644
--- a/src/libs/ssh/sshincomingpacket.cpp
+++ b/src/libs/ssh/sshincomingpacket.cpp
@@ -33,6 +33,7 @@
#include "ssh_global.h"
#include "sshbotanconversions_p.h"
#include "sshcapabilities_p.h"
+#include "sshlogging_p.h"
namespace QSsh {
namespace Internal {
@@ -66,10 +67,8 @@ void SshIncomingPacket::reset()
void SshIncomingPacket::consumeData(QByteArray &newData)
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("%s: current data size = %d, new data size = %d",
+ qCDebug(sshLog, "%s: current data size = %d, new data size = %d",
Q_FUNC_INFO, m_data.size(), newData.size());
-#endif
if (isComplete() || newData.isEmpty())
return;
@@ -83,9 +82,7 @@ void SshIncomingPacket::consumeData(QByteArray &newData)
const int bytesToTake
= qMin<quint32>(minSize - currentDataSize(), newData.size());
moveFirstBytes(m_data, newData, bytesToTake);
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Took %d bytes from new data", bytesToTake);
-#endif
+ qCDebug(sshLog, "Took %d bytes from new data", bytesToTake);
if (currentDataSize() < minSize)
return;
}
@@ -97,14 +94,10 @@ void SshIncomingPacket::consumeData(QByteArray &newData)
= qMin<quint32>(length() + 4 + macLength() - currentDataSize(),
newData.size());
moveFirstBytes(m_data, newData, bytesToTake);
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Took %d bytes from new data", bytesToTake);
-#endif
+ qCDebug(sshLog, "Took %d bytes from new data", bytesToTake);
if (isComplete()) {
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Message complete. Overall size: %u, payload size: %u",
+ qCDebug(sshLog, "Message complete. Overall size: %u, payload size: %u",
m_data.size(), m_length - paddingLength() - 1);
-#endif
decrypt();
++m_serverSeqNr;
}
@@ -509,19 +502,13 @@ QByteArray SshIncomingPacket::extractChannelRequestType() const
void SshIncomingPacket::calculateLength() const
{
Q_ASSERT(currentDataSize() >= minPacketSize());
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Length field before decryption: %d-%d-%d-%d", m_data.at(0) & 0xff,
+ qCDebug(sshLog, "Length field before decryption: %d-%d-%d-%d", m_data.at(0) & 0xff,
m_data.at(1) & 0xff, m_data.at(2) & 0xff, m_data.at(3) & 0xff);
-#endif
m_decrypter.decrypt(m_data, 0, cipherBlockSize());
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Length field after decryption: %d-%d-%d-%d", m_data.at(0) & 0xff, m_data.at(1) & 0xff, m_data.at(2) & 0xff, m_data.at(3) & 0xff);
- qDebug("message type = %d", m_data.at(TypeOffset));
-#endif
+ qCDebug(sshLog, "Length field after decryption: %d-%d-%d-%d", m_data.at(0) & 0xff, m_data.at(1) & 0xff, m_data.at(2) & 0xff, m_data.at(3) & 0xff);
+ qCDebug(sshLog, "message type = %d", m_data.at(TypeOffset));
m_length = SshPacketParser::asUint32(m_data, static_cast<quint32>(0));
-#ifdef CREATOR_SSH_DEBUG
- qDebug("decrypted length is %u", m_length);
-#endif
+ qCDebug(sshLog, "decrypted length is %u", m_length);
}
} // namespace Internal
diff --git a/src/libs/ssh/sshkeyexchange.cpp b/src/libs/ssh/sshkeyexchange.cpp
index 9f8ec9d24c..125f66efe5 100644
--- a/src/libs/ssh/sshkeyexchange.cpp
+++ b/src/libs/ssh/sshkeyexchange.cpp
@@ -33,15 +33,13 @@
#include "ssh_global.h"
#include "sshbotanconversions_p.h"
#include "sshcapabilities_p.h"
+#include "sshlogging_p.h"
#include "sshsendfacility_p.h"
#include "sshexception_p.h"
#include "sshincomingpacket_p.h"
#include <botan/botan.h>
-#ifdef CREATOR_SSH_DEBUG
-#include <iostream>
-#endif
#include <string>
using namespace Botan;
@@ -54,26 +52,16 @@ namespace {
// For debugging
void printNameList(const char *listName, const SshNameList &list)
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("%s:", listName);
+ qCDebug(sshLog, "%s:", listName);
foreach (const QByteArray &name, list.names)
- qDebug("%s", name.constData());
-#else
- Q_UNUSED(listName);
- Q_UNUSED(list);
-#endif
+ qCDebug(sshLog, "%s", name.constData());
}
-#ifdef CREATOR_SSH_DEBUG
void printData(const char *name, const QByteArray &data)
{
- std::cerr << std::hex;
- qDebug("The client thinks the %s has length %d and is:", name, data.count());
- for (int i = 0; i < data.count(); ++i)
- std::cerr << (static_cast<unsigned int>(data.at(i)) & 0xff) << ' ';
- std::cerr << std::endl;
+ qCDebug(sshLog, "The client thinks the %s has length %d and is: %s", name, data.count(),
+ data.toHex().constData());
}
-#endif
} // anonymous namespace
@@ -93,9 +81,7 @@ void SshKeyExchange::sendKexInitPacket(const QByteArray &serverId)
bool SshKeyExchange::sendDhInitPacket(const SshIncomingPacket &serverKexInit)
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("server requests key exchange");
-#endif
+ qCDebug(sshLog, "server requests key exchange");
serverKexInit.printRawBytes();
SshKeyExchangeInit kexInitParams
= serverKexInit.extractKeyExchangeInitData();
@@ -110,9 +96,7 @@ bool SshKeyExchange::sendDhInitPacket(const SshIncomingPacket &serverKexInit)
printNameList("Compression algorithms client to server", kexInitParams.compressionAlgorithmsClientToServer);
printNameList("Languages client to server", kexInitParams.languagesClientToServer);
printNameList("Languages server to client", kexInitParams.languagesServerToClient);
-#ifdef CREATOR_SSH_DEBUG
- qDebug("First packet follows: %d", kexInitParams.firstKexPacketFollows);
-#endif
+ qCDebug(sshLog, "First packet follows: %d", kexInitParams.firstKexPacketFollows);
m_kexAlgoName = SshCapabilities::findBestMatch(SshCapabilities::KeyExchangeMethods,
kexInitParams.keyAlgorithms.names);
@@ -161,6 +145,13 @@ void SshKeyExchange::sendNewKeysPacket(const SshIncomingPacket &dhReply,
concatenatedData += AbstractSshPacket::encodeString(m_clientKexInitPayload);
concatenatedData += AbstractSshPacket::encodeString(m_serverKexInitPayload);
concatenatedData += reply.k_s;
+
+ printData("Client Id", AbstractSshPacket::encodeString(clientId));
+ printData("Server Id", AbstractSshPacket::encodeString(m_serverId));
+ printData("Client Payload", AbstractSshPacket::encodeString(m_clientKexInitPayload));
+ printData("Server payload", AbstractSshPacket::encodeString(m_serverKexInitPayload));
+ printData("K_S", reply.k_s);
+
SecureVector<byte> encodedK;
if (m_dhKey) {
concatenatedData += AbstractSshPacket::encodeMpInt(m_dhKey->get_y());
@@ -169,6 +160,8 @@ void SshKeyExchange::sendNewKeysPacket(const SshIncomingPacket &dhReply,
SecureVector<byte> encodedF = BigInt::encode(reply.f);
encodedK = dhOp.agree(encodedF, encodedF.size());
m_dhKey.reset(nullptr);
+ printData("y", AbstractSshPacket::encodeMpInt(m_dhKey->get_y()));
+ printData("f", AbstractSshPacket::encodeMpInt(reply.f));
} else {
Q_ASSERT(m_ecdhKey);
concatenatedData // Q_C.
@@ -181,25 +174,15 @@ void SshKeyExchange::sendNewKeysPacket(const SshIncomingPacket &dhReply,
const BigInt k = BigInt::decode(encodedK);
m_k = AbstractSshPacket::encodeMpInt(k); // Roundtrip, as Botan encodes BigInts somewhat differently.
+ printData("K", m_k);
concatenatedData += m_k;
+ printData("Concatenated data", concatenatedData);
m_hash.reset(get_hash(botanHMacAlgoName(hashAlgoForKexAlgo())));
const SecureVector<byte> &hashResult = m_hash->process(convertByteArray(concatenatedData),
concatenatedData.size());
m_h = convertByteArray(hashResult);
-
-#ifdef CREATOR_SSH_DEBUG
- printData("Client Id", AbstractSshPacket::encodeString(clientId));
- printData("Server Id", AbstractSshPacket::encodeString(m_serverId));
- printData("Client Payload", AbstractSshPacket::encodeString(m_clientKexInitPayload));
- printData("Server payload", AbstractSshPacket::encodeString(m_serverKexInitPayload));
- printData("K_S", reply.k_s);
- printData("y", AbstractSshPacket::encodeMpInt(m_dhKey->get_y()));
- printData("f", AbstractSshPacket::encodeMpInt(reply.f));
- printData("K", m_k);
- printData("Concatenated data", concatenatedData);
printData("H", m_h);
-#endif // CREATOR_SSH_DEBUG
QScopedPointer<Public_Key> sigKey;
if (m_serverHostKeyAlgo == SshCapabilities::PubKeyDss) {
diff --git a/src/libs/ssh/sshlogging.cpp b/src/libs/ssh/sshlogging.cpp
new file mode 100644
index 0000000000..4027a9be98
--- /dev/null
+++ b/src/libs/ssh/sshlogging.cpp
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "sshlogging_p.h"
+
+namespace QSsh {
+namespace Internal {
+Q_LOGGING_CATEGORY(sshLog, "qtc.ssh")
+} // namespace Internal
+} // namespace QSsh
diff --git a/src/libs/ssh/sshlogging_p.h b/src/libs/ssh/sshlogging_p.h
new file mode 100644
index 0000000000..bf41ef26bf
--- /dev/null
+++ b/src/libs/ssh/sshlogging_p.h
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef SSHLOGGING_P_H
+#define SSHLOGGING_P_H
+
+#include <QLoggingCategory>
+
+namespace QSsh {
+namespace Internal {
+Q_DECLARE_LOGGING_CATEGORY(sshLog)
+} // namespace Internal
+} // namespace QSsh
+
+#endif // Include guard
diff --git a/src/libs/ssh/sshoutgoingpacket.cpp b/src/libs/ssh/sshoutgoingpacket.cpp
index dc3b916f2f..dfdc5c269b 100644
--- a/src/libs/ssh/sshoutgoingpacket.cpp
+++ b/src/libs/ssh/sshoutgoingpacket.cpp
@@ -32,6 +32,7 @@
#include "sshcapabilities_p.h"
#include "sshcryptofacility_p.h"
+#include "sshlogging_p.h"
#include <QtEndian>
@@ -328,13 +329,9 @@ void SshOutgoingPacket::finalize()
setPadding();
setLengthField(m_data);
m_length = m_data.size() - 4;
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Encrypting packet of type %u", m_data.at(TypeOffset));
-#endif
+ qCDebug(sshLog, "Encrypting packet of type %u", m_data.at(TypeOffset));
encrypt();
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Sending packet of size %d", rawData().count());
-#endif
+ qCDebug(sshLog, "Sending packet of size %d", rawData().count());
Q_ASSERT(isComplete());
}
diff --git a/src/libs/ssh/sshpacket.cpp b/src/libs/ssh/sshpacket.cpp
index d73e60a5f0..123dd78ddc 100644
--- a/src/libs/ssh/sshpacket.cpp
+++ b/src/libs/ssh/sshpacket.cpp
@@ -33,6 +33,7 @@
#include "sshcapabilities_p.h"
#include "sshcryptofacility_p.h"
#include "sshexception_p.h"
+#include "sshlogging_p.h"
#include "sshpacketparser_p.h"
#include <QDebug>
@@ -47,18 +48,10 @@ const quint32 AbstractSshPacket::PayloadOffset = PaddingLengthOffset + 1;
const quint32 AbstractSshPacket::TypeOffset = PayloadOffset;
const quint32 AbstractSshPacket::MinPaddingLength = 4;
-namespace {
-
- void printByteArray(const QByteArray &data)
- {
-#ifdef CREATOR_SSH_DEBUG
- for (int i = 0; i < data.count(); ++i)
- qDebug() << std::hex << (static_cast<unsigned int>(data[i]) & 0xff) << " ";
-#else
- Q_UNUSED(data);
-#endif
- }
-} // anonymous namespace
+static void printByteArray(const QByteArray &data)
+{
+ qCDebug(sshLog, "%s", data.toHex().constData());
+}
AbstractSshPacket::AbstractSshPacket() : m_length(0) { }
diff --git a/src/libs/ssh/sshremoteprocess.cpp b/src/libs/ssh/sshremoteprocess.cpp
index c5894e62b5..f36d0bb143 100644
--- a/src/libs/ssh/sshremoteprocess.cpp
+++ b/src/libs/ssh/sshremoteprocess.cpp
@@ -33,6 +33,7 @@
#include "ssh_global.h"
#include "sshincomingpacket_p.h"
+#include "sshlogging_p.h"
#include "sshsendfacility_p.h"
#include <botan/botan.h>
@@ -195,9 +196,7 @@ void SshRemoteProcess::requestTerminal(const SshPseudoTerminal &terminal)
void SshRemoteProcess::start()
{
if (d->channelState() == Internal::SshRemoteProcessPrivate::Inactive) {
-#ifdef CREATOR_SSH_DEBUG
- qDebug("process start requested, channel id = %u", d->localChannelId());
-#endif
+ qCDebug(Internal::sshLog, "process start requested, channel id = %u", d->localChannelId());
QIODevice::open(QIODevice::ReadWrite);
d->requestSessionStart();
}
@@ -267,9 +266,7 @@ void SshRemoteProcessPrivate::init()
void SshRemoteProcessPrivate::setProcState(ProcessState newState)
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("channel: old state = %d,new state = %d", m_procState, newState);
-#endif
+ qCDebug(sshLog, "channel: old state = %d,new state = %d", m_procState, newState);
m_procState = newState;
if (newState == StartFailed) {
emit closed(SshRemoteProcess::FailedToStart);
@@ -351,7 +348,7 @@ void SshRemoteProcessPrivate::handleChannelExtendedDataInternal(quint32 type,
const QByteArray &data)
{
if (type != SSH_EXTENDED_DATA_STDERR) {
- qWarning("Unknown extended data type %u", type);
+ qCWarning(sshLog, "Unknown extended data type %u", type);
} else {
m_stderr += data;
emit readyReadStandardError();
@@ -362,18 +359,14 @@ void SshRemoteProcessPrivate::handleChannelExtendedDataInternal(quint32 type,
void SshRemoteProcessPrivate::handleExitStatus(const SshChannelExitStatus &exitStatus)
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Process exiting with exit code %d", exitStatus.exitStatus);
-#endif
+ qCDebug(sshLog, "Process exiting with exit code %d", exitStatus.exitStatus);
m_exitCode = exitStatus.exitStatus;
m_procState = Exited;
}
void SshRemoteProcessPrivate::handleExitSignal(const SshChannelExitSignal &signal)
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Exit due to signal %s", signal.signal.data());
-#endif
+ qCDebug(sshLog, "Exit due to signal %s", signal.signal.data());
for (size_t i = 0; i < sizeof signalMap/sizeof *signalMap; ++i) {
if (signalMap[i].signalString == signal.signal) {
diff --git a/src/libs/ssh/sshsendfacility.cpp b/src/libs/ssh/sshsendfacility.cpp
index 18c3dde1d0..e1a7d3e000 100644
--- a/src/libs/ssh/sshsendfacility.cpp
+++ b/src/libs/ssh/sshsendfacility.cpp
@@ -31,6 +31,7 @@
#include "sshsendfacility_p.h"
#include "sshkeyexchange_p.h"
+#include "sshlogging_p.h"
#include "sshoutgoingpacket_p.h"
#include <QTcpSocket>
@@ -46,9 +47,7 @@ SshSendFacility::SshSendFacility(QTcpSocket *socket)
void SshSendFacility::sendPacket()
{
-#ifdef CREATOR_SSH_DEBUG
- qDebug("Sending packet, client seq nr is %u", m_clientSeqNr);
-#endif
+ qCDebug(sshLog, "Sending packet, client seq nr is %u", m_clientSeqNr);
if (m_socket->isValid()
&& m_socket->state() == QAbstractSocket::ConnectedState) {
m_socket->write(m_outgoingPacket.rawData());