QSslSocket - bail out early if TLS initialization fails

No need to start with 'connectToHost' from 'connectToHostEncrytped'
- we will fail to start client encryption later anyway. This can happen
if we, for example, fail to resolve some symbols or libraries are missing.

Task-number: QTBUG-65142
Change-Id: I0614d5cdf875aaf5b992d8ab6024bcaf3f84b915
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Timur Pocheptsov 2018-05-16 10:35:56 +02:00
parent 301970018c
commit 59df474e13

View File

@ -448,6 +448,12 @@ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port, O
return;
}
if (!supportsSsl()) {
qCWarning(lcSsl, "QSslSocket::connectToHostEncrypted: TLS initialization failed");
d->setErrorAndEmit(QAbstractSocket::SslInternalError, tr("TLS initialization failed"));
return;
}
d->init();
d->autoStartHandshake = true;
d->initialized = true;
@ -479,6 +485,12 @@ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port,
return;
}
if (!supportsSsl()) {
qCWarning(lcSsl, "QSslSocket::connectToHostEncrypted: TLS initialization failed");
d->setErrorAndEmit(QAbstractSocket::SslInternalError, tr("TLS initialization failed"));
return;
}
d->init();
d->autoStartHandshake = true;
d->initialized = true;
@ -1823,6 +1835,12 @@ void QSslSocket::startClientEncryption()
"QSslSocket::startClientEncryption: cannot start handshake when not connected");
return;
}
if (!supportsSsl()) {
qCWarning(lcSsl, "QSslSocket::startClientEncryption: TLS initialization failed");
d->setErrorAndEmit(QAbstractSocket::SslInternalError, tr("TLS initialization failed"));
return;
}
#ifdef QSSLSOCKET_DEBUG
qCDebug(lcSsl) << "QSslSocket::startClientEncryption()";
#endif
@ -1861,6 +1879,11 @@ void QSslSocket::startServerEncryption()
#ifdef QSSLSOCKET_DEBUG
qCDebug(lcSsl) << "QSslSocket::startServerEncryption()";
#endif
if (!supportsSsl()) {
qCWarning(lcSsl, "QSslSocket::startServerEncryption: TLS initialization failed");
d->setErrorAndEmit(QAbstractSocket::SslInternalError, tr("TLS initialization failed"));
return;
}
d->mode = SslServerMode;
emit modeChanged(d->mode);
d->startServerEncryption();