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