Use categorized logging for ssl code

Place all debug output into the 'qt.network.ssl' category.
This allows people to disable certain warnings at runtime.

Task-number: QTBUG-43173
Change-Id: Ide731fae3109f9cd7730cc096ee069a5b99d35f1
Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
Kai Koehne 2014-12-08 13:35:47 +01:00
parent 7d2357b0a8
commit f17d7a124f
13 changed files with 185 additions and 106 deletions

View File

@ -33,9 +33,12 @@
#include "qsslkey.h" #include "qsslkey.h"
#include "qssl_p.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcSsl, "qt.network.ssl");
/*! \namespace QSsl /*! \namespace QSsl
\brief The QSsl namespace declares enums common to all SSL classes in Qt Network. \brief The QSsl namespace declares enums common to all SSL classes in Qt Network.

58
src/network/ssl/qssl_p.h Normal file
View File

@ -0,0 +1,58 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QSSL_P_H
#define QSSL_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of qsslcertificate.cpp. This header file may change from version to version
// without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/QLoggingCategory>
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(lcSsl)
QT_END_NAMESPACE
#endif // QSSL_P_H

View File

@ -112,6 +112,7 @@
#include "qsslsocket_winrt_p.h" #include "qsslsocket_winrt_p.h"
#endif #endif
#include "qssl_p.h"
#include "qsslcertificate.h" #include "qsslcertificate.h"
#include "qsslcertificate_p.h" #include "qsslcertificate_p.h"
#include "qsslkey_p.h" #include "qsslkey_p.h"
@ -524,7 +525,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path,
QList<QSslCertificate> QSslCertificate::fromDevice(QIODevice *device, QSsl::EncodingFormat format) QList<QSslCertificate> QSslCertificate::fromDevice(QIODevice *device, QSsl::EncodingFormat format)
{ {
if (!device) { if (!device) {
qWarning("QSslCertificate::fromDevice: cannot read from a null device"); qCWarning(lcSsl, "QSslCertificate::fromDevice: cannot read from a null device");
return QList<QSslCertificate>(); return QList<QSslCertificate>();
} }
return fromData(device->readAll(), format); return fromData(device->readAll(), format);

View File

@ -39,6 +39,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "qssl_p.h"
#include "qsslsocket_openssl_symbols_p.h" #include "qsslsocket_openssl_symbols_p.h"
#include "qsslcertificate_p.h" #include "qsslcertificate_p.h"
#include "qsslkey_p.h" #include "qsslkey_p.h"
@ -303,7 +304,7 @@ static QVariant x509UnknownExtensionToValue(X509_EXTENSION *ext)
else else
return list; return list;
} else if (meth->i2s && ext_internal) { } else if (meth->i2s && ext_internal) {
//qDebug() << meth->i2s(meth, ext_internal); //qCDebug(lcSsl) << meth->i2s(meth, ext_internal);
QVariant result(QString::fromUtf8(meth->i2s(meth, ext_internal))); QVariant result(QString::fromUtf8(meth->i2s(meth, ext_internal)));
return result; return result;
} else if (meth->i2r && ext_internal) { } else if (meth->i2r && ext_internal) {
@ -371,7 +372,7 @@ static QVariant x509ExtensionToValue(X509_EXTENSION *ext)
result[QString::fromUtf8(QSslCertificatePrivate::asn1ObjectName(ad->method))] = uri; result[QString::fromUtf8(QSslCertificatePrivate::asn1ObjectName(ad->method))] = uri;
} else { } else {
qWarning() << "Strange location type" << name->type; qCWarning(lcSsl) << "Strange location type" << name->type;
} }
} }
@ -516,7 +517,7 @@ void QSslCertificatePrivate::init(const QByteArray &data, QSsl::EncodingFormat f
QByteArray QSslCertificatePrivate::QByteArray_from_X509(X509 *x509, QSsl::EncodingFormat format) QByteArray QSslCertificatePrivate::QByteArray_from_X509(X509 *x509, QSsl::EncodingFormat format)
{ {
if (!x509) { if (!x509) {
qWarning("QSslSocketBackendPrivate::X509_to_QByteArray: null X509"); qCWarning(lcSsl, "QSslSocketBackendPrivate::X509_to_QByteArray: null X509");
return QByteArray(); return QByteArray();
} }
@ -551,7 +552,7 @@ QByteArray QSslCertificatePrivate::QByteArray_from_X509(X509 *x509, QSsl::Encodi
QString QSslCertificatePrivate::text_from_X509(X509 *x509) QString QSslCertificatePrivate::text_from_X509(X509 *x509)
{ {
if (!x509) { if (!x509) {
qWarning("QSslSocketBackendPrivate::text_from_X509: null X509"); qCWarning(lcSsl, "QSslSocketBackendPrivate::text_from_X509: null X509");
return QString(); return QString();
} }

View File

@ -40,7 +40,7 @@
****************************************************************************/ ****************************************************************************/
#include "qssl_p.h"
#include "qsslcertificate.h" #include "qsslcertificate.h"
#include "qsslcertificate_p.h" #include "qsslcertificate_p.h"
#include "qsslkey.h" #include "qsslkey.h"
@ -83,8 +83,9 @@ bool QSslCertificate::isSelfSigned() const
if (d->null) if (d->null)
return false; return false;
qWarning("QSslCertificate::isSelfSigned: This function does not check, whether the certificate " qCWarning(lcSsl,
"is actually signed. It just checks whether issuer and subject are identical"); "QSslCertificate::isSelfSigned: This function does not check, whether the certificate "
"is actually signed. It just checks whether issuer and subject are identical");
return d->subjectMatchesIssuer; return d->subjectMatchesIssuer;
} }

View File

@ -32,6 +32,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "qssl_p.h"
#include "qsslconfiguration.h" #include "qsslconfiguration.h"
#include "qsslconfiguration_p.h" #include "qsslconfiguration_p.h"
#include "qsslsocket.h" #include "qsslsocket.h"
@ -341,7 +342,8 @@ int QSslConfiguration::peerVerifyDepth() const
void QSslConfiguration::setPeerVerifyDepth(int depth) void QSslConfiguration::setPeerVerifyDepth(int depth)
{ {
if (depth < 0) { if (depth < 0) {
qWarning("QSslConfiguration::setPeerVerifyDepth: cannot set negative depth of %d", depth); qCWarning(lcSsl,
"QSslConfiguration::setPeerVerifyDepth: cannot set negative depth of %d", depth);
return; return;
} }
d->peerVerifyDepth = depth; d->peerVerifyDepth = depth;

View File

@ -36,6 +36,7 @@
#include <QtNetwork/qsslsocket.h> #include <QtNetwork/qsslsocket.h>
#include <QtCore/qmutex.h> #include <QtCore/qmutex.h>
#include "private/qssl_p.h"
#include "private/qsslcontext_openssl_p.h" #include "private/qsslcontext_openssl_p.h"
#include "private/qsslsocket_p.h" #include "private/qsslsocket_p.h"
#include "private/qsslsocket_openssl_p.h" #include "private/qsslsocket_openssl_p.h"
@ -357,7 +358,7 @@ static int next_proto_cb(SSL *, unsigned char **out, unsigned char *outlen,
ctx->status = QSslConfiguration::NextProtocolNegotiationUnsupported; ctx->status = QSslConfiguration::NextProtocolNegotiationUnsupported;
break; break;
default: default:
qWarning("OpenSSL sent unknown NPN status"); qCWarning(lcSsl, "OpenSSL sent unknown NPN status");
} }
return SSL_TLSEXT_ERR_OK; return SSL_TLSEXT_ERR_OK;
@ -384,7 +385,7 @@ SSL* QSslContext::createSsl()
if (session) { if (session) {
// Try to resume the last session we cached // Try to resume the last session we cached
if (!q_SSL_set_session(ssl, session)) { if (!q_SSL_set_session(ssl, session)) {
qWarning("could not set SSL session"); qCWarning(lcSsl, "could not set SSL session");
q_SSL_SESSION_free(session); q_SSL_SESSION_free(session);
session = 0; session = 0;
} }
@ -396,8 +397,8 @@ SSL* QSslContext::createSsl()
m_supportedNPNVersions.clear(); m_supportedNPNVersions.clear();
for (int a = 0; a < protocols.count(); ++a) { for (int a = 0; a < protocols.count(); ++a) {
if (protocols.at(a).size() > 255) { if (protocols.at(a).size() > 255) {
qWarning() << "TLS NPN extension" << protocols.at(a) qCWarning(lcSsl) << "TLS NPN extension" << protocols.at(a)
<< "is too long and will be truncated to 255 characters."; << "is too long and will be truncated to 255 characters.";
protocols[a] = protocols.at(a).left(255); protocols[a] = protocols.at(a).left(255);
} }
m_supportedNPNVersions.append(protocols.at(a).size()).append(protocols.at(a)); m_supportedNPNVersions.append(protocols.at(a).size()).append(protocols.at(a));
@ -433,7 +434,7 @@ bool QSslContext::cacheSession(SSL* ssl)
m_sessionASN1.resize(sessionSize); m_sessionASN1.resize(sessionSize);
unsigned char *data = reinterpret_cast<unsigned char *>(m_sessionASN1.data()); unsigned char *data = reinterpret_cast<unsigned char *>(m_sessionASN1.data());
if (!q_i2d_SSL_SESSION(session, &data)) if (!q_i2d_SSL_SESSION(session, &data))
qWarning("could not store persistent version of SSL session"); qCWarning(lcSsl, "could not store persistent version of SSL session");
m_sessionTicketLifeTimeHint = session->tlsext_tick_lifetime_hint; m_sessionTicketLifeTimeHint = session->tlsext_tick_lifetime_hint;
} }
} }

View File

@ -39,6 +39,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "qssl_p.h"
#include "qsslkey.h" #include "qsslkey.h"
#include "qsslkey_p.h" #include "qsslkey_p.h"
#include "qsslcertificate_p.h" #include "qsslcertificate_p.h"
@ -144,7 +145,7 @@ static QByteArray doCrypt(QSslKeyPrivate::Cipher cipher, QByteArray data, const
if (padding > 0 && padding <= blockLength) if (padding > 0 && padding <= blockLength)
resultLength -= padding; resultLength -= padding;
else else
qWarning("Invalid padding length of %u; decryption likely failed.", padding); qCWarning(lcSsl, "Invalid padding length of %u; decryption likely failed.", padding);
} }
return QByteArray(reinterpret_cast<const char *>(resultData), resultLength); return QByteArray(reinterpret_cast<const char *>(resultData), resultLength);

View File

@ -281,6 +281,7 @@
\sa peerVerifyError() \sa peerVerifyError()
*/ */
#include "qssl_p.h"
#include "qsslsocket.h" #include "qsslsocket.h"
#include "qsslcipher.h" #include "qsslcipher.h"
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
@ -334,7 +335,7 @@ QSslSocket::QSslSocket(QObject *parent)
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::QSslSocket(" << parent << "), this =" << (void *)this; qCDebug(lcSsl) << "QSslSocket::QSslSocket(" << parent << "), this =" << (void *)this;
#endif #endif
d->q_ptr = this; d->q_ptr = this;
d->init(); d->init();
@ -347,7 +348,7 @@ QSslSocket::~QSslSocket()
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::~QSslSocket(), this =" << (void *)this; qCDebug(lcSsl) << "QSslSocket::~QSslSocket(), this =" << (void *)this;
#endif #endif
delete d->plainSocket; delete d->plainSocket;
d->plainSocket = 0; d->plainSocket = 0;
@ -416,7 +417,8 @@ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, O
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
if (d->state == ConnectedState || d->state == ConnectingState) { if (d->state == ConnectedState || d->state == ConnectingState) {
qWarning("QSslSocket::connectToHostEncrypted() called when already connecting/connected"); qCWarning(lcSsl,
"QSslSocket::connectToHostEncrypted() called when already connecting/connected");
return; return;
} }
@ -446,7 +448,8 @@ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port,
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
if (d->state == ConnectedState || d->state == ConnectingState) { if (d->state == ConnectedState || d->state == ConnectingState) {
qWarning("QSslSocket::connectToHostEncrypted() called when already connecting/connected"); qCWarning(lcSsl,
"QSslSocket::connectToHostEncrypted() called when already connecting/connected");
return; return;
} }
@ -476,7 +479,7 @@ bool QSslSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState state
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::setSocketDescriptor(" << socketDescriptor << ',' qCDebug(lcSsl) << "QSslSocket::setSocketDescriptor(" << socketDescriptor << ','
<< state << ',' << openMode << ')'; << state << ',' << openMode << ')';
#endif #endif
if (!d->plainSocket) if (!d->plainSocket)
@ -660,7 +663,7 @@ void QSslSocket::setPeerVerifyDepth(int depth)
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
if (depth < 0) { if (depth < 0) {
qWarning("QSslSocket::setPeerVerifyDepth: cannot set negative depth of %d", depth); qCWarning(lcSsl, "QSslSocket::setPeerVerifyDepth: cannot set negative depth of %d", depth);
return; return;
} }
d->configuration.peerVerifyDepth = depth; d->configuration.peerVerifyDepth = depth;
@ -771,7 +774,7 @@ bool QSslSocket::canReadLine() const
void QSslSocket::close() void QSslSocket::close()
{ {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::close()"; qCDebug(lcSsl) << "QSslSocket::close()";
#endif #endif
Q_D(QSslSocket); Q_D(QSslSocket);
if (encryptedBytesToWrite()) if (encryptedBytesToWrite())
@ -815,7 +818,7 @@ bool QSslSocket::flush()
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::flush()"; qCDebug(lcSsl) << "QSslSocket::flush()";
#endif #endif
if (d->mode != UnencryptedMode) if (d->mode != UnencryptedMode)
// encrypt any unencrypted bytes in our buffer // encrypt any unencrypted bytes in our buffer
@ -849,7 +852,7 @@ void QSslSocket::abort()
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::abort()"; qCDebug(lcSsl) << "QSslSocket::abort()";
#endif #endif
if (d->plainSocket) if (d->plainSocket)
d->plainSocket->abort(); d->plainSocket->abort();
@ -1605,7 +1608,7 @@ bool QSslSocket::waitForDisconnected(int msecs)
// require calling connectToHost() before waitForDisconnected() // require calling connectToHost() before waitForDisconnected()
if (state() == UnconnectedState) { if (state() == UnconnectedState) {
qWarning("QSslSocket::waitForDisconnected() is not allowed in UnconnectedState"); qCWarning(lcSsl, "QSslSocket::waitForDisconnected() is not allowed in UnconnectedState");
return false; return false;
} }
@ -1721,15 +1724,17 @@ void QSslSocket::startClientEncryption()
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
if (d->mode != UnencryptedMode) { if (d->mode != UnencryptedMode) {
qWarning("QSslSocket::startClientEncryption: cannot start handshake on non-plain connection"); qCWarning(lcSsl,
"QSslSocket::startClientEncryption: cannot start handshake on non-plain connection");
return; return;
} }
if (state() != ConnectedState) { if (state() != ConnectedState) {
qWarning("QSslSocket::startClientEncryption: cannot start handshake when not connected"); qCWarning(lcSsl,
"QSslSocket::startClientEncryption: cannot start handshake when not connected");
return; return;
} }
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::startClientEncryption()"; qCDebug(lcSsl) << "QSslSocket::startClientEncryption()";
#endif #endif
d->mode = SslClientMode; d->mode = SslClientMode;
emit modeChanged(d->mode); emit modeChanged(d->mode);
@ -1760,11 +1765,11 @@ void QSslSocket::startServerEncryption()
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
if (d->mode != UnencryptedMode) { if (d->mode != UnencryptedMode) {
qWarning("QSslSocket::startServerEncryption: cannot start handshake on non-plain connection"); qCWarning(lcSsl, "QSslSocket::startServerEncryption: cannot start handshake on non-plain connection");
return; return;
} }
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::startServerEncryption()"; qCDebug(lcSsl) << "QSslSocket::startServerEncryption()";
#endif #endif
d->mode = SslServerMode; d->mode = SslServerMode;
emit modeChanged(d->mode); emit modeChanged(d->mode);
@ -1841,12 +1846,12 @@ void QSslSocket::connectToHost(const QString &hostName, quint16 port, OpenMode o
d->initialized = false; d->initialized = false;
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::connectToHost(" qCDebug(lcSsl) << "QSslSocket::connectToHost("
<< hostName << ',' << port << ',' << openMode << ')'; << hostName << ',' << port << ',' << openMode << ')';
#endif #endif
if (!d->plainSocket) { if (!d->plainSocket) {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "\tcreating internal plain socket"; qCDebug(lcSsl) << "\tcreating internal plain socket";
#endif #endif
d->createPlainSocket(openMode); d->createPlainSocket(openMode);
} }
@ -1865,7 +1870,7 @@ void QSslSocket::disconnectFromHost()
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::disconnectFromHost()"; qCDebug(lcSsl) << "QSslSocket::disconnectFromHost()";
#endif #endif
if (!d->plainSocket) if (!d->plainSocket)
return; return;
@ -1909,7 +1914,7 @@ qint64 QSslSocket::readData(char *data, qint64 maxlen)
if (d->mode == UnencryptedMode && !d->autoStartHandshake) { if (d->mode == UnencryptedMode && !d->autoStartHandshake) {
readBytes = d->plainSocket->read(data, maxlen); readBytes = d->plainSocket->read(data, maxlen);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::readData(" << (void *)data << ',' << maxlen << ") ==" qCDebug(lcSsl) << "QSslSocket::readData(" << (void *)data << ',' << maxlen << ") =="
<< readBytes; << readBytes;
#endif #endif
} else { } else {
@ -1928,7 +1933,7 @@ qint64 QSslSocket::writeData(const char *data, qint64 len)
{ {
Q_D(QSslSocket); Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::writeData(" << (void *)data << ',' << len << ')'; qCDebug(lcSsl) << "QSslSocket::writeData(" << (void *)data << ',' << len << ')';
#endif #endif
if (d->mode == UnencryptedMode && !d->autoStartHandshake) if (d->mode == UnencryptedMode && !d->autoStartHandshake)
return d->plainSocket->write(data, len); return d->plainSocket->write(data, len);
@ -2231,10 +2236,10 @@ void QSslSocketPrivate::_q_connectedSlot()
cachedSocketDescriptor = plainSocket->socketDescriptor(); cachedSocketDescriptor = plainSocket->socketDescriptor();
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::_q_connectedSlot()"; qCDebug(lcSsl) << "QSslSocket::_q_connectedSlot()";
qDebug() << "\tstate =" << q->state(); qCDebug(lcSsl) << "\tstate =" << q->state();
qDebug() << "\tpeer =" << q->peerName() << q->peerAddress() << q->peerPort(); qCDebug(lcSsl) << "\tpeer =" << q->peerName() << q->peerAddress() << q->peerPort();
qDebug() << "\tlocal =" << QHostInfo::fromName(q->localAddress().toString()).hostName() qCDebug(lcSsl) << "\tlocal =" << QHostInfo::fromName(q->localAddress().toString()).hostName()
<< q->localAddress() << q->localPort(); << q->localAddress() << q->localPort();
#endif #endif
@ -2256,8 +2261,8 @@ void QSslSocketPrivate::_q_hostFoundSlot()
{ {
Q_Q(QSslSocket); Q_Q(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::_q_hostFoundSlot()"; qCDebug(lcSsl) << "QSslSocket::_q_hostFoundSlot()";
qDebug() << "\tstate =" << q->state(); qCDebug(lcSsl) << "\tstate =" << q->state();
#endif #endif
emit q->hostFound(); emit q->hostFound();
} }
@ -2269,8 +2274,8 @@ void QSslSocketPrivate::_q_disconnectedSlot()
{ {
Q_Q(QSslSocket); Q_Q(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::_q_disconnectedSlot()"; qCDebug(lcSsl) << "QSslSocket::_q_disconnectedSlot()";
qDebug() << "\tstate =" << q->state(); qCDebug(lcSsl) << "\tstate =" << q->state();
#endif #endif
disconnected(); disconnected();
emit q->disconnected(); emit q->disconnected();
@ -2283,7 +2288,7 @@ void QSslSocketPrivate::_q_stateChangedSlot(QAbstractSocket::SocketState state)
{ {
Q_Q(QSslSocket); Q_Q(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::_q_stateChangedSlot(" << state << ')'; qCDebug(lcSsl) << "QSslSocket::_q_stateChangedSlot(" << state << ')';
#endif #endif
q->setSocketState(state); q->setSocketState(state);
emit q->stateChanged(state); emit q->stateChanged(state);
@ -2296,9 +2301,9 @@ void QSslSocketPrivate::_q_errorSlot(QAbstractSocket::SocketError error)
{ {
Q_Q(QSslSocket); Q_Q(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::_q_errorSlot(" << error << ')'; qCDebug(lcSsl) << "QSslSocket::_q_errorSlot(" << error << ')';
qDebug() << "\tstate =" << q->state(); qCDebug(lcSsl) << "\tstate =" << q->state();
qDebug() << "\terrorString =" << q->errorString(); qCDebug(lcSsl) << "\terrorString =" << q->errorString();
#endif #endif
q->setSocketError(plainSocket->error()); q->setSocketError(plainSocket->error());
q->setErrorString(plainSocket->errorString()); q->setErrorString(plainSocket->errorString());
@ -2312,7 +2317,7 @@ void QSslSocketPrivate::_q_readyReadSlot()
{ {
Q_Q(QSslSocket); Q_Q(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::_q_readyReadSlot() -" << plainSocket->bytesAvailable() << "bytes available"; qCDebug(lcSsl) << "QSslSocket::_q_readyReadSlot() -" << plainSocket->bytesAvailable() << "bytes available";
#endif #endif
if (mode == QSslSocket::UnencryptedMode) { if (mode == QSslSocket::UnencryptedMode) {
if (readyReadEmittedPointer) if (readyReadEmittedPointer)
@ -2331,7 +2336,7 @@ void QSslSocketPrivate::_q_bytesWrittenSlot(qint64 written)
{ {
Q_Q(QSslSocket); Q_Q(QSslSocket);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::_q_bytesWrittenSlot(" << written << ')'; qCDebug(lcSsl) << "QSslSocket::_q_bytesWrittenSlot(" << written << ')';
#endif #endif
if (mode == QSslSocket::UnencryptedMode) if (mode == QSslSocket::UnencryptedMode)

View File

@ -49,6 +49,7 @@
//#define QSSLSOCKET_DEBUG //#define QSSLSOCKET_DEBUG
//#define QT_DECRYPT_SSL_TRAFFIC //#define QT_DECRYPT_SSL_TRAFFIC
#include "qssl_p.h"
#include "qsslsocket_openssl_p.h" #include "qsslsocket_openssl_p.h"
#include "qsslsocket_openssl_symbols_p.h" #include "qsslsocket_openssl_symbols_p.h"
#include "qsslsocket.h" #include "qsslsocket.h"
@ -250,24 +251,24 @@ int q_X509Callback(int ok, X509_STORE_CTX *ctx)
// Store the error and at which depth the error was detected. // Store the error and at which depth the error was detected.
_q_sslErrorList()->errors << qMakePair<int, int>(q_X509_STORE_CTX_get_error(ctx), q_X509_STORE_CTX_get_error_depth(ctx)); _q_sslErrorList()->errors << qMakePair<int, int>(q_X509_STORE_CTX_get_error(ctx), q_X509_STORE_CTX_get_error_depth(ctx));
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "verification error: dumping bad certificate"; qCDebug(lcSsl) << "verification error: dumping bad certificate";
qDebug() << QSslCertificatePrivate::QSslCertificate_from_X509(q_X509_STORE_CTX_get_current_cert(ctx)).toPem(); qCDebug(lcSsl) << QSslCertificatePrivate::QSslCertificate_from_X509(q_X509_STORE_CTX_get_current_cert(ctx)).toPem();
qDebug() << "dumping chain"; qCDebug(lcSsl) << "dumping chain";
foreach (QSslCertificate cert, QSslSocketBackendPrivate::STACKOFX509_to_QSslCertificates(q_X509_STORE_CTX_get_chain(ctx))) { foreach (QSslCertificate cert, QSslSocketBackendPrivate::STACKOFX509_to_QSslCertificates(q_X509_STORE_CTX_get_chain(ctx))) {
QString certFormat(QStringLiteral("O=%1 CN=%2 L=%3 OU=%4 C=%5 ST=%6")); QString certFormat(QStringLiteral("O=%1 CN=%2 L=%3 OU=%4 C=%5 ST=%6"));
qDebug() << "Issuer:" << "O=" << cert.issuerInfo(QSslCertificate::Organization) qCDebug(lcSsl) << "Issuer:" << "O=" << cert.issuerInfo(QSslCertificate::Organization)
<< "CN=" << cert.issuerInfo(QSslCertificate::CommonName) << "CN=" << cert.issuerInfo(QSslCertificate::CommonName)
<< "L=" << cert.issuerInfo(QSslCertificate::LocalityName) << "L=" << cert.issuerInfo(QSslCertificate::LocalityName)
<< "OU=" << cert.issuerInfo(QSslCertificate::OrganizationalUnitName) << "OU=" << cert.issuerInfo(QSslCertificate::OrganizationalUnitName)
<< "C=" << cert.issuerInfo(QSslCertificate::CountryName) << "C=" << cert.issuerInfo(QSslCertificate::CountryName)
<< "ST=" << cert.issuerInfo(QSslCertificate::StateOrProvinceName); << "ST=" << cert.issuerInfo(QSslCertificate::StateOrProvinceName);
qDebug() << "Subject:" << "O=" << cert.subjectInfo(QSslCertificate::Organization) qCDebug(lcSsl) << "Subject:" << "O=" << cert.subjectInfo(QSslCertificate::Organization)
<< "CN=" << cert.subjectInfo(QSslCertificate::CommonName) << "CN=" << cert.subjectInfo(QSslCertificate::CommonName)
<< "L=" << cert.subjectInfo(QSslCertificate::LocalityName) << "L=" << cert.subjectInfo(QSslCertificate::LocalityName)
<< "OU=" << cert.subjectInfo(QSslCertificate::OrganizationalUnitName) << "OU=" << cert.subjectInfo(QSslCertificate::OrganizationalUnitName)
<< "C=" << cert.subjectInfo(QSslCertificate::CountryName) << "C=" << cert.subjectInfo(QSslCertificate::CountryName)
<< "ST=" << cert.subjectInfo(QSslCertificate::StateOrProvinceName); << "ST=" << cert.subjectInfo(QSslCertificate::StateOrProvinceName);
qDebug() << "Valid:" << cert.effectiveDate() << "-" << cert.expiryDate(); qCDebug(lcSsl) << "Valid:" << cert.effectiveDate() << "-" << cert.expiryDate();
} }
#endif #endif
} }
@ -361,7 +362,7 @@ bool QSslSocketBackendPrivate::initSslContext()
&& !QHostAddress().setAddress(tlsHostName) && !QHostAddress().setAddress(tlsHostName)
&& !(configuration.sslOptions & QSsl::SslOptionDisableServerNameIndication)) { && !(configuration.sslOptions & QSsl::SslOptionDisableServerNameIndication)) {
if (!q_SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, ace.data())) if (!q_SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, ace.data()))
qWarning("could not set SSL_CTRL_SET_TLSEXT_HOSTNAME, Server Name Indication disabled"); qCWarning(lcSsl, "could not set SSL_CTRL_SET_TLSEXT_HOSTNAME, Server Name Indication disabled");
} }
} }
#endif #endif
@ -487,16 +488,16 @@ void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
if (securityLib.load()) { if (securityLib.load()) {
ptrSecCertificateCopyData = (PtrSecCertificateCopyData) securityLib.resolve("SecCertificateCopyData"); ptrSecCertificateCopyData = (PtrSecCertificateCopyData) securityLib.resolve("SecCertificateCopyData");
if (!ptrSecCertificateCopyData) if (!ptrSecCertificateCopyData)
qWarning("could not resolve symbols in security library"); // should never happen qCWarning(lcSsl, "could not resolve symbols in security library"); // should never happen
ptrSecTrustSettingsCopyCertificates = (PtrSecTrustSettingsCopyCertificates) securityLib.resolve("SecTrustSettingsCopyCertificates"); ptrSecTrustSettingsCopyCertificates = (PtrSecTrustSettingsCopyCertificates) securityLib.resolve("SecTrustSettingsCopyCertificates");
if (!ptrSecTrustSettingsCopyCertificates) { // method was introduced in Leopard, use legacy method if it's not there if (!ptrSecTrustSettingsCopyCertificates) { // method was introduced in Leopard, use legacy method if it's not there
ptrSecTrustCopyAnchorCertificates = (PtrSecTrustCopyAnchorCertificates) securityLib.resolve("SecTrustCopyAnchorCertificates"); ptrSecTrustCopyAnchorCertificates = (PtrSecTrustCopyAnchorCertificates) securityLib.resolve("SecTrustCopyAnchorCertificates");
if (!ptrSecTrustCopyAnchorCertificates) if (!ptrSecTrustCopyAnchorCertificates)
qWarning("could not resolve symbols in security library"); // should never happen qCWarning(lcSsl, "could not resolve symbols in security library"); // should never happen
} }
} else { } else {
qWarning("could not load security library"); qCWarning(lcSsl, "could not load security library");
} }
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
HINSTANCE hLib = LoadLibraryW(L"Crypt32"); HINSTANCE hLib = LoadLibraryW(L"Crypt32");
@ -511,9 +512,9 @@ void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
ptrCertCloseStore = (PtrCertCloseStore)GetProcAddress(hLib, "CertCloseStore"); ptrCertCloseStore = (PtrCertCloseStore)GetProcAddress(hLib, "CertCloseStore");
#endif #endif
if (!ptrCertOpenSystemStoreW || !ptrCertFindCertificateInStore || !ptrCertCloseStore) if (!ptrCertOpenSystemStoreW || !ptrCertFindCertificateInStore || !ptrCertCloseStore)
qWarning("could not resolve symbols in crypt32 library"); // should never happen qCWarning(lcSsl, "could not resolve symbols in crypt32 library"); // should never happen
} else { } else {
qWarning("could not load crypt32 library"); // should never happen qCWarning(lcSsl, "could not load crypt32 library"); // should never happen
} }
#elif defined(Q_OS_QNX) #elif defined(Q_OS_QNX)
s_loadRootCertsOnDemand = true; s_loadRootCertsOnDemand = true;
@ -657,7 +658,7 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
data = ptrSecCertificateCopyData(cfCert); data = ptrSecCertificateCopyData(cfCert);
if (data == NULL) { if (data == NULL) {
qWarning("error retrieving a CA certificate from the system store"); qCWarning(lcSsl, "error retrieving a CA certificate from the system store");
} else { } else {
QByteArray rawCert = QByteArray::fromRawData((const char *)CFDataGetBytePtr(data), CFDataGetLength(data)); QByteArray rawCert = QByteArray::fromRawData((const char *)CFDataGetBytePtr(data), CFDataGetLength(data));
systemCerts.append(QSslCertificate::fromData(rawCert, QSsl::Der)); systemCerts.append(QSslCertificate::fromData(rawCert, QSsl::Der));
@ -668,7 +669,7 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
} }
else { else {
// no detailed error handling here // no detailed error handling here
qWarning("could not retrieve system CA certificates"); qCWarning(lcSsl, "could not retrieve system CA certificates");
} }
} }
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
@ -742,8 +743,8 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
} }
#endif #endif
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "systemCaCertificates retrieval time " << timer.elapsed() << "ms"; qCDebug(lcSsl) << "systemCaCertificates retrieval time " << timer.elapsed() << "ms";
qDebug() << "imported " << systemCerts.count() << " certificates"; qCDebug(lcSsl) << "imported " << systemCerts.count() << " certificates";
#endif #endif
return systemCerts; return systemCerts;
@ -824,7 +825,7 @@ void QSslSocketBackendPrivate::transmit()
} }
} }
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: encrypted" << writtenBytes << "bytes"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: encrypted" << writtenBytes << "bytes";
#endif #endif
writeBuffer.free(writtenBytes); writeBuffer.free(writtenBytes);
totalBytesWritten += writtenBytes; totalBytesWritten += writtenBytes;
@ -857,7 +858,7 @@ void QSslSocketBackendPrivate::transmit()
// Write encrypted data from the buffer to the socket. // Write encrypted data from the buffer to the socket.
qint64 actualWritten = plainSocket->write(data.constData(), encryptedBytesRead); qint64 actualWritten = plainSocket->write(data.constData(), encryptedBytesRead);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: wrote" << encryptedBytesRead << "encrypted bytes to the socket" << actualWritten << "actual."; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: wrote" << encryptedBytesRead << "encrypted bytes to the socket" << actualWritten << "actual.";
#endif #endif
if (actualWritten < 0) { if (actualWritten < 0) {
//plain socket write fails if it was in the pending close state. //plain socket write fails if it was in the pending close state.
@ -878,7 +879,7 @@ void QSslSocketBackendPrivate::transmit()
int encryptedBytesRead = plainSocket->peek(data.data(), pendingBytes); int encryptedBytesRead = plainSocket->peek(data.data(), pendingBytes);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: read" << encryptedBytesRead << "encrypted bytes from the socket"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: read" << encryptedBytesRead << "encrypted bytes from the socket";
#endif #endif
// Write encrypted data from the buffer into the read BIO. // Write encrypted data from the buffer into the read BIO.
int writtenToBio = q_BIO_write(readBio, data.constData(), encryptedBytesRead); int writtenToBio = q_BIO_write(readBio, data.constData(), encryptedBytesRead);
@ -902,17 +903,17 @@ void QSslSocketBackendPrivate::transmit()
// connect / accept. // connect / accept.
if (!connectionEncrypted) { if (!connectionEncrypted) {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: testing encryption"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: testing encryption";
#endif #endif
if (startHandshake()) { if (startHandshake()) {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: encryption established"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: encryption established";
#endif #endif
connectionEncrypted = true; connectionEncrypted = true;
transmitting = true; transmitting = true;
} else if (plainSocket->state() != QAbstractSocket::ConnectedState) { } else if (plainSocket->state() != QAbstractSocket::ConnectedState) {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: connection lost"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: connection lost";
#endif #endif
break; break;
} else if (paused) { } else if (paused) {
@ -920,7 +921,7 @@ void QSslSocketBackendPrivate::transmit()
return; return;
} else { } else {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: encryption not done yet"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: encryption not done yet";
#endif #endif
} }
} }
@ -941,7 +942,7 @@ void QSslSocketBackendPrivate::transmit()
// Don't use SSL_pending(). It's very unreliable. // Don't use SSL_pending(). It's very unreliable.
if ((readBytes = q_SSL_read(ssl, data.data(), data.size())) > 0) { if ((readBytes = q_SSL_read(ssl, data.data(), data.size())) > 0) {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: decrypted" << readBytes << "bytes"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: decrypted" << readBytes << "bytes";
#endif #endif
char *ptr = buffer.reserve(readBytes); char *ptr = buffer.reserve(readBytes);
::memcpy(ptr, data.data(), readBytes); ::memcpy(ptr, data.data(), readBytes);
@ -962,7 +963,7 @@ void QSslSocketBackendPrivate::transmit()
case SSL_ERROR_ZERO_RETURN: case SSL_ERROR_ZERO_RETURN:
// The remote host closed the connection. // The remote host closed the connection.
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::transmit: remote disconnect"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: remote disconnect";
#endif #endif
shutdown = true; // the other side shut down, make sure we do not send shutdown ourselves shutdown = true; // the other side shut down, make sure we do not send shutdown ourselves
q->setErrorString(QSslSocket::tr("The TLS/SSL connection has been closed")); q->setErrorString(QSslSocket::tr("The TLS/SSL connection has been closed"));
@ -1081,7 +1082,7 @@ bool QSslSocketBackendPrivate::startHandshake()
q->setErrorString(QSslSocket::tr("Error during SSL handshake: %1").arg(getErrorsFromOpenSsl())); q->setErrorString(QSslSocket::tr("Error during SSL handshake: %1").arg(getErrorsFromOpenSsl()));
q->setSocketError(QAbstractSocket::SslHandshakeFailedError); q->setSocketError(QAbstractSocket::SslHandshakeFailedError);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocketBackendPrivate::startHandshake: error!" << q->errorString(); qCDebug(lcSsl) << "QSslSocketBackendPrivate::startHandshake: error!" << q->errorString();
#endif #endif
emit q->error(QAbstractSocket::SslHandshakeFailedError); emit q->error(QAbstractSocket::SslHandshakeFailedError);
q->abort(); q->abort();
@ -1184,7 +1185,7 @@ bool QSslSocketBackendPrivate::startHandshake()
break; break;
default: default:
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << sslErrors.at(i).errorString(); qCDebug(lcSsl) << sslErrors.at(i).errorString();
#endif #endif
break; break;
} }
@ -1318,7 +1319,7 @@ void QWindowsCaRootFetcher::start()
PCCERT_CONTEXT wincert = CertCreateCertificateContext(X509_ASN_ENCODING, (const BYTE *)der.constData(), der.length()); PCCERT_CONTEXT wincert = CertCreateCertificateContext(X509_ASN_ENCODING, (const BYTE *)der.constData(), der.length());
if (!wincert) { if (!wincert) {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug("QWindowsCaRootFetcher failed to convert certificate to windows form"); qCDebug(lcSsl, "QWindowsCaRootFetcher failed to convert certificate to windows form");
#endif #endif
emit finished(cert, QSslCertificate()); emit finished(cert, QSslCertificate());
deleteLater(); deleteLater();
@ -1349,32 +1350,32 @@ void QWindowsCaRootFetcher::start()
0, //reserved 0, //reserved
&chain); &chain);
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QWindowsCaRootFetcher" << stopwatch.elapsed() << "ms to get chain"; qCDebug(lcSsl) << "QWindowsCaRootFetcher" << stopwatch.elapsed() << "ms to get chain";
#endif #endif
QSslCertificate trustedRoot; QSslCertificate trustedRoot;
if (result) { if (result) {
#ifdef QSSLSOCKET_DEBUG #ifdef QSSLSOCKET_DEBUG
qDebug() << "QWindowsCaRootFetcher - examining windows chains"; qCDebug(lcSsl) << "QWindowsCaRootFetcher - examining windows chains";
if (chain->TrustStatus.dwErrorStatus == CERT_TRUST_NO_ERROR) if (chain->TrustStatus.dwErrorStatus == CERT_TRUST_NO_ERROR)
qDebug() << " - TRUSTED"; qCDebug(lcSsl) << " - TRUSTED";
else else
qDebug() << " - NOT TRUSTED" << chain->TrustStatus.dwErrorStatus; qCDebug(lcSsl) << " - NOT TRUSTED" << chain->TrustStatus.dwErrorStatus;
if (chain->TrustStatus.dwInfoStatus & CERT_TRUST_IS_SELF_SIGNED) if (chain->TrustStatus.dwInfoStatus & CERT_TRUST_IS_SELF_SIGNED)
qDebug() << " - SELF SIGNED"; qCDebug(lcSsl) << " - SELF SIGNED";
qDebug() << "QSslSocketBackendPrivate::fetchCaRootForCert - dumping simple chains"; qCDebug(lcSsl) << "QSslSocketBackendPrivate::fetchCaRootForCert - dumping simple chains";
for (unsigned int i = 0; i < chain->cChain; i++) { for (unsigned int i = 0; i < chain->cChain; i++) {
if (chain->rgpChain[i]->TrustStatus.dwErrorStatus == CERT_TRUST_NO_ERROR) if (chain->rgpChain[i]->TrustStatus.dwErrorStatus == CERT_TRUST_NO_ERROR)
qDebug() << " - TRUSTED SIMPLE CHAIN" << i; qCDebug(lcSsl) << " - TRUSTED SIMPLE CHAIN" << i;
else else
qDebug() << " - UNTRUSTED SIMPLE CHAIN" << i << "reason:" << chain->rgpChain[i]->TrustStatus.dwErrorStatus; qCDebug(lcSsl) << " - UNTRUSTED SIMPLE CHAIN" << i << "reason:" << chain->rgpChain[i]->TrustStatus.dwErrorStatus;
for (unsigned int j = 0; j < chain->rgpChain[i]->cElement; j++) { for (unsigned int j = 0; j < chain->rgpChain[i]->cElement; j++) {
QSslCertificate foundCert(QByteArray((const char *)chain->rgpChain[i]->rgpElement[j]->pCertContext->pbCertEncoded QSslCertificate foundCert(QByteArray((const char *)chain->rgpChain[i]->rgpElement[j]->pCertContext->pbCertEncoded
, chain->rgpChain[i]->rgpElement[j]->pCertContext->cbCertEncoded), QSsl::Der); , chain->rgpChain[i]->rgpElement[j]->pCertContext->cbCertEncoded), QSsl::Der);
qDebug() << " - " << foundCert; qCDebug(lcSsl) << " - " << foundCert;
} }
} }
qDebug() << " - and" << chain->cLowerQualityChainContext << "low quality chains"; //expect 0, we haven't asked for them qCDebug(lcSsl) << " - and" << chain->cLowerQualityChainContext << "low quality chains"; //expect 0, we haven't asked for them
#endif #endif
//based on http://msdn.microsoft.com/en-us/library/windows/desktop/aa377182%28v=vs.85%29.aspx //based on http://msdn.microsoft.com/en-us/library/windows/desktop/aa377182%28v=vs.85%29.aspx
@ -1493,12 +1494,12 @@ void QSslSocketBackendPrivate::continueHandshake()
QString sslKeyFile = QDir::tempPath() + QLatin1String("/qt-ssl-keys"); QString sslKeyFile = QDir::tempPath() + QLatin1String("/qt-ssl-keys");
QFile file(sslKeyFile); QFile file(sslKeyFile);
if (!file.open(QIODevice::Append)) if (!file.open(QIODevice::Append))
qWarning() << "could not open file" << sslKeyFile << "for appending"; qCWarning(lcSsl) << "could not open file" << sslKeyFile << "for appending";
if (!file.write(debugLineClientRandom)) if (!file.write(debugLineClientRandom))
qWarning() << "could not write to file" << sslKeyFile; qCWarning(lcSsl) << "could not write to file" << sslKeyFile;
file.close(); file.close();
} else { } else {
qWarning("could not decrypt SSL traffic"); qCWarning(lcSsl, "could not decrypt SSL traffic");
} }
#endif #endif
@ -1557,7 +1558,7 @@ QList<QSslError> QSslSocketBackendPrivate::verify(QList<QSslCertificate> certifi
// Setup the store with the default CA certificates // Setup the store with the default CA certificates
X509_STORE *certStore = q_X509_STORE_new(); X509_STORE *certStore = q_X509_STORE_new();
if (!certStore) { if (!certStore) {
qWarning() << "Unable to create certificate store"; qCWarning(lcSsl) << "Unable to create certificate store";
errors << QSslError(QSslError::UnspecifiedError); errors << QSslError(QSslError::UnspecifiedError);
return errors; return errors;
} }
@ -1694,7 +1695,7 @@ bool QSslSocketBackendPrivate::importPkcs12(QIODevice *device,
// Create the PKCS#12 object // Create the PKCS#12 object
PKCS12 *p12 = q_d2i_PKCS12_bio(bio, 0); PKCS12 *p12 = q_d2i_PKCS12_bio(bio, 0);
if (!p12) { if (!p12) {
qWarning("Unable to read PKCS#12 structure, %s", q_ERR_error_string(q_ERR_get_error(), 0)); qCWarning(lcSsl, "Unable to read PKCS#12 structure, %s", q_ERR_error_string(q_ERR_get_error(), 0));
q_BIO_free(bio); q_BIO_free(bio);
return false; return false;
} }
@ -1705,7 +1706,7 @@ bool QSslSocketBackendPrivate::importPkcs12(QIODevice *device,
STACK_OF(X509) *ca = 0; STACK_OF(X509) *ca = 0;
if (!q_PKCS12_parse(p12, passPhrase.constData(), &pkey, &x509, &ca)) { if (!q_PKCS12_parse(p12, passPhrase.constData(), &pkey, &x509, &ca)) {
qWarning("Unable to parse PKCS#12 structure, %s", q_ERR_error_string(q_ERR_get_error(), 0)); qCWarning(lcSsl, "Unable to parse PKCS#12 structure, %s", q_ERR_error_string(q_ERR_get_error(), 0));
q_PKCS12_free(p12); q_PKCS12_free(p12);
q_BIO_free(bio); q_BIO_free(bio);
return false; return false;
@ -1713,7 +1714,7 @@ bool QSslSocketBackendPrivate::importPkcs12(QIODevice *device,
// Convert to Qt types // Convert to Qt types
if (!key->d->fromEVP_PKEY(pkey)) { if (!key->d->fromEVP_PKEY(pkey)) {
qWarning("Unable to convert private key"); qCWarning(lcSsl, "Unable to convert private key");
q_sk_pop_free(reinterpret_cast<STACK *>(ca), reinterpret_cast<void(*)(void*)>(q_sk_free)); q_sk_pop_free(reinterpret_cast<STACK *>(ca), reinterpret_cast<void(*)(void*)>(q_sk_free));
q_X509_free(x509); q_X509_free(x509);
q_EVP_PKEY_free(pkey); q_EVP_PKEY_free(pkey);

View File

@ -47,6 +47,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "qssl_p.h"
#include "qsslsocket_openssl_symbols_p.h" #include "qsslsocket_openssl_symbols_p.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -115,12 +116,12 @@ QT_BEGIN_NAMESPACE
namespace { namespace {
void qsslSocketUnresolvedSymbolWarning(const char *functionName) void qsslSocketUnresolvedSymbolWarning(const char *functionName)
{ {
qWarning("QSslSocket: cannot call unresolved function %s", functionName); qCWarning(lcSsl, "QSslSocket: cannot call unresolved function %s", functionName);
} }
void qsslSocketCannotResolveSymbolWarning(const char *functionName) void qsslSocketCannotResolveSymbolWarning(const char *functionName)
{ {
qWarning("QSslSocket: cannot resolve %s", functionName); qCWarning(lcSsl, "QSslSocket: cannot resolve %s", functionName);
} }
} }
@ -388,11 +389,11 @@ DEFINEFUNC(void, PKCS12_free, PKCS12 *pkcs12, pkcs12, return, DUMMYARG)
#ifdef QT_NO_LIBRARY #ifdef QT_NO_LIBRARY
bool q_resolveOpenSslSymbols() bool q_resolveOpenSslSymbols()
{ {
qWarning("QSslSocket: unable to resolve symbols. " qCWarning(lcSsl, "QSslSocket: unable to resolve symbols. "
"QT_NO_LIBRARY is defined which means runtime resolving of " "QT_NO_LIBRARY is defined which means runtime resolving of "
"libraries won't work."); "libraries won't work.");
qWarning("Either compile Qt statically or with support for runtime resolving " qCWarning(lcSsl, "Either compile Qt statically or with support for runtime resolving "
"of libraries."); "of libraries.");
return false; return false;
} }
#else #else
@ -992,7 +993,7 @@ QDateTime q_getTimeFromASN1(const ASN1_TIME *aTime)
return result; return result;
} else { } else {
qWarning("unsupported date format detected"); qCWarning(lcSsl, "unsupported date format detected");
return QDateTime(); return QDateTime();
} }

View File

@ -39,6 +39,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "qssl_p.h"
#include "qsslsocket_winrt_p.h" #include "qsslsocket_winrt_p.h"
#include "qsslsocket.h" #include "qsslsocket.h"
#include "qsslcertificate_p.h" #include "qsslcertificate_p.h"
@ -455,8 +456,9 @@ HRESULT QSslSocketBackendPrivate::onSslUpgrade(IAsyncAction *action, AsyncStatus
Q_Q(QSslSocket); Q_Q(QSslSocket);
if (wasDeleted) { if (wasDeleted) {
qWarning("SSL upgrade callback received after the delegate was deleted. " qCWarning(lcSsl,
"This may be indicative of an internal bug in the WinRT SSL implementation."); "SSL upgrade callback received after the delegate was deleted. "
"This may be indicative of an internal bug in the WinRT SSL implementation.");
return S_OK; return S_OK;
} }
@ -477,8 +479,9 @@ HRESULT QSslSocketBackendPrivate::onSslUpgrade(IAsyncAction *action, AsyncStatus
IStreamSocket *socket = reinterpret_cast<IStreamSocket *>(plainSocket->socketDescriptor()); IStreamSocket *socket = reinterpret_cast<IStreamSocket *>(plainSocket->socketDescriptor());
if (qintptr(socket) == -1) { if (qintptr(socket) == -1) {
qWarning("The underlying TCP socket used by the SSL socket is invalid. " qCWarning(lcSsl,
"This may be indicative of an internal bug in the WinRT SSL implementation."); "The underlying TCP socket used by the SSL socket is invalid. "
"This may be indicative of an internal bug in the WinRT SSL implementation.");
return S_OK; return S_OK;
} }

View File

@ -2,6 +2,7 @@
contains(QT_CONFIG, ssl) | contains(QT_CONFIG, openssl) | contains(QT_CONFIG, openssl-linked) { contains(QT_CONFIG, ssl) | contains(QT_CONFIG, openssl) | contains(QT_CONFIG, openssl-linked) {
HEADERS += ssl/qasn1element_p.h \ HEADERS += ssl/qasn1element_p.h \
ssl/qssl.h \ ssl/qssl.h \
ssl/qssl_p.h \
ssl/qsslcertificate.h \ ssl/qsslcertificate.h \
ssl/qsslcertificate_p.h \ ssl/qsslcertificate_p.h \
ssl/qsslconfiguration.h \ ssl/qsslconfiguration.h \