From 8c6f75dc236b5a628d1a0773a6390cc11870c000 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Mon, 1 Jun 2026 15:22:28 +0100 Subject: [PATCH 1/2] Refactor WebRTC exception messages and fingerprint comparison Consolidate exception message formatting to single lines for clarity. Update certificate fingerprint comparison to use string.Equals with ordinal ignore case, following best practices and user preferences. --- src/SIPSorcery/net/WebRTC/RTCDataChannel.cs | 6 ++---- src/SIPSorcery/net/WebRTC/RTCPeerConnection.cs | 5 +++-- src/SIPSorcery/net/WebRTC/RTCSctpTransport.cs | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/SIPSorcery/net/WebRTC/RTCDataChannel.cs b/src/SIPSorcery/net/WebRTC/RTCDataChannel.cs index 8a0d0b570..c4b44b429 100644 --- a/src/SIPSorcery/net/WebRTC/RTCDataChannel.cs +++ b/src/SIPSorcery/net/WebRTC/RTCDataChannel.cs @@ -134,8 +134,7 @@ public void send(string message) { if (message != null && Encoding.UTF8.GetByteCount(message) > _transport.maxMessageSize) { - throw new ApplicationException($"Data channel {label} was requested to send data of length {Encoding.UTF8.GetByteCount(message)} " + - $" that exceeded the maximum allowed message size of {_transport.maxMessageSize}."); + throw new ApplicationException($"Data channel {label} was requested to send data of length {Encoding.UTF8.GetByteCount(message)} that exceeded the maximum allowed message size of {_transport.maxMessageSize}."); } else if (_transport.state != RTCSctpTransportState.Connected) { @@ -173,8 +172,7 @@ public void send(byte[] data, int offset = 0, int count = -1) if (effectiveCount > _transport.maxMessageSize) { - throw new ApplicationException($"Data channel {label} was requested to send data of length {effectiveCount} " + - $" that exceeded the maximum allowed message size of {_transport.maxMessageSize}."); + throw new ApplicationException($"Data channel {label} was requested to send data of length {effectiveCount} that exceeded the maximum allowed message size of {_transport.maxMessageSize}."); } else if (_transport.state != RTCSctpTransportState.Connected) { diff --git a/src/SIPSorcery/net/WebRTC/RTCPeerConnection.cs b/src/SIPSorcery/net/WebRTC/RTCPeerConnection.cs index 4c2b39b72..80866db1c 100644 --- a/src/SIPSorcery/net/WebRTC/RTCPeerConnection.cs +++ b/src/SIPSorcery/net/WebRTC/RTCPeerConnection.cs @@ -1876,12 +1876,13 @@ private bool DoDtlsHandshake(DtlsSrtpTransport dtlsHandle) } else { - logger.LogDebug($"RTCPeerConnection DTLS handshake result {handshakeResult}, is handshake complete {dtlsHandle.IsHandshakeComplete()}."); + logger.LogDebug("RTCPeerConnection DTLS handshake result {HandshakeResult}, is handshake complete {IsHandshakeComplete}.", + handshakeResult, dtlsHandle.IsHandshakeComplete()); var expectedFp = RemotePeerDtlsFingerprint; var remoteFingerprint = DtlsUtils.Fingerprint(expectedFp.algorithm, dtlsHandle.GetRemoteCertificate().GetCertificateAt(0)); - if (remoteFingerprint.value?.ToUpper() != expectedFp.value?.ToUpper()) + if (!string.Equals(remoteFingerprint.value, expectedFp.value, StringComparison.OrdinalIgnoreCase)) { logger.LogWarning("RTCPeerConnection remote certificate fingerprint mismatch, expected {ExpectedFingerprint}, actual {RemoteFingerprint}.", expectedFp, remoteFingerprint); Close("dtls fingerprint mismatch"); diff --git a/src/SIPSorcery/net/WebRTC/RTCSctpTransport.cs b/src/SIPSorcery/net/WebRTC/RTCSctpTransport.cs index e8088412a..91739fcbe 100644 --- a/src/SIPSorcery/net/WebRTC/RTCSctpTransport.cs +++ b/src/SIPSorcery/net/WebRTC/RTCSctpTransport.cs @@ -380,8 +380,7 @@ public override void Send(string associationID, byte[] buffer, int offset, int l { if (length > maxMessageSize) { - throw new ApplicationException($"RTCSctpTransport was requested to send data of length {length} " + - $" that exceeded the maximum allowed message size of {maxMessageSize}."); + throw new ApplicationException($"RTCSctpTransport was requested to send data of length {length} that exceeded the maximum allowed message size of {maxMessageSize}."); } if (!_isClosed) From aa89c104d43990f176e42d71c0e36f73492750ff Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Mon, 1 Jun 2026 16:28:41 +0100 Subject: [PATCH 2/2] Fix extra spaces in RTCDataChannel exception messages Removed unnecessary double spaces in exception strings to improve consistency and readability in RTCDataChannel.cs. --- src/SIPSorcery/net/WebRTC/RTCDataChannel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SIPSorcery/net/WebRTC/RTCDataChannel.cs b/src/SIPSorcery/net/WebRTC/RTCDataChannel.cs index c4b44b429..261373d1d 100644 --- a/src/SIPSorcery/net/WebRTC/RTCDataChannel.cs +++ b/src/SIPSorcery/net/WebRTC/RTCDataChannel.cs @@ -134,7 +134,7 @@ public void send(string message) { if (message != null && Encoding.UTF8.GetByteCount(message) > _transport.maxMessageSize) { - throw new ApplicationException($"Data channel {label} was requested to send data of length {Encoding.UTF8.GetByteCount(message)} that exceeded the maximum allowed message size of {_transport.maxMessageSize}."); + throw new ApplicationException($"Data channel {label} was requested to send data of length {Encoding.UTF8.GetByteCount(message)} that exceeded the maximum allowed message size of {_transport.maxMessageSize}."); } else if (_transport.state != RTCSctpTransportState.Connected) { @@ -172,7 +172,7 @@ public void send(byte[] data, int offset = 0, int count = -1) if (effectiveCount > _transport.maxMessageSize) { - throw new ApplicationException($"Data channel {label} was requested to send data of length {effectiveCount} that exceeded the maximum allowed message size of {_transport.maxMessageSize}."); + throw new ApplicationException($"Data channel {label} was requested to send data of length {effectiveCount} that exceeded the maximum allowed message size of {_transport.maxMessageSize}."); } else if (_transport.state != RTCSctpTransportState.Connected) {