QDtsl::abortHandshake() - generalize the notion of 'abort'

Previously, the function had a different name that made its purpose
clear - "abort after peer verification error was encoutered". Since
now it's just 'abort handshake', it also should abort an ongoing
handshake, even if no peer verification error found so that we
now have an API that can reset a QDtls object to its initial
'nothing done yet' state.

Change-Id: Idadfec6f82d65c8f07d1c2afa4467c921c7e85c4
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Timur Pocheptsov 2018-08-13 12:15:46 +02:00
parent e86b1d4424
commit b58da27aef
2 changed files with 13 additions and 8 deletions

View File

@ -930,8 +930,8 @@ bool QDtls::resumeHandshake(QUdpSocket *socket)
}
/*!
Aborts the handshake in case peer verification errors could not be ignored.
\a socket must be a valid pointer.
Aborts the ongoing handshake. Returns true if one was on-going on \a socket;
otherwise, sets a suitable error and returns false.
\sa doHandshake(), resumeHandshake()
*/
@ -944,9 +944,9 @@ bool QDtls::abortHandshake(QUdpSocket *socket)
return false;
}
if (d->handshakeState != PeerVerificationFailed) {
if (d->handshakeState != PeerVerificationFailed && d->handshakeState != HandshakeInProgress) {
d->setDtlsError(QDtlsError::InvalidOperation,
tr("Not in VerificationError state, nothing to abort"));
tr("No handshake in progress, nothing to abort"));
return false;
}

View File

@ -1115,13 +1115,18 @@ bool QDtlsPrivateOpenSSL::resumeHandshake(QUdpSocket *socket)
void QDtlsPrivateOpenSSL::abortHandshake(QUdpSocket *socket)
{
Q_ASSERT(socket);
Q_ASSERT(handshakeState == QDtls::PeerVerificationFailed);
Q_ASSERT(handshakeState == QDtls::PeerVerificationFailed
|| handshakeState == QDtls::HandshakeInProgress);
clearDtlsError();
// Yes, while peer verification failed, we were actually encrypted.
// Let's play it nice - inform our peer about connection shut down.
sendShutdownAlert(socket);
if (handshakeState == QDtls::PeerVerificationFailed) {
// Yes, while peer verification failed, we were actually encrypted.
// Let's play it nice - inform our peer about connection shut down.
sendShutdownAlert(socket);
} else {
resetDtls();
}
}
void QDtlsPrivateOpenSSL::sendShutdownAlert(QUdpSocket *socket)