提交 bf26d2e7 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Avoid crash when signaled fingerprint does not match the one in DTLS (fixes #209)

上级 e6ebeb97
......@@ -142,7 +142,7 @@ namespace RTC
bool CheckStatus(int returnCode);
void SendPendingOutgoingDtlsData();
bool SetTimeout();
void ProcessHandshake();
bool ProcessHandshake();
bool CheckRemoteFingerprint();
void ExtractSrtpKeys(RTC::SrtpSession::Profile srtpProfile);
RTC::SrtpSession::Profile GetNegotiatedSrtpProfile();
......
......@@ -859,8 +859,10 @@ namespace RTC
this->timer->Stop();
// Process the handshake just once (ignore if DTLS renegotiation).
if (!wasHandshakeDone)
ProcessHandshake();
if (!wasHandshakeDone && this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE)
return ProcessHandshake();
else
return true;
}
// Check if the peer sent close alert or a fatal error happened.
else if (((SSL_get_shutdown(this->ssl) & SSL_RECEIVED_SHUTDOWN) != 0) || err == SSL_ERROR_SSL || err == SSL_ERROR_SYSCALL)
......@@ -888,8 +890,10 @@ namespace RTC
return false;
}
return true;
else
{
return true;
}
}
inline void DtlsTransport::SendPendingOutgoingDtlsData()
......@@ -921,6 +925,10 @@ namespace RTC
{
MS_TRACE();
MS_ASSERT(
this->state == DtlsState::CONNECTING || this->state == DtlsState::CONNECTED,
"invalid DTLS state");
int64_t ret;
struct timeval dtlsTimeout;
uint64_t timeoutMs;
......@@ -957,20 +965,13 @@ namespace RTC
return false;
}
inline void DtlsTransport::ProcessHandshake()
inline bool DtlsTransport::ProcessHandshake()
{
MS_TRACE();
MS_ASSERT(this->handshakeDone, "handshake not done yet");
// If the remote fingerprint is not yet set then do nothing (this method
// will be called when the fingerprint is set).
if (this->remoteFingerprint.algorithm == FingerprintAlgorithm::NONE)
{
MS_DEBUG_TAG(dtls, "remote fingerprint not yet set, waiting for it");
return;
}
MS_ASSERT(
this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE, "remote fingerprint not set");
// Validate the remote fingerprint.
if (!CheckRemoteFingerprint())
......@@ -981,7 +982,7 @@ namespace RTC
this->state = DtlsState::FAILED;
this->listener->OnDtlsFailed(this);
return;
return false;
}
// Get the negotiated SRTP profile.
......@@ -992,6 +993,8 @@ namespace RTC
{
// Extract the SRTP keys (will notify the listener with them).
ExtractSrtpKeys(srtpProfile);
return true;
}
else
{
......@@ -1004,6 +1007,8 @@ namespace RTC
// Set state and notify the listener.
this->state = DtlsState::FAILED;
this->listener->OnDtlsFailed(this);
return false;
}
}
......@@ -1051,6 +1056,7 @@ namespace RTC
}
// Compare the remote fingerprint with the value given via signaling.
ret = X509_digest(certificate, hashFunction, binaryFingerprint, &size);
if (ret == 0)
{
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论