SSL: port QSharedPointer<QSslContext> uses to std-compatible API subset
In preparation of porting to shared_ptr. Add a few strategic moves and remove a rather pointless comment stating the obvious. Change-Id: Ie1c0f3431af79bdb204e00d99323bf9f2d100d0d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
2915921ad2
commit
9cc0c64e08
@ -393,8 +393,8 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
|
||||
// check whether we can re-use an existing SSL session
|
||||
// (meaning another socket in this connection has already
|
||||
// performed a full handshake)
|
||||
if (!connection->sslContext().isNull())
|
||||
QSslSocketPrivate::checkSettingSslContext(sslSocket, connection->sslContext());
|
||||
if (auto ctx = connection->sslContext())
|
||||
QSslSocketPrivate::checkSettingSslContext(sslSocket, std::move(ctx));
|
||||
|
||||
sslSocket->setPeerVerifyName(connection->d_func()->peerVerifyName);
|
||||
sslSocket->connectToHostEncrypted(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference);
|
||||
@ -925,12 +925,11 @@ void QHttpNetworkConnectionChannel::_q_connected()
|
||||
//channels[i].reconnectAttempts = 2;
|
||||
if (ssl || pendingEncrypt) { // FIXME: Didn't work properly with pendingEncrypt only, we should refactor this into an EncrypingState
|
||||
#ifndef QT_NO_SSL
|
||||
if (connection->sslContext().isNull()) {
|
||||
if (!connection->sslContext()) {
|
||||
// this socket is making the 1st handshake for this connection,
|
||||
// we need to set the SSL context so new sockets can reuse it
|
||||
QSharedPointer<QSslContext> socketSslContext = QSslSocketPrivate::sslContext(static_cast<QSslSocket*>(socket));
|
||||
if (!socketSslContext.isNull())
|
||||
connection->setSslContext(socketSslContext);
|
||||
if (auto socketSslContext = QSslSocketPrivate::sslContext(static_cast<QSslSocket*>(socket)))
|
||||
connection->setSslContext(std::move(socketSslContext));
|
||||
}
|
||||
#endif
|
||||
} else if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2Direct) {
|
||||
|
@ -605,7 +605,7 @@ bool DtlsState::init(QDtlsBasePrivate *dtlsBase, QUdpSocket *socket,
|
||||
Q_ASSERT(dtlsBase);
|
||||
Q_ASSERT(socket);
|
||||
|
||||
if (!tlsContext.data() && !initTls(dtlsBase))
|
||||
if (!tlsContext && !initTls(dtlsBase))
|
||||
return false;
|
||||
|
||||
udpSocket = socket;
|
||||
@ -632,7 +632,7 @@ void DtlsState::reset()
|
||||
|
||||
bool DtlsState::initTls(QDtlsBasePrivate *dtlsBase)
|
||||
{
|
||||
if (tlsContext.data())
|
||||
if (tlsContext)
|
||||
return true;
|
||||
|
||||
if (!QSslSocket::supportsSsl())
|
||||
@ -716,7 +716,7 @@ bool DtlsState::initCtxAndConnection(QDtlsBasePrivate *dtlsBase)
|
||||
bool DtlsState::initBIO(QDtlsBasePrivate *dtlsBase)
|
||||
{
|
||||
Q_ASSERT(dtlsBase);
|
||||
Q_ASSERT(tlsContext.data() && tlsConnection.data());
|
||||
Q_ASSERT(tlsContext && tlsConnection);
|
||||
|
||||
BioMethod customMethod(q_BIO_meth_new(BIO_TYPE_DGRAM, dtlsbio::qdtlsMethodName),
|
||||
dtlsutil::delete_bio_method);
|
||||
|
@ -506,8 +506,8 @@ void TlsCryptographOpenSSL::init(QSslSocket *qObj, QSslSocketPrivate *dObj)
|
||||
|
||||
void TlsCryptographOpenSSL::checkSettingSslContext(QSharedPointer<QSslContext> tlsContext)
|
||||
{
|
||||
if (sslContextPointer.isNull())
|
||||
sslContextPointer = tlsContext;
|
||||
if (!sslContextPointer)
|
||||
sslContextPointer = std::move(tlsContext);
|
||||
}
|
||||
|
||||
QSharedPointer<QSslContext> TlsCryptographOpenSSL::sslContext() const
|
||||
@ -815,7 +815,7 @@ void TlsCryptographOpenSSL::continueHandshake()
|
||||
// Cache this SSL session inside the QSslContext
|
||||
if (!(configuration.testSslOption(QSsl::SslOptionDisableSessionSharing))) {
|
||||
if (!sslContextPointer->cacheSession(ssl)) {
|
||||
sslContextPointer.clear(); // we could not cache the session
|
||||
sslContextPointer.reset(); // we could not cache the session
|
||||
} else {
|
||||
// Cache the session for permanent usage as well
|
||||
if (!(configuration.testSslOption(QSsl::SslOptionDisableSessionPersistence))) {
|
||||
@ -1367,7 +1367,7 @@ bool TlsCryptographOpenSSL::initSslContext()
|
||||
|
||||
if (sslContextPointer->error() != QSslError::NoError) {
|
||||
setErrorAndEmit(d, QAbstractSocket::SslInvalidUserDataError, sslContextPointer->errorString());
|
||||
sslContextPointer.clear(); // deletes the QSslContext
|
||||
sslContextPointer.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1495,7 +1495,7 @@ void TlsCryptographOpenSSL::destroySslContext()
|
||||
q_SSL_free(ssl);
|
||||
ssl = nullptr;
|
||||
}
|
||||
sslContextPointer.clear();
|
||||
sslContextPointer.reset();
|
||||
}
|
||||
|
||||
void TlsCryptographOpenSSL::storePeerCertificates()
|
||||
|
Loading…
x
Reference in New Issue
Block a user