From 34817a83d536aea0a303bdf61044e6d74704d11d Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 27 Jan 2020 15:26:56 +0100 Subject: [PATCH] [AFV] Guard against "missing" crypto channel (=> ASSERT) --- .../afv/connection/clientconnection.cpp | 16 +++++++++++++++- src/blackcore/afv/connection/clientconnection.h | 6 ++++++ .../afv/connection/clientconnectiondata.cpp | 1 - 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/blackcore/afv/connection/clientconnection.cpp b/src/blackcore/afv/connection/clientconnection.cpp index 0e9af63b2..e12e910b1 100644 --- a/src/blackcore/afv/connection/clientconnection.cpp +++ b/src/blackcore/afv/connection/clientconnection.cpp @@ -58,7 +58,6 @@ namespace BlackCore { // callback when connection has been established if (!myself) { return; } - m_connection.setConnected(authenticated); if (authenticated) { @@ -72,6 +71,9 @@ namespace BlackCore CLogMessage(this).info(u"Connected: '%1' to voice server, socket open: %2") << callsign << boolToYesNo(m_udpSocket->isOpen()); } + // Make sure crypto channels etc. are created + m_connection.setConnected(authenticated); + // callback of the calling parent if (callback) { callback(authenticated); } } @@ -146,6 +148,12 @@ namespace BlackCore void CClientConnection::processMessage(const QByteArray &messageDdata, bool loopback) { + if (!m_connection.m_voiceCryptoChannel) + { + BLACK_VERIFY_X(false, Q_FUNC_INFO, "processMessage used without crypto channel"); + return; + } + CryptoDtoSerializer::Deserializer deserializer = CryptoDtoSerializer::deserialize(*m_connection.m_voiceCryptoChannel, messageDdata, loopback); if (deserializer.dtoNameBuffer == AudioRxOnTransceiversDto::getShortDtoName()) @@ -176,6 +184,12 @@ namespace BlackCore void CClientConnection::voiceServerHeartbeat() { + if (!m_connection.m_voiceCryptoChannel || !m_udpSocket) + { + BLACK_VERIFY_X(false, Q_FUNC_INFO, "voiceServerHeartbeat used without crypto channel or socket"); + return; + } + const QUrl voiceServerUrl("udp://" + m_connection.getTokens().VoiceServer.addressIpV4); if (CBuildConfig::isLocalDeveloperDebugBuild()) { CLogMessage(this).debug(u"Sending voice server heartbeat to '%1'") << voiceServerUrl.host(); } HeartbeatDto keepAlive; diff --git a/src/blackcore/afv/connection/clientconnection.h b/src/blackcore/afv/connection/clientconnection.h index ad4a38702..6f715efa6 100644 --- a/src/blackcore/afv/connection/clientconnection.h +++ b/src/blackcore/afv/connection/clientconnection.h @@ -15,6 +15,7 @@ #include "blackcore/afv/connection/clientconnectiondata.h" #include "blackcore/afv/connection/apiserverconnection.h" #include "blackcore/afv/dto.h" +#include "blackmisc/verify.h" #include #include @@ -69,6 +70,11 @@ namespace BlackCore template void sendToVoiceServer(const T &dto) { + if (!m_connection.m_voiceCryptoChannel || !m_udpSocket) + { + BLACK_VERIFY_X(false, Q_FUNC_INFO, "sendVoice used without crypto channel or socket"); + return; + } const QUrl voiceServerUrl("udp://" + m_connection.getTokens().VoiceServer.addressIpV4); const QByteArray dataBytes = Crypto::CryptoDtoSerializer::serialize(*m_connection.m_voiceCryptoChannel, Crypto::CryptoDtoMode::AEAD_ChaCha20Poly1305, dto); m_udpSocket->writeDatagram(dataBytes, QHostAddress(voiceServerUrl.host()), static_cast(voiceServerUrl.port())); diff --git a/src/blackcore/afv/connection/clientconnectiondata.cpp b/src/blackcore/afv/connection/clientconnectiondata.cpp index 03ed4710e..73ac8e5d1 100644 --- a/src/blackcore/afv/connection/clientconnectiondata.cpp +++ b/src/blackcore/afv/connection/clientconnectiondata.cpp @@ -43,7 +43,6 @@ namespace BlackCore return; } m_voiceCryptoChannel.reset(new CCryptoDtoChannel(m_tokens.VoiceServer.channelConfig)); - // dataCryptoChannel.reset(new CryptoDtoChannel(m_tokens.DataServer.channelConfig)); } void CClientConnectionData::setTsAuthenticatedToNow()