Skip to content

Commit f158aea

Browse files
authored
Fix selection of protection cipher in srtp set up (#1492)
* Fix the srtp protection profile selection logic. * Updated entry point of webrtccmdline docker image.
1 parent 43b3130 commit f158aea

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

Dockerfile-webrtccmdline

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
# To run a local container:
1111
# docker run -it --rm -p 8081:8081 -p 60042:60042/udp webrtccmdline --ws --stun stun:stun.l.google.com:19302
1212

13-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
13+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
1414
WORKDIR /src
1515
COPY . .
1616
WORKDIR /src/examples/webrtccmdline
1717
RUN dotnet publish "webrtccmdline.csproj" -c Release -o /app/publish
1818

19-
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS final
19+
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS final
2020
WORKDIR /app
2121
EXPOSE 8080-8081
2222
EXPOSE 60042
2323
COPY --from=build /app/publish .
24-
ENTRYPOINT ["dotnet", "webrtccmdline.dll", "--port", "60042", "--ws", "--stun", "stun:stun.l.google.com:19302"]
24+
#ENTRYPOINT ["dotnet", "webrtccmdline.dll", "--port", "60042", "--ws", "--stun", "stun:stun.l.google.com:19302"]
25+
ENTRYPOINT ["dotnet", "webrtccmdline.dll"]

src/net/DtlsSrtp/DtlsSrtpClient.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System;
1717
using System.Collections;
1818
using System.Collections.Generic;
19+
using System.Linq;
1920
using Microsoft.Extensions.Logging;
2021
using Org.BouncyCastle.Crypto;
2122
using Org.BouncyCastle.Security;
@@ -193,16 +194,20 @@ public override void ProcessServerExtensions(IDictionary<int, byte[]> serverExte
193194
int chosenProfile = SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80;
194195
clientSrtpData = TlsSrtpUtilities.GetUseSrtpExtension(serverExtensions);
195196

196-
foreach (int profile in clientSrtpData.ProtectionProfiles)
197+
if (clientSrtpData?.ProtectionProfiles == null)
197198
{
198-
switch (profile)
199+
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
200+
}
201+
202+
if (!clientSrtpData.ProtectionProfiles.Contains(SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80))
203+
{
204+
if (clientSrtpData.ProtectionProfiles.Contains(SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32))
205+
{
206+
chosenProfile = SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32;
207+
}
208+
else
199209
{
200-
case SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32:
201-
case SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80:
202-
case SrtpProtectionProfile.SRTP_NULL_HMAC_SHA1_32:
203-
case SrtpProtectionProfile.SRTP_NULL_HMAC_SHA1_80:
204-
chosenProfile = profile;
205-
break;
210+
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
206211
}
207212
}
208213

src/net/DtlsSrtp/DtlsSrtpServer.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,20 @@ public override void ProcessClientExtensions(IDictionary<int, byte[]> clientExte
361361
int chosenProfile = SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80;
362362
UseSrtpData clientSrtpData = TlsSrtpUtilities.GetUseSrtpExtension(clientExtensions);
363363

364-
foreach (int profile in clientSrtpData.ProtectionProfiles)
364+
if (clientSrtpData?.ProtectionProfiles == null)
365365
{
366-
switch (profile)
366+
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
367+
}
368+
369+
if (!clientSrtpData.ProtectionProfiles.Contains(SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80))
370+
{
371+
if (clientSrtpData.ProtectionProfiles.Contains(SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32))
372+
{
373+
chosenProfile = SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32;
374+
}
375+
else
367376
{
368-
case SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32:
369-
case SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80:
370-
case SrtpProtectionProfile.SRTP_NULL_HMAC_SHA1_32:
371-
case SrtpProtectionProfile.SRTP_NULL_HMAC_SHA1_80:
372-
chosenProfile = profile;
373-
break;
377+
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
374378
}
375379
}
376380

src/net/DtlsSrtp/SrtpParameters.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ public struct SrtpParameters
3232
// hrosa - converted lengths to work with bytes, not bits (1 byte = 8 bits)
3333
public static readonly SrtpParameters SRTP_AES128_CM_HMAC_SHA1_80 = new SrtpParameters(SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80, SrtpPolicy.AESCM_ENCRYPTION, 16, SrtpPolicy.HMACSHA1_AUTHENTICATION, 20, 10, 10, 14);
3434
public static readonly SrtpParameters SRTP_AES128_CM_HMAC_SHA1_32 = new SrtpParameters(SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32, SrtpPolicy.AESCM_ENCRYPTION, 16, SrtpPolicy.HMACSHA1_AUTHENTICATION, 20, 4, 10, 14);
35-
public static readonly SrtpParameters SRTP_NULL_HMAC_SHA1_80 = new SrtpParameters(SrtpProtectionProfile.SRTP_NULL_HMAC_SHA1_80, SrtpPolicy.NULL_ENCRYPTION, 0, SrtpPolicy.HMACSHA1_AUTHENTICATION, 20, 10, 10, 0);
36-
public static readonly SrtpParameters SRTP_NULL_HMAC_SHA1_32 = new SrtpParameters(SrtpProtectionProfile.SRTP_NULL_HMAC_SHA1_32, SrtpPolicy.NULL_ENCRYPTION, 0, SrtpPolicy.HMACSHA1_AUTHENTICATION, 20, 4, 10, 0);
37-
3835

3936
private int profile;
4037
private int encType;
@@ -80,10 +77,6 @@ public static SrtpParameters GetSrtpParametersForProfile(int profileValue)
8077
return SRTP_AES128_CM_HMAC_SHA1_80;
8178
case SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32:
8279
return SRTP_AES128_CM_HMAC_SHA1_32;
83-
case SrtpProtectionProfile.SRTP_NULL_HMAC_SHA1_80:
84-
return SRTP_NULL_HMAC_SHA1_80;
85-
case SrtpProtectionProfile.SRTP_NULL_HMAC_SHA1_32:
86-
return SRTP_NULL_HMAC_SHA1_32;
8780
default:
8881
throw new Exception($"SRTP Protection Profile value {profileValue} is not allowed for DTLS SRTP. See http://tools.ietf.org/html/rfc5764#section-4.1.2 for valid values.");
8982
}

0 commit comments

Comments
 (0)